Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/utilities/decoder.cpp
32285 views
/*1* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#include "precompiled.hpp"25#include "prims/jvm.h"26#include "runtime/os.hpp"27#include "utilities/decoder.hpp"28#include "utilities/vmError.hpp"2930#if defined(_WINDOWS)31#include "decoder_windows.hpp"32#elif defined(__APPLE__)33#include "decoder_machO.hpp"34#elif defined(AIX)35#include "decoder_aix.hpp"36#else37#include "decoder_elf.hpp"38#endif3940AbstractDecoder* Decoder::_shared_decoder = NULL;41AbstractDecoder* Decoder::_error_handler_decoder = NULL;42NullDecoder Decoder::_do_nothing_decoder;43Mutex* Decoder::_shared_decoder_lock = new Mutex(Mutex::native,44"SharedDecoderLock");4546AbstractDecoder* Decoder::get_shared_instance() {47assert(_shared_decoder_lock != NULL && _shared_decoder_lock->owned_by_self(),48"Require DecoderLock to enter");4950if (_shared_decoder == NULL) {51_shared_decoder = create_decoder();52}53return _shared_decoder;54}5556AbstractDecoder* Decoder::get_error_handler_instance() {57if (_error_handler_decoder == NULL) {58_error_handler_decoder = create_decoder();59}60return _error_handler_decoder;61}626364AbstractDecoder* Decoder::create_decoder() {65AbstractDecoder* decoder;66#if defined(_WINDOWS)67decoder = new (std::nothrow) WindowsDecoder();68#elif defined (__APPLE__)69decoder = new (std::nothrow)MachODecoder();70#elif defined(AIX)71decoder = new (std::nothrow)AIXDecoder();72#else73decoder = new (std::nothrow)ElfDecoder();74#endif7576if (decoder == NULL || decoder->has_error()) {77if (decoder != NULL) {78delete decoder;79}80decoder = &_do_nothing_decoder;81}82return decoder;83}8485inline bool DecoderLocker::is_first_error_thread() {86return (os::current_thread_id() == VMError::get_first_error_tid());87}8889DecoderLocker::DecoderLocker() :90MutexLockerEx(DecoderLocker::is_first_error_thread() ?91NULL : Decoder::shared_decoder_lock(), true) {92_decoder = is_first_error_thread() ?93Decoder::get_error_handler_instance() : Decoder::get_shared_instance();94assert(_decoder != NULL, "null decoder");95}9697Mutex* Decoder::shared_decoder_lock() {98assert(_shared_decoder_lock != NULL, "Just check");99return _shared_decoder_lock;100}101102bool Decoder::decode(address addr, char* buf, int buflen, int* offset, const char* modulepath) {103assert(_shared_decoder_lock != NULL, "Just check");104bool error_handling_thread = os::current_thread_id() == VMError::first_error_tid;105MutexLockerEx locker(error_handling_thread ? NULL : _shared_decoder_lock, true);106AbstractDecoder* decoder = error_handling_thread ?107get_error_handler_instance(): get_shared_instance();108assert(decoder != NULL, "null decoder");109110return decoder->decode(addr, buf, buflen, offset, modulepath);111}112113bool Decoder::decode(address addr, char* buf, int buflen, int* offset, const void* base) {114assert(_shared_decoder_lock != NULL, "Just check");115bool error_handling_thread = os::current_thread_id() == VMError::first_error_tid;116MutexLockerEx locker(error_handling_thread ? NULL : _shared_decoder_lock, true);117AbstractDecoder* decoder = error_handling_thread ?118get_error_handler_instance(): get_shared_instance();119assert(decoder != NULL, "null decoder");120121return decoder->decode(addr, buf, buflen, offset, base);122}123124125bool Decoder::demangle(const char* symbol, char* buf, int buflen) {126assert(_shared_decoder_lock != NULL, "Just check");127bool error_handling_thread = os::current_thread_id() == VMError::first_error_tid;128MutexLockerEx locker(error_handling_thread ? NULL : _shared_decoder_lock, true);129AbstractDecoder* decoder = error_handling_thread ?130get_error_handler_instance(): get_shared_instance();131assert(decoder != NULL, "null decoder");132return decoder->demangle(symbol, buf, buflen);133}134135bool Decoder::can_decode_C_frame_in_vm() {136assert(_shared_decoder_lock != NULL, "Just check");137bool error_handling_thread = os::current_thread_id() == VMError::first_error_tid;138MutexLockerEx locker(error_handling_thread ? NULL : _shared_decoder_lock, true);139AbstractDecoder* decoder = error_handling_thread ?140get_error_handler_instance(): get_shared_instance();141assert(decoder != NULL, "null decoder");142return decoder->can_decode_C_frame_in_vm();143}144145/*146* Shutdown shared decoder and replace it with147* _do_nothing_decoder. Do nothing with error handler148* instance, since the JVM is going down.149*/150void Decoder::shutdown() {151assert(_shared_decoder_lock != NULL, "Just check");152MutexLockerEx locker(_shared_decoder_lock, true);153154if (_shared_decoder != NULL &&155_shared_decoder != &_do_nothing_decoder) {156delete _shared_decoder;157}158159_shared_decoder = &_do_nothing_decoder;160}161162163164