author | coleenp |
Tue, 31 Oct 2017 11:55:09 -0400 | |
changeset 47765 | b7c7428eaab9 |
parent 47666 | 19219ec3f176 |
child 48157 | 7c4d43c26352 |
permissions | -rw-r--r-- |
7447
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
1 |
/* |
47086
2b35673f6297
8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
31352
diff
changeset
|
2 |
* Copyright (c) 1997, 2017, 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" |
47765
b7c7428eaab9
8189610: Reconcile jvm.h and all jvm_md.h between java.base and hotspot
coleenp
parents:
47666
diff
changeset
|
26 |
#include "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 |
|
47666 | 31 |
#ifndef _WINDOWS |
32 |
#if defined(__APPLE__) |
|
11483 | 33 |
#include "decoder_machO.hpp" |
22827 | 34 |
#elif defined(AIX) |
35 |
#include "decoder_aix.hpp" |
|
11483 | 36 |
#else |
37 |
#include "decoder_elf.hpp" |
|
38 |
#endif |
|
7447
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
39 |
|
11761 | 40 |
AbstractDecoder* Decoder::_shared_decoder = NULL; |
41 |
AbstractDecoder* Decoder::_error_handler_decoder = NULL; |
|
42 |
NullDecoder Decoder::_do_nothing_decoder; |
|
43 |
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
|
44 |
"SharedDecoderLock", |
322d55d167be
8047290: Make Mutex::_no_safepoint_check_flag locks verify that this lock never checks for safepoint
coleenp
parents:
22872
diff
changeset
|
45 |
false, |
322d55d167be
8047290: Make Mutex::_no_safepoint_check_flag locks verify that this lock never checks for safepoint
coleenp
parents:
22872
diff
changeset
|
46 |
Monitor::_safepoint_check_never); |
7447
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
47 |
|
11761 | 48 |
AbstractDecoder* Decoder::get_shared_instance() { |
49 |
assert(_shared_decoder_lock != NULL && _shared_decoder_lock->owned_by_self(), |
|
11483 | 50 |
"Require DecoderLock to enter"); |
7447
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
51 |
|
11761 | 52 |
if (_shared_decoder == NULL) { |
53 |
_shared_decoder = create_decoder(); |
|
7447
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
54 |
} |
11761 | 55 |
return _shared_decoder; |
56 |
} |
|
7447
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
57 |
|
11761 | 58 |
AbstractDecoder* Decoder::get_error_handler_instance() { |
59 |
if (_error_handler_decoder == NULL) { |
|
60 |
_error_handler_decoder = create_decoder(); |
|
61 |
} |
|
62 |
return _error_handler_decoder; |
|
63 |
} |
|
64 |
||
65 |
||
66 |
AbstractDecoder* Decoder::create_decoder() { |
|
67 |
AbstractDecoder* decoder; |
|
47666 | 68 |
#if defined (__APPLE__) |
11761 | 69 |
decoder = new (std::nothrow)MachODecoder(); |
22827 | 70 |
#elif defined(AIX) |
71 |
decoder = new (std::nothrow)AIXDecoder(); |
|
11483 | 72 |
#else |
11761 | 73 |
decoder = new (std::nothrow)ElfDecoder(); |
11483 | 74 |
#endif |
75 |
||
11761 | 76 |
if (decoder == NULL || decoder->has_error()) { |
77 |
if (decoder != NULL) { |
|
78 |
delete decoder; |
|
7447
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
79 |
} |
11761 | 80 |
decoder = &_do_nothing_decoder; |
7447
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
81 |
} |
11761 | 82 |
return decoder; |
11483 | 83 |
} |
84 |
||
19952
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
13963
diff
changeset
|
85 |
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
|
86 |
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
|
87 |
} |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
13963
diff
changeset
|
88 |
|
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
13963
diff
changeset
|
89 |
DecoderLocker::DecoderLocker() : |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
13963
diff
changeset
|
90 |
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
|
91 |
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
|
92 |
_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
|
93 |
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
|
94 |
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
|
95 |
} |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
13963
diff
changeset
|
96 |
|
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
13963
diff
changeset
|
97 |
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
|
98 |
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
|
99 |
return _shared_decoder_lock; |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
13963
diff
changeset
|
100 |
} |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
13963
diff
changeset
|
101 |
|
31352
a6ab7217b5cc
8079473: allow demangling to be optional in dll_address_to_function_name
bdelsart
parents:
28163
diff
changeset
|
102 |
bool Decoder::decode(address addr, char* buf, int buflen, int* offset, const char* modulepath, bool demangle) { |
11761 | 103 |
assert(_shared_decoder_lock != NULL, "Just check"); |
104 |
bool error_handling_thread = os::current_thread_id() == VMError::first_error_tid; |
|
105 |
MutexLockerEx locker(error_handling_thread ? NULL : _shared_decoder_lock, true); |
|
106 |
AbstractDecoder* decoder = error_handling_thread ? |
|
107 |
get_error_handler_instance(): get_shared_instance(); |
|
11483 | 108 |
assert(decoder != NULL, "null decoder"); |
109 |
||
31352
a6ab7217b5cc
8079473: allow demangling to be optional in dll_address_to_function_name
bdelsart
parents:
28163
diff
changeset
|
110 |
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
|
111 |
} |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
112 |
|
13340 | 113 |
bool Decoder::decode(address addr, char* buf, int buflen, int* offset, const void* base) { |
114 |
assert(_shared_decoder_lock != NULL, "Just check"); |
|
115 |
bool error_handling_thread = os::current_thread_id() == VMError::first_error_tid; |
|
116 |
MutexLockerEx locker(error_handling_thread ? NULL : _shared_decoder_lock, true); |
|
117 |
AbstractDecoder* decoder = error_handling_thread ? |
|
118 |
get_error_handler_instance(): get_shared_instance(); |
|
119 |
assert(decoder != NULL, "null decoder"); |
|
120 |
||
121 |
return decoder->decode(addr, buf, buflen, offset, base); |
|
122 |
} |
|
123 |
||
124 |
||
11483 | 125 |
bool Decoder::demangle(const char* symbol, char* buf, int buflen) { |
11761 | 126 |
assert(_shared_decoder_lock != NULL, "Just check"); |
127 |
bool error_handling_thread = os::current_thread_id() == VMError::first_error_tid; |
|
128 |
MutexLockerEx locker(error_handling_thread ? NULL : _shared_decoder_lock, true); |
|
129 |
AbstractDecoder* decoder = error_handling_thread ? |
|
130 |
get_error_handler_instance(): get_shared_instance(); |
|
11483 | 131 |
assert(decoder != NULL, "null decoder"); |
132 |
return decoder->demangle(symbol, buf, buflen); |
|
133 |
} |
|
134 |
||
47666 | 135 |
void Decoder::print_state_on(outputStream* st) { |
11483 | 136 |
} |
137 |
||
47666 | 138 |
bool Decoder::get_source_info(address pc, char* buf, size_t buflen, int* line) { |
139 |
return false; |
|
7447
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
140 |
} |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
141 |
|
47666 | 142 |
#endif // !_WINDOWS |
47086
2b35673f6297
8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
31352
diff
changeset
|
143 |