8213137: Remove static initialization of monitor/mutex instances
authordholmes
Thu, 08 Nov 2018 07:42:08 -0500
changeset 52448 bc5c7f63dbae
parent 52447 4547f8303f2d
child 52449 bac05440d98c
8213137: Remove static initialization of monitor/mutex instances Summary: moved to the global mutex list in mutexLocker Reviewed-by: tschatzl, dcubed, rehn, eosterlund
src/hotspot/share/gc/shared/parallelCleaning.cpp
src/hotspot/share/gc/shared/parallelCleaning.hpp
src/hotspot/share/jfr/periodic/sampling/jfrThreadSampler.cpp
src/hotspot/share/runtime/mutexLocker.cpp
src/hotspot/share/runtime/mutexLocker.hpp
src/hotspot/share/runtime/sweeper.cpp
src/hotspot/share/runtime/sweeper.hpp
src/hotspot/share/runtime/threadSMR.cpp
src/hotspot/share/runtime/threadSMR.hpp
src/hotspot/share/services/diagnosticFramework.cpp
src/hotspot/share/services/diagnosticFramework.hpp
src/hotspot/share/utilities/decoder.cpp
src/hotspot/share/utilities/decoder.hpp
--- a/src/hotspot/share/gc/shared/parallelCleaning.cpp	Thu Nov 08 12:24:08 2018 +0100
+++ b/src/hotspot/share/gc/shared/parallelCleaning.cpp	Thu Nov 08 07:42:08 2018 -0500
@@ -89,8 +89,6 @@
   CodeCache::verify_icholder_relocations();
 }
 
-Monitor* CodeCacheUnloadingTask::_lock = new Monitor(Mutex::leaf, "Code Cache Unload lock", false, Monitor::_safepoint_check_never);
-
 void CodeCacheUnloadingTask::claim_nmethods(CompiledMethod** claimed_nmethods, int *num_claimed_nmethods) {
   CompiledMethod* first;
   CompiledMethodIterator last;
--- a/src/hotspot/share/gc/shared/parallelCleaning.hpp	Thu Nov 08 12:24:08 2018 +0100
+++ b/src/hotspot/share/gc/shared/parallelCleaning.hpp	Thu Nov 08 07:42:08 2018 -0500
@@ -56,7 +56,6 @@
 };
 
 class CodeCacheUnloadingTask {
-  static Monitor* _lock;
 
   CodeCache::UnloadingScope _unloading_scope;
   const bool                _unloading_occurred;
--- a/src/hotspot/share/jfr/periodic/sampling/jfrThreadSampler.cpp	Thu Nov 08 12:24:08 2018 +0100
+++ b/src/hotspot/share/jfr/periodic/sampling/jfrThreadSampler.cpp	Thu Nov 08 07:42:08 2018 -0500
@@ -321,7 +321,6 @@
   int _cur_index;
   const u4 _max_frames;
   volatile bool _disenrolled;
-  static Monitor* _transition_block_lock;
 
   JavaThread* next_thread(ThreadsList* t_list, JavaThread* first_sampled, JavaThread* current);
   void task_stacktrace(JfrSampleType type, JavaThread** last_thread);
@@ -339,12 +338,10 @@
 
  public:
   void run();
-  static Monitor* transition_block() { return _transition_block_lock; }
+  static Monitor* transition_block() { return JfrThreadSampler_lock; }
   static void on_javathread_suspend(JavaThread* thread);
 };
 
-Monitor* JfrThreadSampler::_transition_block_lock = new Monitor(Mutex::leaf, "Trace block", true, Monitor::_safepoint_check_never);
-
 static void clear_transition_block(JavaThread* jt) {
   jt->clear_trace_flag();
   JfrThreadLocal* const tl = jt->jfr_thread_local();
--- a/src/hotspot/share/runtime/mutexLocker.cpp	Thu Nov 08 12:24:08 2018 +0100
+++ b/src/hotspot/share/runtime/mutexLocker.cpp	Thu Nov 08 07:42:08 2018 -0500
@@ -106,7 +106,7 @@
 Mutex*   ProfilePrint_lock            = NULL;
 Mutex*   ExceptionCache_lock          = NULL;
 Mutex*   OsrList_lock                 = NULL;
-
+Mutex*   NMethodSweeperStats_lock     = NULL;
 #ifndef PRODUCT
 Mutex*   FullGCALot_lock              = NULL;
 #endif
@@ -138,6 +138,7 @@
 Monitor* JfrMsg_lock                  = NULL;
 Mutex*   JfrBuffer_lock               = NULL;
 Mutex*   JfrStream_lock               = NULL;
+Monitor* JfrThreadSampler_lock        = NULL;
 #endif
 
 #ifndef SUPPORTS_NATIVE_CX8
@@ -147,6 +148,9 @@
 
 Mutex*   MetaspaceExpand_lock         = NULL;
 Mutex*   ClassLoaderDataGraph_lock    = NULL;
+Monitor* ThreadsSMRDelete_lock       = NULL;
+Mutex*   SharedDecoder_lock           = NULL;
+Mutex*   DCmdFactory_lock             = NULL;
 
 #define MAX_NUM_MUTEX 128
 static Monitor * _mutex_array[MAX_NUM_MUTEX];
@@ -243,7 +247,7 @@
   def(JmethodIdCreation_lock       , PaddedMutex  , leaf,        true,  Monitor::_safepoint_check_always);     // used for creating jmethodIDs.
 
   def(SystemDictionary_lock        , PaddedMonitor, leaf,        true,  Monitor::_safepoint_check_always);     // lookups done by VM thread
-  def(SharedDictionary_lock        , PaddedMutex,   leaf,        true,  Monitor::_safepoint_check_always);     // lookups done by VM thread
+  def(SharedDictionary_lock        , PaddedMutex  , leaf,        true,  Monitor::_safepoint_check_always);     // lookups done by VM thread
   def(Module_lock                  , PaddedMutex  , leaf+2,      true,  Monitor::_safepoint_check_always);
   def(InlineCacheBuffer_lock       , PaddedMutex  , leaf,        true,  Monitor::_safepoint_check_always);
   def(VMStatistic_lock             , PaddedMutex  , leaf,        false, Monitor::_safepoint_check_always);
@@ -318,6 +322,7 @@
   def(JfrBuffer_lock               , PaddedMutex  , leaf,        true,  Monitor::_safepoint_check_never);
   def(JfrStream_lock               , PaddedMutex  , leaf+1,      true,  Monitor::_safepoint_check_never);      // ensure to rank lower than 'safepoint'
   def(JfrStacktrace_lock           , PaddedMutex  , special,     true,  Monitor::_safepoint_check_sometimes);
+  def(JfrThreadSampler_lock        , PaddedMonitor, leaf,        true,  Monitor::_safepoint_check_never);
 #endif
 
 #ifndef SUPPORTS_NATIVE_CX8
@@ -325,6 +330,11 @@
 #endif
 
   def(CodeHeapStateAnalytics_lock  , PaddedMutex  , leaf,        true,  Monitor::_safepoint_check_never);
+
+  def(NMethodSweeperStats_lock     , PaddedMutex  , special,     true,  Monitor::_safepoint_check_sometimes);
+  def(ThreadsSMRDelete_lock        , PaddedMonitor, special,     false, Monitor::_safepoint_check_never);
+  def(SharedDecoder_lock           , PaddedMutex  , native,      false, Monitor::_safepoint_check_never);
+  def(DCmdFactory_lock             , PaddedMutex  , leaf,        true,  Monitor::_safepoint_check_never);
 }
 
 GCMutexLocker::GCMutexLocker(Monitor * mutex) {
--- a/src/hotspot/share/runtime/mutexLocker.hpp	Thu Nov 08 12:24:08 2018 +0100
+++ b/src/hotspot/share/runtime/mutexLocker.hpp	Thu Nov 08 07:42:08 2018 -0500
@@ -110,6 +110,7 @@
 extern Mutex*   ProfilePrint_lock;               // a lock used to serialize the printing of profiles
 extern Mutex*   ExceptionCache_lock;             // a lock used to synchronize exception cache updates
 extern Mutex*   OsrList_lock;                    // a lock used to serialize access to OSR queues
+extern Mutex*   NMethodSweeperStats_lock;        // a lock used to serialize access to sweeper statistics
 
 #ifndef PRODUCT
 extern Mutex*   FullGCALot_lock;                 // a lock to make FullGCALot MT safe
@@ -132,12 +133,15 @@
 extern Monitor* Service_lock;                    // a lock used for service thread operation
 extern Monitor* PeriodicTask_lock;               // protects the periodic task structure
 extern Monitor* RedefineClasses_lock;            // locks classes from parallel redefinition
-
+extern Monitor* ThreadsSMRDelete_lock;           // Used by ThreadsSMRSupport to take pressure off the Threads_lock
+extern Mutex*   SharedDecoder_lock;              // serializes access to the decoder during normal (not error reporting) use
+extern Mutex*   DCmdFactory_lock;                // serialize access to DCmdFactory information
 #if INCLUDE_JFR
 extern Mutex*   JfrStacktrace_lock;              // used to guard access to the JFR stacktrace table
 extern Monitor* JfrMsg_lock;                     // protects JFR messaging
 extern Mutex*   JfrBuffer_lock;                  // protects JFR buffer operations
 extern Mutex*   JfrStream_lock;                  // protects JFR stream access
+extern Monitor* JfrThreadSampler_lock;           // used to suspend/resume JFR thread sampler
 #endif
 
 #ifndef SUPPORTS_NATIVE_CX8
--- a/src/hotspot/share/runtime/sweeper.cpp	Thu Nov 08 12:24:08 2018 +0100
+++ b/src/hotspot/share/runtime/sweeper.cpp	Thu Nov 08 07:42:08 2018 -0500
@@ -164,8 +164,6 @@
 Tickspan NMethodSweeper::_peak_sweep_time;                     // Peak time for a full sweep
 Tickspan NMethodSweeper::_peak_sweep_fraction_time;            // Peak time sweeping one fraction
 
-Monitor* NMethodSweeper::_stat_lock = new Monitor(Mutex::special, "Sweeper::Statistics", true, Monitor::_safepoint_check_sometimes);
-
 class MarkActivationClosure: public CodeBlobClosure {
 public:
   virtual void do_code_blob(CodeBlob* cb) {
@@ -578,7 +576,7 @@
   const Ticks sweep_end_counter = Ticks::now();
   const Tickspan sweep_time = sweep_end_counter - sweep_start_counter;
   {
-    MutexLockerEx mu(_stat_lock, Mutex::_no_safepoint_check_flag);
+    MutexLockerEx mu(NMethodSweeperStats_lock, Mutex::_no_safepoint_check_flag);
     _total_time_sweeping  += sweep_time;
     _total_time_this_sweep += sweep_time;
     _peak_sweep_fraction_time = MAX2(sweep_time, _peak_sweep_fraction_time);
--- a/src/hotspot/share/runtime/sweeper.hpp	Thu Nov 08 12:24:08 2018 +0100
+++ b/src/hotspot/share/runtime/sweeper.hpp	Thu Nov 08 07:42:08 2018 -0500
@@ -88,8 +88,6 @@
   static Tickspan  _peak_sweep_time;              // Peak time for a full sweep
   static Tickspan  _peak_sweep_fraction_time;     // Peak time sweeping one fraction
 
-  static Monitor*  _stat_lock;
-
   static MethodStateChange process_compiled_method(CompiledMethod *nm);
   static void              release_compiled_method(CompiledMethod* nm);
 
--- a/src/hotspot/share/runtime/threadSMR.cpp	Thu Nov 08 12:24:08 2018 +0100
+++ b/src/hotspot/share/runtime/threadSMR.cpp	Thu Nov 08 07:42:08 2018 -0500
@@ -36,10 +36,6 @@
 #include "utilities/resourceHash.hpp"
 #include "utilities/vmError.hpp"
 
-Monitor*              ThreadsSMRSupport::_delete_lock =
-                          new Monitor(Monitor::special, "Thread_SMR_delete_lock",
-                                      false /* allow_vm_block */,
-                                      Monitor::_safepoint_check_never);
 // The '_cnt', '_max' and '_times" fields are enabled via
 // -XX:+EnableThreadSMRStatistics:
 
--- a/src/hotspot/share/runtime/threadSMR.hpp	Thu Nov 08 12:24:08 2018 +0100
+++ b/src/hotspot/share/runtime/threadSMR.hpp	Thu Nov 08 07:42:08 2018 -0500
@@ -91,7 +91,8 @@
   // The coordination between ThreadsSMRSupport::release_stable_list() and
   // ThreadsSMRSupport::smr_delete() uses the delete_lock in order to
   // reduce the traffic on the Threads_lock.
-  static Monitor*              _delete_lock;
+  static Monitor* delete_lock() { return ThreadsSMRDelete_lock; }
+
   // The '_cnt', '_max' and '_times" fields are enabled via
   // -XX:+EnableThreadSMRStatistics (see thread.cpp for a
   // description about each field):
@@ -121,7 +122,6 @@
   static void add_deleted_thread_times(uint add_value);
   static void add_tlh_times(uint add_value);
   static void clear_delete_notify();
-  static Monitor* delete_lock() { return _delete_lock; }
   static bool delete_notify();
   static void free_list(ThreadsList* threads);
   static void inc_deleted_thread_cnt();
--- a/src/hotspot/share/services/diagnosticFramework.cpp	Thu Nov 08 12:24:08 2018 +0100
+++ b/src/hotspot/share/services/diagnosticFramework.cpp	Thu Nov 08 07:42:08 2018 -0500
@@ -491,11 +491,10 @@
   }
 }
 
-Mutex* DCmdFactory::_dcmdFactory_lock = new Mutex(Mutex::leaf, "DCmdFactory", true, Monitor::_safepoint_check_never);
 bool DCmdFactory::_send_jmx_notification = false;
 
 DCmdFactory* DCmdFactory::factory(DCmdSource source, const char* name, size_t len) {
-  MutexLockerEx ml(_dcmdFactory_lock, Mutex::_no_safepoint_check_flag);
+  MutexLockerEx ml(DCmdFactory_lock, Mutex::_no_safepoint_check_flag);
   DCmdFactory* factory = _DCmdFactoryList;
   while (factory != NULL) {
     if (strlen(factory->name()) == len &&
@@ -512,7 +511,7 @@
 }
 
 int DCmdFactory::register_DCmdFactory(DCmdFactory* factory) {
-  MutexLockerEx ml(_dcmdFactory_lock, Mutex::_no_safepoint_check_flag);
+  MutexLockerEx ml(DCmdFactory_lock, Mutex::_no_safepoint_check_flag);
   factory->_next = _DCmdFactoryList;
   _DCmdFactoryList = factory;
   if (_send_jmx_notification && !factory->_hidden
@@ -537,7 +536,7 @@
 }
 
 GrowableArray<const char*>* DCmdFactory::DCmd_list(DCmdSource source) {
-  MutexLockerEx ml(_dcmdFactory_lock, Mutex::_no_safepoint_check_flag);
+  MutexLockerEx ml(DCmdFactory_lock, Mutex::_no_safepoint_check_flag);
   GrowableArray<const char*>* array = new GrowableArray<const char*>();
   DCmdFactory* factory = _DCmdFactoryList;
   while (factory != NULL) {
@@ -550,7 +549,7 @@
 }
 
 GrowableArray<DCmdInfo*>* DCmdFactory::DCmdInfo_list(DCmdSource source ) {
-  MutexLockerEx ml(_dcmdFactory_lock, Mutex::_no_safepoint_check_flag);
+  MutexLockerEx ml(DCmdFactory_lock, Mutex::_no_safepoint_check_flag);
   GrowableArray<DCmdInfo*>* array = new GrowableArray<DCmdInfo*>();
   DCmdFactory* factory = _DCmdFactoryList;
   while (factory != NULL) {
--- a/src/hotspot/share/services/diagnosticFramework.hpp	Thu Nov 08 12:24:08 2018 +0100
+++ b/src/hotspot/share/services/diagnosticFramework.hpp	Thu Nov 08 07:42:08 2018 -0500
@@ -344,7 +344,6 @@
 // management.cpp)
 class DCmdFactory: public CHeapObj<mtInternal> {
 private:
-  static Mutex*       _dcmdFactory_lock;
   static bool         _send_jmx_notification;
   static bool         _has_pending_jmx_notification;
   static DCmdFactory* _DCmdFactoryList;
--- a/src/hotspot/share/utilities/decoder.cpp	Thu Nov 08 12:24:08 2018 +0100
+++ b/src/hotspot/share/utilities/decoder.cpp	Thu Nov 08 07:42:08 2018 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -41,14 +41,9 @@
 AbstractDecoder*  Decoder::_shared_decoder = NULL;
 AbstractDecoder*  Decoder::_error_handler_decoder = NULL;
 NullDecoder       Decoder::_do_nothing_decoder;
-Mutex*            Decoder::_shared_decoder_lock = new Mutex(Mutex::native,
-                                "SharedDecoderLock",
-                                false,
-                                Monitor::_safepoint_check_never);
 
 AbstractDecoder* Decoder::get_shared_instance() {
-  assert(_shared_decoder_lock != NULL && _shared_decoder_lock->owned_by_self(),
-    "Require DecoderLock to enter");
+  assert(shared_decoder_lock()->owned_by_self(), "Require DecoderLock to enter");
 
   if (_shared_decoder == NULL) {
     _shared_decoder = create_decoder();
@@ -89,21 +84,22 @@
 
 DecoderLocker::DecoderLocker() :
   MutexLockerEx(DecoderLocker::is_first_error_thread() ?
-                NULL : Decoder::shared_decoder_lock(), true) {
+                NULL : Decoder::shared_decoder_lock(),
+                Mutex::_no_safepoint_check_flag) {
   _decoder = is_first_error_thread() ?
     Decoder::get_error_handler_instance() : Decoder::get_shared_instance();
   assert(_decoder != NULL, "null decoder");
 }
 
 Mutex* Decoder::shared_decoder_lock() {
-  assert(_shared_decoder_lock != NULL, "Just check");
-  return _shared_decoder_lock;
+  assert(SharedDecoder_lock != NULL, "Just check");
+  return SharedDecoder_lock;
 }
 
 bool Decoder::decode(address addr, char* buf, int buflen, int* offset, const char* modulepath, bool demangle) {
-  assert(_shared_decoder_lock != NULL, "Just check");
   bool error_handling_thread = os::current_thread_id() == VMError::first_error_tid;
-  MutexLockerEx locker(error_handling_thread ? NULL : _shared_decoder_lock, true);
+  MutexLockerEx locker(error_handling_thread ? NULL : shared_decoder_lock(),
+                       Mutex::_no_safepoint_check_flag);
   AbstractDecoder* decoder = error_handling_thread ?
     get_error_handler_instance(): get_shared_instance();
   assert(decoder != NULL, "null decoder");
@@ -112,9 +108,9 @@
 }
 
 bool Decoder::decode(address addr, char* buf, int buflen, int* offset, const void* base) {
-  assert(_shared_decoder_lock != NULL, "Just check");
   bool error_handling_thread = os::current_thread_id() == VMError::first_error_tid;
-  MutexLockerEx locker(error_handling_thread ? NULL : _shared_decoder_lock, true);
+  MutexLockerEx locker(error_handling_thread ? NULL : shared_decoder_lock(),
+                       Mutex::_no_safepoint_check_flag);
   AbstractDecoder* decoder = error_handling_thread ?
     get_error_handler_instance(): get_shared_instance();
   assert(decoder != NULL, "null decoder");
@@ -124,9 +120,9 @@
 
 
 bool Decoder::demangle(const char* symbol, char* buf, int buflen) {
-  assert(_shared_decoder_lock != NULL, "Just check");
   bool error_handling_thread = os::current_thread_id() == VMError::first_error_tid;
-  MutexLockerEx locker(error_handling_thread ? NULL : _shared_decoder_lock, true);
+  MutexLockerEx locker(error_handling_thread ? NULL : shared_decoder_lock(),
+                       Mutex::_no_safepoint_check_flag);
   AbstractDecoder* decoder = error_handling_thread ?
     get_error_handler_instance(): get_shared_instance();
   assert(decoder != NULL, "null decoder");
--- a/src/hotspot/share/utilities/decoder.hpp	Thu Nov 08 12:24:08 2018 +0100
+++ b/src/hotspot/share/utilities/decoder.hpp	Thu Nov 08 07:42:08 2018 -0500
@@ -131,7 +131,6 @@
   static NullDecoder          _do_nothing_decoder;
 
 protected:
-  static Mutex*               _shared_decoder_lock;
   static Mutex* shared_decoder_lock();
 
   friend class DecoderLocker;