Path: blob/master/src/hotspot/share/utilities/decoder.hpp
40950 views
/*1* Copyright (c) 1997, 2019, 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_UTILITIES_DECODER_HPP26#define SHARE_UTILITIES_DECODER_HPP2728#include "memory/allocation.hpp"29#include "runtime/mutex.hpp"30#include "runtime/mutexLocker.hpp"31#include "utilities/ostream.hpp"3233class AbstractDecoder : public CHeapObj<mtInternal> {34public:35// status code for decoding native C frame36enum decoder_status {37not_available = -10, // real decoder is not available38no_error = 0, // no error encountered39out_of_memory, // out of memory40file_invalid, // invalid elf file41file_not_found, // could not found symbol file (on windows), such as jvm.pdb or jvm.map42helper_func_error, // decoding functions not found (Windows only)43helper_init_error // SymInitialize failed (Windows only)44};4546protected:47decoder_status _decoder_status;4849public:50virtual ~AbstractDecoder() {}5152// decode an pc address to corresponding function name and an offset from the beginning of53// the function54//55// Note: the 'base' variant does not demangle names. The56// demangling that was done systematically in the 'modulepath' variant57// is now optional.58virtual bool decode(address pc, char* buf, int buflen, int* offset,59const char* modulepath = NULL, bool demangle = true) = 0;60virtual bool decode(address pc, char* buf, int buflen, int* offset, const void* base) = 0;6162// demangle a C++ symbol63virtual bool demangle(const char* symbol, char* buf, int buflen) = 0;6465virtual decoder_status status() const {66return _decoder_status;67}6869virtual bool has_error() const {70return is_error(_decoder_status);71}7273static bool is_error(decoder_status status) {74return (status > no_error);75}76};7778// Do nothing decoder79class NullDecoder : public AbstractDecoder {80public:81NullDecoder() {82_decoder_status = not_available;83}8485virtual ~NullDecoder() {};8687virtual bool decode(address pc, char* buf, int buflen, int* offset,88const char* modulepath, bool demangle) {89return false;90}9192virtual bool decode(address pc, char* buf, int buflen, int* offset, const void* base) {93return false;94}9596virtual bool demangle(const char* symbol, char* buf, int buflen) {97return false;98}99};100101class Decoder : AllStatic {102public:103static bool decode(address pc, char* buf, int buflen, int* offset, const char* modulepath = NULL, bool demangle = true);104static bool decode(address pc, char* buf, int buflen, int* offset, bool demangle) {105return decode(pc, buf, buflen, offset, (const char*) NULL, demangle);106}107static bool decode(address pc, char* buf, int buflen, int* offset, const void* base);108static bool demangle(const char* symbol, char* buf, int buflen);109110// Attempts to retrieve source file name and line number associated with a pc.111// If buf != NULL, points to a buffer of size buflen which will receive the112// file name. File name will be silently truncated if output buffer is too small.113static bool get_source_info(address pc, char* buf, size_t buflen, int* line);114115static void print_state_on(outputStream* st);116117protected:118// shared decoder instance, _shared_instance_lock is needed119static AbstractDecoder* get_shared_instance();120// a private instance for error handler. Error handler can be121// triggered almost everywhere, including signal handler, where122// no lock can be taken. So the shared decoder can not be used123// in this scenario.124static AbstractDecoder* get_error_handler_instance();125126static AbstractDecoder* create_decoder();127private:128static AbstractDecoder* _shared_decoder;129static AbstractDecoder* _error_handler_decoder;130static NullDecoder _do_nothing_decoder;131132protected:133static Mutex* shared_decoder_lock();134135friend class DecoderLocker;136};137138#endif // SHARE_UTILITIES_DECODER_HPP139140141