1 /*
2 * Copyright (c) 1997, 2017, 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 *
24
25 #include "precompiled.hpp"
26 #include "jvm.h"
27 #include "memory/allocation.inline.hpp"
28 #include "runtime/os.hpp"
29 #include "utilities/decoder.hpp"
30 #include "utilities/vmError.hpp"
31
32 #ifndef _WINDOWS
33 #if defined(__APPLE__)
34 #include "decoder_machO.hpp"
35 #elif defined(AIX)
36 #include "decoder_aix.hpp"
37 #else
38 #include "decoder_elf.hpp"
39 #endif
40
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,
45 "SharedDecoderLock",
46 false,
47 Monitor::_safepoint_check_never);
48
49 AbstractDecoder* Decoder::get_shared_instance() {
50 assert(_shared_decoder_lock != NULL && _shared_decoder_lock->owned_by_self(),
51 "Require DecoderLock to enter");
52
53 if (_shared_decoder == NULL) {
54 _shared_decoder = create_decoder();
55 }
56 return _shared_decoder;
57 }
58
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;
69 #if defined (__APPLE__)
70 decoder = new (std::nothrow)MachODecoder();
71 #elif defined(AIX)
72 decoder = new (std::nothrow)AIXDecoder();
73 #else
74 decoder = new (std::nothrow)ElfDecoder();
75 #endif
76
77 if (decoder == NULL || decoder->has_error()) {
78 if (decoder != NULL) {
79 delete decoder;
80 }
81 decoder = &_do_nothing_decoder;
82 }
83 return decoder;
84 }
85
86 inline bool DecoderLocker::is_first_error_thread() {
87 return (os::current_thread_id() == VMError::get_first_error_tid());
88 }
89
90 DecoderLocker::DecoderLocker() :
91 MutexLockerEx(DecoderLocker::is_first_error_thread() ?
92 NULL : Decoder::shared_decoder_lock(), true) {
93 _decoder = is_first_error_thread() ?
94 Decoder::get_error_handler_instance() : Decoder::get_shared_instance();
95 assert(_decoder != NULL, "null decoder");
96 }
97
98 Mutex* Decoder::shared_decoder_lock() {
99 assert(_shared_decoder_lock != NULL, "Just check");
100 return _shared_decoder_lock;
101 }
102
103 bool Decoder::decode(address addr, char* buf, int buflen, int* offset, const char* modulepath, bool demangle) {
104 assert(_shared_decoder_lock != NULL, "Just check");
105 bool error_handling_thread = os::current_thread_id() == VMError::first_error_tid;
106 MutexLockerEx locker(error_handling_thread ? NULL : _shared_decoder_lock, true);
107 AbstractDecoder* decoder = error_handling_thread ?
108 get_error_handler_instance(): get_shared_instance();
109 assert(decoder != NULL, "null decoder");
110
111 return decoder->decode(addr, buf, buflen, offset, modulepath, demangle);
112 }
113
114 bool Decoder::decode(address addr, char* buf, int buflen, int* offset, const void* base) {
115 assert(_shared_decoder_lock != NULL, "Just check");
116 bool error_handling_thread = os::current_thread_id() == VMError::first_error_tid;
117 MutexLockerEx locker(error_handling_thread ? NULL : _shared_decoder_lock, true);
118 AbstractDecoder* decoder = error_handling_thread ?
119 get_error_handler_instance(): get_shared_instance();
120 assert(decoder != NULL, "null decoder");
121
122 return decoder->decode(addr, buf, buflen, offset, base);
123 }
124
125
126 bool Decoder::demangle(const char* symbol, char* buf, int buflen) {
127 assert(_shared_decoder_lock != NULL, "Just check");
128 bool error_handling_thread = os::current_thread_id() == VMError::first_error_tid;
129 MutexLockerEx locker(error_handling_thread ? NULL : _shared_decoder_lock, true);
130 AbstractDecoder* decoder = error_handling_thread ?
131 get_error_handler_instance(): get_shared_instance();
132 assert(decoder != NULL, "null decoder");
133 return decoder->demangle(symbol, buf, buflen);
134 }
135
136 void Decoder::print_state_on(outputStream* st) {
137 }
138
139 bool Decoder::get_source_info(address pc, char* buf, size_t buflen, int* line) {
140 return false;
141 }
142
143 #endif // !_WINDOWS
144
|
1 /*
2 * Copyright (c) 1997, 2018, 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 *
24
25 #include "precompiled.hpp"
26 #include "jvm.h"
27 #include "memory/allocation.inline.hpp"
28 #include "runtime/os.hpp"
29 #include "utilities/decoder.hpp"
30 #include "utilities/vmError.hpp"
31
32 #ifndef _WINDOWS
33 #if defined(__APPLE__)
34 #include "decoder_machO.hpp"
35 #elif defined(AIX)
36 #include "decoder_aix.hpp"
37 #else
38 #include "decoder_elf.hpp"
39 #endif
40
41 AbstractDecoder* Decoder::_shared_decoder = NULL;
42 AbstractDecoder* Decoder::_error_handler_decoder = NULL;
43 NullDecoder Decoder::_do_nothing_decoder;
44
45 AbstractDecoder* Decoder::get_shared_instance() {
46 assert(shared_decoder_lock()->owned_by_self(), "Require DecoderLock to enter");
47
48 if (_shared_decoder == NULL) {
49 _shared_decoder = create_decoder();
50 }
51 return _shared_decoder;
52 }
53
54 AbstractDecoder* Decoder::get_error_handler_instance() {
55 if (_error_handler_decoder == NULL) {
56 _error_handler_decoder = create_decoder();
57 }
58 return _error_handler_decoder;
59 }
60
61
62 AbstractDecoder* Decoder::create_decoder() {
63 AbstractDecoder* decoder;
64 #if defined (__APPLE__)
65 decoder = new (std::nothrow)MachODecoder();
66 #elif defined(AIX)
67 decoder = new (std::nothrow)AIXDecoder();
68 #else
69 decoder = new (std::nothrow)ElfDecoder();
70 #endif
71
72 if (decoder == NULL || decoder->has_error()) {
73 if (decoder != NULL) {
74 delete decoder;
75 }
76 decoder = &_do_nothing_decoder;
77 }
78 return decoder;
79 }
80
81 inline bool DecoderLocker::is_first_error_thread() {
82 return (os::current_thread_id() == VMError::get_first_error_tid());
83 }
84
85 DecoderLocker::DecoderLocker() :
86 MutexLockerEx(DecoderLocker::is_first_error_thread() ?
87 NULL : Decoder::shared_decoder_lock(),
88 Mutex::_no_safepoint_check_flag) {
89 _decoder = is_first_error_thread() ?
90 Decoder::get_error_handler_instance() : Decoder::get_shared_instance();
91 assert(_decoder != NULL, "null decoder");
92 }
93
94 Mutex* Decoder::shared_decoder_lock() {
95 assert(Decoder_shared_decoder_lock != NULL, "Just check");
96 return Decoder_shared_decoder_lock;
97 }
98
99 bool Decoder::decode(address addr, char* buf, int buflen, int* offset, const char* modulepath, bool demangle) {
100 bool error_handling_thread = os::current_thread_id() == VMError::first_error_tid;
101 MutexLockerEx locker(error_handling_thread ? NULL : shared_decoder_lock(),
102 Mutex::_no_safepoint_check_flag);
103 AbstractDecoder* decoder = error_handling_thread ?
104 get_error_handler_instance(): get_shared_instance();
105 assert(decoder != NULL, "null decoder");
106
107 return decoder->decode(addr, buf, buflen, offset, modulepath, demangle);
108 }
109
110 bool Decoder::decode(address addr, char* buf, int buflen, int* offset, const void* base) {
111 bool error_handling_thread = os::current_thread_id() == VMError::first_error_tid;
112 MutexLockerEx locker(error_handling_thread ? NULL : shared_decoder_lock(),
113 Mutex::_no_safepoint_check_flag);
114 AbstractDecoder* decoder = error_handling_thread ?
115 get_error_handler_instance(): get_shared_instance();
116 assert(decoder != NULL, "null decoder");
117
118 return decoder->decode(addr, buf, buflen, offset, base);
119 }
120
121
122 bool Decoder::demangle(const char* symbol, char* buf, int buflen) {
123 bool error_handling_thread = os::current_thread_id() == VMError::first_error_tid;
124 MutexLockerEx locker(error_handling_thread ? NULL : shared_decoder_lock(),
125 Mutex::_no_safepoint_check_flag);
126 AbstractDecoder* decoder = error_handling_thread ?
127 get_error_handler_instance(): get_shared_instance();
128 assert(decoder != NULL, "null decoder");
129 return decoder->demangle(symbol, buf, buflen);
130 }
131
132 void Decoder::print_state_on(outputStream* st) {
133 }
134
135 bool Decoder::get_source_info(address pc, char* buf, size_t buflen, int* line) {
136 return false;
137 }
138
139 #endif // !_WINDOWS
140
|