src/hotspot/share/runtime/thread.cpp
changeset 50113 caf115bb98ad
parent 50077 e32abf6409af
child 50184 1a4101ebec92
equal deleted inserted replaced
50112:7a2a740815b7 50113:caf115bb98ad
    38 #include "gc/shared/gcLocker.inline.hpp"
    38 #include "gc/shared/gcLocker.inline.hpp"
    39 #include "gc/shared/workgroup.hpp"
    39 #include "gc/shared/workgroup.hpp"
    40 #include "interpreter/interpreter.hpp"
    40 #include "interpreter/interpreter.hpp"
    41 #include "interpreter/linkResolver.hpp"
    41 #include "interpreter/linkResolver.hpp"
    42 #include "interpreter/oopMapCache.hpp"
    42 #include "interpreter/oopMapCache.hpp"
       
    43 #include "jfr/jfrEvents.hpp"
       
    44 #include "jfr/support/jfrThreadId.hpp"
    43 #include "jvmtifiles/jvmtiEnv.hpp"
    45 #include "jvmtifiles/jvmtiEnv.hpp"
    44 #include "logging/log.hpp"
    46 #include "logging/log.hpp"
    45 #include "logging/logConfiguration.hpp"
    47 #include "logging/logConfiguration.hpp"
    46 #include "logging/logStream.hpp"
    48 #include "logging/logStream.hpp"
    47 #include "memory/allocation.inline.hpp"
    49 #include "memory/allocation.inline.hpp"
   101 #include "runtime/vm_version.hpp"
   103 #include "runtime/vm_version.hpp"
   102 #include "services/attachListener.hpp"
   104 #include "services/attachListener.hpp"
   103 #include "services/management.hpp"
   105 #include "services/management.hpp"
   104 #include "services/memTracker.hpp"
   106 #include "services/memTracker.hpp"
   105 #include "services/threadService.hpp"
   107 #include "services/threadService.hpp"
   106 #include "trace/traceMacros.hpp"
       
   107 #include "trace/tracing.hpp"
       
   108 #include "trace/tracingExport.hpp"
       
   109 #include "utilities/align.hpp"
   108 #include "utilities/align.hpp"
   110 #include "utilities/copy.hpp"
   109 #include "utilities/copy.hpp"
   111 #include "utilities/defaultStream.hpp"
   110 #include "utilities/defaultStream.hpp"
   112 #include "utilities/dtrace.hpp"
   111 #include "utilities/dtrace.hpp"
   113 #include "utilities/events.hpp"
   112 #include "utilities/events.hpp"
   127 #include "opto/idealGraphPrinter.hpp"
   126 #include "opto/idealGraphPrinter.hpp"
   128 #endif
   127 #endif
   129 #if INCLUDE_RTM_OPT
   128 #if INCLUDE_RTM_OPT
   130 #include "runtime/rtmLocking.hpp"
   129 #include "runtime/rtmLocking.hpp"
   131 #endif
   130 #endif
       
   131 #if INCLUDE_JFR
       
   132 #include "jfr/jfr.hpp"
       
   133 #endif
   132 
   134 
   133 // Initialization after module runtime initialization
   135 // Initialization after module runtime initialization
   134 void universe_post_module_init();  // must happen after call_initPhase2
   136 void universe_post_module_init();  // must happen after call_initPhase2
   135 
   137 
   136 #ifdef DTRACE_ENABLED
   138 #ifdef DTRACE_ENABLED
   363     p2i(stack_base()), stack_size()/1024);
   365     p2i(stack_base()), stack_size()/1024);
   364 }
   366 }
   365 
   367 
   366 
   368 
   367 Thread::~Thread() {
   369 Thread::~Thread() {
   368   EVENT_THREAD_DESTRUCT(this);
   370   JFR_ONLY(Jfr::on_thread_destruct(this);)
   369 
   371 
   370   // Notify the barrier set that a thread is being destroyed. Note that a barrier
   372   // Notify the barrier set that a thread is being destroyed. Note that a barrier
   371   // set might not be available if we encountered errors during bootstrapping.
   373   // set might not be available if we encountered errors during bootstrapping.
   372   BarrierSet* const barrier_set = BarrierSet::barrier_set();
   374   BarrierSet* const barrier_set = BarrierSet::barrier_set();
   373   if (barrier_set != NULL) {
   375   if (barrier_set != NULL) {
   374     barrier_set->on_thread_destroy(this);
   376     barrier_set->on_thread_destroy(this);
   375   }
   377   }
       
   378 
   376 
   379 
   377   // stack_base can be NULL if the thread is never started or exited before
   380   // stack_base can be NULL if the thread is never started or exited before
   378   // record_stack_base_and_size called. Although, we would like to ensure
   381   // record_stack_base_and_size called. Although, we would like to ensure
   379   // that all started threads do call record_stack_base_and_size(), there is
   382   // that all started threads do call record_stack_base_and_size(), there is
   380   // not proper way to enforce that.
   383   // not proper way to enforce that.
  1736     JvmtiExport::post_thread_start(this);
  1739     JvmtiExport::post_thread_start(this);
  1737   }
  1740   }
  1738 
  1741 
  1739   EventThreadStart event;
  1742   EventThreadStart event;
  1740   if (event.should_commit()) {
  1743   if (event.should_commit()) {
  1741     event.set_thread(THREAD_TRACE_ID(this));
  1744     event.set_thread(JFR_THREAD_ID(this));
  1742     event.commit();
  1745     event.commit();
  1743   }
  1746   }
  1744 
  1747 
  1745   // We call another function to do the rest so we are sure that the stack addresses used
  1748   // We call another function to do the rest so we are sure that the stack addresses used
  1746   // from there will be lower than the stack base just computed
  1749   // from there will be lower than the stack base just computed
  1843 
  1846 
  1844     // Called before the java thread exit since we want to read info
  1847     // Called before the java thread exit since we want to read info
  1845     // from java_lang_Thread object
  1848     // from java_lang_Thread object
  1846     EventThreadEnd event;
  1849     EventThreadEnd event;
  1847     if (event.should_commit()) {
  1850     if (event.should_commit()) {
  1848       event.set_thread(THREAD_TRACE_ID(this));
  1851       event.set_thread(JFR_THREAD_ID(this));
  1849       event.commit();
  1852       event.commit();
  1850     }
  1853     }
  1851 
  1854 
  1852     // Call after last event on thread
  1855     // Call after last event on thread
  1853     EVENT_THREAD_EXIT(this);
  1856     JFR_ONLY(Jfr::on_thread_exit(this);)
  1854 
  1857 
  1855     // Call Thread.exit(). We try 3 times in case we got another Thread.stop during
  1858     // Call Thread.exit(). We try 3 times in case we got another Thread.stop during
  1856     // the execution of the method. If that is not enough, then we don't really care. Thread.stop
  1859     // the execution of the method. If that is not enough, then we don't really care. Thread.stop
  1857     // is deprecated anyhow.
  1860     // is deprecated anyhow.
  1858     if (!is_Compiler_thread()) {
  1861     if (!is_Compiler_thread()) {
  2205   }
  2208   }
  2206 
  2209 
  2207   if (check_asyncs) {
  2210   if (check_asyncs) {
  2208     check_and_handle_async_exceptions();
  2211     check_and_handle_async_exceptions();
  2209   }
  2212   }
  2210 #if INCLUDE_TRACE
  2213 
  2211   if (is_trace_suspend()) {
  2214   JFR_ONLY(SUSPEND_THREAD_CONDITIONAL(this);)
  2212     TRACE_SUSPEND_THREAD(this);
       
  2213   }
       
  2214 #endif
       
  2215 }
  2215 }
  2216 
  2216 
  2217 void JavaThread::send_thread_stop(oop java_throwable)  {
  2217 void JavaThread::send_thread_stop(oop java_throwable)  {
  2218   assert(Thread::current()->is_VM_thread(), "should be in the vm thread");
  2218   assert(Thread::current()->is_VM_thread(), "should be in the vm thread");
  2219   assert(Threads_lock->is_locked(), "Threads_lock should be locked by safepoint code");
  2219   assert(Threads_lock->is_locked(), "Threads_lock should be locked by safepoint code");
  2431       f.deoptimize(thread);
  2431       f.deoptimize(thread);
  2432     } else {
  2432     } else {
  2433       fatal("missed deoptimization!");
  2433       fatal("missed deoptimization!");
  2434     }
  2434     }
  2435   }
  2435   }
  2436 #if INCLUDE_TRACE
  2436 
  2437   if (thread->is_trace_suspend()) {
  2437   JFR_ONLY(SUSPEND_THREAD_CONDITIONAL(thread);)
  2438     TRACE_SUSPEND_THREAD(thread);
       
  2439   }
       
  2440 #endif
       
  2441 }
  2438 }
  2442 
  2439 
  2443 // Slow path when the native==>VM/Java barriers detect a safepoint is in
  2440 // Slow path when the native==>VM/Java barriers detect a safepoint is in
  2444 // progress or when _suspend_flags is non-zero.
  2441 // progress or when _suspend_flags is non-zero.
  2445 // Current thread needs to self-suspend if there is a suspend request and/or
  2442 // Current thread needs to self-suspend if there is a suspend request and/or
  3420   // checking in some cases.
  3417   // checking in some cases.
  3421   if (wt != NULL) {
  3418   if (wt != NULL) {
  3422     tc->do_thread(wt);
  3419     tc->do_thread(wt);
  3423   }
  3420   }
  3424 
  3421 
  3425 #if INCLUDE_TRACE
  3422 #if INCLUDE_JFR
  3426   Thread* sampler_thread = TracingExport::sampler_thread_acquire();
  3423   Thread* sampler_thread = Jfr::sampler_thread();
  3427   if (sampler_thread != NULL) {
  3424   if (sampler_thread != NULL) {
  3428     tc->do_thread(sampler_thread);
  3425     tc->do_thread(sampler_thread);
  3429   }
  3426   }
       
  3427 
  3430 #endif
  3428 #endif
  3431 
  3429 
  3432   // If CompilerThreads ever become non-JavaThreads, add them here
  3430   // If CompilerThreads ever become non-JavaThreads, add them here
  3433 }
  3431 }
  3434 
  3432 
  3733     main_thread->smr_delete();
  3731     main_thread->smr_delete();
  3734     *canTryAgain = false; // don't let caller call JNI_CreateJavaVM again
  3732     *canTryAgain = false; // don't let caller call JNI_CreateJavaVM again
  3735     return status;
  3733     return status;
  3736   }
  3734   }
  3737 
  3735 
  3738   if (TRACE_INITIALIZE() != JNI_OK) {
  3736   JFR_ONLY(Jfr::on_vm_init();)
  3739     vm_exit_during_initialization("Failed to initialize tracing backend");
       
  3740   }
       
  3741 
  3737 
  3742   // Should be done after the heap is fully created
  3738   // Should be done after the heap is fully created
  3743   main_thread->cache_global_variables();
  3739   main_thread->cache_global_variables();
  3744 
  3740 
  3745   HandleMark hm;
  3741   HandleMark hm;
  3906   JvmtiExport::enter_live_phase();
  3902   JvmtiExport::enter_live_phase();
  3907 
  3903 
  3908   // Notify JVMTI agents that VM initialization is complete - nop if no agents.
  3904   // Notify JVMTI agents that VM initialization is complete - nop if no agents.
  3909   JvmtiExport::post_vm_initialized();
  3905   JvmtiExport::post_vm_initialized();
  3910 
  3906 
  3911   if (TRACE_START() != JNI_OK) {
  3907   JFR_ONLY(Jfr::on_vm_start();)
  3912     vm_exit_during_initialization("Failed to start tracing backend.");
       
  3913   }
       
  3914 
  3908 
  3915 #if INCLUDE_MANAGEMENT
  3909 #if INCLUDE_MANAGEMENT
  3916   Management::initialize(THREAD);
  3910   Management::initialize(THREAD);
  3917 
  3911 
  3918   if (HAS_PENDING_EXCEPTION) {
  3912   if (HAS_PENDING_EXCEPTION) {