400 continue;
401 }
402 ThreadConcurrentLocks* tcl = NULL;
403 if (_with_locked_synchronizers) {
404 tcl = concurrent_locks.thread_concurrent_locks(jt);
405 }
406 ThreadSnapshot* ts = snapshot_thread(jt, tcl);
407 _result->add_thread_snapshot(ts);
408 }
409 }
410 }
411
412 ThreadSnapshot* VM_ThreadDump::snapshot_thread(JavaThread* java_thread, ThreadConcurrentLocks* tcl) {
413 ThreadSnapshot* snapshot = new ThreadSnapshot(_result->t_list(), java_thread);
414 snapshot->dump_stack_at_safepoint(_max_depth, _with_locked_monitors);
415 snapshot->set_concurrent_locks(tcl);
416 return snapshot;
417 }
418
419 volatile bool VM_Exit::_vm_exited = false;
420 Thread * VM_Exit::_shutdown_thread = NULL;
421
422 int VM_Exit::set_vm_exited() {
423
424 Thread * thr_cur = Thread::current();
425
426 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint already");
427
428 int num_active = 0;
429
430 _shutdown_thread = thr_cur;
431 _vm_exited = true; // global flag
432 for (JavaThreadIteratorWithHandle jtiwh; JavaThread *thr = jtiwh.next(); ) {
433 if (thr!=thr_cur && thr->thread_state() == _thread_in_native) {
434 ++num_active;
435 thr->set_terminated(JavaThread::_vm_exited); // per-thread flag
436 }
437 }
438
439 return num_active;
440 }
441
442 int VM_Exit::wait_for_threads_in_native_to_block() {
443 // VM exits at safepoint. This function must be called at the final safepoint
444 // to wait for threads in _thread_in_native state to be quiescent.
445 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint already");
446
447 Thread * thr_cur = Thread::current();
448 Monitor timer(Mutex::leaf, "VM_Exit timer", true,
449 Monitor::_safepoint_check_never);
450
485 return num_active;
486 }
487
488 attempts++;
489
490 MutexLockerEx ml(&timer, Mutex::_no_safepoint_check_flag);
491 timer.wait(Mutex::_no_safepoint_check_flag, 10);
492 }
493 }
494
495 void VM_Exit::doit() {
496 CompileBroker::set_should_block();
497
498 // Wait for a short period for threads in native to block. Any thread
499 // still executing native code after the wait will be stopped at
500 // native==>Java/VM barriers.
501 // Among 16276 JCK tests, 94% of them come here without any threads still
502 // running in native; the other 6% are quiescent within 250ms (Ultra 80).
503 wait_for_threads_in_native_to_block();
504
505 set_vm_exited();
506
507 // cleanup globals resources before exiting. exit_globals() currently
508 // cleans up outputStream resources and PerfMemory resources.
509 exit_globals();
510
511 // Check for exit hook
512 exit_hook_t exit_hook = Arguments::exit_hook();
513 if (exit_hook != NULL) {
514 // exit hook should exit.
515 exit_hook(_exit_code);
516 // ... but if it didn't, we must do it here
517 vm_direct_exit(_exit_code);
518 } else {
519 vm_direct_exit(_exit_code);
520 }
521 }
522
523
524 void VM_Exit::wait_if_vm_exited() {
|
400 continue;
401 }
402 ThreadConcurrentLocks* tcl = NULL;
403 if (_with_locked_synchronizers) {
404 tcl = concurrent_locks.thread_concurrent_locks(jt);
405 }
406 ThreadSnapshot* ts = snapshot_thread(jt, tcl);
407 _result->add_thread_snapshot(ts);
408 }
409 }
410 }
411
412 ThreadSnapshot* VM_ThreadDump::snapshot_thread(JavaThread* java_thread, ThreadConcurrentLocks* tcl) {
413 ThreadSnapshot* snapshot = new ThreadSnapshot(_result->t_list(), java_thread);
414 snapshot->dump_stack_at_safepoint(_max_depth, _with_locked_monitors);
415 snapshot->set_concurrent_locks(tcl);
416 return snapshot;
417 }
418
419 volatile bool VM_Exit::_vm_exited = false;
420 Thread * volatile VM_Exit::_shutdown_thread = NULL;
421
422 int VM_Exit::set_vm_exited() {
423 Thread * thr_cur = Thread::current();
424 assert(_shutdown_thread == thr_cur, "_shutdown_thread should be current thread");
425 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint already");
426
427 int num_active = 0;
428
429 _vm_exited = true; // global flag
430 for (JavaThreadIteratorWithHandle jtiwh; JavaThread *thr = jtiwh.next(); ) {
431 if (thr!=thr_cur && thr->thread_state() == _thread_in_native) {
432 ++num_active;
433 thr->set_terminated(JavaThread::_vm_exited); // per-thread flag
434 }
435 }
436
437 return num_active;
438 }
439
440 int VM_Exit::wait_for_threads_in_native_to_block() {
441 // VM exits at safepoint. This function must be called at the final safepoint
442 // to wait for threads in _thread_in_native state to be quiescent.
443 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint already");
444
445 Thread * thr_cur = Thread::current();
446 Monitor timer(Mutex::leaf, "VM_Exit timer", true,
447 Monitor::_safepoint_check_never);
448
483 return num_active;
484 }
485
486 attempts++;
487
488 MutexLockerEx ml(&timer, Mutex::_no_safepoint_check_flag);
489 timer.wait(Mutex::_no_safepoint_check_flag, 10);
490 }
491 }
492
493 void VM_Exit::doit() {
494 CompileBroker::set_should_block();
495
496 // Wait for a short period for threads in native to block. Any thread
497 // still executing native code after the wait will be stopped at
498 // native==>Java/VM barriers.
499 // Among 16276 JCK tests, 94% of them come here without any threads still
500 // running in native; the other 6% are quiescent within 250ms (Ultra 80).
501 wait_for_threads_in_native_to_block();
502
503 // Remember the Thread that is shutting down the VM because it needs
504 // to be immune to some of the sanity checks and policies that have
505 // to happen at VM shutdown time.
506 VM_Exit::set_shutdown_thread(Thread::current());
507
508 set_vm_exited();
509
510 // cleanup globals resources before exiting. exit_globals() currently
511 // cleans up outputStream resources and PerfMemory resources.
512 exit_globals();
513
514 // Check for exit hook
515 exit_hook_t exit_hook = Arguments::exit_hook();
516 if (exit_hook != NULL) {
517 // exit hook should exit.
518 exit_hook(_exit_code);
519 // ... but if it didn't, we must do it here
520 vm_direct_exit(_exit_code);
521 } else {
522 vm_direct_exit(_exit_code);
523 }
524 }
525
526
527 void VM_Exit::wait_if_vm_exited() {
|