Path: blob/master/src/hotspot/share/utilities/decoder.cpp
40949 views
/*1* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.2* Copyright (c) 2017, 2020 SAP SE. 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 it6* under the terms of the GNU General Public License version 2 only, as7* published by the Free Software Foundation.8*9* This code is distributed in the hope that it will be useful, but WITHOUT10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License12* version 2 for more details (a copy is included in the LICENSE file that13* accompanied this code).14*15* You should have received a copy of the GNU General Public License version16* 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 USA20* or visit www.oracle.com if you need additional information or have any21* questions.22*23*/2425#include "precompiled.hpp"26#include "jvm.h"27#include "memory/allocation.inline.hpp"28#include "utilities/decoder.hpp"29#include "utilities/vmError.hpp"3031#ifndef _WINDOWS32#if 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;4344AbstractDecoder* Decoder::get_shared_instance() {45assert(shared_decoder_lock()->owned_by_self(), "Require DecoderLock to enter");4647if (_shared_decoder == NULL) {48_shared_decoder = create_decoder();49}50return _shared_decoder;51}5253AbstractDecoder* Decoder::get_error_handler_instance() {54if (_error_handler_decoder == NULL) {55_error_handler_decoder = create_decoder();56}57return _error_handler_decoder;58}596061AbstractDecoder* Decoder::create_decoder() {62AbstractDecoder* decoder;63#if defined (__APPLE__)64decoder = new (std::nothrow)MachODecoder();65#elif defined(AIX)66decoder = new (std::nothrow)AIXDecoder();67#else68decoder = new (std::nothrow)ElfDecoder();69#endif7071if (decoder == NULL || decoder->has_error()) {72if (decoder != NULL) {73delete decoder;74}75decoder = &_do_nothing_decoder;76}77return decoder;78}7980Mutex* Decoder::shared_decoder_lock() {81assert(SharedDecoder_lock != NULL, "Just check");82return SharedDecoder_lock;83}8485bool Decoder::decode(address addr, char* buf, int buflen, int* offset, const char* modulepath, bool demangle) {86if (VMError::is_error_reported_in_current_thread()) {87return get_error_handler_instance()->decode(addr, buf, buflen, offset, modulepath, demangle);88} else {89MutexLocker locker(shared_decoder_lock(), Mutex::_no_safepoint_check_flag);90return get_shared_instance()->decode(addr, buf, buflen, offset, modulepath, demangle);91}92}9394bool Decoder::decode(address addr, char* buf, int buflen, int* offset, const void* base) {95if (VMError::is_error_reported_in_current_thread()) {96return get_error_handler_instance()->decode(addr, buf, buflen, offset, base);97} else {98MutexLocker locker(shared_decoder_lock(), Mutex::_no_safepoint_check_flag);99return get_shared_instance()->decode(addr, buf, buflen, offset, base);100}101}102103bool Decoder::demangle(const char* symbol, char* buf, int buflen) {104if (VMError::is_error_reported_in_current_thread()) {105return get_error_handler_instance()->demangle(symbol, buf, buflen);106} else {107MutexLocker locker(shared_decoder_lock(), Mutex::_no_safepoint_check_flag);108return get_shared_instance()->demangle(symbol, buf, buflen);109}110}111112void Decoder::print_state_on(outputStream* st) {113}114115bool Decoder::get_source_info(address pc, char* buf, size_t buflen, int* line) {116return false;117}118119#endif // !_WINDOWS120121122123