src/share/vm/utilities/decoder.hpp

Thu, 22 May 2014 15:52:41 -0400

author
drchase
date
Thu, 22 May 2014 15:52:41 -0400
changeset 6680
78bbf4d43a14
parent 6198
55fb97c4c58d
child 6876
710a3c8b516e
permissions
-rw-r--r--

8037816: Fix for 8036122 breaks build with Xcode5/clang
8043029: Change 8037816 breaks HS build with older GCC versions which don't support diagnostic pragmas
8043164: Format warning in traceStream.hpp
Summary: Backport of main fix + two corrections, enables clang compilation, turns on format attributes, corrects/mutes warnings
Reviewed-by: kvn, coleenp, iveresov, twisti

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

mercurial