373 NMethodSweeper::print(); 374 } 375 376 #ifdef COMPILER2 377 if (PrintPreciseBiasedLockingStatistics || PrintPreciseRTMLockingStatistics) { 378 OptoRuntime::print_named_counters(); 379 } 380 #endif 381 if (PrintBiasedLockingStatistics) { 382 BiasedLocking::print_counters(); 383 } 384 385 // Native memory tracking data 386 if (PrintNMTStatistics) { 387 MemTracker::final_report(tty); 388 } 389 } 390 391 #endif 392 393 394 // Helper class for registering on_exit calls through JVM_OnExit 395 396 extern "C" { 397 typedef void (*__exit_proc)(void); 398 } 399 400 class ExitProc : public CHeapObj<mtInternal> { 401 private: 402 __exit_proc _proc; 403 // void (*_proc)(void); 404 ExitProc* _next; 405 public: 406 // ExitProc(void (*proc)(void)) { 407 ExitProc(__exit_proc proc) { 408 _proc = proc; 409 _next = NULL; 410 } 411 void evaluate() { _proc(); } 412 ExitProc* next() const { return _next; } 413 void set_next(ExitProc* next) { _next = next; } 414 }; 415 416 417 // Linked list of registered on_exit procedures 418 419 static ExitProc* exit_procs = NULL; 420 421 422 extern "C" { 423 void register_on_exit_function(void (*func)(void)) { 424 ExitProc *entry = new ExitProc(func); 425 // Classic vm does not throw an exception in case the allocation failed, 426 if (entry != NULL) { 427 entry->set_next(exit_procs); 428 exit_procs = entry; 429 } 430 } 431 } 432 433 // Note: before_exit() can be executed only once, if more than one threads 434 // are trying to shutdown the VM at the same time, only one thread 435 // can run before_exit() and all other threads must wait. 436 void before_exit(JavaThread * thread) { 437 #define BEFORE_EXIT_NOT_RUN 0 438 #define BEFORE_EXIT_RUNNING 1 439 #define BEFORE_EXIT_DONE 2 440 static jint volatile _before_exit_status = BEFORE_EXIT_NOT_RUN; 441 442 // Note: don't use a Mutex to guard the entire before_exit(), as 443 // JVMTI post_thread_end_event and post_vm_death_event will run native code. 444 // A CAS or OSMutex would work just fine but then we need to manipulate 445 // thread state for Safepoint. Here we use Monitor wait() and notify_all() 446 // for synchronization. 447 { MutexLocker ml(BeforeExit_lock); 448 switch (_before_exit_status) { 449 case BEFORE_EXIT_NOT_RUN: 450 _before_exit_status = BEFORE_EXIT_RUNNING; 451 break; 452 case BEFORE_EXIT_RUNNING: 453 while (_before_exit_status == BEFORE_EXIT_RUNNING) { 454 BeforeExit_lock->wait(); 455 } 456 assert(_before_exit_status == BEFORE_EXIT_DONE, "invalid state"); 457 return; 458 case BEFORE_EXIT_DONE: 459 return; 460 } 461 } 462 463 // The only difference between this and Win32's _onexit procs is that 464 // this version is invoked before any threads get killed. 465 ExitProc* current = exit_procs; 466 while (current != NULL) { 467 ExitProc* next = current->next(); 468 current->evaluate(); 469 delete current; 470 current = next; 471 } 472 473 // Hang forever on exit if we're reporting an error. 474 if (ShowMessageBoxOnError && is_error_reported()) { 475 os::infinite_sleep(); 476 } 477 478 // Terminate watcher thread - must before disenrolling any periodic task 479 if (PeriodicTask::num_tasks() > 0) 480 WatcherThread::stop(); 481 482 // Print statistics gathered (profiling ...) 483 if (Arguments::has_profile()) { 484 FlatProfiler::disengage(); 485 FlatProfiler::print(10); 486 } 487 488 // shut down the StatSampler task 489 StatSampler::disengage(); 490 StatSampler::destroy(); 491 492 // Stop concurrent GC threads | 373 NMethodSweeper::print(); 374 } 375 376 #ifdef COMPILER2 377 if (PrintPreciseBiasedLockingStatistics || PrintPreciseRTMLockingStatistics) { 378 OptoRuntime::print_named_counters(); 379 } 380 #endif 381 if (PrintBiasedLockingStatistics) { 382 BiasedLocking::print_counters(); 383 } 384 385 // Native memory tracking data 386 if (PrintNMTStatistics) { 387 MemTracker::final_report(tty); 388 } 389 } 390 391 #endif 392 393 // Note: before_exit() can be executed only once, if more than one threads 394 // are trying to shutdown the VM at the same time, only one thread 395 // can run before_exit() and all other threads must wait. 396 void before_exit(JavaThread * thread) { 397 #define BEFORE_EXIT_NOT_RUN 0 398 #define BEFORE_EXIT_RUNNING 1 399 #define BEFORE_EXIT_DONE 2 400 static jint volatile _before_exit_status = BEFORE_EXIT_NOT_RUN; 401 402 // Note: don't use a Mutex to guard the entire before_exit(), as 403 // JVMTI post_thread_end_event and post_vm_death_event will run native code. 404 // A CAS or OSMutex would work just fine but then we need to manipulate 405 // thread state for Safepoint. Here we use Monitor wait() and notify_all() 406 // for synchronization. 407 { MutexLocker ml(BeforeExit_lock); 408 switch (_before_exit_status) { 409 case BEFORE_EXIT_NOT_RUN: 410 _before_exit_status = BEFORE_EXIT_RUNNING; 411 break; 412 case BEFORE_EXIT_RUNNING: 413 while (_before_exit_status == BEFORE_EXIT_RUNNING) { 414 BeforeExit_lock->wait(); 415 } 416 assert(_before_exit_status == BEFORE_EXIT_DONE, "invalid state"); 417 return; 418 case BEFORE_EXIT_DONE: 419 return; 420 } 421 } 422 423 // Hang forever on exit if we're reporting an error. 424 if (ShowMessageBoxOnError && is_error_reported()) { 425 os::infinite_sleep(); 426 } 427 428 // Terminate watcher thread - must before disenrolling any periodic task 429 if (PeriodicTask::num_tasks() > 0) 430 WatcherThread::stop(); 431 432 // Print statistics gathered (profiling ...) 433 if (Arguments::has_profile()) { 434 FlatProfiler::disengage(); 435 FlatProfiler::print(10); 436 } 437 438 // shut down the StatSampler task 439 StatSampler::disengage(); 440 StatSampler::destroy(); 441 442 // Stop concurrent GC threads |