36 #include "runtime/arguments.hpp" |
36 #include "runtime/arguments.hpp" |
37 #include "runtime/deoptimization.hpp" |
37 #include "runtime/deoptimization.hpp" |
38 #include "runtime/interfaceSupport.hpp" |
38 #include "runtime/interfaceSupport.hpp" |
39 #include "runtime/sweeper.hpp" |
39 #include "runtime/sweeper.hpp" |
40 #include "runtime/thread.inline.hpp" |
40 #include "runtime/thread.inline.hpp" |
|
41 #include "runtime/threadSMR.inline.hpp" |
41 #include "runtime/vm_operations.hpp" |
42 #include "runtime/vm_operations.hpp" |
42 #include "services/threadService.hpp" |
43 #include "services/threadService.hpp" |
43 #include "trace/tracing.hpp" |
44 #include "trace/tracing.hpp" |
44 |
45 |
45 #define VM_OP_NAME_INITIALIZE(name) #name, |
46 #define VM_OP_NAME_INITIALIZE(name) #name, |
94 } |
95 } |
95 } |
96 } |
96 |
97 |
97 void VM_ThreadStop::doit() { |
98 void VM_ThreadStop::doit() { |
98 assert(SafepointSynchronize::is_at_safepoint(), "must be at a safepoint"); |
99 assert(SafepointSynchronize::is_at_safepoint(), "must be at a safepoint"); |
|
100 ThreadsListHandle tlh; |
99 JavaThread* target = java_lang_Thread::thread(target_thread()); |
101 JavaThread* target = java_lang_Thread::thread(target_thread()); |
100 // Note that this now allows multiple ThreadDeath exceptions to be |
102 // Note that this now allows multiple ThreadDeath exceptions to be |
101 // thrown at a thread. |
103 // thrown at a thread. |
102 if (target != NULL) { |
104 if (target != NULL && (!EnableThreadSMRExtraValidityChecks || tlh.includes(target))) { |
103 // the thread has run and is not already in the process of exiting |
105 // The target thread has run and has not exited yet. |
104 target->send_thread_stop(throwable()); |
106 target->send_thread_stop(throwable()); |
105 } |
107 } |
106 } |
108 } |
107 |
109 |
108 void VM_ClearICs::doit() { |
110 void VM_ClearICs::doit() { |
144 |
146 |
145 #ifndef PRODUCT |
147 #ifndef PRODUCT |
146 |
148 |
147 void VM_DeoptimizeAll::doit() { |
149 void VM_DeoptimizeAll::doit() { |
148 DeoptimizationMarker dm; |
150 DeoptimizationMarker dm; |
|
151 JavaThreadIteratorWithHandle jtiwh; |
149 // deoptimize all java threads in the system |
152 // deoptimize all java threads in the system |
150 if (DeoptimizeALot) { |
153 if (DeoptimizeALot) { |
151 for (JavaThread* thread = Threads::first(); thread != NULL; thread = thread->next()) { |
154 for (; JavaThread *thread = jtiwh.next(); ) { |
152 if (thread->has_last_Java_frame()) { |
155 if (thread->has_last_Java_frame()) { |
153 thread->deoptimize(); |
156 thread->deoptimize(); |
154 } |
157 } |
155 } |
158 } |
156 } else if (DeoptimizeRandom) { |
159 } else if (DeoptimizeRandom) { |
157 |
160 |
158 // Deoptimize some selected threads and frames |
161 // Deoptimize some selected threads and frames |
159 int tnum = os::random() & 0x3; |
162 int tnum = os::random() & 0x3; |
160 int fnum = os::random() & 0x3; |
163 int fnum = os::random() & 0x3; |
161 int tcount = 0; |
164 int tcount = 0; |
162 for (JavaThread* thread = Threads::first(); thread != NULL; thread = thread->next()) { |
165 for (; JavaThread *thread = jtiwh.next(); ) { |
163 if (thread->has_last_Java_frame()) { |
166 if (thread->has_last_Java_frame()) { |
164 if (tcount++ == tnum) { |
167 if (tcount++ == tnum) { |
165 tcount = 0; |
168 tcount = 0; |
166 int fcount = 0; |
169 int fcount = 0; |
167 // Deoptimize some selected frames. |
170 // Deoptimize some selected frames. |
257 |
260 |
258 return true; |
261 return true; |
259 } |
262 } |
260 |
263 |
261 void VM_FindDeadlocks::doit() { |
264 void VM_FindDeadlocks::doit() { |
262 _deadlocks = ThreadService::find_deadlocks_at_safepoint(_concurrent_locks); |
265 // Update the hazard ptr in the originating thread to the current |
|
266 // list of threads. This VM operation needs the current list of |
|
267 // threads for proper deadlock detection and those are the |
|
268 // JavaThreads we need to be protected when we return info to the |
|
269 // originating thread. |
|
270 _setter.set(); |
|
271 |
|
272 _deadlocks = ThreadService::find_deadlocks_at_safepoint(_setter.list(), _concurrent_locks); |
263 if (_out != NULL) { |
273 if (_out != NULL) { |
264 int num_deadlocks = 0; |
274 int num_deadlocks = 0; |
265 for (DeadlockCycle* cycle = _deadlocks; cycle != NULL; cycle = cycle->next()) { |
275 for (DeadlockCycle* cycle = _deadlocks; cycle != NULL; cycle = cycle->next()) { |
266 num_deadlocks++; |
276 num_deadlocks++; |
267 cycle->print_on(_out); |
277 cycle->print_on_with(_setter.list(), _out); |
268 } |
278 } |
269 |
279 |
270 if (num_deadlocks == 1) { |
280 if (num_deadlocks == 1) { |
271 _out->print_cr("\nFound 1 deadlock.\n"); |
281 _out->print_cr("\nFound 1 deadlock.\n"); |
272 _out->flush(); |
282 _out->flush(); |
329 } |
339 } |
330 |
340 |
331 void VM_ThreadDump::doit() { |
341 void VM_ThreadDump::doit() { |
332 ResourceMark rm; |
342 ResourceMark rm; |
333 |
343 |
|
344 // Set the hazard ptr in the originating thread to protect the |
|
345 // current list of threads. This VM operation needs the current list |
|
346 // of threads for a proper dump and those are the JavaThreads we need |
|
347 // to be protected when we return info to the originating thread. |
|
348 _result->set_t_list(); |
|
349 |
334 ConcurrentLocksDump concurrent_locks(true); |
350 ConcurrentLocksDump concurrent_locks(true); |
335 if (_with_locked_synchronizers) { |
351 if (_with_locked_synchronizers) { |
336 concurrent_locks.dump_at_safepoint(); |
352 concurrent_locks.dump_at_safepoint(); |
337 } |
353 } |
338 |
354 |
339 if (_num_threads == 0) { |
355 if (_num_threads == 0) { |
340 // Snapshot all live threads |
356 // Snapshot all live threads |
341 for (JavaThread* jt = Threads::first(); jt != NULL; jt = jt->next()) { |
357 |
|
358 for (uint i = 0; i < _result->t_list()->length(); i++) { |
|
359 JavaThread* jt = _result->t_list()->thread_at(i); |
342 if (jt->is_exiting() || |
360 if (jt->is_exiting() || |
343 jt->is_hidden_from_external_view()) { |
361 jt->is_hidden_from_external_view()) { |
344 // skip terminating threads and hidden threads |
362 // skip terminating threads and hidden threads |
345 continue; |
363 continue; |
346 } |
364 } |
352 _result->add_thread_snapshot(ts); |
370 _result->add_thread_snapshot(ts); |
353 } |
371 } |
354 } else { |
372 } else { |
355 // Snapshot threads in the given _threads array |
373 // Snapshot threads in the given _threads array |
356 // A dummy snapshot is created if a thread doesn't exist |
374 // A dummy snapshot is created if a thread doesn't exist |
|
375 |
357 for (int i = 0; i < _num_threads; i++) { |
376 for (int i = 0; i < _num_threads; i++) { |
358 instanceHandle th = _threads->at(i); |
377 instanceHandle th = _threads->at(i); |
359 if (th() == NULL) { |
378 if (th() == NULL) { |
360 // skip if the thread doesn't exist |
379 // skip if the thread doesn't exist |
361 // Add a dummy snapshot |
380 // Add a dummy snapshot |
364 } |
383 } |
365 |
384 |
366 // Dump thread stack only if the thread is alive and not exiting |
385 // Dump thread stack only if the thread is alive and not exiting |
367 // and not VM internal thread. |
386 // and not VM internal thread. |
368 JavaThread* jt = java_lang_Thread::thread(th()); |
387 JavaThread* jt = java_lang_Thread::thread(th()); |
|
388 if (jt != NULL && !_result->t_list()->includes(jt)) { |
|
389 // _threads[i] doesn't refer to a valid JavaThread; this check |
|
390 // is primarily for JVM_DumpThreads() which doesn't have a good |
|
391 // way to validate the _threads array. |
|
392 jt = NULL; |
|
393 } |
369 if (jt == NULL || /* thread not alive */ |
394 if (jt == NULL || /* thread not alive */ |
370 jt->is_exiting() || |
395 jt->is_exiting() || |
371 jt->is_hidden_from_external_view()) { |
396 jt->is_hidden_from_external_view()) { |
372 // add a NULL snapshot if skipped |
397 // add a NULL snapshot if skipped |
373 _result->add_thread_snapshot(new ThreadSnapshot()); |
398 _result->add_thread_snapshot(new ThreadSnapshot()); |
382 } |
407 } |
383 } |
408 } |
384 } |
409 } |
385 |
410 |
386 ThreadSnapshot* VM_ThreadDump::snapshot_thread(JavaThread* java_thread, ThreadConcurrentLocks* tcl) { |
411 ThreadSnapshot* VM_ThreadDump::snapshot_thread(JavaThread* java_thread, ThreadConcurrentLocks* tcl) { |
387 ThreadSnapshot* snapshot = new ThreadSnapshot(java_thread); |
412 ThreadSnapshot* snapshot = new ThreadSnapshot(_result->t_list(), java_thread); |
388 snapshot->dump_stack_at_safepoint(_max_depth, _with_locked_monitors); |
413 snapshot->dump_stack_at_safepoint(_max_depth, _with_locked_monitors); |
389 snapshot->set_concurrent_locks(tcl); |
414 snapshot->set_concurrent_locks(tcl); |
390 return snapshot; |
415 return snapshot; |
391 } |
416 } |
392 |
417 |
401 |
426 |
402 int num_active = 0; |
427 int num_active = 0; |
403 |
428 |
404 _shutdown_thread = thr_cur; |
429 _shutdown_thread = thr_cur; |
405 _vm_exited = true; // global flag |
430 _vm_exited = true; // global flag |
406 for(JavaThread *thr = Threads::first(); thr != NULL; thr = thr->next()) |
431 for (JavaThreadIteratorWithHandle jtiwh; JavaThread *thr = jtiwh.next(); ) { |
407 if (thr!=thr_cur && thr->thread_state() == _thread_in_native) { |
432 if (thr!=thr_cur && thr->thread_state() == _thread_in_native) { |
408 ++num_active; |
433 ++num_active; |
409 thr->set_terminated(JavaThread::_vm_exited); // per-thread flag |
434 thr->set_terminated(JavaThread::_vm_exited); // per-thread flag |
410 } |
435 } |
|
436 } |
411 |
437 |
412 return num_active; |
438 return num_active; |
413 } |
439 } |
414 |
440 |
415 int VM_Exit::wait_for_threads_in_native_to_block() { |
441 int VM_Exit::wait_for_threads_in_native_to_block() { |
433 int max_wait_compiler_thread = 1000; // at least 10 seconds |
459 int max_wait_compiler_thread = 1000; // at least 10 seconds |
434 |
460 |
435 int max_wait = max_wait_compiler_thread; |
461 int max_wait = max_wait_compiler_thread; |
436 |
462 |
437 int attempts = 0; |
463 int attempts = 0; |
|
464 JavaThreadIteratorWithHandle jtiwh; |
438 while (true) { |
465 while (true) { |
439 int num_active = 0; |
466 int num_active = 0; |
440 int num_active_compiler_thread = 0; |
467 int num_active_compiler_thread = 0; |
441 |
468 |
442 for(JavaThread *thr = Threads::first(); thr != NULL; thr = thr->next()) { |
469 jtiwh.rewind(); |
|
470 for (; JavaThread *thr = jtiwh.next(); ) { |
443 if (thr!=thr_cur && thr->thread_state() == _thread_in_native) { |
471 if (thr!=thr_cur && thr->thread_state() == _thread_in_native) { |
444 num_active++; |
472 num_active++; |
445 if (thr->is_Compiler_thread()) { |
473 if (thr->is_Compiler_thread()) { |
446 num_active_compiler_thread++; |
474 num_active_compiler_thread++; |
447 } |
475 } |