src/share/vm/runtime/java.cpp

Print this page
rev 13113 : 8182651: Add TRACE_ONLY conditional macro to support more fine-grained INCLUDE_TRACE programming
Reviewed-by:


  49 #include "oops/oop.inline.hpp"
  50 #include "oops/symbol.hpp"
  51 #include "prims/jvmtiExport.hpp"
  52 #include "runtime/arguments.hpp"
  53 #include "runtime/biasedLocking.hpp"
  54 #include "runtime/compilationPolicy.hpp"
  55 #include "runtime/deoptimization.hpp"
  56 #include "runtime/fprofiler.hpp"
  57 #include "runtime/init.hpp"
  58 #include "runtime/interfaceSupport.hpp"
  59 #include "runtime/java.hpp"
  60 #include "runtime/memprofiler.hpp"
  61 #include "runtime/sharedRuntime.hpp"
  62 #include "runtime/statSampler.hpp"
  63 #include "runtime/sweeper.hpp"
  64 #include "runtime/task.hpp"
  65 #include "runtime/thread.inline.hpp"
  66 #include "runtime/timer.hpp"
  67 #include "runtime/vm_operations.hpp"
  68 #include "services/memTracker.hpp"
  69 #include "trace/traceMacros.hpp"
  70 #include "trace/tracing.hpp"
  71 #include "utilities/dtrace.hpp"
  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   methodHandle mh(thread, m);
 103   if ((m->method_data() != NULL) &&
 104       (PrintMethodData || CompilerOracle::should_print(mh))) {
 105     collected_profiled_methods->push(m);
 106   }
 107 }
 108 
 109 void print_method_profiling_data() {
 110   if (ProfileInterpreter COMPILER1_PRESENT(|| C1UpdateMethodData) &&


 382   if (PrintPreciseBiasedLockingStatistics || PrintPreciseRTMLockingStatistics) {
 383     OptoRuntime::print_named_counters();
 384   }
 385 #endif
 386   if (PrintBiasedLockingStatistics) {
 387     BiasedLocking::print_counters();
 388   }
 389 
 390   // Native memory tracking data
 391   if (PrintNMTStatistics) {
 392     MemTracker::final_report(tty);
 393   }
 394 
 395   if (LogTouchedMethods && PrintTouchedMethodsAtExit) {
 396     Method::print_touched_methods(tty);
 397   }
 398 }
 399 
 400 #endif
 401 










 402 // Note: before_exit() can be executed only once, if more than one threads
 403 //       are trying to shutdown the VM at the same time, only one thread
 404 //       can run before_exit() and all other threads must wait.
 405 void before_exit(JavaThread* thread) {
 406   #define BEFORE_EXIT_NOT_RUN 0
 407   #define BEFORE_EXIT_RUNNING 1
 408   #define BEFORE_EXIT_DONE    2
 409   static jint volatile _before_exit_status = BEFORE_EXIT_NOT_RUN;
 410 
 411   // Note: don't use a Mutex to guard the entire before_exit(), as
 412   // JVMTI post_thread_end_event and post_vm_death_event will run native code.
 413   // A CAS or OSMutex would work just fine but then we need to manipulate
 414   // thread state for Safepoint. Here we use Monitor wait() and notify_all()
 415   // for synchronization.
 416   { MutexLocker ml(BeforeExit_lock);
 417     switch (_before_exit_status) {
 418     case BEFORE_EXIT_NOT_RUN:
 419       _before_exit_status = BEFORE_EXIT_RUNNING;
 420       break;
 421     case BEFORE_EXIT_RUNNING:


 431       }
 432     }
 433   }
 434 
 435 #if INCLUDE_JVMCI
 436   // We are not using CATCH here because we want the exit to continue normally.
 437   Thread* THREAD = thread;
 438   JVMCIRuntime::shutdown(THREAD);
 439   if (HAS_PENDING_EXCEPTION) {
 440     Handle exception(THREAD, PENDING_EXCEPTION);
 441     CLEAR_PENDING_EXCEPTION;
 442     java_lang_Throwable::java_printStackTrace(exception, THREAD);
 443   }
 444 #endif
 445 
 446   // Hang forever on exit if we're reporting an error.
 447   if (ShowMessageBoxOnError && is_error_reported()) {
 448     os::infinite_sleep();
 449   }
 450 
 451   EventThreadEnd event;
 452   if (event.should_commit()) {
 453     event.set_thread(THREAD_TRACE_ID(thread));
 454     event.commit();
 455   }
 456 
 457   TRACE_VM_EXIT();
 458 
 459   // Stop the WatcherThread. We do this before disenrolling various
 460   // PeriodicTasks to reduce the likelihood of races.
 461   if (PeriodicTask::num_tasks() > 0) {
 462     WatcherThread::stop();
 463   }
 464 
 465   // Print statistics gathered (profiling ...)
 466   if (Arguments::has_profile()) {
 467     FlatProfiler::disengage();
 468     FlatProfiler::print(10);
 469   }
 470 
 471   // shut down the StatSampler task
 472   StatSampler::disengage();
 473   StatSampler::destroy();
 474 
 475   // Stop concurrent GC threads
 476   Universe::heap()->stop();




  49 #include "oops/oop.inline.hpp"
  50 #include "oops/symbol.hpp"
  51 #include "prims/jvmtiExport.hpp"
  52 #include "runtime/arguments.hpp"
  53 #include "runtime/biasedLocking.hpp"
  54 #include "runtime/compilationPolicy.hpp"
  55 #include "runtime/deoptimization.hpp"
  56 #include "runtime/fprofiler.hpp"
  57 #include "runtime/init.hpp"
  58 #include "runtime/interfaceSupport.hpp"
  59 #include "runtime/java.hpp"
  60 #include "runtime/memprofiler.hpp"
  61 #include "runtime/sharedRuntime.hpp"
  62 #include "runtime/statSampler.hpp"
  63 #include "runtime/sweeper.hpp"
  64 #include "runtime/task.hpp"
  65 #include "runtime/thread.inline.hpp"
  66 #include "runtime/timer.hpp"
  67 #include "runtime/vm_operations.hpp"
  68 #include "services/memTracker.hpp"


  69 #include "utilities/dtrace.hpp"
  70 #include "utilities/globalDefinitions.hpp"
  71 #include "utilities/histogram.hpp"
  72 #include "utilities/macros.hpp"
  73 #include "utilities/vmError.hpp"
  74 #if INCLUDE_ALL_GCS
  75 #include "gc/cms/concurrentMarkSweepThread.hpp"
  76 #include "gc/parallel/psScavenge.hpp"
  77 #endif // INCLUDE_ALL_GCS
  78 #ifdef COMPILER1
  79 #include "c1/c1_Compiler.hpp"
  80 #include "c1/c1_Runtime1.hpp"
  81 #endif
  82 #ifdef COMPILER2
  83 #include "code/compiledIC.hpp"
  84 #include "compiler/methodLiveness.hpp"
  85 #include "opto/compile.hpp"
  86 #include "opto/indexSet.hpp"
  87 #include "opto/runtime.hpp"
  88 #endif
  89 #if INCLUDE_TRACE
  90 #include "trace/traceMacros.hpp"
  91 #include "trace/tracing.hpp"
  92 #endif
  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   methodHandle mh(thread, m);
 105   if ((m->method_data() != NULL) &&
 106       (PrintMethodData || CompilerOracle::should_print(mh))) {
 107     collected_profiled_methods->push(m);
 108   }
 109 }
 110 
 111 void print_method_profiling_data() {
 112   if (ProfileInterpreter COMPILER1_PRESENT(|| C1UpdateMethodData) &&


 384   if (PrintPreciseBiasedLockingStatistics || PrintPreciseRTMLockingStatistics) {
 385     OptoRuntime::print_named_counters();
 386   }
 387 #endif
 388   if (PrintBiasedLockingStatistics) {
 389     BiasedLocking::print_counters();
 390   }
 391 
 392   // Native memory tracking data
 393   if (PrintNMTStatistics) {
 394     MemTracker::final_report(tty);
 395   }
 396 
 397   if (LogTouchedMethods && PrintTouchedMethodsAtExit) {
 398     Method::print_touched_methods(tty);
 399   }
 400 }
 401 
 402 #endif
 403 
 404 #if INCLUDE_TRACE
 405 static void post_thread_end_event(const JavaThread* jt) {
 406   EventThreadEnd event;
 407   if (event.should_commit()) {
 408     event.set_thread(THREAD_TRACE_ID(jt));
 409     event.commit();
 410   }
 411 }
 412 #endif
 413 
 414 // Note: before_exit() can be executed only once, if more than one threads
 415 //       are trying to shutdown the VM at the same time, only one thread
 416 //       can run before_exit() and all other threads must wait.
 417 void before_exit(JavaThread* thread) {
 418   #define BEFORE_EXIT_NOT_RUN 0
 419   #define BEFORE_EXIT_RUNNING 1
 420   #define BEFORE_EXIT_DONE    2
 421   static jint volatile _before_exit_status = BEFORE_EXIT_NOT_RUN;
 422 
 423   // Note: don't use a Mutex to guard the entire before_exit(), as
 424   // JVMTI post_thread_end_event and post_vm_death_event will run native code.
 425   // A CAS or OSMutex would work just fine but then we need to manipulate
 426   // thread state for Safepoint. Here we use Monitor wait() and notify_all()
 427   // for synchronization.
 428   { MutexLocker ml(BeforeExit_lock);
 429     switch (_before_exit_status) {
 430     case BEFORE_EXIT_NOT_RUN:
 431       _before_exit_status = BEFORE_EXIT_RUNNING;
 432       break;
 433     case BEFORE_EXIT_RUNNING:


 443       }
 444     }
 445   }
 446 
 447 #if INCLUDE_JVMCI
 448   // We are not using CATCH here because we want the exit to continue normally.
 449   Thread* THREAD = thread;
 450   JVMCIRuntime::shutdown(THREAD);
 451   if (HAS_PENDING_EXCEPTION) {
 452     Handle exception(THREAD, PENDING_EXCEPTION);
 453     CLEAR_PENDING_EXCEPTION;
 454     java_lang_Throwable::java_printStackTrace(exception, THREAD);
 455   }
 456 #endif
 457 
 458   // Hang forever on exit if we're reporting an error.
 459   if (ShowMessageBoxOnError && is_error_reported()) {
 460     os::infinite_sleep();
 461   }
 462 
 463   TRACE_ONLY(post_thread_end_event(thread);)





 464   TRACE_VM_EXIT();
 465 
 466   // Stop the WatcherThread. We do this before disenrolling various
 467   // PeriodicTasks to reduce the likelihood of races.
 468   if (PeriodicTask::num_tasks() > 0) {
 469     WatcherThread::stop();
 470   }
 471 
 472   // Print statistics gathered (profiling ...)
 473   if (Arguments::has_profile()) {
 474     FlatProfiler::disengage();
 475     FlatProfiler::print(10);
 476   }
 477 
 478   // shut down the StatSampler task
 479   StatSampler::disengage();
 480   StatSampler::destroy();
 481 
 482   // Stop concurrent GC threads
 483   Universe::heap()->stop();