decoder.cpp revision 5965:bdd155477289
1/* 2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25#include "precompiled.hpp" 26#include "prims/jvm.h" 27#include "runtime/mutexLocker.hpp" 28#include "runtime/os.hpp" 29#include "utilities/decoder.hpp" 30#include "utilities/vmError.hpp" 31 32#if defined(_WINDOWS) 33 #include "decoder_windows.hpp" 34#elif defined(__APPLE__) 35 #include "decoder_machO.hpp" 36#elif defined(AIX) 37 #include "decoder_aix.hpp" 38#else 39 #include "decoder_elf.hpp" 40#endif 41 42AbstractDecoder* Decoder::_shared_decoder = NULL; 43AbstractDecoder* Decoder::_error_handler_decoder = NULL; 44NullDecoder Decoder::_do_nothing_decoder; 45Mutex* Decoder::_shared_decoder_lock = new Mutex(Mutex::native, 46 "SharedDecoderLock"); 47 48AbstractDecoder* Decoder::get_shared_instance() { 49 assert(_shared_decoder_lock != NULL && _shared_decoder_lock->owned_by_self(), 50 "Require DecoderLock to enter"); 51 52 if (_shared_decoder == NULL) { 53 _shared_decoder = create_decoder(); 54 } 55 return _shared_decoder; 56} 57 58AbstractDecoder* Decoder::get_error_handler_instance() { 59 if (_error_handler_decoder == NULL) { 60 _error_handler_decoder = create_decoder(); 61 } 62 return _error_handler_decoder; 63} 64 65 66AbstractDecoder* Decoder::create_decoder() { 67 AbstractDecoder* decoder; 68#if defined(_WINDOWS) 69 decoder = new (std::nothrow) WindowsDecoder(); 70#elif defined (__APPLE__) 71 decoder = new (std::nothrow)MachODecoder(); 72#elif defined(AIX) 73 decoder = new (std::nothrow)AIXDecoder(); 74#else 75 decoder = new (std::nothrow)ElfDecoder(); 76#endif 77 78 if (decoder == NULL || decoder->has_error()) { 79 if (decoder != NULL) { 80 delete decoder; 81 } 82 decoder = &_do_nothing_decoder; 83 } 84 return decoder; 85} 86 87bool Decoder::decode(address addr, char* buf, int buflen, int* offset, const char* modulepath) { 88 assert(_shared_decoder_lock != NULL, "Just check"); 89 bool error_handling_thread = os::current_thread_id() == VMError::first_error_tid; 90 MutexLockerEx locker(error_handling_thread ? NULL : _shared_decoder_lock, true); 91 AbstractDecoder* decoder = error_handling_thread ? 92 get_error_handler_instance(): get_shared_instance(); 93 assert(decoder != NULL, "null decoder"); 94 95 return decoder->decode(addr, buf, buflen, offset, modulepath); 96} 97 98bool Decoder::decode(address addr, char* buf, int buflen, int* offset, const void* base) { 99 assert(_shared_decoder_lock != NULL, "Just check"); 100 bool error_handling_thread = os::current_thread_id() == VMError::first_error_tid; 101 MutexLockerEx locker(error_handling_thread ? NULL : _shared_decoder_lock, true); 102 AbstractDecoder* decoder = error_handling_thread ? 103 get_error_handler_instance(): get_shared_instance(); 104 assert(decoder != NULL, "null decoder"); 105 106 return decoder->decode(addr, buf, buflen, offset, base); 107} 108 109 110bool Decoder::demangle(const char* symbol, char* buf, int buflen) { 111 assert(_shared_decoder_lock != NULL, "Just check"); 112 bool error_handling_thread = os::current_thread_id() == VMError::first_error_tid; 113 MutexLockerEx locker(error_handling_thread ? NULL : _shared_decoder_lock, true); 114 AbstractDecoder* decoder = error_handling_thread ? 115 get_error_handler_instance(): get_shared_instance(); 116 assert(decoder != NULL, "null decoder"); 117 return decoder->demangle(symbol, buf, buflen); 118} 119 120bool Decoder::can_decode_C_frame_in_vm() { 121 assert(_shared_decoder_lock != NULL, "Just check"); 122 bool error_handling_thread = os::current_thread_id() == VMError::first_error_tid; 123 MutexLockerEx locker(error_handling_thread ? NULL : _shared_decoder_lock, true); 124 AbstractDecoder* decoder = error_handling_thread ? 125 get_error_handler_instance(): get_shared_instance(); 126 assert(decoder != NULL, "null decoder"); 127 return decoder->can_decode_C_frame_in_vm(); 128} 129 130/* 131 * Shutdown shared decoder and replace it with 132 * _do_nothing_decoder. Do nothing with error handler 133 * instance, since the JVM is going down. 134 */ 135void Decoder::shutdown() { 136 assert(_shared_decoder_lock != NULL, "Just check"); 137 MutexLockerEx locker(_shared_decoder_lock, true); 138 139 if (_shared_decoder != NULL && 140 _shared_decoder != &_do_nothing_decoder) { 141 delete _shared_decoder; 142 } 143 144 _shared_decoder = &_do_nothing_decoder; 145} 146 147