< prev index next >

src/share/vm/runtime/vm_operations.cpp

Print this page




 361       }
 362       ThreadSnapshot* ts = snapshot_thread(jt, tcl);
 363       _result->add_thread_snapshot(ts);
 364     }
 365   }
 366 }
 367 
 368 ThreadSnapshot* VM_ThreadDump::snapshot_thread(JavaThread* java_thread, ThreadConcurrentLocks* tcl) {
 369   ThreadSnapshot* snapshot = new ThreadSnapshot(java_thread);
 370   snapshot->dump_stack_at_safepoint(_max_depth, _with_locked_monitors);
 371   snapshot->set_concurrent_locks(tcl);
 372   return snapshot;
 373 }
 374 
 375 volatile bool VM_Exit::_vm_exited = false;
 376 Thread * VM_Exit::_shutdown_thread = NULL;
 377 
 378 int VM_Exit::set_vm_exited() {
 379   CodeCacheExtensions::complete_step(CodeCacheExtensionsSteps::LastStep);
 380 
 381   Thread * thr_cur = ThreadLocalStorage::get_thread_slow();
 382 
 383   assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint already");
 384 
 385   int num_active = 0;
 386 
 387   _shutdown_thread = thr_cur;
 388   _vm_exited = true;                                // global flag
 389   for(JavaThread *thr = Threads::first(); thr != NULL; thr = thr->next())
 390     if (thr!=thr_cur && thr->thread_state() == _thread_in_native) {
 391       ++num_active;
 392       thr->set_terminated(JavaThread::_vm_exited);  // per-thread flag
 393     }
 394 
 395   return num_active;
 396 }
 397 
 398 int VM_Exit::wait_for_threads_in_native_to_block() {
 399   // VM exits at safepoint. This function must be called at the final safepoint
 400   // to wait for threads in _thread_in_native state to be quiescent.
 401   assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint already");
 402 
 403   Thread * thr_cur = ThreadLocalStorage::get_thread_slow();
 404   Monitor timer(Mutex::leaf, "VM_Exit timer", true,
 405                 Monitor::_safepoint_check_never);
 406 
 407   // Compiler threads need longer wait because they can access VM data directly
 408   // while in native. If they are active and some structures being used are
 409   // deleted by the shutdown sequence, they will crash. On the other hand, user
 410   // threads must go through native=>Java/VM transitions first to access VM
 411   // data, and they will be stopped during state transition. In theory, we
 412   // don't have to wait for user threads to be quiescent, but it's always
 413   // better to terminate VM when current thread is the only active thread, so
 414   // wait for user threads too. Numbers are in 10 milliseconds.
 415   int max_wait_user_thread = 30;                  // at least 300 milliseconds
 416   int max_wait_compiler_thread = 1000;            // at least 10 seconds
 417 
 418   int max_wait = max_wait_compiler_thread;
 419 
 420   int attempts = 0;
 421   while (true) {
 422     int num_active = 0;
 423     int num_active_compiler_thread = 0;


 460 
 461   // cleanup globals resources before exiting. exit_globals() currently
 462   // cleans up outputStream resources and PerfMemory resources.
 463   exit_globals();
 464 
 465   // Check for exit hook
 466   exit_hook_t exit_hook = Arguments::exit_hook();
 467   if (exit_hook != NULL) {
 468     // exit hook should exit.
 469     exit_hook(_exit_code);
 470     // ... but if it didn't, we must do it here
 471     vm_direct_exit(_exit_code);
 472   } else {
 473     vm_direct_exit(_exit_code);
 474   }
 475 }
 476 
 477 
 478 void VM_Exit::wait_if_vm_exited() {
 479   if (_vm_exited &&
 480       ThreadLocalStorage::get_thread_slow() != _shutdown_thread) {
 481     // _vm_exited is set at safepoint, and the Threads_lock is never released
 482     // we will block here until the process dies
 483     Threads_lock->lock_without_safepoint_check();
 484     ShouldNotReachHere();
 485   }
 486 }
 487 
 488 void VM_PrintCompileQueue::doit() {
 489   CompileBroker::print_compile_queues(_out);
 490 }
 491 
 492 void VM_PrintCodeList::doit() {
 493   CodeCache::print_codelist(_out);
 494 }
 495 
 496 void VM_PrintCodeCache::doit() {
 497   CodeCache::print_layout(_out);
 498 }
 499 
 500 #if INCLUDE_SERVICES


 361       }
 362       ThreadSnapshot* ts = snapshot_thread(jt, tcl);
 363       _result->add_thread_snapshot(ts);
 364     }
 365   }
 366 }
 367 
 368 ThreadSnapshot* VM_ThreadDump::snapshot_thread(JavaThread* java_thread, ThreadConcurrentLocks* tcl) {
 369   ThreadSnapshot* snapshot = new ThreadSnapshot(java_thread);
 370   snapshot->dump_stack_at_safepoint(_max_depth, _with_locked_monitors);
 371   snapshot->set_concurrent_locks(tcl);
 372   return snapshot;
 373 }
 374 
 375 volatile bool VM_Exit::_vm_exited = false;
 376 Thread * VM_Exit::_shutdown_thread = NULL;
 377 
 378 int VM_Exit::set_vm_exited() {
 379   CodeCacheExtensions::complete_step(CodeCacheExtensionsSteps::LastStep);
 380 
 381   Thread * thr_cur = Thread::current();
 382 
 383   assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint already");
 384 
 385   int num_active = 0;
 386 
 387   _shutdown_thread = thr_cur;
 388   _vm_exited = true;                                // global flag
 389   for(JavaThread *thr = Threads::first(); thr != NULL; thr = thr->next())
 390     if (thr!=thr_cur && thr->thread_state() == _thread_in_native) {
 391       ++num_active;
 392       thr->set_terminated(JavaThread::_vm_exited);  // per-thread flag
 393     }
 394 
 395   return num_active;
 396 }
 397 
 398 int VM_Exit::wait_for_threads_in_native_to_block() {
 399   // VM exits at safepoint. This function must be called at the final safepoint
 400   // to wait for threads in _thread_in_native state to be quiescent.
 401   assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint already");
 402 
 403   Thread * thr_cur = Thread::current();
 404   Monitor timer(Mutex::leaf, "VM_Exit timer", true,
 405                 Monitor::_safepoint_check_never);
 406 
 407   // Compiler threads need longer wait because they can access VM data directly
 408   // while in native. If they are active and some structures being used are
 409   // deleted by the shutdown sequence, they will crash. On the other hand, user
 410   // threads must go through native=>Java/VM transitions first to access VM
 411   // data, and they will be stopped during state transition. In theory, we
 412   // don't have to wait for user threads to be quiescent, but it's always
 413   // better to terminate VM when current thread is the only active thread, so
 414   // wait for user threads too. Numbers are in 10 milliseconds.
 415   int max_wait_user_thread = 30;                  // at least 300 milliseconds
 416   int max_wait_compiler_thread = 1000;            // at least 10 seconds
 417 
 418   int max_wait = max_wait_compiler_thread;
 419 
 420   int attempts = 0;
 421   while (true) {
 422     int num_active = 0;
 423     int num_active_compiler_thread = 0;


 460 
 461   // cleanup globals resources before exiting. exit_globals() currently
 462   // cleans up outputStream resources and PerfMemory resources.
 463   exit_globals();
 464 
 465   // Check for exit hook
 466   exit_hook_t exit_hook = Arguments::exit_hook();
 467   if (exit_hook != NULL) {
 468     // exit hook should exit.
 469     exit_hook(_exit_code);
 470     // ... but if it didn't, we must do it here
 471     vm_direct_exit(_exit_code);
 472   } else {
 473     vm_direct_exit(_exit_code);
 474   }
 475 }
 476 
 477 
 478 void VM_Exit::wait_if_vm_exited() {
 479   if (_vm_exited &&
 480       Thread::current_or_null() != _shutdown_thread) {
 481     // _vm_exited is set at safepoint, and the Threads_lock is never released
 482     // we will block here until the process dies
 483     Threads_lock->lock_without_safepoint_check();
 484     ShouldNotReachHere();
 485   }
 486 }
 487 
 488 void VM_PrintCompileQueue::doit() {
 489   CompileBroker::print_compile_queues(_out);
 490 }
 491 
 492 void VM_PrintCodeList::doit() {
 493   CodeCache::print_codelist(_out);
 494 }
 495 
 496 void VM_PrintCodeCache::doit() {
 497   CodeCache::print_layout(_out);
 498 }
 499 
 500 #if INCLUDE_SERVICES
< prev index next >