author | tschatzl |
Wed, 04 Nov 2015 17:36:29 +0100 | |
changeset 33759 | 8a0e9139a9c5 |
parent 31352 | a6ab7217b5cc |
child 47086 | 2b35673f6297 |
permissions | -rw-r--r-- |
7447
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
1 |
/* |
31352
a6ab7217b5cc
8079473: allow demangling to be optional in dll_address_to_function_name
bdelsart
parents:
28163
diff
changeset
|
2 |
* Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved. |
7447
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
4 |
* |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
8 |
* |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
13 |
* accompanied this code). |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
14 |
* |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
18 |
* |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
21 |
* questions. |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
22 |
* |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
23 |
*/ |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
24 |
|
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
25 |
#include "precompiled.hpp" |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
26 |
#include "prims/jvm.h" |
11761 | 27 |
#include "runtime/os.hpp" |
7447
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
28 |
#include "utilities/decoder.hpp" |
11761 | 29 |
#include "utilities/vmError.hpp" |
7447
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
30 |
|
11483 | 31 |
#if defined(_WINDOWS) |
32 |
#include "decoder_windows.hpp" |
|
33 |
#elif defined(__APPLE__) |
|
34 |
#include "decoder_machO.hpp" |
|
22827 | 35 |
#elif defined(AIX) |
36 |
#include "decoder_aix.hpp" |
|
11483 | 37 |
#else |
38 |
#include "decoder_elf.hpp" |
|
39 |
#endif |
|
7447
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
40 |
|
11761 | 41 |
AbstractDecoder* Decoder::_shared_decoder = NULL; |
42 |
AbstractDecoder* Decoder::_error_handler_decoder = NULL; |
|
43 |
NullDecoder Decoder::_do_nothing_decoder; |
|
44 |
Mutex* Decoder::_shared_decoder_lock = new Mutex(Mutex::native, |
|
28163
322d55d167be
8047290: Make Mutex::_no_safepoint_check_flag locks verify that this lock never checks for safepoint
coleenp
parents:
22872
diff
changeset
|
45 |
"SharedDecoderLock", |
322d55d167be
8047290: Make Mutex::_no_safepoint_check_flag locks verify that this lock never checks for safepoint
coleenp
parents:
22872
diff
changeset
|
46 |
false, |
322d55d167be
8047290: Make Mutex::_no_safepoint_check_flag locks verify that this lock never checks for safepoint
coleenp
parents:
22872
diff
changeset
|
47 |
Monitor::_safepoint_check_never); |
7447
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
48 |
|
11761 | 49 |
AbstractDecoder* Decoder::get_shared_instance() { |
50 |
assert(_shared_decoder_lock != NULL && _shared_decoder_lock->owned_by_self(), |
|
11483 | 51 |
"Require DecoderLock to enter"); |
7447
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
52 |
|
11761 | 53 |
if (_shared_decoder == NULL) { |
54 |
_shared_decoder = create_decoder(); |
|
7447
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
55 |
} |
11761 | 56 |
return _shared_decoder; |
57 |
} |
|
7447
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
58 |
|
11761 | 59 |
AbstractDecoder* Decoder::get_error_handler_instance() { |
60 |
if (_error_handler_decoder == NULL) { |
|
61 |
_error_handler_decoder = create_decoder(); |
|
62 |
} |
|
63 |
return _error_handler_decoder; |
|
64 |
} |
|
65 |
||
66 |
||
67 |
AbstractDecoder* Decoder::create_decoder() { |
|
68 |
AbstractDecoder* decoder; |
|
11483 | 69 |
#if defined(_WINDOWS) |
11761 | 70 |
decoder = new (std::nothrow) WindowsDecoder(); |
11483 | 71 |
#elif defined (__APPLE__) |
11761 | 72 |
decoder = new (std::nothrow)MachODecoder(); |
22827 | 73 |
#elif defined(AIX) |
74 |
decoder = new (std::nothrow)AIXDecoder(); |
|
11483 | 75 |
#else |
11761 | 76 |
decoder = new (std::nothrow)ElfDecoder(); |
11483 | 77 |
#endif |
78 |
||
11761 | 79 |
if (decoder == NULL || decoder->has_error()) { |
80 |
if (decoder != NULL) { |
|
81 |
delete decoder; |
|
7447
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
82 |
} |
11761 | 83 |
decoder = &_do_nothing_decoder; |
7447
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
84 |
} |
11761 | 85 |
return decoder; |
11483 | 86 |
} |
87 |
||
19952
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
13963
diff
changeset
|
88 |
inline bool DecoderLocker::is_first_error_thread() { |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
13963
diff
changeset
|
89 |
return (os::current_thread_id() == VMError::get_first_error_tid()); |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
13963
diff
changeset
|
90 |
} |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
13963
diff
changeset
|
91 |
|
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
13963
diff
changeset
|
92 |
DecoderLocker::DecoderLocker() : |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
13963
diff
changeset
|
93 |
MutexLockerEx(DecoderLocker::is_first_error_thread() ? |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
13963
diff
changeset
|
94 |
NULL : Decoder::shared_decoder_lock(), true) { |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
13963
diff
changeset
|
95 |
_decoder = is_first_error_thread() ? |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
13963
diff
changeset
|
96 |
Decoder::get_error_handler_instance() : Decoder::get_shared_instance(); |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
13963
diff
changeset
|
97 |
assert(_decoder != NULL, "null decoder"); |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
13963
diff
changeset
|
98 |
} |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
13963
diff
changeset
|
99 |
|
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
13963
diff
changeset
|
100 |
Mutex* Decoder::shared_decoder_lock() { |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
13963
diff
changeset
|
101 |
assert(_shared_decoder_lock != NULL, "Just check"); |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
13963
diff
changeset
|
102 |
return _shared_decoder_lock; |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
13963
diff
changeset
|
103 |
} |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
13963
diff
changeset
|
104 |
|
31352
a6ab7217b5cc
8079473: allow demangling to be optional in dll_address_to_function_name
bdelsart
parents:
28163
diff
changeset
|
105 |
bool Decoder::decode(address addr, char* buf, int buflen, int* offset, const char* modulepath, bool demangle) { |
11761 | 106 |
assert(_shared_decoder_lock != NULL, "Just check"); |
107 |
bool error_handling_thread = os::current_thread_id() == VMError::first_error_tid; |
|
108 |
MutexLockerEx locker(error_handling_thread ? NULL : _shared_decoder_lock, true); |
|
109 |
AbstractDecoder* decoder = error_handling_thread ? |
|
110 |
get_error_handler_instance(): get_shared_instance(); |
|
11483 | 111 |
assert(decoder != NULL, "null decoder"); |
112 |
||
31352
a6ab7217b5cc
8079473: allow demangling to be optional in dll_address_to_function_name
bdelsart
parents:
28163
diff
changeset
|
113 |
return decoder->decode(addr, buf, buflen, offset, modulepath, demangle); |
7447
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
114 |
} |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
115 |
|
13340 | 116 |
bool Decoder::decode(address addr, char* buf, int buflen, int* offset, const void* base) { |
117 |
assert(_shared_decoder_lock != NULL, "Just check"); |
|
118 |
bool error_handling_thread = os::current_thread_id() == VMError::first_error_tid; |
|
119 |
MutexLockerEx locker(error_handling_thread ? NULL : _shared_decoder_lock, true); |
|
120 |
AbstractDecoder* decoder = error_handling_thread ? |
|
121 |
get_error_handler_instance(): get_shared_instance(); |
|
122 |
assert(decoder != NULL, "null decoder"); |
|
123 |
||
124 |
return decoder->decode(addr, buf, buflen, offset, base); |
|
125 |
} |
|
126 |
||
127 |
||
11483 | 128 |
bool Decoder::demangle(const char* symbol, char* buf, int buflen) { |
11761 | 129 |
assert(_shared_decoder_lock != NULL, "Just check"); |
130 |
bool error_handling_thread = os::current_thread_id() == VMError::first_error_tid; |
|
131 |
MutexLockerEx locker(error_handling_thread ? NULL : _shared_decoder_lock, true); |
|
132 |
AbstractDecoder* decoder = error_handling_thread ? |
|
133 |
get_error_handler_instance(): get_shared_instance(); |
|
11483 | 134 |
assert(decoder != NULL, "null decoder"); |
135 |
return decoder->demangle(symbol, buf, buflen); |
|
136 |
} |
|
137 |
||
138 |
bool Decoder::can_decode_C_frame_in_vm() { |
|
11761 | 139 |
assert(_shared_decoder_lock != NULL, "Just check"); |
140 |
bool error_handling_thread = os::current_thread_id() == VMError::first_error_tid; |
|
141 |
MutexLockerEx locker(error_handling_thread ? NULL : _shared_decoder_lock, true); |
|
142 |
AbstractDecoder* decoder = error_handling_thread ? |
|
143 |
get_error_handler_instance(): get_shared_instance(); |
|
11483 | 144 |
assert(decoder != NULL, "null decoder"); |
145 |
return decoder->can_decode_C_frame_in_vm(); |
|
146 |
} |
|
147 |
||
11761 | 148 |
/* |
149 |
* Shutdown shared decoder and replace it with |
|
150 |
* _do_nothing_decoder. Do nothing with error handler |
|
151 |
* instance, since the JVM is going down. |
|
152 |
*/ |
|
11483 | 153 |
void Decoder::shutdown() { |
11761 | 154 |
assert(_shared_decoder_lock != NULL, "Just check"); |
155 |
MutexLockerEx locker(_shared_decoder_lock, true); |
|
11483 | 156 |
|
11761 | 157 |
if (_shared_decoder != NULL && |
158 |
_shared_decoder != &_do_nothing_decoder) { |
|
159 |
delete _shared_decoder; |
|
7447
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
160 |
} |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
161 |
|
11761 | 162 |
_shared_decoder = &_do_nothing_decoder; |
7447
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
163 |
} |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
164 |