src/share/vm/runtime/thread.cpp

changeset 9931
fd44df5e3bc3
parent 9852
70aa912cebe5
parent 9925
30fb8c8cceb9
child 10015
eb7ce841ccec
     1.1 --- a/src/share/vm/runtime/thread.cpp	Wed Oct 14 16:43:13 2020 +0800
     1.2 +++ b/src/share/vm/runtime/thread.cpp	Wed Oct 14 17:44:48 2020 +0800
     1.3 @@ -38,6 +38,7 @@
     1.4  #include "interpreter/interpreter.hpp"
     1.5  #include "interpreter/linkResolver.hpp"
     1.6  #include "interpreter/oopMapCache.hpp"
     1.7 +#include "jfr/jfrEvents.hpp"
     1.8  #include "jvmtifiles/jvmtiEnv.hpp"
     1.9  #include "memory/gcLocker.inline.hpp"
    1.10  #include "memory/metaspaceShared.hpp"
    1.11 @@ -83,8 +84,6 @@
    1.12  #include "services/management.hpp"
    1.13  #include "services/memTracker.hpp"
    1.14  #include "services/threadService.hpp"
    1.15 -#include "trace/tracing.hpp"
    1.16 -#include "trace/traceMacros.hpp"
    1.17  #include "utilities/defaultStream.hpp"
    1.18  #include "utilities/dtrace.hpp"
    1.19  #include "utilities/events.hpp"
    1.20 @@ -117,6 +116,9 @@
    1.21  #if INCLUDE_RTM_OPT
    1.22  #include "runtime/rtmLocking.hpp"
    1.23  #endif
    1.24 +#if INCLUDE_JFR
    1.25 +#include "jfr/jfr.hpp"
    1.26 +#endif
    1.27  
    1.28  PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
    1.29  
    1.30 @@ -348,8 +350,6 @@
    1.31    // Reclaim the objectmonitors from the omFreeList of the moribund thread.
    1.32    ObjectSynchronizer::omFlush (this) ;
    1.33  
    1.34 -  EVENT_THREAD_DESTRUCT(this);
    1.35 -
    1.36    // stack_base can be NULL if the thread is never started or exited before
    1.37    // record_stack_base_and_size called. Although, we would like to ensure
    1.38    // that all started threads do call record_stack_base_and_size(), there is
    1.39 @@ -968,7 +968,7 @@
    1.40    address end = os::current_stack_pointer();
    1.41    // Allow non Java threads to call this without stack_base
    1.42    if (_stack_base == NULL) return true;
    1.43 -  if (stack_base() >= adr && adr >= end) return true;
    1.44 +  if (stack_base() > adr && adr >= end) return true;
    1.45  
    1.46    return false;
    1.47  }
    1.48 @@ -1220,6 +1220,7 @@
    1.49  }
    1.50  
    1.51  NamedThread::~NamedThread() {
    1.52 +  JFR_ONLY(Jfr::on_thread_exit(this);)
    1.53    if (_name != NULL) {
    1.54      FREE_C_HEAP_ARRAY(char, _name, mtThread);
    1.55      _name = NULL;
    1.56 @@ -1246,7 +1247,7 @@
    1.57  bool WatcherThread::_startable = false;
    1.58  volatile bool  WatcherThread::_should_terminate = false;
    1.59  
    1.60 -WatcherThread::WatcherThread() : Thread(), _crash_protection(NULL) {
    1.61 +WatcherThread::WatcherThread() : Thread() {
    1.62    assert(watcher_thread() == NULL, "we can only allocate one WatcherThread");
    1.63    if (os::create_thread(this, os::watcher_thread)) {
    1.64      _watcher_thread = this;
    1.65 @@ -1677,11 +1678,7 @@
    1.66      JvmtiExport::post_thread_start(this);
    1.67    }
    1.68  
    1.69 -  EventThreadStart event;
    1.70 -  if (event.should_commit()) {
    1.71 -     event.set_javalangthread(java_lang_Thread::thread_id(this->threadObj()));
    1.72 -     event.commit();
    1.73 -  }
    1.74 +  JFR_ONLY(Jfr::on_thread_start(this);)
    1.75  
    1.76    // We call another function to do the rest so we are sure that the stack addresses used
    1.77    // from there will be lower than the stack base just computed
    1.78 @@ -1808,17 +1805,7 @@
    1.79          }
    1.80        }
    1.81      }
    1.82 -
    1.83 -    // Called before the java thread exit since we want to read info
    1.84 -    // from java_lang_Thread object
    1.85 -    EventThreadEnd event;
    1.86 -    if (event.should_commit()) {
    1.87 -        event.set_javalangthread(java_lang_Thread::thread_id(this->threadObj()));
    1.88 -        event.commit();
    1.89 -    }
    1.90 -
    1.91 -    // Call after last event on thread
    1.92 -    EVENT_THREAD_EXIT(this);
    1.93 +    JFR_ONLY(Jfr::on_java_thread_dismantle(this);)
    1.94  
    1.95      // Call Thread.exit(). We try 3 times in case we got another Thread.stop during
    1.96      // the execution of the method. If that is not enough, then we don't really care. Thread.stop
    1.97 @@ -1895,6 +1882,7 @@
    1.98    // These things needs to be done while we are still a Java Thread. Make sure that thread
    1.99    // is in a consistent state, in case GC happens
   1.100    assert(_privileged_stack_top == NULL, "must be NULL when we get here");
   1.101 +  JFR_ONLY(Jfr::on_thread_exit(this);)
   1.102  
   1.103    if (active_handles() != NULL) {
   1.104      JNIHandleBlock* block = active_handles();
   1.105 @@ -2194,6 +2182,8 @@
   1.106    if (check_asyncs) {
   1.107      check_and_handle_async_exceptions();
   1.108    }
   1.109 +
   1.110 +  JFR_ONLY(SUSPEND_THREAD_CONDITIONAL(this);)
   1.111  }
   1.112  
   1.113  void JavaThread::send_thread_stop(oop java_throwable)  {
   1.114 @@ -2432,6 +2422,8 @@
   1.115        fatal("missed deoptimization!");
   1.116      }
   1.117    }
   1.118 +
   1.119 +  JFR_ONLY(SUSPEND_THREAD_CONDITIONAL(thread);)
   1.120  }
   1.121  
   1.122  // Slow path when the native==>VM/Java barriers detect a safepoint is in
   1.123 @@ -3320,6 +3312,14 @@
   1.124    if (wt != NULL)
   1.125      tc->do_thread(wt);
   1.126  
   1.127 +#if INCLUDE_JFR
   1.128 +  Thread* sampler_thread = Jfr::sampler_thread();
   1.129 +  if (sampler_thread != NULL) {
   1.130 +    tc->do_thread(sampler_thread);
   1.131 +  }
   1.132 +
   1.133 +#endif
   1.134 +
   1.135    // If CompilerThreads ever become non-JavaThreads, add them here
   1.136  }
   1.137  
   1.138 @@ -3446,6 +3446,8 @@
   1.139      return status;
   1.140    }
   1.141  
   1.142 +  JFR_ONLY(Jfr::on_create_vm_1();)
   1.143 +
   1.144  #if defined MIPS && !defined ZERO
   1.145    /* 2013/11/5 Jin: To be accessed in NativeGeneralJump::patch_verified_entry() */
   1.146    main_thread->set_handle_wrong_method_stub(SharedRuntime::get_handle_wrong_method_stub());
   1.147 @@ -3500,12 +3502,16 @@
   1.148      ShouldNotReachHere();
   1.149    }
   1.150  
   1.151 +#if !INCLUDE_JFR
   1.152 +  // if JFR is not enabled at the build time keep the original JvmtiExport location
   1.153 +
   1.154    // Always call even when there are not JVMTI environments yet, since environments
   1.155    // may be attached late and JVMTI must track phases of VM execution
   1.156    JvmtiExport::enter_start_phase();
   1.157  
   1.158    // Notify JVMTI agents that VM has started (JNI is up) - nop if no agents.
   1.159    JvmtiExport::post_vm_start();
   1.160 +#endif
   1.161  
   1.162    {
   1.163      TraceTime timer("Initialize java.lang classes", TraceStartupTime);
   1.164 @@ -3552,6 +3558,19 @@
   1.165      initialize_class(vmSymbols::java_lang_IllegalArgumentException(), CHECK_0);
   1.166    }
   1.167  
   1.168 +  JFR_ONLY(
   1.169 +    Jfr::on_create_vm_2();
   1.170 +
   1.171 +    // if JFR is enabled at build time the JVMTI needs to be handled only after on_create_vm_2() call
   1.172 +
   1.173 +    // Always call even when there are not JVMTI environments yet, since environments
   1.174 +    // may be attached late and JVMTI must track phases of VM execution
   1.175 +    JvmtiExport::enter_start_phase();
   1.176 +
   1.177 +    // Notify JVMTI agents that VM has started (JNI is up) - nop if no agents.
   1.178 +    JvmtiExport::post_vm_start();
   1.179 +  )
   1.180 +
   1.181    // See        : bugid 4211085.
   1.182    // Background : the static initializer of java.lang.Compiler tries to read
   1.183    //              property"java.compiler" and read & write property "java.vm.info".
   1.184 @@ -3578,11 +3597,6 @@
   1.185  
   1.186    quicken_jni_functions();
   1.187  
   1.188 -  // Must be run after init_ft which initializes ft_enabled
   1.189 -  if (TRACE_INITIALIZE() != JNI_OK) {
   1.190 -    vm_exit_during_initialization("Failed to initialize tracing backend");
   1.191 -  }
   1.192 -
   1.193    // Set flag that basic initialization has completed. Used by exceptions and various
   1.194    // debug stuff, that does not work until all basic classes have been initialized.
   1.195    set_init_completed();
   1.196 @@ -3651,9 +3665,7 @@
   1.197    // Notify JVMTI agents that VM initialization is complete - nop if no agents.
   1.198    JvmtiExport::post_vm_initialized();
   1.199  
   1.200 -  if (TRACE_START() != JNI_OK) {
   1.201 -    vm_exit_during_initialization("Failed to start tracing backend.");
   1.202 -  }
   1.203 +  JFR_ONLY(Jfr::on_create_vm_3();)
   1.204  
   1.205    if (CleanChunkPoolAsync) {
   1.206      Chunk::start_chunk_pool_cleaner_task();
   1.207 @@ -4015,6 +4027,12 @@
   1.208                           Mutex::_as_suspend_equivalent_flag);
   1.209    }
   1.210  
   1.211 +  EventShutdown e;
   1.212 +  if (e.should_commit()) {
   1.213 +    e.set_reason("No remaining non-daemon Java threads");
   1.214 +    e.commit();
   1.215 +  }
   1.216 +
   1.217    // Hang forever on exit if we are reporting an error.
   1.218    if (ShowMessageBoxOnError && is_error_reported()) {
   1.219      os::infinite_sleep();

mercurial