Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/utilities/decoder.hpp
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*/232425#ifndef SHARE_VM_UTILITIES_DECODER_HPP26#define SHARE_VM_UTILITIES_DECODER_HPP2728#include "memory/allocation.hpp"29#include "runtime/mutex.hpp"30#include "runtime/mutexLocker.hpp"3132class AbstractDecoder : public CHeapObj<mtInternal> {33public:34// status code for decoding native C frame35enum decoder_status {36not_available = -10, // real decoder is not available37no_error = 0, // successfully decoded frames38out_of_memory, // out of memory39file_invalid, // invalid elf file40file_not_found, // could not found symbol file (on windows), such as jvm.pdb or jvm.map41helper_not_found, // could not load dbghelp.dll (Windows only)42helper_func_error, // decoding functions not found (Windows only)43helper_init_error // SymInitialize failed (Windows only)44};4546// decode an pc address to corresponding function name and an offset from the beginning of47// the function48virtual bool decode(address pc, char* buf, int buflen, int* offset,49const char* modulepath = NULL) = 0;50virtual bool decode(address pc, char* buf, int buflen, int* offset, const void* base) = 0;5152// demangle a C++ symbol53virtual bool demangle(const char* symbol, char* buf, int buflen) = 0;54// if the decoder can decode symbols in vm55virtual bool can_decode_C_frame_in_vm() const = 0;5657virtual decoder_status status() const {58return _decoder_status;59}6061virtual bool has_error() const {62return is_error(_decoder_status);63}6465static bool is_error(decoder_status status) {66return (status > 0);67}6869protected:70decoder_status _decoder_status;71};7273// Do nothing decoder74class NullDecoder : public AbstractDecoder {75public:76NullDecoder() {77_decoder_status = not_available;78}7980~NullDecoder() {};8182virtual bool decode(address pc, char* buf, int buflen, int* offset,83const char* modulepath = NULL) {84return false;85}8687virtual bool decode(address pc, char* buf, int buflen, int* offset, const void* base) {88return false;89}9091virtual bool demangle(const char* symbol, char* buf, int buflen) {92return false;93}9495virtual bool can_decode_C_frame_in_vm() const {96return false;97}98};99100101class Decoder : AllStatic {102public:103static bool decode(address pc, char* buf, int buflen, int* offset, const char* modulepath = NULL);104static bool decode(address pc, char* buf, int buflen, int* offset, const void* base);105static bool demangle(const char* symbol, char* buf, int buflen);106static bool can_decode_C_frame_in_vm();107108// shutdown shared instance109static void shutdown();110protected:111// shared decoder instance, _shared_instance_lock is needed112static AbstractDecoder* get_shared_instance();113// a private instance for error handler. Error handler can be114// triggered almost everywhere, including signal handler, where115// no lock can be taken. So the shared decoder can not be used116// in this scenario.117static AbstractDecoder* get_error_handler_instance();118119static AbstractDecoder* create_decoder();120private:121static AbstractDecoder* _shared_decoder;122static AbstractDecoder* _error_handler_decoder;123static NullDecoder _do_nothing_decoder;124125protected:126static Mutex* _shared_decoder_lock;127static Mutex* shared_decoder_lock();128129friend class DecoderLocker;130};131132class DecoderLocker : public MutexLockerEx {133AbstractDecoder* _decoder;134inline bool is_first_error_thread();135public:136DecoderLocker();137AbstractDecoder* decoder() {138return _decoder;139}140};141142#endif // SHARE_VM_UTILITIES_DECODER_HPP143144145