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