author | coleenp |
Fri, 28 Sep 2018 16:07:39 -0400 | |
changeset 51959 | db0c3952de52 |
parent 51608 | 625a5bdde0c5 |
child 52877 | 9e041366c764 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
48823
99c973b56994
7179701: MaxJavaStackTraceDepth of zero is not handled correctly/consistently in the VM
coleenp
parents:
48105
diff
changeset
|
2 |
* Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. |
1 | 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 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4573
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4573
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4573
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#include "precompiled.hpp" |
51959
db0c3952de52
8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
51608
diff
changeset
|
26 |
#include "classfile/classLoaderDataGraph.hpp" |
7397 | 27 |
#include "classfile/systemDictionary.hpp" |
28 |
#include "jvmtifiles/jvmtiEnv.hpp" |
|
37248 | 29 |
#include "memory/resourceArea.hpp" |
7397 | 30 |
#include "oops/objArrayKlass.hpp" |
31 |
#include "oops/objArrayOop.hpp" |
|
29081
c61eb4914428
8072911: Remove includes of oop.inline.hpp from .hpp files
stefank
parents:
27165
diff
changeset
|
32 |
#include "oops/oop.inline.hpp" |
49816 | 33 |
#include "oops/oopHandle.inline.hpp" |
7397 | 34 |
#include "prims/jvmtiEnvBase.hpp" |
35 |
#include "prims/jvmtiEventController.inline.hpp" |
|
36 |
#include "prims/jvmtiExtensions.hpp" |
|
37 |
#include "prims/jvmtiImpl.hpp" |
|
38 |
#include "prims/jvmtiManageCapabilities.hpp" |
|
39 |
#include "prims/jvmtiTagMap.hpp" |
|
40 |
#include "prims/jvmtiThreadState.inline.hpp" |
|
41 |
#include "runtime/biasedLocking.hpp" |
|
42 |
#include "runtime/deoptimization.hpp" |
|
49480
d7df2dd501ce
8199809: Don't include frame.inline.hpp and other.inline.hpp from .hpp files
coleenp
parents:
49449
diff
changeset
|
43 |
#include "runtime/frame.inline.hpp" |
49449
ef5d5d343e2a
8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents:
49192
diff
changeset
|
44 |
#include "runtime/interfaceSupport.inline.hpp" |
7397 | 45 |
#include "runtime/jfieldIDWorkaround.hpp" |
49192
6734eeef4283
8198474: Move JNIHandles::resolve into jniHandles.inline.hpp
kbarrett
parents:
48823
diff
changeset
|
46 |
#include "runtime/jniHandles.inline.hpp" |
7397 | 47 |
#include "runtime/objectMonitor.hpp" |
48 |
#include "runtime/objectMonitor.inline.hpp" |
|
49 |
#include "runtime/signature.hpp" |
|
24351
61b33cc6d3cf
8042195: Introduce umbrella header orderAccess.inline.hpp.
goetz
parents:
23518
diff
changeset
|
50 |
#include "runtime/thread.inline.hpp" |
48105
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
51 |
#include "runtime/threadSMR.hpp" |
7397 | 52 |
#include "runtime/vframe.hpp" |
53 |
#include "runtime/vframe_hp.hpp" |
|
54 |
#include "runtime/vmThread.hpp" |
|
55 |
#include "runtime/vm_operations.hpp" |
|
1 | 56 |
|
57 |
/////////////////////////////////////////////////////////////// |
|
58 |
// |
|
59 |
// JvmtiEnvBase |
|
60 |
// |
|
61 |
||
62 |
JvmtiEnvBase* JvmtiEnvBase::_head_environment = NULL; |
|
63 |
||
64 |
bool JvmtiEnvBase::_globally_initialized = false; |
|
65 |
volatile bool JvmtiEnvBase::_needs_clean_up = false; |
|
66 |
||
67 |
jvmtiPhase JvmtiEnvBase::_phase = JVMTI_PHASE_PRIMORDIAL; |
|
68 |
||
69 |
volatile int JvmtiEnvBase::_dying_thread_env_iteration_count = 0; |
|
70 |
||
71 |
extern jvmtiInterface_1_ jvmti_Interface; |
|
72 |
extern jvmtiInterface_1_ jvmtiTrace_Interface; |
|
73 |
||
74 |
||
75 |
// perform initializations that must occur before any JVMTI environments |
|
76 |
// are released but which should only be initialized once (no matter |
|
77 |
// how many environments are created). |
|
78 |
void |
|
79 |
JvmtiEnvBase::globally_initialize() { |
|
80 |
assert(Threads::number_of_threads() == 0 || JvmtiThreadState_lock->is_locked(), "sanity check"); |
|
81 |
assert(_globally_initialized == false, "bad call"); |
|
82 |
||
83 |
JvmtiManageCapabilities::initialize(); |
|
84 |
||
85 |
// register extension functions and events |
|
86 |
JvmtiExtensions::register_extensions(); |
|
87 |
||
88 |
#ifdef JVMTI_TRACE |
|
89 |
JvmtiTrace::initialize(); |
|
90 |
#endif |
|
91 |
||
92 |
_globally_initialized = true; |
|
93 |
} |
|
94 |
||
95 |
||
96 |
void |
|
97 |
JvmtiEnvBase::initialize() { |
|
98 |
assert(Threads::number_of_threads() == 0 || JvmtiThreadState_lock->is_locked(), "sanity check"); |
|
99 |
||
100 |
// Add this environment to the end of the environment list (order is important) |
|
101 |
{ |
|
102 |
// This block of code must not contain any safepoints, as list deallocation |
|
103 |
// (which occurs at a safepoint) cannot occur simultaneously with this list |
|
35492
c8c0273e6b91
8146690: Make all classes in GC follow the naming convention.
david
parents:
33589
diff
changeset
|
104 |
// addition. Note: NoSafepointVerifier cannot, currently, be used before |
1 | 105 |
// threads exist. |
106 |
JvmtiEnvIterator it; |
|
107 |
JvmtiEnvBase *previous_env = NULL; |
|
108 |
for (JvmtiEnvBase* env = it.first(); env != NULL; env = it.next(env)) { |
|
109 |
previous_env = env; |
|
110 |
} |
|
111 |
if (previous_env == NULL) { |
|
112 |
_head_environment = this; |
|
113 |
} else { |
|
114 |
previous_env->set_next_environment(this); |
|
115 |
} |
|
116 |
} |
|
117 |
||
118 |
if (_globally_initialized == false) { |
|
119 |
globally_initialize(); |
|
120 |
} |
|
121 |
} |
|
122 |
||
36508 | 123 |
jvmtiPhase |
124 |
JvmtiEnvBase::phase() { |
|
125 |
// For the JVMTI environments possessed the can_generate_early_vmstart: |
|
126 |
// replace JVMTI_PHASE_PRIMORDIAL with JVMTI_PHASE_START |
|
127 |
if (_phase == JVMTI_PHASE_PRIMORDIAL && |
|
128 |
JvmtiExport::early_vmstart_recorded() && |
|
129 |
early_vmstart_env()) { |
|
130 |
return JVMTI_PHASE_START; |
|
131 |
} |
|
132 |
return _phase; // Normal case |
|
133 |
} |
|
1 | 134 |
|
2137
b03f1da1a3d3
6567360: 3/4 SIGBUS in jvmti RawMonitor magic check for unaligned bad monitor pointer
dcubed
parents:
2135
diff
changeset
|
135 |
bool |
b03f1da1a3d3
6567360: 3/4 SIGBUS in jvmti RawMonitor magic check for unaligned bad monitor pointer
dcubed
parents:
2135
diff
changeset
|
136 |
JvmtiEnvBase::is_valid() { |
b03f1da1a3d3
6567360: 3/4 SIGBUS in jvmti RawMonitor magic check for unaligned bad monitor pointer
dcubed
parents:
2135
diff
changeset
|
137 |
jint value = 0; |
b03f1da1a3d3
6567360: 3/4 SIGBUS in jvmti RawMonitor magic check for unaligned bad monitor pointer
dcubed
parents:
2135
diff
changeset
|
138 |
|
b03f1da1a3d3
6567360: 3/4 SIGBUS in jvmti RawMonitor magic check for unaligned bad monitor pointer
dcubed
parents:
2135
diff
changeset
|
139 |
// This object might not be a JvmtiEnvBase so we can't assume |
b03f1da1a3d3
6567360: 3/4 SIGBUS in jvmti RawMonitor magic check for unaligned bad monitor pointer
dcubed
parents:
2135
diff
changeset
|
140 |
// the _magic field is properly aligned. Get the value in a safe |
b03f1da1a3d3
6567360: 3/4 SIGBUS in jvmti RawMonitor magic check for unaligned bad monitor pointer
dcubed
parents:
2135
diff
changeset
|
141 |
// way and then check against JVMTI_MAGIC. |
b03f1da1a3d3
6567360: 3/4 SIGBUS in jvmti RawMonitor magic check for unaligned bad monitor pointer
dcubed
parents:
2135
diff
changeset
|
142 |
|
b03f1da1a3d3
6567360: 3/4 SIGBUS in jvmti RawMonitor magic check for unaligned bad monitor pointer
dcubed
parents:
2135
diff
changeset
|
143 |
switch (sizeof(_magic)) { |
b03f1da1a3d3
6567360: 3/4 SIGBUS in jvmti RawMonitor magic check for unaligned bad monitor pointer
dcubed
parents:
2135
diff
changeset
|
144 |
case 2: |
b03f1da1a3d3
6567360: 3/4 SIGBUS in jvmti RawMonitor magic check for unaligned bad monitor pointer
dcubed
parents:
2135
diff
changeset
|
145 |
value = Bytes::get_native_u2((address)&_magic); |
b03f1da1a3d3
6567360: 3/4 SIGBUS in jvmti RawMonitor magic check for unaligned bad monitor pointer
dcubed
parents:
2135
diff
changeset
|
146 |
break; |
b03f1da1a3d3
6567360: 3/4 SIGBUS in jvmti RawMonitor magic check for unaligned bad monitor pointer
dcubed
parents:
2135
diff
changeset
|
147 |
|
b03f1da1a3d3
6567360: 3/4 SIGBUS in jvmti RawMonitor magic check for unaligned bad monitor pointer
dcubed
parents:
2135
diff
changeset
|
148 |
case 4: |
b03f1da1a3d3
6567360: 3/4 SIGBUS in jvmti RawMonitor magic check for unaligned bad monitor pointer
dcubed
parents:
2135
diff
changeset
|
149 |
value = Bytes::get_native_u4((address)&_magic); |
b03f1da1a3d3
6567360: 3/4 SIGBUS in jvmti RawMonitor magic check for unaligned bad monitor pointer
dcubed
parents:
2135
diff
changeset
|
150 |
break; |
b03f1da1a3d3
6567360: 3/4 SIGBUS in jvmti RawMonitor magic check for unaligned bad monitor pointer
dcubed
parents:
2135
diff
changeset
|
151 |
|
b03f1da1a3d3
6567360: 3/4 SIGBUS in jvmti RawMonitor magic check for unaligned bad monitor pointer
dcubed
parents:
2135
diff
changeset
|
152 |
case 8: |
b03f1da1a3d3
6567360: 3/4 SIGBUS in jvmti RawMonitor magic check for unaligned bad monitor pointer
dcubed
parents:
2135
diff
changeset
|
153 |
value = Bytes::get_native_u8((address)&_magic); |
b03f1da1a3d3
6567360: 3/4 SIGBUS in jvmti RawMonitor magic check for unaligned bad monitor pointer
dcubed
parents:
2135
diff
changeset
|
154 |
break; |
b03f1da1a3d3
6567360: 3/4 SIGBUS in jvmti RawMonitor magic check for unaligned bad monitor pointer
dcubed
parents:
2135
diff
changeset
|
155 |
|
b03f1da1a3d3
6567360: 3/4 SIGBUS in jvmti RawMonitor magic check for unaligned bad monitor pointer
dcubed
parents:
2135
diff
changeset
|
156 |
default: |
b03f1da1a3d3
6567360: 3/4 SIGBUS in jvmti RawMonitor magic check for unaligned bad monitor pointer
dcubed
parents:
2135
diff
changeset
|
157 |
guarantee(false, "_magic field is an unexpected size"); |
b03f1da1a3d3
6567360: 3/4 SIGBUS in jvmti RawMonitor magic check for unaligned bad monitor pointer
dcubed
parents:
2135
diff
changeset
|
158 |
} |
b03f1da1a3d3
6567360: 3/4 SIGBUS in jvmti RawMonitor magic check for unaligned bad monitor pointer
dcubed
parents:
2135
diff
changeset
|
159 |
|
b03f1da1a3d3
6567360: 3/4 SIGBUS in jvmti RawMonitor magic check for unaligned bad monitor pointer
dcubed
parents:
2135
diff
changeset
|
160 |
return value == JVMTI_MAGIC; |
b03f1da1a3d3
6567360: 3/4 SIGBUS in jvmti RawMonitor magic check for unaligned bad monitor pointer
dcubed
parents:
2135
diff
changeset
|
161 |
} |
b03f1da1a3d3
6567360: 3/4 SIGBUS in jvmti RawMonitor magic check for unaligned bad monitor pointer
dcubed
parents:
2135
diff
changeset
|
162 |
|
b03f1da1a3d3
6567360: 3/4 SIGBUS in jvmti RawMonitor magic check for unaligned bad monitor pointer
dcubed
parents:
2135
diff
changeset
|
163 |
|
4492 | 164 |
bool |
4491 | 165 |
JvmtiEnvBase::use_version_1_0_semantics() { |
166 |
int major, minor, micro; |
|
167 |
||
168 |
JvmtiExport::decode_version_values(_version, &major, &minor, µ); |
|
169 |
return major == 1 && minor == 0; // micro version doesn't matter here |
|
170 |
} |
|
171 |
||
172 |
||
173 |
bool |
|
174 |
JvmtiEnvBase::use_version_1_1_semantics() { |
|
175 |
int major, minor, micro; |
|
176 |
||
177 |
JvmtiExport::decode_version_values(_version, &major, &minor, µ); |
|
178 |
return major == 1 && minor == 1; // micro version doesn't matter here |
|
179 |
} |
|
180 |
||
7413 | 181 |
bool |
182 |
JvmtiEnvBase::use_version_1_2_semantics() { |
|
183 |
int major, minor, micro; |
|
184 |
||
185 |
JvmtiExport::decode_version_values(_version, &major, &minor, µ); |
|
186 |
return major == 1 && minor == 2; // micro version doesn't matter here |
|
187 |
} |
|
188 |
||
4491 | 189 |
|
190 |
JvmtiEnvBase::JvmtiEnvBase(jint version) : _env_event_enable() { |
|
191 |
_version = version; |
|
1 | 192 |
_env_local_storage = NULL; |
193 |
_tag_map = NULL; |
|
194 |
_native_method_prefix_count = 0; |
|
195 |
_native_method_prefixes = NULL; |
|
196 |
_next = NULL; |
|
197 |
_class_file_load_hook_ever_enabled = false; |
|
198 |
||
199 |
// Moot since ClassFileLoadHook not yet enabled. |
|
200 |
// But "true" will give a more predictable ClassFileLoadHook behavior |
|
201 |
// for environment creation during ClassFileLoadHook. |
|
202 |
_is_retransformable = true; |
|
203 |
||
204 |
// all callbacks initially NULL |
|
205 |
memset(&_event_callbacks,0,sizeof(jvmtiEventCallbacks)); |
|
206 |
||
207 |
// all capabilities initially off |
|
208 |
memset(&_current_capabilities, 0, sizeof(_current_capabilities)); |
|
209 |
||
210 |
// all prohibited capabilities initially off |
|
211 |
memset(&_prohibited_capabilities, 0, sizeof(_prohibited_capabilities)); |
|
212 |
||
213 |
_magic = JVMTI_MAGIC; |
|
214 |
||
215 |
JvmtiEventController::env_initialize((JvmtiEnv*)this); |
|
216 |
||
217 |
#ifdef JVMTI_TRACE |
|
1403 | 218 |
_jvmti_external.functions = TraceJVMTI != NULL ? &jvmtiTrace_Interface : &jvmti_Interface; |
1 | 219 |
#else |
220 |
_jvmti_external.functions = &jvmti_Interface; |
|
221 |
#endif |
|
222 |
} |
|
223 |
||
224 |
||
225 |
void |
|
226 |
JvmtiEnvBase::dispose() { |
|
227 |
||
228 |
#ifdef JVMTI_TRACE |
|
229 |
JvmtiTrace::shutdown(); |
|
230 |
#endif |
|
231 |
||
232 |
// Dispose of event info and let the event controller call us back |
|
233 |
// in a locked state (env_dispose, below) |
|
234 |
JvmtiEventController::env_dispose(this); |
|
235 |
} |
|
236 |
||
237 |
void |
|
238 |
JvmtiEnvBase::env_dispose() { |
|
239 |
assert(Threads::number_of_threads() == 0 || JvmtiThreadState_lock->is_locked(), "sanity check"); |
|
240 |
||
241 |
// We have been entered with all events disabled on this environment. |
|
242 |
// A race to re-enable events (by setting callbacks) is prevented by |
|
243 |
// checking for a valid environment when setting callbacks (while |
|
244 |
// holding the JvmtiThreadState_lock). |
|
245 |
||
246 |
// Mark as invalid. |
|
247 |
_magic = DISPOSED_MAGIC; |
|
248 |
||
249 |
// Relinquish all capabilities. |
|
250 |
jvmtiCapabilities *caps = get_capabilities(); |
|
251 |
JvmtiManageCapabilities::relinquish_capabilities(caps, caps, caps); |
|
252 |
||
253 |
// Same situation as with events (see above) |
|
254 |
set_native_method_prefixes(0, NULL); |
|
255 |
||
256 |
JvmtiTagMap* tag_map_to_deallocate = _tag_map; |
|
257 |
set_tag_map(NULL); |
|
258 |
// A tag map can be big, deallocate it now |
|
259 |
if (tag_map_to_deallocate != NULL) { |
|
260 |
delete tag_map_to_deallocate; |
|
261 |
} |
|
262 |
||
263 |
_needs_clean_up = true; |
|
264 |
} |
|
265 |
||
266 |
||
267 |
JvmtiEnvBase::~JvmtiEnvBase() { |
|
268 |
assert(SafepointSynchronize::is_at_safepoint(), "sanity check"); |
|
269 |
||
270 |
// There is a small window of time during which the tag map of a |
|
271 |
// disposed environment could have been reallocated. |
|
272 |
// Make sure it is gone. |
|
273 |
JvmtiTagMap* tag_map_to_deallocate = _tag_map; |
|
274 |
set_tag_map(NULL); |
|
275 |
// A tag map can be big, deallocate it now |
|
276 |
if (tag_map_to_deallocate != NULL) { |
|
277 |
delete tag_map_to_deallocate; |
|
278 |
} |
|
279 |
||
280 |
_magic = BAD_MAGIC; |
|
281 |
} |
|
282 |
||
283 |
||
284 |
void |
|
285 |
JvmtiEnvBase::periodic_clean_up() { |
|
286 |
assert(SafepointSynchronize::is_at_safepoint(), "sanity check"); |
|
287 |
||
288 |
// JvmtiEnvBase reference is saved in JvmtiEnvThreadState. So |
|
289 |
// clean up JvmtiThreadState before deleting JvmtiEnv pointer. |
|
290 |
JvmtiThreadState::periodic_clean_up(); |
|
291 |
||
292 |
// Unlink all invalid environments from the list of environments |
|
293 |
// and deallocate them |
|
294 |
JvmtiEnvIterator it; |
|
295 |
JvmtiEnvBase* previous_env = NULL; |
|
296 |
JvmtiEnvBase* env = it.first(); |
|
297 |
while (env != NULL) { |
|
298 |
if (env->is_valid()) { |
|
299 |
previous_env = env; |
|
300 |
env = it.next(env); |
|
301 |
} else { |
|
302 |
// This one isn't valid, remove it from the list and deallocate it |
|
303 |
JvmtiEnvBase* defunct_env = env; |
|
304 |
env = it.next(env); |
|
305 |
if (previous_env == NULL) { |
|
306 |
_head_environment = env; |
|
307 |
} else { |
|
308 |
previous_env->set_next_environment(env); |
|
309 |
} |
|
310 |
delete defunct_env; |
|
311 |
} |
|
312 |
} |
|
313 |
||
314 |
} |
|
315 |
||
316 |
||
317 |
void |
|
318 |
JvmtiEnvBase::check_for_periodic_clean_up() { |
|
319 |
assert(SafepointSynchronize::is_at_safepoint(), "sanity check"); |
|
320 |
||
321 |
class ThreadInsideIterationClosure: public ThreadClosure { |
|
322 |
private: |
|
323 |
bool _inside; |
|
324 |
public: |
|
325 |
ThreadInsideIterationClosure() : _inside(false) {}; |
|
326 |
||
327 |
void do_thread(Thread* thread) { |
|
328 |
_inside |= thread->is_inside_jvmti_env_iteration(); |
|
329 |
} |
|
330 |
||
331 |
bool is_inside_jvmti_env_iteration() { |
|
332 |
return _inside; |
|
333 |
} |
|
334 |
}; |
|
335 |
||
336 |
if (_needs_clean_up) { |
|
337 |
// Check if we are currently iterating environment, |
|
338 |
// deallocation should not occur if we are |
|
339 |
ThreadInsideIterationClosure tiic; |
|
340 |
Threads::threads_do(&tiic); |
|
341 |
if (!tiic.is_inside_jvmti_env_iteration() && |
|
342 |
!is_inside_dying_thread_env_iteration()) { |
|
343 |
_needs_clean_up = false; |
|
344 |
JvmtiEnvBase::periodic_clean_up(); |
|
345 |
} |
|
346 |
} |
|
347 |
} |
|
348 |
||
349 |
||
350 |
void |
|
351 |
JvmtiEnvBase::record_first_time_class_file_load_hook_enabled() { |
|
352 |
assert(Threads::number_of_threads() == 0 || JvmtiThreadState_lock->is_locked(), |
|
353 |
"sanity check"); |
|
354 |
||
355 |
if (!_class_file_load_hook_ever_enabled) { |
|
356 |
_class_file_load_hook_ever_enabled = true; |
|
357 |
||
358 |
if (get_capabilities()->can_retransform_classes) { |
|
359 |
_is_retransformable = true; |
|
360 |
} else { |
|
361 |
_is_retransformable = false; |
|
362 |
||
363 |
// cannot add retransform capability after ClassFileLoadHook has been enabled |
|
364 |
get_prohibited_capabilities()->can_retransform_classes = 1; |
|
365 |
} |
|
366 |
} |
|
367 |
} |
|
368 |
||
369 |
||
370 |
void |
|
371 |
JvmtiEnvBase::record_class_file_load_hook_enabled() { |
|
372 |
if (!_class_file_load_hook_ever_enabled) { |
|
373 |
if (Threads::number_of_threads() == 0) { |
|
374 |
record_first_time_class_file_load_hook_enabled(); |
|
375 |
} else { |
|
376 |
MutexLocker mu(JvmtiThreadState_lock); |
|
377 |
record_first_time_class_file_load_hook_enabled(); |
|
378 |
} |
|
379 |
} |
|
380 |
} |
|
381 |
||
382 |
||
383 |
jvmtiError |
|
384 |
JvmtiEnvBase::set_native_method_prefixes(jint prefix_count, char** prefixes) { |
|
385 |
assert(Threads::number_of_threads() == 0 || JvmtiThreadState_lock->is_locked(), |
|
386 |
"sanity check"); |
|
387 |
||
388 |
int old_prefix_count = get_native_method_prefix_count(); |
|
389 |
char **old_prefixes = get_native_method_prefixes(); |
|
390 |
||
391 |
// allocate and install the new prefixex |
|
392 |
if (prefix_count == 0 || !is_valid()) { |
|
393 |
_native_method_prefix_count = 0; |
|
394 |
_native_method_prefixes = NULL; |
|
395 |
} else { |
|
396 |
// there are prefixes, allocate an array to hold them, and fill it |
|
13195 | 397 |
char** new_prefixes = (char**)os::malloc((prefix_count) * sizeof(char*), mtInternal); |
1 | 398 |
if (new_prefixes == NULL) { |
399 |
return JVMTI_ERROR_OUT_OF_MEMORY; |
|
400 |
} |
|
401 |
for (int i = 0; i < prefix_count; i++) { |
|
402 |
char* prefix = prefixes[i]; |
|
403 |
if (prefix == NULL) { |
|
404 |
for (int j = 0; j < (i-1); j++) { |
|
405 |
os::free(new_prefixes[j]); |
|
406 |
} |
|
407 |
os::free(new_prefixes); |
|
408 |
return JVMTI_ERROR_NULL_POINTER; |
|
409 |
} |
|
410 |
prefix = os::strdup(prefixes[i]); |
|
411 |
if (prefix == NULL) { |
|
412 |
for (int j = 0; j < (i-1); j++) { |
|
413 |
os::free(new_prefixes[j]); |
|
414 |
} |
|
415 |
os::free(new_prefixes); |
|
416 |
return JVMTI_ERROR_OUT_OF_MEMORY; |
|
417 |
} |
|
418 |
new_prefixes[i] = prefix; |
|
419 |
} |
|
420 |
_native_method_prefix_count = prefix_count; |
|
421 |
_native_method_prefixes = new_prefixes; |
|
422 |
} |
|
423 |
||
424 |
// now that we know the new prefixes have been successfully installed we can |
|
425 |
// safely remove the old ones |
|
426 |
if (old_prefix_count != 0) { |
|
427 |
for (int i = 0; i < old_prefix_count; i++) { |
|
428 |
os::free(old_prefixes[i]); |
|
429 |
} |
|
430 |
os::free(old_prefixes); |
|
431 |
} |
|
432 |
||
433 |
return JVMTI_ERROR_NONE; |
|
434 |
} |
|
435 |
||
436 |
||
437 |
// Collect all the prefixes which have been set in any JVM TI environments |
|
438 |
// by the SetNativeMethodPrefix(es) functions. Be sure to maintain the |
|
439 |
// order of environments and the order of prefixes within each environment. |
|
440 |
// Return in a resource allocated array. |
|
441 |
char** |
|
442 |
JvmtiEnvBase::get_all_native_method_prefixes(int* count_ptr) { |
|
443 |
assert(Threads::number_of_threads() == 0 || |
|
444 |
SafepointSynchronize::is_at_safepoint() || |
|
445 |
JvmtiThreadState_lock->is_locked(), |
|
446 |
"sanity check"); |
|
447 |
||
448 |
int total_count = 0; |
|
449 |
GrowableArray<char*>* prefix_array =new GrowableArray<char*>(5); |
|
450 |
||
451 |
JvmtiEnvIterator it; |
|
452 |
for (JvmtiEnvBase* env = it.first(); env != NULL; env = it.next(env)) { |
|
453 |
int prefix_count = env->get_native_method_prefix_count(); |
|
454 |
char** prefixes = env->get_native_method_prefixes(); |
|
455 |
for (int j = 0; j < prefix_count; j++) { |
|
456 |
// retrieve a prefix and so that it is safe against asynchronous changes |
|
457 |
// copy it into the resource area |
|
458 |
char* prefix = prefixes[j]; |
|
459 |
char* prefix_copy = NEW_RESOURCE_ARRAY(char, strlen(prefix)+1); |
|
460 |
strcpy(prefix_copy, prefix); |
|
461 |
prefix_array->at_put_grow(total_count++, prefix_copy); |
|
462 |
} |
|
463 |
} |
|
464 |
||
465 |
char** all_prefixes = NEW_RESOURCE_ARRAY(char*, total_count); |
|
466 |
char** p = all_prefixes; |
|
467 |
for (int i = 0; i < total_count; ++i) { |
|
468 |
*p++ = prefix_array->at(i); |
|
469 |
} |
|
470 |
*count_ptr = total_count; |
|
471 |
return all_prefixes; |
|
472 |
} |
|
473 |
||
474 |
void |
|
475 |
JvmtiEnvBase::set_event_callbacks(const jvmtiEventCallbacks* callbacks, |
|
476 |
jint size_of_callbacks) { |
|
477 |
assert(Threads::number_of_threads() == 0 || JvmtiThreadState_lock->is_locked(), "sanity check"); |
|
478 |
||
479 |
size_t byte_cnt = sizeof(jvmtiEventCallbacks); |
|
480 |
||
481 |
// clear in either case to be sure we got any gap between sizes |
|
482 |
memset(&_event_callbacks, 0, byte_cnt); |
|
483 |
||
484 |
// Now that JvmtiThreadState_lock is held, prevent a possible race condition where events |
|
485 |
// are re-enabled by a call to set event callbacks where the DisposeEnvironment |
|
486 |
// occurs after the boiler-plate environment check and before the lock is acquired. |
|
487 |
if (callbacks != NULL && is_valid()) { |
|
488 |
if (size_of_callbacks < (jint)byte_cnt) { |
|
489 |
byte_cnt = size_of_callbacks; |
|
490 |
} |
|
491 |
memcpy(&_event_callbacks, callbacks, byte_cnt); |
|
492 |
} |
|
493 |
} |
|
494 |
||
495 |
||
496 |
// In the fullness of time, all users of the method should instead |
|
497 |
// directly use allocate, besides being cleaner and faster, this will |
|
498 |
// mean much better out of memory handling |
|
499 |
unsigned char * |
|
500 |
JvmtiEnvBase::jvmtiMalloc(jlong size) { |
|
33589
7cbd1b2c139b
8139040: Fix initializations before ShouldNotReachHere() etc. and enable -Wuninitialized on linux.
goetz
parents:
31024
diff
changeset
|
501 |
unsigned char* mem = NULL; |
1 | 502 |
jvmtiError result = allocate(size, &mem); |
503 |
assert(result == JVMTI_ERROR_NONE, "Allocate failed"); |
|
504 |
return mem; |
|
505 |
} |
|
506 |
||
507 |
||
49192
6734eeef4283
8198474: Move JNIHandles::resolve into jniHandles.inline.hpp
kbarrett
parents:
48823
diff
changeset
|
508 |
// Handle management |
6734eeef4283
8198474: Move JNIHandles::resolve into jniHandles.inline.hpp
kbarrett
parents:
48823
diff
changeset
|
509 |
|
6734eeef4283
8198474: Move JNIHandles::resolve into jniHandles.inline.hpp
kbarrett
parents:
48823
diff
changeset
|
510 |
jobject JvmtiEnvBase::jni_reference(Handle hndl) { |
6734eeef4283
8198474: Move JNIHandles::resolve into jniHandles.inline.hpp
kbarrett
parents:
48823
diff
changeset
|
511 |
return JNIHandles::make_local(hndl()); |
6734eeef4283
8198474: Move JNIHandles::resolve into jniHandles.inline.hpp
kbarrett
parents:
48823
diff
changeset
|
512 |
} |
6734eeef4283
8198474: Move JNIHandles::resolve into jniHandles.inline.hpp
kbarrett
parents:
48823
diff
changeset
|
513 |
|
6734eeef4283
8198474: Move JNIHandles::resolve into jniHandles.inline.hpp
kbarrett
parents:
48823
diff
changeset
|
514 |
jobject JvmtiEnvBase::jni_reference(JavaThread *thread, Handle hndl) { |
6734eeef4283
8198474: Move JNIHandles::resolve into jniHandles.inline.hpp
kbarrett
parents:
48823
diff
changeset
|
515 |
return JNIHandles::make_local(thread, hndl()); |
6734eeef4283
8198474: Move JNIHandles::resolve into jniHandles.inline.hpp
kbarrett
parents:
48823
diff
changeset
|
516 |
} |
6734eeef4283
8198474: Move JNIHandles::resolve into jniHandles.inline.hpp
kbarrett
parents:
48823
diff
changeset
|
517 |
|
6734eeef4283
8198474: Move JNIHandles::resolve into jniHandles.inline.hpp
kbarrett
parents:
48823
diff
changeset
|
518 |
void JvmtiEnvBase::destroy_jni_reference(jobject jobj) { |
6734eeef4283
8198474: Move JNIHandles::resolve into jniHandles.inline.hpp
kbarrett
parents:
48823
diff
changeset
|
519 |
JNIHandles::destroy_local(jobj); |
6734eeef4283
8198474: Move JNIHandles::resolve into jniHandles.inline.hpp
kbarrett
parents:
48823
diff
changeset
|
520 |
} |
6734eeef4283
8198474: Move JNIHandles::resolve into jniHandles.inline.hpp
kbarrett
parents:
48823
diff
changeset
|
521 |
|
6734eeef4283
8198474: Move JNIHandles::resolve into jniHandles.inline.hpp
kbarrett
parents:
48823
diff
changeset
|
522 |
void JvmtiEnvBase::destroy_jni_reference(JavaThread *thread, jobject jobj) { |
6734eeef4283
8198474: Move JNIHandles::resolve into jniHandles.inline.hpp
kbarrett
parents:
48823
diff
changeset
|
523 |
JNIHandles::destroy_local(jobj); // thread is unused. |
6734eeef4283
8198474: Move JNIHandles::resolve into jniHandles.inline.hpp
kbarrett
parents:
48823
diff
changeset
|
524 |
} |
6734eeef4283
8198474: Move JNIHandles::resolve into jniHandles.inline.hpp
kbarrett
parents:
48823
diff
changeset
|
525 |
|
1 | 526 |
// |
527 |
// Threads |
|
528 |
// |
|
529 |
||
530 |
jobject * |
|
531 |
JvmtiEnvBase::new_jobjectArray(int length, Handle *handles) { |
|
532 |
if (length == 0) { |
|
533 |
return NULL; |
|
534 |
} |
|
535 |
||
536 |
jobject *objArray = (jobject *) jvmtiMalloc(sizeof(jobject) * length); |
|
537 |
NULL_CHECK(objArray, NULL); |
|
538 |
||
539 |
for (int i=0; i<length; i++) { |
|
540 |
objArray[i] = jni_reference(handles[i]); |
|
541 |
} |
|
542 |
return objArray; |
|
543 |
} |
|
544 |
||
545 |
jthread * |
|
546 |
JvmtiEnvBase::new_jthreadArray(int length, Handle *handles) { |
|
547 |
return (jthread *) new_jobjectArray(length,handles); |
|
548 |
} |
|
549 |
||
550 |
jthreadGroup * |
|
551 |
JvmtiEnvBase::new_jthreadGroupArray(int length, Handle *handles) { |
|
552 |
return (jthreadGroup *) new_jobjectArray(length,handles); |
|
553 |
} |
|
554 |
||
555 |
// return the vframe on the specified thread and depth, NULL if no such frame |
|
556 |
vframe* |
|
557 |
JvmtiEnvBase::vframeFor(JavaThread* java_thread, jint depth) { |
|
558 |
if (!java_thread->has_last_Java_frame()) { |
|
559 |
return NULL; |
|
560 |
} |
|
561 |
RegisterMap reg_map(java_thread); |
|
562 |
vframe *vf = java_thread->last_java_vframe(®_map); |
|
563 |
int d = 0; |
|
564 |
while ((vf != NULL) && (d < depth)) { |
|
565 |
vf = vf->java_sender(); |
|
566 |
d++; |
|
567 |
} |
|
568 |
return vf; |
|
569 |
} |
|
570 |
||
571 |
||
572 |
// |
|
573 |
// utilities: JNI objects |
|
574 |
// |
|
575 |
||
576 |
||
577 |
jclass |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
578 |
JvmtiEnvBase::get_jni_class_non_null(Klass* k) { |
1 | 579 |
assert(k != NULL, "k != NULL"); |
46271
979ebd346ecf
8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents:
37480
diff
changeset
|
580 |
Thread *thread = Thread::current(); |
979ebd346ecf
8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents:
37480
diff
changeset
|
581 |
return (jclass)jni_reference(Handle(thread, k->java_mirror())); |
1 | 582 |
} |
583 |
||
584 |
// |
|
585 |
// Field Information |
|
586 |
// |
|
587 |
||
588 |
bool |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
589 |
JvmtiEnvBase::get_field_descriptor(Klass* k, jfieldID field, fieldDescriptor* fd) { |
1 | 590 |
if (!jfieldIDWorkaround::is_valid_jfieldID(k, field)) { |
591 |
return false; |
|
592 |
} |
|
593 |
bool found = false; |
|
594 |
if (jfieldIDWorkaround::is_static_jfieldID(field)) { |
|
595 |
JNIid* id = jfieldIDWorkaround::from_static_jfieldID(field); |
|
8725
8c1e3dd5fe1b
7017732: move static fields into Class to prepare for perm gen removal
never
parents:
8076
diff
changeset
|
596 |
found = id->find_local_field(fd); |
1 | 597 |
} else { |
598 |
// Non-static field. The fieldID is really the offset of the field within the object. |
|
599 |
int offset = jfieldIDWorkaround::from_instance_jfieldID(k, field); |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
600 |
found = InstanceKlass::cast(k)->find_field_from_offset(offset, false, fd); |
1 | 601 |
} |
602 |
return found; |
|
603 |
} |
|
604 |
||
605 |
// |
|
606 |
// Object Monitor Information |
|
607 |
// |
|
608 |
||
609 |
// |
|
610 |
// Count the number of objects for a lightweight monitor. The hobj |
|
611 |
// parameter is object that owns the monitor so this routine will |
|
612 |
// count the number of times the same object was locked by frames |
|
613 |
// in java_thread. |
|
614 |
// |
|
615 |
jint |
|
616 |
JvmtiEnvBase::count_locked_objects(JavaThread *java_thread, Handle hobj) { |
|
617 |
jint ret = 0; |
|
618 |
if (!java_thread->has_last_Java_frame()) { |
|
619 |
return ret; // no Java frames so no monitors |
|
620 |
} |
|
621 |
||
622 |
ResourceMark rm; |
|
623 |
HandleMark hm; |
|
624 |
RegisterMap reg_map(java_thread); |
|
625 |
||
626 |
for(javaVFrame *jvf=java_thread->last_java_vframe(®_map); jvf != NULL; |
|
627 |
jvf = jvf->java_sender()) { |
|
628 |
GrowableArray<MonitorInfo*>* mons = jvf->monitors(); |
|
629 |
if (!mons->is_empty()) { |
|
630 |
for (int i = 0; i < mons->length(); i++) { |
|
631 |
MonitorInfo *mi = mons->at(i); |
|
3171
aa289b22b577
6837472: com/sun/jdi/MonitorFrameInfo.java fails with AggressiveOpts in 6u14
kvn
parents:
2137
diff
changeset
|
632 |
if (mi->owner_is_scalar_replaced()) continue; |
1 | 633 |
|
634 |
// see if owner of the monitor is our object |
|
635 |
if (mi->owner() != NULL && mi->owner() == hobj()) { |
|
636 |
ret++; |
|
637 |
} |
|
638 |
} |
|
639 |
} |
|
640 |
} |
|
641 |
return ret; |
|
642 |
} |
|
643 |
||
644 |
||
645 |
||
646 |
jvmtiError |
|
647 |
JvmtiEnvBase::get_current_contended_monitor(JavaThread *calling_thread, JavaThread *java_thread, jobject *monitor_ptr) { |
|
648 |
#ifdef ASSERT |
|
649 |
uint32_t debug_bits = 0; |
|
650 |
#endif |
|
651 |
assert((SafepointSynchronize::is_at_safepoint() || |
|
48105
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
652 |
java_thread->is_thread_fully_suspended(false, &debug_bits)), |
1 | 653 |
"at safepoint or target thread is suspended"); |
654 |
oop obj = NULL; |
|
655 |
ObjectMonitor *mon = java_thread->current_waiting_monitor(); |
|
656 |
if (mon == NULL) { |
|
657 |
// thread is not doing an Object.wait() call |
|
658 |
mon = java_thread->current_pending_monitor(); |
|
659 |
if (mon != NULL) { |
|
660 |
// The thread is trying to enter() or raw_enter() an ObjectMonitor. |
|
661 |
obj = (oop)mon->object(); |
|
662 |
// If obj == NULL, then ObjectMonitor is raw which doesn't count |
|
663 |
// as contended for this API |
|
664 |
} |
|
665 |
// implied else: no contended ObjectMonitor |
|
666 |
} else { |
|
667 |
// thread is doing an Object.wait() call |
|
668 |
obj = (oop)mon->object(); |
|
669 |
assert(obj != NULL, "Object.wait() should have an object"); |
|
670 |
} |
|
671 |
||
672 |
if (obj == NULL) { |
|
673 |
*monitor_ptr = NULL; |
|
674 |
} else { |
|
675 |
HandleMark hm; |
|
46271
979ebd346ecf
8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents:
37480
diff
changeset
|
676 |
Handle hobj(Thread::current(), obj); |
1 | 677 |
*monitor_ptr = jni_reference(calling_thread, hobj); |
678 |
} |
|
679 |
return JVMTI_ERROR_NONE; |
|
680 |
} |
|
681 |
||
682 |
||
683 |
jvmtiError |
|
684 |
JvmtiEnvBase::get_owned_monitors(JavaThread *calling_thread, JavaThread* java_thread, |
|
685 |
GrowableArray<jvmtiMonitorStackDepthInfo*> *owned_monitors_list) { |
|
686 |
jvmtiError err = JVMTI_ERROR_NONE; |
|
687 |
#ifdef ASSERT |
|
688 |
uint32_t debug_bits = 0; |
|
689 |
#endif |
|
690 |
assert((SafepointSynchronize::is_at_safepoint() || |
|
48105
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
691 |
java_thread->is_thread_fully_suspended(false, &debug_bits)), |
1 | 692 |
"at safepoint or target thread is suspended"); |
693 |
||
694 |
if (java_thread->has_last_Java_frame()) { |
|
695 |
ResourceMark rm; |
|
696 |
HandleMark hm; |
|
697 |
RegisterMap reg_map(java_thread); |
|
698 |
||
699 |
int depth = 0; |
|
700 |
for (javaVFrame *jvf = java_thread->last_java_vframe(®_map); jvf != NULL; |
|
701 |
jvf = jvf->java_sender()) { |
|
48823
99c973b56994
7179701: MaxJavaStackTraceDepth of zero is not handled correctly/consistently in the VM
coleenp
parents:
48105
diff
changeset
|
702 |
if (MaxJavaStackTraceDepth == 0 || depth++ < MaxJavaStackTraceDepth) { // check for stack too deep |
1 | 703 |
// add locked objects for this frame into list |
704 |
err = get_locked_objects_in_frame(calling_thread, java_thread, jvf, owned_monitors_list, depth-1); |
|
705 |
if (err != JVMTI_ERROR_NONE) { |
|
706 |
return err; |
|
707 |
} |
|
708 |
} |
|
709 |
} |
|
710 |
} |
|
711 |
||
712 |
// Get off stack monitors. (e.g. acquired via jni MonitorEnter). |
|
713 |
JvmtiMonitorClosure jmc(java_thread, calling_thread, owned_monitors_list, this); |
|
714 |
ObjectSynchronizer::monitors_iterate(&jmc); |
|
715 |
err = jmc.error(); |
|
716 |
||
717 |
return err; |
|
718 |
} |
|
719 |
||
720 |
// Save JNI local handles for any objects that this frame owns. |
|
721 |
jvmtiError |
|
722 |
JvmtiEnvBase::get_locked_objects_in_frame(JavaThread* calling_thread, JavaThread* java_thread, |
|
47765
b7c7428eaab9
8189610: Reconcile jvm.h and all jvm_md.h between java.base and hotspot
coleenp
parents:
47216
diff
changeset
|
723 |
javaVFrame *jvf, GrowableArray<jvmtiMonitorStackDepthInfo*>* owned_monitors_list, jint stack_depth) { |
1 | 724 |
jvmtiError err = JVMTI_ERROR_NONE; |
725 |
ResourceMark rm; |
|
726 |
||
727 |
GrowableArray<MonitorInfo*>* mons = jvf->monitors(); |
|
728 |
if (mons->is_empty()) { |
|
729 |
return err; // this javaVFrame holds no monitors |
|
730 |
} |
|
731 |
||
732 |
HandleMark hm; |
|
733 |
oop wait_obj = NULL; |
|
734 |
{ |
|
735 |
// save object of current wait() call (if any) for later comparison |
|
736 |
ObjectMonitor *mon = java_thread->current_waiting_monitor(); |
|
737 |
if (mon != NULL) { |
|
738 |
wait_obj = (oop)mon->object(); |
|
739 |
} |
|
740 |
} |
|
741 |
oop pending_obj = NULL; |
|
742 |
{ |
|
743 |
// save object of current enter() call (if any) for later comparison |
|
744 |
ObjectMonitor *mon = java_thread->current_pending_monitor(); |
|
745 |
if (mon != NULL) { |
|
746 |
pending_obj = (oop)mon->object(); |
|
747 |
} |
|
748 |
} |
|
749 |
||
750 |
for (int i = 0; i < mons->length(); i++) { |
|
751 |
MonitorInfo *mi = mons->at(i); |
|
752 |
||
3171
aa289b22b577
6837472: com/sun/jdi/MonitorFrameInfo.java fails with AggressiveOpts in 6u14
kvn
parents:
2137
diff
changeset
|
753 |
if (mi->owner_is_scalar_replaced()) continue; |
aa289b22b577
6837472: com/sun/jdi/MonitorFrameInfo.java fails with AggressiveOpts in 6u14
kvn
parents:
2137
diff
changeset
|
754 |
|
1 | 755 |
oop obj = mi->owner(); |
756 |
if (obj == NULL) { |
|
757 |
// this monitor doesn't have an owning object so skip it |
|
758 |
continue; |
|
759 |
} |
|
760 |
||
761 |
if (wait_obj == obj) { |
|
762 |
// the thread is waiting on this monitor so it isn't really owned |
|
763 |
continue; |
|
764 |
} |
|
765 |
||
766 |
if (pending_obj == obj) { |
|
767 |
// the thread is pending on this monitor so it isn't really owned |
|
768 |
continue; |
|
769 |
} |
|
770 |
||
771 |
if (owned_monitors_list->length() > 0) { |
|
772 |
// Our list has at least one object on it so we have to check |
|
773 |
// for recursive object locking |
|
774 |
bool found = false; |
|
775 |
for (int j = 0; j < owned_monitors_list->length(); j++) { |
|
776 |
jobject jobj = ((jvmtiMonitorStackDepthInfo*)owned_monitors_list->at(j))->monitor; |
|
777 |
oop check = JNIHandles::resolve(jobj); |
|
778 |
if (check == obj) { |
|
779 |
found = true; // we found the object |
|
780 |
break; |
|
781 |
} |
|
782 |
} |
|
783 |
||
784 |
if (found) { |
|
785 |
// already have this object so don't include it |
|
786 |
continue; |
|
787 |
} |
|
788 |
} |
|
789 |
||
790 |
// add the owning object to our list |
|
791 |
jvmtiMonitorStackDepthInfo *jmsdi; |
|
792 |
err = allocate(sizeof(jvmtiMonitorStackDepthInfo), (unsigned char **)&jmsdi); |
|
793 |
if (err != JVMTI_ERROR_NONE) { |
|
794 |
return err; |
|
795 |
} |
|
46271
979ebd346ecf
8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents:
37480
diff
changeset
|
796 |
Handle hobj(Thread::current(), obj); |
1 | 797 |
jmsdi->monitor = jni_reference(calling_thread, hobj); |
798 |
jmsdi->stack_depth = stack_depth; |
|
799 |
owned_monitors_list->append(jmsdi); |
|
800 |
} |
|
801 |
||
802 |
return err; |
|
803 |
} |
|
804 |
||
805 |
jvmtiError |
|
806 |
JvmtiEnvBase::get_stack_trace(JavaThread *java_thread, |
|
807 |
jint start_depth, jint max_count, |
|
808 |
jvmtiFrameInfo* frame_buffer, jint* count_ptr) { |
|
809 |
#ifdef ASSERT |
|
810 |
uint32_t debug_bits = 0; |
|
811 |
#endif |
|
812 |
assert((SafepointSynchronize::is_at_safepoint() || |
|
48105
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
813 |
java_thread->is_thread_fully_suspended(false, &debug_bits)), |
1 | 814 |
"at safepoint or target thread is suspended"); |
815 |
int count = 0; |
|
816 |
if (java_thread->has_last_Java_frame()) { |
|
817 |
RegisterMap reg_map(java_thread); |
|
818 |
Thread* current_thread = Thread::current(); |
|
819 |
ResourceMark rm(current_thread); |
|
820 |
javaVFrame *jvf = java_thread->last_java_vframe(®_map); |
|
821 |
HandleMark hm(current_thread); |
|
822 |
if (start_depth != 0) { |
|
823 |
if (start_depth > 0) { |
|
824 |
for (int j = 0; j < start_depth && jvf != NULL; j++) { |
|
825 |
jvf = jvf->java_sender(); |
|
826 |
} |
|
827 |
if (jvf == NULL) { |
|
828 |
// start_depth is deeper than the stack depth |
|
829 |
return JVMTI_ERROR_ILLEGAL_ARGUMENT; |
|
830 |
} |
|
831 |
} else { // start_depth < 0 |
|
832 |
// we are referencing the starting depth based on the oldest |
|
833 |
// part of the stack. |
|
834 |
// optimize to limit the number of times that java_sender() is called |
|
835 |
javaVFrame *jvf_cursor = jvf; |
|
836 |
javaVFrame *jvf_prev = NULL; |
|
31024
b619cc1d6ea6
8080928: Uninitialised variable in hotspot/src/share/vm/prims/jvmtiEnvBase.cpp
sla
parents:
29081
diff
changeset
|
837 |
javaVFrame *jvf_prev_prev = NULL; |
1 | 838 |
int j = 0; |
839 |
while (jvf_cursor != NULL) { |
|
840 |
jvf_prev_prev = jvf_prev; |
|
841 |
jvf_prev = jvf_cursor; |
|
842 |
for (j = 0; j > start_depth && jvf_cursor != NULL; j--) { |
|
843 |
jvf_cursor = jvf_cursor->java_sender(); |
|
844 |
} |
|
845 |
} |
|
846 |
if (j == start_depth) { |
|
847 |
// previous pointer is exactly where we want to start |
|
848 |
jvf = jvf_prev; |
|
849 |
} else { |
|
850 |
// we need to back up further to get to the right place |
|
851 |
if (jvf_prev_prev == NULL) { |
|
852 |
// the -start_depth is greater than the stack depth |
|
853 |
return JVMTI_ERROR_ILLEGAL_ARGUMENT; |
|
854 |
} |
|
855 |
// j now is the number of frames on the stack starting with |
|
856 |
// jvf_prev, we start from jvf_prev_prev and move older on |
|
857 |
// the stack that many, the result is -start_depth frames |
|
858 |
// remaining. |
|
859 |
jvf = jvf_prev_prev; |
|
860 |
for (; j < 0; j++) { |
|
861 |
jvf = jvf->java_sender(); |
|
862 |
} |
|
863 |
} |
|
864 |
} |
|
865 |
} |
|
866 |
for (; count < max_count && jvf != NULL; count++) { |
|
867 |
frame_buffer[count].method = jvf->method()->jmethod_id(); |
|
868 |
frame_buffer[count].location = (jvf->method()->is_native() ? -1 : jvf->bci()); |
|
869 |
jvf = jvf->java_sender(); |
|
870 |
} |
|
871 |
} else { |
|
872 |
if (start_depth != 0) { |
|
873 |
// no frames and there is a starting depth |
|
874 |
return JVMTI_ERROR_ILLEGAL_ARGUMENT; |
|
875 |
} |
|
876 |
} |
|
877 |
*count_ptr = count; |
|
878 |
return JVMTI_ERROR_NONE; |
|
879 |
} |
|
880 |
||
881 |
jvmtiError |
|
882 |
JvmtiEnvBase::get_frame_count(JvmtiThreadState *state, jint *count_ptr) { |
|
883 |
assert((state != NULL), |
|
884 |
"JavaThread should create JvmtiThreadState before calling this method"); |
|
885 |
*count_ptr = state->count_frames(); |
|
886 |
return JVMTI_ERROR_NONE; |
|
887 |
} |
|
888 |
||
889 |
jvmtiError |
|
890 |
JvmtiEnvBase::get_frame_location(JavaThread *java_thread, jint depth, |
|
891 |
jmethodID* method_ptr, jlocation* location_ptr) { |
|
892 |
#ifdef ASSERT |
|
893 |
uint32_t debug_bits = 0; |
|
894 |
#endif |
|
895 |
assert((SafepointSynchronize::is_at_safepoint() || |
|
48105
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
896 |
java_thread->is_thread_fully_suspended(false, &debug_bits)), |
1 | 897 |
"at safepoint or target thread is suspended"); |
898 |
Thread* current_thread = Thread::current(); |
|
899 |
ResourceMark rm(current_thread); |
|
900 |
||
901 |
vframe *vf = vframeFor(java_thread, depth); |
|
902 |
if (vf == NULL) { |
|
903 |
return JVMTI_ERROR_NO_MORE_FRAMES; |
|
904 |
} |
|
905 |
||
906 |
// vframeFor should return a java frame. If it doesn't |
|
907 |
// it means we've got an internal error and we return the |
|
908 |
// error in product mode. In debug mode we will instead |
|
909 |
// attempt to cast the vframe to a javaVFrame and will |
|
910 |
// cause an assertion/crash to allow further diagnosis. |
|
911 |
#ifdef PRODUCT |
|
912 |
if (!vf->is_java_frame()) { |
|
913 |
return JVMTI_ERROR_INTERNAL; |
|
914 |
} |
|
915 |
#endif |
|
916 |
||
917 |
HandleMark hm(current_thread); |
|
918 |
javaVFrame *jvf = javaVFrame::cast(vf); |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
919 |
Method* method = jvf->method(); |
1 | 920 |
if (method->is_native()) { |
921 |
*location_ptr = -1; |
|
922 |
} else { |
|
923 |
*location_ptr = jvf->bci(); |
|
924 |
} |
|
925 |
*method_ptr = method->jmethod_id(); |
|
926 |
||
927 |
return JVMTI_ERROR_NONE; |
|
928 |
} |
|
929 |
||
930 |
||
931 |
jvmtiError |
|
932 |
JvmtiEnvBase::get_object_monitor_usage(JavaThread* calling_thread, jobject object, jvmtiMonitorUsage* info_ptr) { |
|
933 |
HandleMark hm; |
|
934 |
Handle hobj; |
|
935 |
||
46271
979ebd346ecf
8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents:
37480
diff
changeset
|
936 |
Thread* current_thread = Thread::current(); |
1 | 937 |
bool at_safepoint = SafepointSynchronize::is_at_safepoint(); |
938 |
||
939 |
// Check arguments |
|
940 |
{ |
|
941 |
oop mirror = JNIHandles::resolve_external_guard(object); |
|
942 |
NULL_CHECK(mirror, JVMTI_ERROR_INVALID_OBJECT); |
|
943 |
NULL_CHECK(info_ptr, JVMTI_ERROR_NULL_POINTER); |
|
944 |
||
46271
979ebd346ecf
8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents:
37480
diff
changeset
|
945 |
hobj = Handle(current_thread, mirror); |
1 | 946 |
} |
947 |
||
948 |
JavaThread *owning_thread = NULL; |
|
949 |
ObjectMonitor *mon = NULL; |
|
950 |
jvmtiMonitorUsage ret = { |
|
951 |
NULL, 0, 0, NULL, 0, NULL |
|
952 |
}; |
|
953 |
||
954 |
uint32_t debug_bits = 0; |
|
955 |
// first derive the object's owner and entry_count (if any) |
|
956 |
{ |
|
957 |
// Revoke any biases before querying the mark word |
|
48105
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
958 |
if (at_safepoint) { |
1 | 959 |
BiasedLocking::revoke_at_safepoint(hobj); |
960 |
} else { |
|
961 |
BiasedLocking::revoke_and_rebias(hobj, false, calling_thread); |
|
962 |
} |
|
963 |
||
964 |
address owner = NULL; |
|
965 |
{ |
|
966 |
markOop mark = hobj()->mark(); |
|
967 |
||
968 |
if (!mark->has_monitor()) { |
|
969 |
// this object has a lightweight monitor |
|
970 |
||
971 |
if (mark->has_locker()) { |
|
972 |
owner = (address)mark->locker(); // save the address of the Lock word |
|
973 |
} |
|
974 |
// implied else: no owner |
|
975 |
} else { |
|
976 |
// this object has a heavyweight monitor |
|
977 |
mon = mark->monitor(); |
|
978 |
||
979 |
// The owner field of a heavyweight monitor may be NULL for no |
|
980 |
// owner, a JavaThread * or it may still be the address of the |
|
981 |
// Lock word in a JavaThread's stack. A monitor can be inflated |
|
982 |
// by a non-owning JavaThread, but only the owning JavaThread |
|
983 |
// can change the owner field from the Lock word to the |
|
984 |
// JavaThread * and it may not have done that yet. |
|
985 |
owner = (address)mon->owner(); |
|
986 |
} |
|
987 |
} |
|
988 |
||
989 |
if (owner != NULL) { |
|
48105
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
990 |
// Use current thread since function can be called from a |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
991 |
// JavaThread or the VMThread. |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
992 |
ThreadsListHandle tlh; |
1 | 993 |
// This monitor is owned so we have to find the owning JavaThread. |
48105
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
994 |
owning_thread = Threads::owning_thread_from_monitor_owner(tlh.list(), owner); |
15853
1c4e16950e96
8007476: assert(the_owner != NULL) failed: Did not find owning Java thread for lock word address
dcubed
parents:
15432
diff
changeset
|
995 |
// Cannot assume (owning_thread != NULL) here because this function |
1c4e16950e96
8007476: assert(the_owner != NULL) failed: Did not find owning Java thread for lock word address
dcubed
parents:
15432
diff
changeset
|
996 |
// may not have been called at a safepoint and the owning_thread |
1c4e16950e96
8007476: assert(the_owner != NULL) failed: Did not find owning Java thread for lock word address
dcubed
parents:
15432
diff
changeset
|
997 |
// might not be suspended. |
1c4e16950e96
8007476: assert(the_owner != NULL) failed: Did not find owning Java thread for lock word address
dcubed
parents:
15432
diff
changeset
|
998 |
if (owning_thread != NULL) { |
1 | 999 |
// The monitor's owner either has to be the current thread, at safepoint |
1000 |
// or it has to be suspended. Any of these conditions will prevent both |
|
1001 |
// contending and waiting threads from modifying the state of |
|
1002 |
// the monitor. |
|
48105
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1003 |
if (!at_safepoint && !owning_thread->is_thread_fully_suspended(true, &debug_bits)) { |
15853
1c4e16950e96
8007476: assert(the_owner != NULL) failed: Did not find owning Java thread for lock word address
dcubed
parents:
15432
diff
changeset
|
1004 |
// Don't worry! This return of JVMTI_ERROR_THREAD_NOT_SUSPENDED |
1c4e16950e96
8007476: assert(the_owner != NULL) failed: Did not find owning Java thread for lock word address
dcubed
parents:
15432
diff
changeset
|
1005 |
// will not make it back to the JVM/TI agent. The error code will |
1c4e16950e96
8007476: assert(the_owner != NULL) failed: Did not find owning Java thread for lock word address
dcubed
parents:
15432
diff
changeset
|
1006 |
// get intercepted in JvmtiEnv::GetObjectMonitorUsage() which |
1c4e16950e96
8007476: assert(the_owner != NULL) failed: Did not find owning Java thread for lock word address
dcubed
parents:
15432
diff
changeset
|
1007 |
// will retry the call via a VM_GetObjectMonitorUsage VM op. |
1 | 1008 |
return JVMTI_ERROR_THREAD_NOT_SUSPENDED; |
1009 |
} |
|
1010 |
HandleMark hm; |
|
46271
979ebd346ecf
8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents:
37480
diff
changeset
|
1011 |
Handle th(current_thread, owning_thread->threadObj()); |
1 | 1012 |
ret.owner = (jthread)jni_reference(calling_thread, th); |
1013 |
} |
|
1014 |
// implied else: no owner |
|
48105
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1015 |
} // ThreadsListHandle is destroyed here. |
1 | 1016 |
|
1017 |
if (owning_thread != NULL) { // monitor is owned |
|
23518
00028482ef09
8036666: VMTI GetObjectMonitorUsage does not return correct recursion count
asiebenborn
parents:
15853
diff
changeset
|
1018 |
// The recursions field of a monitor does not reflect recursions |
00028482ef09
8036666: VMTI GetObjectMonitorUsage does not return correct recursion count
asiebenborn
parents:
15853
diff
changeset
|
1019 |
// as lightweight locks before inflating the monitor are not included. |
00028482ef09
8036666: VMTI GetObjectMonitorUsage does not return correct recursion count
asiebenborn
parents:
15853
diff
changeset
|
1020 |
// We have to count the number of recursive monitor entries the hard way. |
00028482ef09
8036666: VMTI GetObjectMonitorUsage does not return correct recursion count
asiebenborn
parents:
15853
diff
changeset
|
1021 |
// We pass a handle to survive any GCs along the way. |
00028482ef09
8036666: VMTI GetObjectMonitorUsage does not return correct recursion count
asiebenborn
parents:
15853
diff
changeset
|
1022 |
ResourceMark rm; |
00028482ef09
8036666: VMTI GetObjectMonitorUsage does not return correct recursion count
asiebenborn
parents:
15853
diff
changeset
|
1023 |
ret.entry_count = count_locked_objects(owning_thread, hobj); |
1 | 1024 |
} |
1025 |
// implied else: entry_count == 0 |
|
1026 |
} |
|
1027 |
||
33589
7cbd1b2c139b
8139040: Fix initializations before ShouldNotReachHere() etc. and enable -Wuninitialized on linux.
goetz
parents:
31024
diff
changeset
|
1028 |
jint nWant = 0, nWait = 0; |
1 | 1029 |
if (mon != NULL) { |
1030 |
// this object has a heavyweight monitor |
|
1031 |
nWant = mon->contentions(); // # of threads contending for monitor |
|
1032 |
nWait = mon->waiters(); // # of threads in Object.wait() |
|
1033 |
ret.waiter_count = nWant + nWait; |
|
1034 |
ret.notify_waiter_count = nWait; |
|
1035 |
} else { |
|
1036 |
// this object has a lightweight monitor |
|
1037 |
ret.waiter_count = 0; |
|
1038 |
ret.notify_waiter_count = 0; |
|
1039 |
} |
|
1040 |
||
1041 |
// Allocate memory for heavyweight and lightweight monitor. |
|
1042 |
jvmtiError err; |
|
1043 |
err = allocate(ret.waiter_count * sizeof(jthread *), (unsigned char**)&ret.waiters); |
|
1044 |
if (err != JVMTI_ERROR_NONE) { |
|
1045 |
return err; |
|
1046 |
} |
|
1047 |
err = allocate(ret.notify_waiter_count * sizeof(jthread *), |
|
1048 |
(unsigned char**)&ret.notify_waiters); |
|
1049 |
if (err != JVMTI_ERROR_NONE) { |
|
1050 |
deallocate((unsigned char*)ret.waiters); |
|
1051 |
return err; |
|
1052 |
} |
|
1053 |
||
1054 |
// now derive the rest of the fields |
|
1055 |
if (mon != NULL) { |
|
1056 |
// this object has a heavyweight monitor |
|
1057 |
||
1058 |
// Number of waiters may actually be less than the waiter count. |
|
1059 |
// So NULL out memory so that unused memory will be NULL. |
|
1060 |
memset(ret.waiters, 0, ret.waiter_count * sizeof(jthread *)); |
|
1061 |
memset(ret.notify_waiters, 0, ret.notify_waiter_count * sizeof(jthread *)); |
|
1062 |
||
1063 |
if (ret.waiter_count > 0) { |
|
1064 |
// we have contending and/or waiting threads |
|
1065 |
HandleMark hm; |
|
48105
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1066 |
// Use current thread since function can be called from a |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1067 |
// JavaThread or the VMThread. |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1068 |
ThreadsListHandle tlh; |
1 | 1069 |
if (nWant > 0) { |
1070 |
// we have contending threads |
|
1071 |
ResourceMark rm; |
|
1072 |
// get_pending_threads returns only java thread so we do not need to |
|
48105
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1073 |
// check for non java threads. |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1074 |
GrowableArray<JavaThread*>* wantList = Threads::get_pending_threads(tlh.list(), nWant, (address)mon); |
1 | 1075 |
if (wantList->length() < nWant) { |
1076 |
// robustness: the pending list has gotten smaller |
|
1077 |
nWant = wantList->length(); |
|
1078 |
} |
|
1079 |
for (int i = 0; i < nWant; i++) { |
|
1080 |
JavaThread *pending_thread = wantList->at(i); |
|
1081 |
// If the monitor has no owner, then a non-suspended contending |
|
1082 |
// thread could potentially change the state of the monitor by |
|
1083 |
// entering it. The JVM/TI spec doesn't allow this. |
|
1084 |
if (owning_thread == NULL && !at_safepoint & |
|
48105
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1085 |
!pending_thread->is_thread_fully_suspended(true, &debug_bits)) { |
1 | 1086 |
if (ret.owner != NULL) { |
1087 |
destroy_jni_reference(calling_thread, ret.owner); |
|
1088 |
} |
|
1089 |
for (int j = 0; j < i; j++) { |
|
1090 |
destroy_jni_reference(calling_thread, ret.waiters[j]); |
|
1091 |
} |
|
1092 |
deallocate((unsigned char*)ret.waiters); |
|
1093 |
deallocate((unsigned char*)ret.notify_waiters); |
|
1094 |
return JVMTI_ERROR_THREAD_NOT_SUSPENDED; |
|
1095 |
} |
|
46271
979ebd346ecf
8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents:
37480
diff
changeset
|
1096 |
Handle th(current_thread, pending_thread->threadObj()); |
1 | 1097 |
ret.waiters[i] = (jthread)jni_reference(calling_thread, th); |
1098 |
} |
|
1099 |
} |
|
1100 |
if (nWait > 0) { |
|
1101 |
// we have threads in Object.wait() |
|
1102 |
int offset = nWant; // add after any contending threads |
|
1103 |
ObjectWaiter *waiter = mon->first_waiter(); |
|
1104 |
for (int i = 0, j = 0; i < nWait; i++) { |
|
1105 |
if (waiter == NULL) { |
|
1106 |
// robustness: the waiting list has gotten smaller |
|
1107 |
nWait = j; |
|
1108 |
break; |
|
1109 |
} |
|
1110 |
Thread *t = mon->thread_of_waiter(waiter); |
|
1111 |
if (t != NULL && t->is_Java_thread()) { |
|
1112 |
JavaThread *wjava_thread = (JavaThread *)t; |
|
1113 |
// If the thread was found on the ObjectWaiter list, then |
|
1114 |
// it has not been notified. This thread can't change the |
|
1115 |
// state of the monitor so it doesn't need to be suspended. |
|
46271
979ebd346ecf
8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents:
37480
diff
changeset
|
1116 |
Handle th(current_thread, wjava_thread->threadObj()); |
1 | 1117 |
ret.waiters[offset + j] = (jthread)jni_reference(calling_thread, th); |
1118 |
ret.notify_waiters[j++] = (jthread)jni_reference(calling_thread, th); |
|
1119 |
} |
|
1120 |
waiter = mon->next_waiter(waiter); |
|
1121 |
} |
|
1122 |
} |
|
48105
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1123 |
} // ThreadsListHandle is destroyed here. |
1 | 1124 |
|
1125 |
// Adjust count. nWant and nWait count values may be less than original. |
|
1126 |
ret.waiter_count = nWant + nWait; |
|
1127 |
ret.notify_waiter_count = nWait; |
|
1128 |
} else { |
|
1129 |
// this object has a lightweight monitor and we have nothing more |
|
1130 |
// to do here because the defaults are just fine. |
|
1131 |
} |
|
1132 |
||
1133 |
// we don't update return parameter unless everything worked |
|
1134 |
*info_ptr = ret; |
|
1135 |
||
1136 |
return JVMTI_ERROR_NONE; |
|
1137 |
} |
|
1138 |
||
1139 |
ResourceTracker::ResourceTracker(JvmtiEnv* env) { |
|
1140 |
_env = env; |
|
13195 | 1141 |
_allocations = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<unsigned char*>(20, true); |
1 | 1142 |
_failed = false; |
1143 |
} |
|
1144 |
ResourceTracker::~ResourceTracker() { |
|
1145 |
if (_failed) { |
|
1146 |
for (int i=0; i<_allocations->length(); i++) { |
|
1147 |
_env->deallocate(_allocations->at(i)); |
|
1148 |
} |
|
1149 |
} |
|
1150 |
delete _allocations; |
|
1151 |
} |
|
1152 |
||
1153 |
jvmtiError ResourceTracker::allocate(jlong size, unsigned char** mem_ptr) { |
|
1154 |
unsigned char *ptr; |
|
1155 |
jvmtiError err = _env->allocate(size, &ptr); |
|
1156 |
if (err == JVMTI_ERROR_NONE) { |
|
1157 |
_allocations->append(ptr); |
|
1158 |
*mem_ptr = ptr; |
|
1159 |
} else { |
|
1160 |
*mem_ptr = NULL; |
|
1161 |
_failed = true; |
|
1162 |
} |
|
1163 |
return err; |
|
1164 |
} |
|
1165 |
||
1166 |
unsigned char* ResourceTracker::allocate(jlong size) { |
|
1167 |
unsigned char* ptr; |
|
1168 |
allocate(size, &ptr); |
|
1169 |
return ptr; |
|
1170 |
} |
|
1171 |
||
1172 |
char* ResourceTracker::strdup(const char* str) { |
|
1173 |
char *dup_str = (char*)allocate(strlen(str)+1); |
|
1174 |
if (dup_str != NULL) { |
|
1175 |
strcpy(dup_str, str); |
|
1176 |
} |
|
1177 |
return dup_str; |
|
1178 |
} |
|
1179 |
||
1180 |
struct StackInfoNode { |
|
1181 |
struct StackInfoNode *next; |
|
1182 |
jvmtiStackInfo info; |
|
1183 |
}; |
|
1184 |
||
1185 |
// Create a jvmtiStackInfo inside a linked list node and create a |
|
1186 |
// buffer for the frame information, both allocated as resource objects. |
|
1187 |
// Fill in both the jvmtiStackInfo and the jvmtiFrameInfo. |
|
1188 |
// Note that either or both of thr and thread_oop |
|
1189 |
// may be null if the thread is new or has exited. |
|
1190 |
void |
|
1191 |
VM_GetMultipleStackTraces::fill_frames(jthread jt, JavaThread *thr, oop thread_oop) { |
|
1192 |
assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint"); |
|
1193 |
||
1194 |
jint state = 0; |
|
1195 |
struct StackInfoNode *node = NEW_RESOURCE_OBJ(struct StackInfoNode); |
|
1196 |
jvmtiStackInfo *infop = &(node->info); |
|
1197 |
node->next = head(); |
|
1198 |
set_head(node); |
|
1199 |
infop->frame_count = 0; |
|
1200 |
infop->thread = jt; |
|
1201 |
||
1202 |
if (thread_oop != NULL) { |
|
1203 |
// get most state bits |
|
1204 |
state = (jint)java_lang_Thread::get_thread_status(thread_oop); |
|
1205 |
} |
|
1206 |
||
1207 |
if (thr != NULL) { // add more state bits if there is a JavaThead to query |
|
1208 |
// same as is_being_ext_suspended() but without locking |
|
1209 |
if (thr->is_ext_suspended() || thr->is_external_suspend()) { |
|
1210 |
state |= JVMTI_THREAD_STATE_SUSPENDED; |
|
1211 |
} |
|
1212 |
JavaThreadState jts = thr->thread_state(); |
|
1213 |
if (jts == _thread_in_native) { |
|
1214 |
state |= JVMTI_THREAD_STATE_IN_NATIVE; |
|
1215 |
} |
|
1216 |
OSThread* osThread = thr->osthread(); |
|
1217 |
if (osThread != NULL && osThread->interrupted()) { |
|
1218 |
state |= JVMTI_THREAD_STATE_INTERRUPTED; |
|
1219 |
} |
|
1220 |
} |
|
1221 |
infop->state = state; |
|
1222 |
||
51070 | 1223 |
if (thr != NULL && (state & JVMTI_THREAD_STATE_ALIVE) != 0) { |
1 | 1224 |
infop->frame_buffer = NEW_RESOURCE_ARRAY(jvmtiFrameInfo, max_frame_count()); |
1225 |
env()->get_stack_trace(thr, 0, max_frame_count(), |
|
1226 |
infop->frame_buffer, &(infop->frame_count)); |
|
1227 |
} else { |
|
1228 |
infop->frame_buffer = NULL; |
|
1229 |
infop->frame_count = 0; |
|
1230 |
} |
|
1231 |
_frame_count_total += infop->frame_count; |
|
1232 |
} |
|
1233 |
||
1234 |
// Based on the stack information in the linked list, allocate memory |
|
1235 |
// block to return and fill it from the info in the linked list. |
|
1236 |
void |
|
1237 |
VM_GetMultipleStackTraces::allocate_and_fill_stacks(jint thread_count) { |
|
1238 |
// do I need to worry about alignment issues? |
|
1239 |
jlong alloc_size = thread_count * sizeof(jvmtiStackInfo) |
|
1240 |
+ _frame_count_total * sizeof(jvmtiFrameInfo); |
|
1241 |
env()->allocate(alloc_size, (unsigned char **)&_stack_info); |
|
1242 |
||
1243 |
// pointers to move through the newly allocated space as it is filled in |
|
1244 |
jvmtiStackInfo *si = _stack_info + thread_count; // bottom of stack info |
|
1245 |
jvmtiFrameInfo *fi = (jvmtiFrameInfo *)si; // is the top of frame info |
|
1246 |
||
1247 |
// copy information in resource area into allocated buffer |
|
1248 |
// insert stack info backwards since linked list is backwards |
|
1249 |
// insert frame info forwards |
|
1250 |
// walk the StackInfoNodes |
|
1251 |
for (struct StackInfoNode *sin = head(); sin != NULL; sin = sin->next) { |
|
1252 |
jint frame_count = sin->info.frame_count; |
|
1253 |
size_t frames_size = frame_count * sizeof(jvmtiFrameInfo); |
|
1254 |
--si; |
|
1255 |
memcpy(si, &(sin->info), sizeof(jvmtiStackInfo)); |
|
1256 |
if (frames_size == 0) { |
|
1257 |
si->frame_buffer = NULL; |
|
1258 |
} else { |
|
1259 |
memcpy(fi, sin->info.frame_buffer, frames_size); |
|
1260 |
si->frame_buffer = fi; // point to the new allocated copy of the frames |
|
1261 |
fi += frame_count; |
|
1262 |
} |
|
1263 |
} |
|
1264 |
assert(si == _stack_info, "the last copied stack info must be the first record"); |
|
1265 |
assert((unsigned char *)fi == ((unsigned char *)_stack_info) + alloc_size, |
|
1266 |
"the last copied frame info must be the last record"); |
|
1267 |
} |
|
1268 |
||
1269 |
||
1270 |
void |
|
1271 |
VM_GetThreadListStackTraces::doit() { |
|
1272 |
assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint"); |
|
1273 |
||
1274 |
ResourceMark rm; |
|
48105
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1275 |
ThreadsListHandle tlh; |
1 | 1276 |
for (int i = 0; i < _thread_count; ++i) { |
1277 |
jthread jt = _thread_list[i]; |
|
48105
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1278 |
JavaThread* java_thread = NULL; |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1279 |
oop thread_oop = NULL; |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1280 |
jvmtiError err = JvmtiExport::cv_external_thread_to_JavaThread(tlh.list(), jt, &java_thread, &thread_oop); |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1281 |
if (err != JVMTI_ERROR_NONE) { |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1282 |
// We got an error code so we don't have a JavaThread *, but |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1283 |
// only return an error from here if we didn't get a valid |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1284 |
// thread_oop. |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1285 |
if (thread_oop == NULL) { |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1286 |
set_result(err); |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1287 |
return; |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1288 |
} |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1289 |
// We have a valid thread_oop. |
1 | 1290 |
} |
48105
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1291 |
fill_frames(jt, java_thread, thread_oop); |
1 | 1292 |
} |
1293 |
allocate_and_fill_stacks(_thread_count); |
|
1294 |
} |
|
1295 |
||
1296 |
void |
|
1297 |
VM_GetAllStackTraces::doit() { |
|
1298 |
assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint"); |
|
1299 |
||
1300 |
ResourceMark rm; |
|
1301 |
_final_thread_count = 0; |
|
48105
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1302 |
for (JavaThreadIteratorWithHandle jtiwh; JavaThread *jt = jtiwh.next(); ) { |
1 | 1303 |
oop thread_oop = jt->threadObj(); |
1304 |
if (thread_oop != NULL && |
|
1305 |
!jt->is_exiting() && |
|
1306 |
java_lang_Thread::is_alive(thread_oop) && |
|
1307 |
!jt->is_hidden_from_external_view()) { |
|
1308 |
++_final_thread_count; |
|
1309 |
// Handle block of the calling thread is used to create local refs. |
|
1310 |
fill_frames((jthread)JNIHandles::make_local(_calling_thread, thread_oop), |
|
1311 |
jt, thread_oop); |
|
1312 |
} |
|
1313 |
} |
|
1314 |
allocate_and_fill_stacks(_final_thread_count); |
|
1315 |
} |
|
1316 |
||
1317 |
// Verifies that the top frame is a java frame in an expected state. |
|
1318 |
// Deoptimizes frame if needed. |
|
1319 |
// Checks that the frame method signature matches the return type (tos). |
|
1320 |
// HandleMark must be defined in the caller only. |
|
1321 |
// It is to keep a ret_ob_h handle alive after return to the caller. |
|
1322 |
jvmtiError |
|
1323 |
JvmtiEnvBase::check_top_frame(JavaThread* current_thread, JavaThread* java_thread, |
|
1324 |
jvalue value, TosState tos, Handle* ret_ob_h) { |
|
1325 |
ResourceMark rm(current_thread); |
|
1326 |
||
1327 |
vframe *vf = vframeFor(java_thread, 0); |
|
1328 |
NULL_CHECK(vf, JVMTI_ERROR_NO_MORE_FRAMES); |
|
1329 |
||
1330 |
javaVFrame *jvf = (javaVFrame*) vf; |
|
1331 |
if (!vf->is_java_frame() || jvf->method()->is_native()) { |
|
1332 |
return JVMTI_ERROR_OPAQUE_FRAME; |
|
1333 |
} |
|
1334 |
||
1335 |
// If the frame is a compiled one, need to deoptimize it. |
|
1336 |
if (vf->is_compiled_frame()) { |
|
1337 |
if (!vf->fr().can_be_deoptimized()) { |
|
1338 |
return JVMTI_ERROR_OPAQUE_FRAME; |
|
1339 |
} |
|
7106
867c9d296c6b
6968367: can_post_on_exceptions is still using VM_DeoptimizeFrame in some places
never
parents:
5547
diff
changeset
|
1340 |
Deoptimization::deoptimize_frame(java_thread, jvf->fr().id()); |
1 | 1341 |
} |
1342 |
||
1343 |
// Get information about method return type |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7413
diff
changeset
|
1344 |
Symbol* signature = jvf->method()->signature(); |
1 | 1345 |
|
1346 |
ResultTypeFinder rtf(signature); |
|
1347 |
TosState fr_tos = as_TosState(rtf.type()); |
|
1348 |
if (fr_tos != tos) { |
|
37480 | 1349 |
if (tos != itos || (fr_tos != btos && fr_tos != ztos && fr_tos != ctos && fr_tos != stos)) { |
1 | 1350 |
return JVMTI_ERROR_TYPE_MISMATCH; |
1351 |
} |
|
1352 |
} |
|
1353 |
||
1354 |
// Check that the jobject class matches the return type signature. |
|
1355 |
jobject jobj = value.l; |
|
1356 |
if (tos == atos && jobj != NULL) { // NULL reference is allowed |
|
46271
979ebd346ecf
8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents:
37480
diff
changeset
|
1357 |
Handle ob_h(current_thread, JNIHandles::resolve_external_guard(jobj)); |
1 | 1358 |
NULL_CHECK(ob_h, JVMTI_ERROR_INVALID_OBJECT); |
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46271
diff
changeset
|
1359 |
Klass* ob_k = ob_h()->klass(); |
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46271
diff
changeset
|
1360 |
NULL_CHECK(ob_k, JVMTI_ERROR_INVALID_OBJECT); |
1 | 1361 |
|
1362 |
// Method return type signature. |
|
1363 |
char* ty_sign = 1 + strchr(signature->as_C_string(), ')'); |
|
1364 |
||
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46271
diff
changeset
|
1365 |
if (!VM_GetOrSetLocal::is_assignable(ty_sign, ob_k, current_thread)) { |
1 | 1366 |
return JVMTI_ERROR_TYPE_MISMATCH; |
1367 |
} |
|
1368 |
*ret_ob_h = ob_h; |
|
1369 |
} |
|
1370 |
return JVMTI_ERROR_NONE; |
|
1371 |
} /* end check_top_frame */ |
|
1372 |
||
1373 |
||
1374 |
// ForceEarlyReturn<type> follows the PopFrame approach in many aspects. |
|
1375 |
// Main difference is on the last stage in the interpreter. |
|
1376 |
// The PopFrame stops method execution to continue execution |
|
1377 |
// from the same method call instruction. |
|
1378 |
// The ForceEarlyReturn forces return from method so the execution |
|
1379 |
// continues at the bytecode following the method call. |
|
1380 |
||
1381 |
// Threads_lock NOT held, java_thread not protected by lock |
|
1382 |
// java_thread - pre-checked |
|
1383 |
||
1384 |
jvmtiError |
|
1385 |
JvmtiEnvBase::force_early_return(JavaThread* java_thread, jvalue value, TosState tos) { |
|
1386 |
JavaThread* current_thread = JavaThread::current(); |
|
1387 |
HandleMark hm(current_thread); |
|
1388 |
uint32_t debug_bits = 0; |
|
1389 |
||
2135
f82c3012ec86
6800721: 3/4 JavaThread::jvmti_thread_state() and JvmtiThreadState::state_for() robustness
dcubed
parents:
1623
diff
changeset
|
1390 |
// retrieve or create the state |
f82c3012ec86
6800721: 3/4 JavaThread::jvmti_thread_state() and JvmtiThreadState::state_for() robustness
dcubed
parents:
1623
diff
changeset
|
1391 |
JvmtiThreadState* state = JvmtiThreadState::state_for(java_thread); |
f82c3012ec86
6800721: 3/4 JavaThread::jvmti_thread_state() and JvmtiThreadState::state_for() robustness
dcubed
parents:
1623
diff
changeset
|
1392 |
if (state == NULL) { |
f82c3012ec86
6800721: 3/4 JavaThread::jvmti_thread_state() and JvmtiThreadState::state_for() robustness
dcubed
parents:
1623
diff
changeset
|
1393 |
return JVMTI_ERROR_THREAD_NOT_ALIVE; |
f82c3012ec86
6800721: 3/4 JavaThread::jvmti_thread_state() and JvmtiThreadState::state_for() robustness
dcubed
parents:
1623
diff
changeset
|
1394 |
} |
f82c3012ec86
6800721: 3/4 JavaThread::jvmti_thread_state() and JvmtiThreadState::state_for() robustness
dcubed
parents:
1623
diff
changeset
|
1395 |
|
1 | 1396 |
// Check if java_thread is fully suspended |
48105
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1397 |
if (!java_thread->is_thread_fully_suspended(true /* wait for suspend completion */, &debug_bits)) { |
1 | 1398 |
return JVMTI_ERROR_THREAD_NOT_SUSPENDED; |
1399 |
} |
|
1400 |
||
1401 |
// Check to see if a ForceEarlyReturn was already in progress |
|
1402 |
if (state->is_earlyret_pending()) { |
|
1403 |
// Probably possible for JVMTI clients to trigger this, but the |
|
1404 |
// JPDA backend shouldn't allow this to happen |
|
1405 |
return JVMTI_ERROR_INTERNAL; |
|
1406 |
} |
|
1407 |
{ |
|
1408 |
// The same as for PopFrame. Workaround bug: |
|
1409 |
// 4812902: popFrame hangs if the method is waiting at a synchronize |
|
1410 |
// Catch this condition and return an error to avoid hanging. |
|
1411 |
// Now JVMTI spec allows an implementation to bail out with an opaque |
|
1412 |
// frame error. |
|
1413 |
OSThread* osThread = java_thread->osthread(); |
|
1414 |
if (osThread->get_state() == MONITOR_WAIT) { |
|
1415 |
return JVMTI_ERROR_OPAQUE_FRAME; |
|
1416 |
} |
|
1417 |
} |
|
46271
979ebd346ecf
8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents:
37480
diff
changeset
|
1418 |
Handle ret_ob_h; |
1 | 1419 |
jvmtiError err = check_top_frame(current_thread, java_thread, value, tos, &ret_ob_h); |
1420 |
if (err != JVMTI_ERROR_NONE) { |
|
1421 |
return err; |
|
1422 |
} |
|
1423 |
assert(tos != atos || value.l == NULL || ret_ob_h() != NULL, |
|
1424 |
"return object oop must not be NULL if jobject is not NULL"); |
|
1425 |
||
1426 |
// Update the thread state to reflect that the top frame must be |
|
1427 |
// forced to return. |
|
1428 |
// The current frame will be returned later when the suspended |
|
1429 |
// thread is resumed and right before returning from VM to Java. |
|
1430 |
// (see call_VM_base() in assembler_<cpu>.cpp). |
|
1431 |
||
1432 |
state->set_earlyret_pending(); |
|
1433 |
state->set_earlyret_oop(ret_ob_h()); |
|
1434 |
state->set_earlyret_value(value, tos); |
|
1435 |
||
1436 |
// Set pending step flag for this early return. |
|
1437 |
// It is cleared when next step event is posted. |
|
1438 |
state->set_pending_step_for_earlyret(); |
|
1439 |
||
1440 |
return JVMTI_ERROR_NONE; |
|
1441 |
} /* end force_early_return */ |
|
1442 |
||
1443 |
void |
|
1444 |
JvmtiMonitorClosure::do_monitor(ObjectMonitor* mon) { |
|
1445 |
if ( _error != JVMTI_ERROR_NONE) { |
|
1446 |
// Error occurred in previous iteration so no need to add |
|
1447 |
// to the list. |
|
1448 |
return; |
|
1449 |
} |
|
1450 |
if (mon->owner() == _java_thread ) { |
|
1451 |
// Filter out on stack monitors collected during stack walk. |
|
1452 |
oop obj = (oop)mon->object(); |
|
1453 |
bool found = false; |
|
1454 |
for (int j = 0; j < _owned_monitors_list->length(); j++) { |
|
1455 |
jobject jobj = ((jvmtiMonitorStackDepthInfo*)_owned_monitors_list->at(j))->monitor; |
|
1456 |
oop check = JNIHandles::resolve(jobj); |
|
1457 |
if (check == obj) { |
|
1458 |
// On stack monitor already collected during the stack walk. |
|
1459 |
found = true; |
|
1460 |
break; |
|
1461 |
} |
|
1462 |
} |
|
1463 |
if (found == false) { |
|
1464 |
// This is off stack monitor (e.g. acquired via jni MonitorEnter). |
|
1465 |
jvmtiError err; |
|
1466 |
jvmtiMonitorStackDepthInfo *jmsdi; |
|
1467 |
err = _env->allocate(sizeof(jvmtiMonitorStackDepthInfo), (unsigned char **)&jmsdi); |
|
1468 |
if (err != JVMTI_ERROR_NONE) { |
|
1469 |
_error = err; |
|
1470 |
return; |
|
1471 |
} |
|
46271
979ebd346ecf
8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents:
37480
diff
changeset
|
1472 |
Handle hobj(Thread::current(), obj); |
1 | 1473 |
jmsdi->monitor = _env->jni_reference(_calling_thread, hobj); |
1474 |
// stack depth is unknown for this monitor. |
|
1475 |
jmsdi->stack_depth = -1; |
|
1476 |
_owned_monitors_list->append(jmsdi); |
|
1477 |
} |
|
1478 |
} |
|
1479 |
} |
|
36508 | 1480 |
|
46961
c9094b1e5f87
8186088: ConstantPoolCache::_resolved_references is not a JNIHandle
coleenp
parents:
46329
diff
changeset
|
1481 |
GrowableArray<OopHandle>* JvmtiModuleClosure::_tbl = NULL; |
36508 | 1482 |
|
49816 | 1483 |
void JvmtiModuleClosure::do_module(ModuleEntry* entry) { |
1484 |
assert_locked_or_safepoint(Module_lock); |
|
1485 |
OopHandle module = entry->module_handle(); |
|
1486 |
guarantee(module.resolve() != NULL, "module object is NULL"); |
|
1487 |
_tbl->push(module); |
|
1488 |
} |
|
1489 |
||
36508 | 1490 |
jvmtiError |
1491 |
JvmtiModuleClosure::get_all_modules(JvmtiEnv* env, jint* module_count_ptr, jobject** modules_ptr) { |
|
1492 |
ResourceMark rm; |
|
51608 | 1493 |
MutexLocker mcld(ClassLoaderDataGraph_lock); |
36508 | 1494 |
MutexLocker ml(Module_lock); |
1495 |
||
46961
c9094b1e5f87
8186088: ConstantPoolCache::_resolved_references is not a JNIHandle
coleenp
parents:
46329
diff
changeset
|
1496 |
_tbl = new GrowableArray<OopHandle>(77); |
36508 | 1497 |
if (_tbl == NULL) { |
1498 |
return JVMTI_ERROR_OUT_OF_MEMORY; |
|
1499 |
} |
|
1500 |
||
1501 |
// Iterate over all the modules loaded to the system. |
|
1502 |
ClassLoaderDataGraph::modules_do(&do_module); |
|
1503 |
||
1504 |
jint len = _tbl->length(); |
|
1505 |
guarantee(len > 0, "at least one module must be present"); |
|
1506 |
||
1507 |
jobject* array = (jobject*)env->jvmtiMalloc((jlong)(len * sizeof(jobject))); |
|
1508 |
if (array == NULL) { |
|
1509 |
return JVMTI_ERROR_OUT_OF_MEMORY; |
|
1510 |
} |
|
1511 |
for (jint idx = 0; idx < len; idx++) { |
|
46961
c9094b1e5f87
8186088: ConstantPoolCache::_resolved_references is not a JNIHandle
coleenp
parents:
46329
diff
changeset
|
1512 |
array[idx] = JNIHandles::make_local(Thread::current(), _tbl->at(idx).resolve()); |
36508 | 1513 |
} |
1514 |
_tbl = NULL; |
|
1515 |
*modules_ptr = array; |
|
1516 |
*module_count_ptr = len; |
|
1517 |
return JVMTI_ERROR_NONE; |
|
1518 |
} |
|
1519 |
||
48105
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1520 |
void |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1521 |
VM_UpdateForPopTopFrame::doit() { |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1522 |
JavaThread* jt = _state->get_thread(); |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1523 |
ThreadsListHandle tlh; |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1524 |
if (jt != NULL && tlh.includes(jt) && !jt->is_exiting() && jt->threadObj() != NULL) { |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1525 |
_state->update_for_pop_top_frame(); |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1526 |
} else { |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1527 |
_result = JVMTI_ERROR_THREAD_NOT_ALIVE; |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1528 |
} |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1529 |
} |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1530 |
|
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1531 |
void |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1532 |
VM_SetFramePop::doit() { |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1533 |
JavaThread* jt = _state->get_thread(); |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1534 |
ThreadsListHandle tlh; |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1535 |
if (jt != NULL && tlh.includes(jt) && !jt->is_exiting() && jt->threadObj() != NULL) { |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1536 |
int frame_number = _state->count_frames() - _depth; |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1537 |
_state->env_thread_state((JvmtiEnvBase*)_env)->set_frame_pop(frame_number); |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1538 |
} else { |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1539 |
_result = JVMTI_ERROR_THREAD_NOT_ALIVE; |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1540 |
} |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1541 |
} |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1542 |
|
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1543 |
void |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1544 |
VM_GetOwnedMonitorInfo::doit() { |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1545 |
_result = JVMTI_ERROR_THREAD_NOT_ALIVE; |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1546 |
ThreadsListHandle tlh; |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1547 |
if (_java_thread != NULL && tlh.includes(_java_thread) |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1548 |
&& !_java_thread->is_exiting() && _java_thread->threadObj() != NULL) { |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1549 |
_result = ((JvmtiEnvBase *)_env)->get_owned_monitors(_calling_thread, _java_thread, |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1550 |
_owned_monitors_list); |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1551 |
} |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1552 |
} |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1553 |
|
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1554 |
void |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1555 |
VM_GetCurrentContendedMonitor::doit() { |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1556 |
_result = JVMTI_ERROR_THREAD_NOT_ALIVE; |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1557 |
ThreadsListHandle tlh; |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1558 |
if (_java_thread != NULL && tlh.includes(_java_thread) |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1559 |
&& !_java_thread->is_exiting() && _java_thread->threadObj() != NULL) { |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1560 |
_result = ((JvmtiEnvBase *)_env)->get_current_contended_monitor(_calling_thread,_java_thread,_owned_monitor_ptr); |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1561 |
} |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1562 |
} |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1563 |
|
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1564 |
void |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1565 |
VM_GetStackTrace::doit() { |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1566 |
_result = JVMTI_ERROR_THREAD_NOT_ALIVE; |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1567 |
ThreadsListHandle tlh; |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1568 |
if (_java_thread != NULL && tlh.includes(_java_thread) |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1569 |
&& !_java_thread->is_exiting() && _java_thread->threadObj() != NULL) { |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1570 |
_result = ((JvmtiEnvBase *)_env)->get_stack_trace(_java_thread, |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1571 |
_start_depth, _max_count, |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1572 |
_frame_buffer, _count_ptr); |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1573 |
} |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1574 |
} |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1575 |
|
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1576 |
void |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1577 |
VM_GetFrameCount::doit() { |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1578 |
_result = JVMTI_ERROR_THREAD_NOT_ALIVE; |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1579 |
JavaThread* jt = _state->get_thread(); |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1580 |
ThreadsListHandle tlh; |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1581 |
if (jt != NULL && tlh.includes(jt) && !jt->is_exiting() && jt->threadObj() != NULL) { |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1582 |
_result = ((JvmtiEnvBase*)_env)->get_frame_count(_state, _count_ptr); |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1583 |
} |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1584 |
} |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1585 |
|
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1586 |
void |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1587 |
VM_GetFrameLocation::doit() { |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1588 |
_result = JVMTI_ERROR_THREAD_NOT_ALIVE; |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1589 |
ThreadsListHandle tlh; |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1590 |
if (_java_thread != NULL && tlh.includes(_java_thread) |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1591 |
&& !_java_thread->is_exiting() && _java_thread->threadObj() != NULL) { |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1592 |
_result = ((JvmtiEnvBase*)_env)->get_frame_location(_java_thread, _depth, |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1593 |
_method_ptr, _location_ptr); |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1594 |
} |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
1595 |
} |