Mercurial > hg > truffle
annotate src/share/vm/prims/jvmtiImpl.cpp @ 2125:7246a374a9f2
6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
Summary: Make JvmtiGCMark safe to run non-safepoint and instrument CMS
Reviewed-by: ysr, dcubed
author | kamg |
---|---|
date | Mon, 10 Jan 2011 17:14:53 -0500 |
parents | 09b4dd4f152b |
children | 9afee0b9fc1d |
rev | line source |
---|---|
0 | 1 /* |
1972 | 2 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. |
0 | 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 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
611
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
611
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
611
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
1972 | 25 #include "precompiled.hpp" |
26 #include "classfile/systemDictionary.hpp" | |
27 #include "interpreter/interpreter.hpp" | |
28 #include "jvmtifiles/jvmtiEnv.hpp" | |
29 #include "memory/resourceArea.hpp" | |
30 #include "oops/instanceKlass.hpp" | |
31 #include "prims/jvmtiAgentThread.hpp" | |
32 #include "prims/jvmtiEventController.inline.hpp" | |
33 #include "prims/jvmtiImpl.hpp" | |
34 #include "prims/jvmtiRedefineClasses.hpp" | |
35 #include "runtime/deoptimization.hpp" | |
36 #include "runtime/handles.hpp" | |
37 #include "runtime/handles.inline.hpp" | |
38 #include "runtime/interfaceSupport.hpp" | |
39 #include "runtime/javaCalls.hpp" | |
40 #include "runtime/signature.hpp" | |
41 #include "runtime/vframe.hpp" | |
42 #include "runtime/vframe_hp.hpp" | |
43 #include "runtime/vm_operations.hpp" | |
44 #include "utilities/exceptions.hpp" | |
45 #ifdef TARGET_OS_FAMILY_linux | |
46 # include "thread_linux.inline.hpp" | |
47 #endif | |
48 #ifdef TARGET_OS_FAMILY_solaris | |
49 # include "thread_solaris.inline.hpp" | |
50 #endif | |
51 #ifdef TARGET_OS_FAMILY_windows | |
52 # include "thread_windows.inline.hpp" | |
53 #endif | |
0 | 54 |
55 // | |
56 // class JvmtiAgentThread | |
57 // | |
58 // JavaThread used to wrap a thread started by an agent | |
59 // using the JVMTI method RunAgentThread. | |
60 // | |
61 | |
62 JvmtiAgentThread::JvmtiAgentThread(JvmtiEnv* env, jvmtiStartFunction start_fn, const void *start_arg) | |
63 : JavaThread(start_function_wrapper) { | |
64 _env = env; | |
65 _start_fn = start_fn; | |
66 _start_arg = start_arg; | |
67 } | |
68 | |
69 void | |
70 JvmtiAgentThread::start_function_wrapper(JavaThread *thread, TRAPS) { | |
71 // It is expected that any Agent threads will be created as | |
72 // Java Threads. If this is the case, notification of the creation | |
73 // of the thread is given in JavaThread::thread_main(). | |
74 assert(thread->is_Java_thread(), "debugger thread should be a Java Thread"); | |
75 assert(thread == JavaThread::current(), "sanity check"); | |
76 | |
77 JvmtiAgentThread *dthread = (JvmtiAgentThread *)thread; | |
78 dthread->call_start_function(); | |
79 } | |
80 | |
81 void | |
82 JvmtiAgentThread::call_start_function() { | |
83 ThreadToNativeFromVM transition(this); | |
84 _start_fn(_env->jvmti_external(), jni_environment(), (void*)_start_arg); | |
85 } | |
86 | |
87 | |
88 // | |
89 // class GrowableCache - private methods | |
90 // | |
91 | |
92 void GrowableCache::recache() { | |
93 int len = _elements->length(); | |
94 | |
95 FREE_C_HEAP_ARRAY(address, _cache); | |
96 _cache = NEW_C_HEAP_ARRAY(address,len+1); | |
97 | |
98 for (int i=0; i<len; i++) { | |
99 _cache[i] = _elements->at(i)->getCacheValue(); | |
100 // | |
101 // The cache entry has gone bad. Without a valid frame pointer | |
102 // value, the entry is useless so we simply delete it in product | |
103 // mode. The call to remove() will rebuild the cache again | |
104 // without the bad entry. | |
105 // | |
106 if (_cache[i] == NULL) { | |
107 assert(false, "cannot recache NULL elements"); | |
108 remove(i); | |
109 return; | |
110 } | |
111 } | |
112 _cache[len] = NULL; | |
113 | |
114 _listener_fun(_this_obj,_cache); | |
115 } | |
116 | |
117 bool GrowableCache::equals(void* v, GrowableElement *e2) { | |
118 GrowableElement *e1 = (GrowableElement *) v; | |
119 assert(e1 != NULL, "e1 != NULL"); | |
120 assert(e2 != NULL, "e2 != NULL"); | |
121 | |
122 return e1->equals(e2); | |
123 } | |
124 | |
125 // | |
126 // class GrowableCache - public methods | |
127 // | |
128 | |
129 GrowableCache::GrowableCache() { | |
130 _this_obj = NULL; | |
131 _listener_fun = NULL; | |
132 _elements = NULL; | |
133 _cache = NULL; | |
134 } | |
135 | |
136 GrowableCache::~GrowableCache() { | |
137 clear(); | |
138 delete _elements; | |
139 FREE_C_HEAP_ARRAY(address, _cache); | |
140 } | |
141 | |
142 void GrowableCache::initialize(void *this_obj, void listener_fun(void *, address*) ) { | |
143 _this_obj = this_obj; | |
144 _listener_fun = listener_fun; | |
145 _elements = new (ResourceObj::C_HEAP) GrowableArray<GrowableElement*>(5,true); | |
146 recache(); | |
147 } | |
148 | |
149 // number of elements in the collection | |
150 int GrowableCache::length() { | |
151 return _elements->length(); | |
152 } | |
153 | |
154 // get the value of the index element in the collection | |
155 GrowableElement* GrowableCache::at(int index) { | |
156 GrowableElement *e = (GrowableElement *) _elements->at(index); | |
157 assert(e != NULL, "e != NULL"); | |
158 return e; | |
159 } | |
160 | |
161 int GrowableCache::find(GrowableElement* e) { | |
162 return _elements->find(e, GrowableCache::equals); | |
163 } | |
164 | |
165 // append a copy of the element to the end of the collection | |
166 void GrowableCache::append(GrowableElement* e) { | |
167 GrowableElement *new_e = e->clone(); | |
168 _elements->append(new_e); | |
169 recache(); | |
170 } | |
171 | |
172 // insert a copy of the element using lessthan() | |
173 void GrowableCache::insert(GrowableElement* e) { | |
174 GrowableElement *new_e = e->clone(); | |
175 _elements->append(new_e); | |
176 | |
177 int n = length()-2; | |
178 for (int i=n; i>=0; i--) { | |
179 GrowableElement *e1 = _elements->at(i); | |
180 GrowableElement *e2 = _elements->at(i+1); | |
181 if (e2->lessThan(e1)) { | |
182 _elements->at_put(i+1, e1); | |
183 _elements->at_put(i, e2); | |
184 } | |
185 } | |
186 | |
187 recache(); | |
188 } | |
189 | |
190 // remove the element at index | |
191 void GrowableCache::remove (int index) { | |
192 GrowableElement *e = _elements->at(index); | |
193 assert(e != NULL, "e != NULL"); | |
194 _elements->remove(e); | |
195 delete e; | |
196 recache(); | |
197 } | |
198 | |
199 // clear out all elements, release all heap space and | |
200 // let our listener know that things have changed. | |
201 void GrowableCache::clear() { | |
202 int len = _elements->length(); | |
203 for (int i=0; i<len; i++) { | |
204 delete _elements->at(i); | |
205 } | |
206 _elements->clear(); | |
207 recache(); | |
208 } | |
209 | |
210 void GrowableCache::oops_do(OopClosure* f) { | |
211 int len = _elements->length(); | |
212 for (int i=0; i<len; i++) { | |
213 GrowableElement *e = _elements->at(i); | |
214 e->oops_do(f); | |
2125
7246a374a9f2
6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents:
2019
diff
changeset
|
215 _cache[i] = e->getCacheValue(); |
0 | 216 } |
217 } | |
218 | |
219 // | |
220 // class JvmtiBreakpoint | |
221 // | |
222 | |
223 JvmtiBreakpoint::JvmtiBreakpoint() { | |
224 _method = NULL; | |
225 _bci = 0; | |
226 #ifdef CHECK_UNHANDLED_OOPS | |
227 // This one is always allocated with new, but check it just in case. | |
228 Thread *thread = Thread::current(); | |
229 if (thread->is_in_stack((address)&_method)) { | |
230 thread->allow_unhandled_oop((oop*)&_method); | |
231 } | |
232 #endif // CHECK_UNHANDLED_OOPS | |
233 } | |
234 | |
235 JvmtiBreakpoint::JvmtiBreakpoint(methodOop m_method, jlocation location) { | |
236 _method = m_method; | |
237 assert(_method != NULL, "_method != NULL"); | |
238 _bci = (int) location; | |
239 #ifdef CHECK_UNHANDLED_OOPS | |
240 // Could be allocated with new and wouldn't be on the unhandled oop list. | |
241 Thread *thread = Thread::current(); | |
242 if (thread->is_in_stack((address)&_method)) { | |
243 thread->allow_unhandled_oop(&_method); | |
244 } | |
245 #endif // CHECK_UNHANDLED_OOPS | |
246 | |
247 assert(_bci >= 0, "_bci >= 0"); | |
248 } | |
249 | |
250 void JvmtiBreakpoint::copy(JvmtiBreakpoint& bp) { | |
251 _method = bp._method; | |
252 _bci = bp._bci; | |
253 } | |
254 | |
255 bool JvmtiBreakpoint::lessThan(JvmtiBreakpoint& bp) { | |
256 Unimplemented(); | |
257 return false; | |
258 } | |
259 | |
260 bool JvmtiBreakpoint::equals(JvmtiBreakpoint& bp) { | |
261 return _method == bp._method | |
262 && _bci == bp._bci; | |
263 } | |
264 | |
265 bool JvmtiBreakpoint::is_valid() { | |
266 return _method != NULL && | |
267 _bci >= 0; | |
268 } | |
269 | |
270 address JvmtiBreakpoint::getBcp() { | |
271 return _method->bcp_from(_bci); | |
272 } | |
273 | |
274 void JvmtiBreakpoint::each_method_version_do(method_action meth_act) { | |
275 ((methodOopDesc*)_method->*meth_act)(_bci); | |
276 | |
277 // add/remove breakpoint to/from versions of the method that | |
278 // are EMCP. Directly or transitively obsolete methods are | |
279 // not saved in the PreviousVersionInfo. | |
280 Thread *thread = Thread::current(); | |
281 instanceKlassHandle ikh = instanceKlassHandle(thread, _method->method_holder()); | |
282 symbolOop m_name = _method->name(); | |
283 symbolOop m_signature = _method->signature(); | |
284 | |
285 { | |
286 ResourceMark rm(thread); | |
287 // PreviousVersionInfo objects returned via PreviousVersionWalker | |
288 // contain a GrowableArray of handles. We have to clean up the | |
289 // GrowableArray _after_ the PreviousVersionWalker destructor | |
290 // has destroyed the handles. | |
291 { | |
292 // search previous versions if they exist | |
293 PreviousVersionWalker pvw((instanceKlass *)ikh()->klass_part()); | |
294 for (PreviousVersionInfo * pv_info = pvw.next_previous_version(); | |
295 pv_info != NULL; pv_info = pvw.next_previous_version()) { | |
296 GrowableArray<methodHandle>* methods = | |
297 pv_info->prev_EMCP_method_handles(); | |
298 | |
299 if (methods == NULL) { | |
300 // We have run into a PreviousVersion generation where | |
301 // all methods were made obsolete during that generation's | |
302 // RedefineClasses() operation. At the time of that | |
303 // operation, all EMCP methods were flushed so we don't | |
304 // have to go back any further. | |
305 // | |
306 // A NULL methods array is different than an empty methods | |
307 // array. We cannot infer any optimizations about older | |
308 // generations from an empty methods array for the current | |
309 // generation. | |
310 break; | |
311 } | |
312 | |
313 for (int i = methods->length() - 1; i >= 0; i--) { | |
314 methodHandle method = methods->at(i); | |
315 if (method->name() == m_name && method->signature() == m_signature) { | |
316 RC_TRACE(0x00000800, ("%sing breakpoint in %s(%s)", | |
317 meth_act == &methodOopDesc::set_breakpoint ? "sett" : "clear", | |
318 method->name()->as_C_string(), | |
319 method->signature()->as_C_string())); | |
320 assert(!method->is_obsolete(), "only EMCP methods here"); | |
321 | |
322 ((methodOopDesc*)method()->*meth_act)(_bci); | |
323 break; | |
324 } | |
325 } | |
326 } | |
327 } // pvw is cleaned up | |
328 } // rm is cleaned up | |
329 } | |
330 | |
331 void JvmtiBreakpoint::set() { | |
332 each_method_version_do(&methodOopDesc::set_breakpoint); | |
333 } | |
334 | |
335 void JvmtiBreakpoint::clear() { | |
336 each_method_version_do(&methodOopDesc::clear_breakpoint); | |
337 } | |
338 | |
339 void JvmtiBreakpoint::print() { | |
340 #ifndef PRODUCT | |
341 const char *class_name = (_method == NULL) ? "NULL" : _method->klass_name()->as_C_string(); | |
342 const char *method_name = (_method == NULL) ? "NULL" : _method->name()->as_C_string(); | |
343 | |
344 tty->print("Breakpoint(%s,%s,%d,%p)",class_name, method_name, _bci, getBcp()); | |
345 #endif | |
346 } | |
347 | |
348 | |
349 // | |
350 // class VM_ChangeBreakpoints | |
351 // | |
352 // Modify the Breakpoints data structure at a safepoint | |
353 // | |
354 | |
355 void VM_ChangeBreakpoints::doit() { | |
356 switch (_operation) { | |
357 case SET_BREAKPOINT: | |
358 _breakpoints->set_at_safepoint(*_bp); | |
359 break; | |
360 case CLEAR_BREAKPOINT: | |
361 _breakpoints->clear_at_safepoint(*_bp); | |
362 break; | |
363 case CLEAR_ALL_BREAKPOINT: | |
364 _breakpoints->clearall_at_safepoint(); | |
365 break; | |
366 default: | |
367 assert(false, "Unknown operation"); | |
368 } | |
369 } | |
370 | |
371 void VM_ChangeBreakpoints::oops_do(OopClosure* f) { | |
372 // This operation keeps breakpoints alive | |
373 if (_breakpoints != NULL) { | |
374 _breakpoints->oops_do(f); | |
375 } | |
376 if (_bp != NULL) { | |
377 _bp->oops_do(f); | |
378 } | |
379 } | |
380 | |
381 // | |
382 // class JvmtiBreakpoints | |
383 // | |
384 // a JVMTI internal collection of JvmtiBreakpoint | |
385 // | |
386 | |
387 JvmtiBreakpoints::JvmtiBreakpoints(void listener_fun(void *,address *)) { | |
388 _bps.initialize(this,listener_fun); | |
389 } | |
390 | |
391 JvmtiBreakpoints:: ~JvmtiBreakpoints() {} | |
392 | |
393 void JvmtiBreakpoints::oops_do(OopClosure* f) { | |
394 _bps.oops_do(f); | |
395 } | |
396 | |
397 void JvmtiBreakpoints::print() { | |
398 #ifndef PRODUCT | |
399 ResourceMark rm; | |
400 | |
401 int n = _bps.length(); | |
402 for (int i=0; i<n; i++) { | |
403 JvmtiBreakpoint& bp = _bps.at(i); | |
404 tty->print("%d: ", i); | |
405 bp.print(); | |
406 tty->print_cr(""); | |
407 } | |
408 #endif | |
409 } | |
410 | |
411 | |
412 void JvmtiBreakpoints::set_at_safepoint(JvmtiBreakpoint& bp) { | |
413 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint"); | |
414 | |
415 int i = _bps.find(bp); | |
416 if (i == -1) { | |
417 _bps.append(bp); | |
418 bp.set(); | |
419 } | |
420 } | |
421 | |
422 void JvmtiBreakpoints::clear_at_safepoint(JvmtiBreakpoint& bp) { | |
423 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint"); | |
424 | |
425 int i = _bps.find(bp); | |
426 if (i != -1) { | |
427 _bps.remove(i); | |
428 bp.clear(); | |
429 } | |
430 } | |
431 | |
432 void JvmtiBreakpoints::clearall_at_safepoint() { | |
433 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint"); | |
434 | |
435 int len = _bps.length(); | |
436 for (int i=0; i<len; i++) { | |
437 _bps.at(i).clear(); | |
438 } | |
439 _bps.clear(); | |
440 } | |
441 | |
442 int JvmtiBreakpoints::length() { return _bps.length(); } | |
443 | |
444 int JvmtiBreakpoints::set(JvmtiBreakpoint& bp) { | |
445 if ( _bps.find(bp) != -1) { | |
446 return JVMTI_ERROR_DUPLICATE; | |
447 } | |
448 VM_ChangeBreakpoints set_breakpoint(this,VM_ChangeBreakpoints::SET_BREAKPOINT, &bp); | |
449 VMThread::execute(&set_breakpoint); | |
450 return JVMTI_ERROR_NONE; | |
451 } | |
452 | |
453 int JvmtiBreakpoints::clear(JvmtiBreakpoint& bp) { | |
454 if ( _bps.find(bp) == -1) { | |
455 return JVMTI_ERROR_NOT_FOUND; | |
456 } | |
457 | |
458 VM_ChangeBreakpoints clear_breakpoint(this,VM_ChangeBreakpoints::CLEAR_BREAKPOINT, &bp); | |
459 VMThread::execute(&clear_breakpoint); | |
460 return JVMTI_ERROR_NONE; | |
461 } | |
462 | |
463 void JvmtiBreakpoints::clearall_in_class_at_safepoint(klassOop klass) { | |
464 bool changed = true; | |
465 // We are going to run thru the list of bkpts | |
466 // and delete some. This deletion probably alters | |
467 // the list in some implementation defined way such | |
468 // that when we delete entry i, the next entry might | |
469 // no longer be at i+1. To be safe, each time we delete | |
470 // an entry, we'll just start again from the beginning. | |
471 // We'll stop when we make a pass thru the whole list without | |
472 // deleting anything. | |
473 while (changed) { | |
474 int len = _bps.length(); | |
475 changed = false; | |
476 for (int i = 0; i < len; i++) { | |
477 JvmtiBreakpoint& bp = _bps.at(i); | |
478 if (bp.method()->method_holder() == klass) { | |
479 bp.clear(); | |
480 _bps.remove(i); | |
481 // This changed 'i' so we have to start over. | |
482 changed = true; | |
483 break; | |
484 } | |
485 } | |
486 } | |
487 } | |
488 | |
489 void JvmtiBreakpoints::clearall() { | |
490 VM_ChangeBreakpoints clearall_breakpoint(this,VM_ChangeBreakpoints::CLEAR_ALL_BREAKPOINT); | |
491 VMThread::execute(&clearall_breakpoint); | |
492 } | |
493 | |
494 // | |
495 // class JvmtiCurrentBreakpoints | |
496 // | |
497 | |
498 JvmtiBreakpoints *JvmtiCurrentBreakpoints::_jvmti_breakpoints = NULL; | |
499 address * JvmtiCurrentBreakpoints::_breakpoint_list = NULL; | |
500 | |
501 | |
502 JvmtiBreakpoints& JvmtiCurrentBreakpoints::get_jvmti_breakpoints() { | |
503 if (_jvmti_breakpoints != NULL) return (*_jvmti_breakpoints); | |
504 _jvmti_breakpoints = new JvmtiBreakpoints(listener_fun); | |
505 assert(_jvmti_breakpoints != NULL, "_jvmti_breakpoints != NULL"); | |
506 return (*_jvmti_breakpoints); | |
507 } | |
508 | |
509 void JvmtiCurrentBreakpoints::listener_fun(void *this_obj, address *cache) { | |
510 JvmtiBreakpoints *this_jvmti = (JvmtiBreakpoints *) this_obj; | |
511 assert(this_jvmti != NULL, "this_jvmti != NULL"); | |
512 | |
513 debug_only(int n = this_jvmti->length();); | |
514 assert(cache[n] == NULL, "cache must be NULL terminated"); | |
515 | |
516 set_breakpoint_list(cache); | |
517 } | |
518 | |
519 | |
520 void JvmtiCurrentBreakpoints::oops_do(OopClosure* f) { | |
521 if (_jvmti_breakpoints != NULL) { | |
522 _jvmti_breakpoints->oops_do(f); | |
523 } | |
524 } | |
525 | |
526 /////////////////////////////////////////////////////////////// | |
527 // | |
528 // class VM_GetOrSetLocal | |
529 // | |
530 | |
531 // Constructor for non-object getter | |
532 VM_GetOrSetLocal::VM_GetOrSetLocal(JavaThread* thread, jint depth, int index, BasicType type) | |
533 : _thread(thread) | |
534 , _calling_thread(NULL) | |
535 , _depth(depth) | |
536 , _index(index) | |
537 , _type(type) | |
538 , _set(false) | |
539 , _jvf(NULL) | |
540 , _result(JVMTI_ERROR_NONE) | |
541 { | |
542 } | |
543 | |
544 // Constructor for object or non-object setter | |
545 VM_GetOrSetLocal::VM_GetOrSetLocal(JavaThread* thread, jint depth, int index, BasicType type, jvalue value) | |
546 : _thread(thread) | |
547 , _calling_thread(NULL) | |
548 , _depth(depth) | |
549 , _index(index) | |
550 , _type(type) | |
551 , _value(value) | |
552 , _set(true) | |
553 , _jvf(NULL) | |
554 , _result(JVMTI_ERROR_NONE) | |
555 { | |
556 } | |
557 | |
558 // Constructor for object getter | |
559 VM_GetOrSetLocal::VM_GetOrSetLocal(JavaThread* thread, JavaThread* calling_thread, jint depth, int index) | |
560 : _thread(thread) | |
561 , _calling_thread(calling_thread) | |
562 , _depth(depth) | |
563 , _index(index) | |
564 , _type(T_OBJECT) | |
565 , _set(false) | |
566 , _jvf(NULL) | |
567 , _result(JVMTI_ERROR_NONE) | |
568 { | |
569 } | |
570 | |
571 vframe *VM_GetOrSetLocal::get_vframe() { | |
572 if (!_thread->has_last_Java_frame()) { | |
573 return NULL; | |
574 } | |
575 RegisterMap reg_map(_thread); | |
576 vframe *vf = _thread->last_java_vframe(®_map); | |
577 int d = 0; | |
578 while ((vf != NULL) && (d < _depth)) { | |
579 vf = vf->java_sender(); | |
580 d++; | |
581 } | |
582 return vf; | |
583 } | |
584 | |
585 javaVFrame *VM_GetOrSetLocal::get_java_vframe() { | |
586 vframe* vf = get_vframe(); | |
587 if (vf == NULL) { | |
588 _result = JVMTI_ERROR_NO_MORE_FRAMES; | |
589 return NULL; | |
590 } | |
591 javaVFrame *jvf = (javaVFrame*)vf; | |
592 | |
2019 | 593 if (!vf->is_java_frame()) { |
0 | 594 _result = JVMTI_ERROR_OPAQUE_FRAME; |
595 return NULL; | |
596 } | |
597 return jvf; | |
598 } | |
599 | |
600 // Check that the klass is assignable to a type with the given signature. | |
601 // Another solution could be to use the function Klass::is_subtype_of(type). | |
602 // But the type class can be forced to load/initialize eagerly in such a case. | |
603 // This may cause unexpected consequences like CFLH or class-init JVMTI events. | |
604 // It is better to avoid such a behavior. | |
605 bool VM_GetOrSetLocal::is_assignable(const char* ty_sign, Klass* klass, Thread* thread) { | |
606 assert(ty_sign != NULL, "type signature must not be NULL"); | |
607 assert(thread != NULL, "thread must not be NULL"); | |
608 assert(klass != NULL, "klass must not be NULL"); | |
609 | |
610 int len = (int) strlen(ty_sign); | |
611 if (ty_sign[0] == 'L' && ty_sign[len-1] == ';') { // Need pure class/interface name | |
612 ty_sign++; | |
613 len -= 2; | |
614 } | |
615 symbolHandle ty_sym = oopFactory::new_symbol_handle(ty_sign, len, thread); | |
616 if (klass->name() == ty_sym()) { | |
617 return true; | |
618 } | |
619 // Compare primary supers | |
620 int super_depth = klass->super_depth(); | |
621 int idx; | |
622 for (idx = 0; idx < super_depth; idx++) { | |
623 if (Klass::cast(klass->primary_super_of_depth(idx))->name() == ty_sym()) { | |
624 return true; | |
625 } | |
626 } | |
627 // Compare secondary supers | |
628 objArrayOop sec_supers = klass->secondary_supers(); | |
629 for (idx = 0; idx < sec_supers->length(); idx++) { | |
630 if (Klass::cast((klassOop) sec_supers->obj_at(idx))->name() == ty_sym()) { | |
631 return true; | |
632 } | |
633 } | |
634 return false; | |
635 } | |
636 | |
637 // Checks error conditions: | |
638 // JVMTI_ERROR_INVALID_SLOT | |
639 // JVMTI_ERROR_TYPE_MISMATCH | |
640 // Returns: 'true' - everything is Ok, 'false' - error code | |
641 | |
642 bool VM_GetOrSetLocal::check_slot_type(javaVFrame* jvf) { | |
643 methodOop method_oop = jvf->method(); | |
644 if (!method_oop->has_localvariable_table()) { | |
645 // Just to check index boundaries | |
646 jint extra_slot = (_type == T_LONG || _type == T_DOUBLE) ? 1 : 0; | |
647 if (_index < 0 || _index + extra_slot >= method_oop->max_locals()) { | |
648 _result = JVMTI_ERROR_INVALID_SLOT; | |
649 return false; | |
650 } | |
651 return true; | |
652 } | |
653 | |
654 jint num_entries = method_oop->localvariable_table_length(); | |
655 if (num_entries == 0) { | |
656 _result = JVMTI_ERROR_INVALID_SLOT; | |
657 return false; // There are no slots | |
658 } | |
659 int signature_idx = -1; | |
660 int vf_bci = jvf->bci(); | |
661 LocalVariableTableElement* table = method_oop->localvariable_table_start(); | |
662 for (int i = 0; i < num_entries; i++) { | |
663 int start_bci = table[i].start_bci; | |
664 int end_bci = start_bci + table[i].length; | |
665 | |
666 // Here we assume that locations of LVT entries | |
667 // with the same slot number cannot be overlapped | |
668 if (_index == (jint) table[i].slot && start_bci <= vf_bci && vf_bci <= end_bci) { | |
669 signature_idx = (int) table[i].descriptor_cp_index; | |
670 break; | |
671 } | |
672 } | |
673 if (signature_idx == -1) { | |
674 _result = JVMTI_ERROR_INVALID_SLOT; | |
675 return false; // Incorrect slot index | |
676 } | |
677 symbolOop sign_sym = method_oop->constants()->symbol_at(signature_idx); | |
678 const char* signature = (const char *) sign_sym->as_utf8(); | |
679 BasicType slot_type = char2type(signature[0]); | |
680 | |
681 switch (slot_type) { | |
682 case T_BYTE: | |
683 case T_SHORT: | |
684 case T_CHAR: | |
685 case T_BOOLEAN: | |
686 slot_type = T_INT; | |
687 break; | |
688 case T_ARRAY: | |
689 slot_type = T_OBJECT; | |
690 break; | |
691 }; | |
692 if (_type != slot_type) { | |
693 _result = JVMTI_ERROR_TYPE_MISMATCH; | |
694 return false; | |
695 } | |
696 | |
697 jobject jobj = _value.l; | |
698 if (_set && slot_type == T_OBJECT && jobj != NULL) { // NULL reference is allowed | |
699 // Check that the jobject class matches the return type signature. | |
700 JavaThread* cur_thread = JavaThread::current(); | |
701 HandleMark hm(cur_thread); | |
702 | |
703 Handle obj = Handle(cur_thread, JNIHandles::resolve_external_guard(jobj)); | |
704 NULL_CHECK(obj, (_result = JVMTI_ERROR_INVALID_OBJECT, false)); | |
705 KlassHandle ob_kh = KlassHandle(cur_thread, obj->klass()); | |
706 NULL_CHECK(ob_kh, (_result = JVMTI_ERROR_INVALID_OBJECT, false)); | |
707 | |
708 if (!is_assignable(signature, Klass::cast(ob_kh()), cur_thread)) { | |
709 _result = JVMTI_ERROR_TYPE_MISMATCH; | |
710 return false; | |
711 } | |
712 } | |
713 return true; | |
714 } | |
715 | |
716 static bool can_be_deoptimized(vframe* vf) { | |
717 return (vf->is_compiled_frame() && vf->fr().can_be_deoptimized()); | |
718 } | |
719 | |
720 bool VM_GetOrSetLocal::doit_prologue() { | |
721 _jvf = get_java_vframe(); | |
722 NULL_CHECK(_jvf, false); | |
723 | |
2019 | 724 if (_jvf->method()->is_native()) { |
725 if (getting_receiver() && !_jvf->method()->is_static()) { | |
726 return true; | |
727 } else { | |
728 _result = JVMTI_ERROR_OPAQUE_FRAME; | |
729 return false; | |
730 } | |
731 } | |
732 | |
0 | 733 if (!check_slot_type(_jvf)) { |
734 return false; | |
735 } | |
736 return true; | |
737 } | |
738 | |
739 void VM_GetOrSetLocal::doit() { | |
740 if (_set) { | |
741 // Force deoptimization of frame if compiled because it's | |
742 // possible the compiler emitted some locals as constant values, | |
743 // meaning they are not mutable. | |
744 if (can_be_deoptimized(_jvf)) { | |
745 | |
746 // Schedule deoptimization so that eventually the local | |
747 // update will be written to an interpreter frame. | |
1905
ce6848d0666d
6968367: can_post_on_exceptions is still using VM_DeoptimizeFrame in some places
never
parents:
1552
diff
changeset
|
748 Deoptimization::deoptimize_frame(_jvf->thread(), _jvf->fr().id()); |
0 | 749 |
750 // Now store a new value for the local which will be applied | |
751 // once deoptimization occurs. Note however that while this | |
752 // write is deferred until deoptimization actually happens | |
753 // can vframe created after this point will have its locals | |
754 // reflecting this update so as far as anyone can see the | |
755 // write has already taken place. | |
756 | |
757 // If we are updating an oop then get the oop from the handle | |
758 // since the handle will be long gone by the time the deopt | |
759 // happens. The oop stored in the deferred local will be | |
760 // gc'd on its own. | |
761 if (_type == T_OBJECT) { | |
762 _value.l = (jobject) (JNIHandles::resolve_external_guard(_value.l)); | |
763 } | |
764 // Re-read the vframe so we can see that it is deoptimized | |
765 // [ Only need because of assert in update_local() ] | |
766 _jvf = get_java_vframe(); | |
767 ((compiledVFrame*)_jvf)->update_local(_type, _index, _value); | |
768 return; | |
769 } | |
770 StackValueCollection *locals = _jvf->locals(); | |
771 HandleMark hm; | |
772 | |
773 switch (_type) { | |
2019 | 774 case T_INT: locals->set_int_at (_index, _value.i); break; |
775 case T_LONG: locals->set_long_at (_index, _value.j); break; | |
776 case T_FLOAT: locals->set_float_at (_index, _value.f); break; | |
777 case T_DOUBLE: locals->set_double_at(_index, _value.d); break; | |
778 case T_OBJECT: { | |
779 Handle ob_h(JNIHandles::resolve_external_guard(_value.l)); | |
780 locals->set_obj_at (_index, ob_h); | |
781 break; | |
782 } | |
783 default: ShouldNotReachHere(); | |
0 | 784 } |
785 _jvf->set_locals(locals); | |
786 } else { | |
2019 | 787 if (_jvf->method()->is_native() && _jvf->is_compiled_frame()) { |
788 assert(getting_receiver(), "Can only get here when getting receiver"); | |
789 oop receiver = _jvf->fr().get_native_receiver(); | |
790 _value.l = JNIHandles::make_local(_calling_thread, receiver); | |
791 } else { | |
792 StackValueCollection *locals = _jvf->locals(); | |
0 | 793 |
2019 | 794 if (locals->at(_index)->type() == T_CONFLICT) { |
795 memset(&_value, 0, sizeof(_value)); | |
796 _value.l = NULL; | |
797 return; | |
798 } | |
0 | 799 |
2019 | 800 switch (_type) { |
801 case T_INT: _value.i = locals->int_at (_index); break; | |
802 case T_LONG: _value.j = locals->long_at (_index); break; | |
803 case T_FLOAT: _value.f = locals->float_at (_index); break; | |
804 case T_DOUBLE: _value.d = locals->double_at(_index); break; | |
805 case T_OBJECT: { | |
806 // Wrap the oop to be returned in a local JNI handle since | |
807 // oops_do() no longer applies after doit() is finished. | |
808 oop obj = locals->obj_at(_index)(); | |
809 _value.l = JNIHandles::make_local(_calling_thread, obj); | |
810 break; | |
811 } | |
812 default: ShouldNotReachHere(); | |
813 } | |
0 | 814 } |
815 } | |
816 } | |
817 | |
818 | |
819 bool VM_GetOrSetLocal::allow_nested_vm_operations() const { | |
820 return true; // May need to deoptimize | |
821 } | |
822 | |
823 | |
2019 | 824 VM_GetReceiver::VM_GetReceiver( |
825 JavaThread* thread, JavaThread* caller_thread, jint depth) | |
826 : VM_GetOrSetLocal(thread, caller_thread, depth, 0) {} | |
827 | |
0 | 828 ///////////////////////////////////////////////////////////////////////////////////////// |
829 | |
830 // | |
831 // class JvmtiSuspendControl - see comments in jvmtiImpl.hpp | |
832 // | |
833 | |
834 bool JvmtiSuspendControl::suspend(JavaThread *java_thread) { | |
835 // external suspend should have caught suspending a thread twice | |
836 | |
837 // Immediate suspension required for JPDA back-end so JVMTI agent threads do | |
838 // not deadlock due to later suspension on transitions while holding | |
839 // raw monitors. Passing true causes the immediate suspension. | |
840 // java_suspend() will catch threads in the process of exiting | |
841 // and will ignore them. | |
842 java_thread->java_suspend(); | |
843 | |
844 // It would be nice to have the following assertion in all the time, | |
845 // but it is possible for a racing resume request to have resumed | |
846 // this thread right after we suspended it. Temporarily enable this | |
847 // assertion if you are chasing a different kind of bug. | |
848 // | |
849 // assert(java_lang_Thread::thread(java_thread->threadObj()) == NULL || | |
850 // java_thread->is_being_ext_suspended(), "thread is not suspended"); | |
851 | |
852 if (java_lang_Thread::thread(java_thread->threadObj()) == NULL) { | |
853 // check again because we can get delayed in java_suspend(): | |
854 // the thread is in process of exiting. | |
855 return false; | |
856 } | |
857 | |
858 return true; | |
859 } | |
860 | |
861 bool JvmtiSuspendControl::resume(JavaThread *java_thread) { | |
862 // external suspend should have caught resuming a thread twice | |
863 assert(java_thread->is_being_ext_suspended(), "thread should be suspended"); | |
864 | |
865 // resume thread | |
866 { | |
867 // must always grab Threads_lock, see JVM_SuspendThread | |
868 MutexLocker ml(Threads_lock); | |
869 java_thread->java_resume(); | |
870 } | |
871 | |
872 return true; | |
873 } | |
874 | |
875 | |
876 void JvmtiSuspendControl::print() { | |
877 #ifndef PRODUCT | |
878 MutexLocker mu(Threads_lock); | |
879 ResourceMark rm; | |
880 | |
881 tty->print("Suspended Threads: ["); | |
882 for (JavaThread *thread = Threads::first(); thread != NULL; thread = thread->next()) { | |
883 #if JVMTI_TRACE | |
884 const char *name = JvmtiTrace::safe_get_thread_name(thread); | |
885 #else | |
886 const char *name = ""; | |
887 #endif /*JVMTI_TRACE */ | |
888 tty->print("%s(%c ", name, thread->is_being_ext_suspended() ? 'S' : '_'); | |
889 if (!thread->has_last_Java_frame()) { | |
890 tty->print("no stack"); | |
891 } | |
892 tty->print(") "); | |
893 } | |
894 tty->print_cr("]"); | |
895 #endif | |
896 } |