72 #include "utilities/globalDefinitions.hpp" 73 #include "utilities/histogram.hpp" 74 #include "utilities/macros.hpp" 75 #include "utilities/vmError.hpp" 76 #if INCLUDE_ALL_GCS 77 #include "gc/cms/concurrentMarkSweepThread.hpp" 78 #include "gc/parallel/psScavenge.hpp" 79 #endif // INCLUDE_ALL_GCS 80 #ifdef COMPILER1 81 #include "c1/c1_Compiler.hpp" 82 #include "c1/c1_Runtime1.hpp" 83 #endif 84 #ifdef COMPILER2 85 #include "code/compiledIC.hpp" 86 #include "compiler/methodLiveness.hpp" 87 #include "opto/compile.hpp" 88 #include "opto/indexSet.hpp" 89 #include "opto/runtime.hpp" 90 #endif 91 92 GrowableArray<Method*>* collected_profiled_methods; 93 94 int compare_methods(Method** a, Method** b) { 95 // %%% there can be 32-bit overflow here 96 return ((*b)->invocation_count() + (*b)->compiled_invocation_count()) 97 - ((*a)->invocation_count() + (*a)->compiled_invocation_count()); 98 } 99 100 void collect_profiled_methods(Method* m) { 101 Thread* thread = Thread::current(); 102 // This HandleMark prevents a huge amount of handles from being added 103 // to the metadata_handles() array on the thread. 104 HandleMark hm(thread); 105 methodHandle mh(thread, m); 106 if ((m->method_data() != NULL) && 107 (PrintMethodData || CompilerOracle::should_print(mh))) { 108 collected_profiled_methods->push(m); 109 } 110 } 111 341 alloc_stats.print(); 342 tty->cr(); 343 } 344 345 if (PrintSystemDictionaryAtExit) { 346 SystemDictionary::print(); 347 } 348 349 if (LogTouchedMethods && PrintTouchedMethodsAtExit) { 350 Method::print_touched_methods(tty); 351 } 352 353 if (PrintBiasedLockingStatistics) { 354 BiasedLocking::print_counters(); 355 } 356 357 // Native memory tracking data 358 if (PrintNMTStatistics) { 359 MemTracker::final_report(tty); 360 } 361 } 362 363 #else // PRODUCT MODE STATISTICS 364 365 void print_statistics() { 366 367 if (PrintMethodData) { 368 print_method_profiling_data(); 369 } 370 371 if (CITime) { 372 CompileBroker::print_times(); 373 } 374 375 if (PrintCodeCache) { 376 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); 377 CodeCache::print(); 378 } 379 380 if (PrintMethodFlushingStatistics) { 381 NMethodSweeper::print(); 382 } 383 384 #ifdef COMPILER2 385 if (PrintPreciseBiasedLockingStatistics || PrintPreciseRTMLockingStatistics) { 386 OptoRuntime::print_named_counters(); 387 } 388 #endif 389 if (PrintBiasedLockingStatistics) { 390 BiasedLocking::print_counters(); 391 } 392 393 // Native memory tracking data 394 if (PrintNMTStatistics) { 395 MemTracker::final_report(tty); 396 } 397 398 if (LogTouchedMethods && PrintTouchedMethodsAtExit) { 399 Method::print_touched_methods(tty); 400 } 401 } 402 403 #endif 404 405 // Note: before_exit() can be executed only once, if more than one threads 406 // are trying to shutdown the VM at the same time, only one thread 407 // can run before_exit() and all other threads must wait. 408 void before_exit(JavaThread* thread) { 409 #define BEFORE_EXIT_NOT_RUN 0 410 #define BEFORE_EXIT_RUNNING 1 411 #define BEFORE_EXIT_DONE 2 412 static jint volatile _before_exit_status = BEFORE_EXIT_NOT_RUN; 413 414 // Note: don't use a Mutex to guard the entire before_exit(), as 415 // JVMTI post_thread_end_event and post_vm_death_event will run native code. 416 // A CAS or OSMutex would work just fine but then we need to manipulate 417 // thread state for Safepoint. Here we use Monitor wait() and notify_all() 418 // for synchronization. 419 { MutexLocker ml(BeforeExit_lock); 420 switch (_before_exit_status) { | 72 #include "utilities/globalDefinitions.hpp" 73 #include "utilities/histogram.hpp" 74 #include "utilities/macros.hpp" 75 #include "utilities/vmError.hpp" 76 #if INCLUDE_ALL_GCS 77 #include "gc/cms/concurrentMarkSweepThread.hpp" 78 #include "gc/parallel/psScavenge.hpp" 79 #endif // INCLUDE_ALL_GCS 80 #ifdef COMPILER1 81 #include "c1/c1_Compiler.hpp" 82 #include "c1/c1_Runtime1.hpp" 83 #endif 84 #ifdef COMPILER2 85 #include "code/compiledIC.hpp" 86 #include "compiler/methodLiveness.hpp" 87 #include "opto/compile.hpp" 88 #include "opto/indexSet.hpp" 89 #include "opto/runtime.hpp" 90 #endif 91 92 #include "gc/shenandoah/shenandoahWorkGroup.hpp" 93 94 GrowableArray<Method*>* collected_profiled_methods; 95 96 int compare_methods(Method** a, Method** b) { 97 // %%% there can be 32-bit overflow here 98 return ((*b)->invocation_count() + (*b)->compiled_invocation_count()) 99 - ((*a)->invocation_count() + (*a)->compiled_invocation_count()); 100 } 101 102 void collect_profiled_methods(Method* m) { 103 Thread* thread = Thread::current(); 104 // This HandleMark prevents a huge amount of handles from being added 105 // to the metadata_handles() array on the thread. 106 HandleMark hm(thread); 107 methodHandle mh(thread, m); 108 if ((m->method_data() != NULL) && 109 (PrintMethodData || CompilerOracle::should_print(mh))) { 110 collected_profiled_methods->push(m); 111 } 112 } 113 343 alloc_stats.print(); 344 tty->cr(); 345 } 346 347 if (PrintSystemDictionaryAtExit) { 348 SystemDictionary::print(); 349 } 350 351 if (LogTouchedMethods && PrintTouchedMethodsAtExit) { 352 Method::print_touched_methods(tty); 353 } 354 355 if (PrintBiasedLockingStatistics) { 356 BiasedLocking::print_counters(); 357 } 358 359 // Native memory tracking data 360 if (PrintNMTStatistics) { 361 MemTracker::final_report(tty); 362 } 363 364 if (PrintShenandoahWorkGangStats) { 365 ShenandoahWorkGang::print_stats(); 366 } 367 } 368 369 #else // PRODUCT MODE STATISTICS 370 371 void print_statistics() { 372 373 if (PrintMethodData) { 374 print_method_profiling_data(); 375 } 376 377 if (CITime) { 378 CompileBroker::print_times(); 379 } 380 381 if (PrintCodeCache) { 382 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); 383 CodeCache::print(); 384 } 385 386 if (PrintMethodFlushingStatistics) { 387 NMethodSweeper::print(); 388 } 389 390 #ifdef COMPILER2 391 if (PrintPreciseBiasedLockingStatistics || PrintPreciseRTMLockingStatistics) { 392 OptoRuntime::print_named_counters(); 393 } 394 #endif 395 if (PrintBiasedLockingStatistics) { 396 BiasedLocking::print_counters(); 397 } 398 399 // Native memory tracking data 400 if (PrintNMTStatistics) { 401 MemTracker::final_report(tty); 402 } 403 404 if (LogTouchedMethods && PrintTouchedMethodsAtExit) { 405 Method::print_touched_methods(tty); 406 } 407 408 if (PrintShenandoahWorkGangStats) { 409 ShenandoahWorkGang::print_stats(); 410 } 411 412 } 413 414 #endif 415 416 // Note: before_exit() can be executed only once, if more than one threads 417 // are trying to shutdown the VM at the same time, only one thread 418 // can run before_exit() and all other threads must wait. 419 void before_exit(JavaThread* thread) { 420 #define BEFORE_EXIT_NOT_RUN 0 421 #define BEFORE_EXIT_RUNNING 1 422 #define BEFORE_EXIT_DONE 2 423 static jint volatile _before_exit_status = BEFORE_EXIT_NOT_RUN; 424 425 // Note: don't use a Mutex to guard the entire before_exit(), as 426 // JVMTI post_thread_end_event and post_vm_death_event will run native code. 427 // A CAS or OSMutex would work just fine but then we need to manipulate 428 // thread state for Safepoint. Here we use Monitor wait() and notify_all() 429 // for synchronization. 430 { MutexLocker ml(BeforeExit_lock); 431 switch (_before_exit_status) { |