src/share/vm/utilities/decoder.hpp

Fri, 29 Apr 2016 00:06:10 +0800

author
aoqi
date
Fri, 29 Apr 2016 00:06:10 +0800
changeset 1
2d8a650513c2
parent 0
f90c822e73f8
child 6876
710a3c8b516e
permissions
-rw-r--r--

Added MIPS 64-bit port.

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25
aoqi@0 26 #ifndef SHARE_VM_UTILITIES_DECODER_HPP
aoqi@0 27 #define SHARE_VM_UTILITIES_DECODER_HPP
aoqi@0 28
aoqi@0 29 #include "memory/allocation.hpp"
aoqi@0 30 #include "runtime/mutex.hpp"
aoqi@0 31 #include "runtime/mutexLocker.hpp"
aoqi@0 32
aoqi@0 33 class AbstractDecoder : public CHeapObj<mtInternal> {
aoqi@0 34 public:
aoqi@0 35 // status code for decoding native C frame
aoqi@0 36 enum decoder_status {
aoqi@0 37 not_available = -10, // real decoder is not available
aoqi@0 38 no_error = 0, // successfully decoded frames
aoqi@0 39 out_of_memory, // out of memory
aoqi@0 40 file_invalid, // invalid elf file
aoqi@0 41 file_not_found, // could not found symbol file (on windows), such as jvm.pdb or jvm.map
aoqi@0 42 helper_not_found, // could not load dbghelp.dll (Windows only)
aoqi@0 43 helper_func_error, // decoding functions not found (Windows only)
aoqi@0 44 helper_init_error // SymInitialize failed (Windows only)
aoqi@0 45 };
aoqi@0 46
aoqi@0 47 // decode an pc address to corresponding function name and an offset from the beginning of
aoqi@0 48 // the function
aoqi@0 49 virtual bool decode(address pc, char* buf, int buflen, int* offset,
aoqi@0 50 const char* modulepath = NULL) = 0;
aoqi@0 51 virtual bool decode(address pc, char* buf, int buflen, int* offset, const void* base) = 0;
aoqi@0 52
aoqi@0 53 // demangle a C++ symbol
aoqi@0 54 virtual bool demangle(const char* symbol, char* buf, int buflen) = 0;
aoqi@0 55 // if the decoder can decode symbols in vm
aoqi@0 56 virtual bool can_decode_C_frame_in_vm() const = 0;
aoqi@0 57
aoqi@0 58 virtual decoder_status status() const {
aoqi@0 59 return _decoder_status;
aoqi@0 60 }
aoqi@0 61
aoqi@0 62 virtual bool has_error() const {
aoqi@0 63 return is_error(_decoder_status);
aoqi@0 64 }
aoqi@0 65
aoqi@0 66 static bool is_error(decoder_status status) {
aoqi@0 67 return (status > 0);
aoqi@0 68 }
aoqi@0 69
aoqi@0 70 protected:
aoqi@0 71 decoder_status _decoder_status;
aoqi@0 72 };
aoqi@0 73
aoqi@0 74 // Do nothing decoder
aoqi@0 75 class NullDecoder : public AbstractDecoder {
aoqi@0 76 public:
aoqi@0 77 NullDecoder() {
aoqi@0 78 _decoder_status = not_available;
aoqi@0 79 }
aoqi@0 80
aoqi@0 81 ~NullDecoder() {};
aoqi@0 82
aoqi@0 83 virtual bool decode(address pc, char* buf, int buflen, int* offset,
aoqi@0 84 const char* modulepath = NULL) {
aoqi@0 85 return false;
aoqi@0 86 }
aoqi@0 87
aoqi@0 88 virtual bool decode(address pc, char* buf, int buflen, int* offset, const void* base) {
aoqi@0 89 return false;
aoqi@0 90 }
aoqi@0 91
aoqi@0 92 virtual bool demangle(const char* symbol, char* buf, int buflen) {
aoqi@0 93 return false;
aoqi@0 94 }
aoqi@0 95
aoqi@0 96 virtual bool can_decode_C_frame_in_vm() const {
aoqi@0 97 return false;
aoqi@0 98 }
aoqi@0 99 };
aoqi@0 100
aoqi@0 101
aoqi@0 102 class Decoder : AllStatic {
aoqi@0 103 public:
aoqi@0 104 static bool decode(address pc, char* buf, int buflen, int* offset, const char* modulepath = NULL);
aoqi@0 105 static bool decode(address pc, char* buf, int buflen, int* offset, const void* base);
aoqi@0 106 static bool demangle(const char* symbol, char* buf, int buflen);
aoqi@0 107 static bool can_decode_C_frame_in_vm();
aoqi@0 108
aoqi@0 109 // shutdown shared instance
aoqi@0 110 static void shutdown();
aoqi@0 111 protected:
aoqi@0 112 // shared decoder instance, _shared_instance_lock is needed
aoqi@0 113 static AbstractDecoder* get_shared_instance();
aoqi@0 114 // a private instance for error handler. Error handler can be
aoqi@0 115 // triggered almost everywhere, including signal handler, where
aoqi@0 116 // no lock can be taken. So the shared decoder can not be used
aoqi@0 117 // in this scenario.
aoqi@0 118 static AbstractDecoder* get_error_handler_instance();
aoqi@0 119
aoqi@0 120 static AbstractDecoder* create_decoder();
aoqi@0 121 private:
aoqi@0 122 static AbstractDecoder* _shared_decoder;
aoqi@0 123 static AbstractDecoder* _error_handler_decoder;
aoqi@0 124 static NullDecoder _do_nothing_decoder;
aoqi@0 125
aoqi@0 126 protected:
aoqi@0 127 static Mutex* _shared_decoder_lock;
aoqi@0 128 static Mutex* shared_decoder_lock();
aoqi@0 129
aoqi@0 130 friend class DecoderLocker;
aoqi@0 131 };
aoqi@0 132
aoqi@0 133 class DecoderLocker : public MutexLockerEx {
aoqi@0 134 AbstractDecoder* _decoder;
aoqi@0 135 inline bool is_first_error_thread();
aoqi@0 136 public:
aoqi@0 137 DecoderLocker();
aoqi@0 138 AbstractDecoder* decoder() {
aoqi@0 139 return _decoder;
aoqi@0 140 }
aoqi@0 141 };
aoqi@0 142
aoqi@0 143 #endif // SHARE_VM_UTILITIES_DECODER_HPP

mercurial