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