src/share/vm/runtime/mutexLocker.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File 8047290final Sdiff src/share/vm/runtime

src/share/vm/runtime/mutexLocker.cpp

Print this page




 150   if (IgnoreLockingAssertions) return;
 151   assert(lock != NULL, "Need non-NULL lock");
 152   if (lock->owned_by_self()) return;
 153   if (SafepointSynchronize::is_at_safepoint()) return;
 154   if (!Universe::is_fully_initialized()) return;
 155   // see if invoker of VM operation owns it
 156   VM_Operation* op = VMThread::vm_operation();
 157   if (op != NULL && op->calling_thread() == lock->owner()) return;
 158   fatal(err_msg("must own lock %s", lock->name()));
 159 }
 160 
 161 // a stronger assertion than the above
 162 void assert_lock_strong(const Monitor * lock) {
 163   if (IgnoreLockingAssertions) return;
 164   assert(lock != NULL, "Need non-NULL lock");
 165   if (lock->owned_by_self()) return;
 166   fatal(err_msg("must own lock %s", lock->name()));
 167 }
 168 #endif
 169 
 170 #define def(var, type, pri, vm_block) {                           \
 171   var = new type(Mutex::pri, #var, vm_block);                     \
 172   assert(_num_mutex < MAX_NUM_MUTEX,                              \
 173                     "increase MAX_NUM_MUTEX");                    \
 174   _mutex_array[_num_mutex++] = var;                               \
 175 }
 176 
 177 void mutex_init() {
 178   def(tty_lock                     , Mutex  , event,       true ); // allow to lock in VM



 179 
 180   def(CGC_lock                   , Monitor, special,     true ); // coordinate between fore- and background GC
 181   def(STS_lock                   , Monitor, leaf,        true );
 182   if (UseConcMarkSweepGC || UseG1GC) {
 183     def(FullGCCount_lock           , Monitor, leaf,        true ); // in support of ExplicitGCInvokesConcurrent
 184   }
 185   if (UseG1GC) {
 186     def(CMark_lock                 , Monitor, nonleaf,     true ); // coordinate concurrent mark thread
 187     def(CMRegionStack_lock         , Mutex,   leaf,        true );
 188     def(SATB_Q_FL_lock             , Mutex  , special,     true );
 189     def(SATB_Q_CBL_mon             , Monitor, nonleaf,     true );
 190     def(Shared_SATB_Q_lock         , Mutex,   nonleaf,     true );
 191 
 192     def(DirtyCardQ_FL_lock         , Mutex  , special,     true );
 193     def(DirtyCardQ_CBL_mon         , Monitor, nonleaf,     true );
 194     def(Shared_DirtyCardQ_lock     , Mutex,   nonleaf,     true );
 195 
 196     def(FreeList_lock              , Mutex,   leaf     ,   true );
 197     def(SecondaryFreeList_lock     , Monitor, leaf     ,   true );
 198     def(OldSets_lock               , Mutex  , leaf     ,   true );
 199     def(RootRegionScan_lock        , Monitor, leaf     ,   true );
 200     def(MMUTracker_lock            , Mutex  , leaf     ,   true );
 201     def(HotCardCache_lock          , Mutex  , special  ,   true );
 202     def(EvacFailureStack_lock      , Mutex  , nonleaf  ,   true );
 203 
 204     def(StringDedupQueue_lock      , Monitor, leaf,        true );
 205     def(StringDedupTable_lock      , Mutex  , leaf,        true );
 206   }
 207   def(ParGCRareEvent_lock          , Mutex  , leaf     ,   true );
 208   def(DerivedPointerTableGC_lock   , Mutex,   leaf,        true );
 209   def(CodeCache_lock               , Monitor, special,     true );
 210   def(Interrupt_lock               , Monitor, special,     true ); // used for interrupt processing
 211   def(RawMonitor_lock              , Mutex,   special,     true );
 212   def(OopMapCacheAlloc_lock        , Mutex,   leaf,        true ); // used for oop_map_cache allocation.
 213 
 214   def(Patching_lock                , Mutex  , special,     true ); // used for safepointing and code patching.
 215   def(ObjAllocPost_lock            , Monitor, special,     false);
 216   def(Service_lock                 , Monitor, special,     true ); // used for service thread operations
 217   def(JmethodIdCreation_lock       , Mutex  , leaf,        true ); // used for creating jmethodIDs.
 218 
 219   def(SystemDictionary_lock        , Monitor, leaf,        true ); // lookups done by VM thread
 220   def(PackageTable_lock            , Mutex  , leaf,        false);
 221   def(InlineCacheBuffer_lock       , Mutex  , leaf,        true );
 222   def(VMStatistic_lock             , Mutex  , leaf,        false);
 223   def(ExpandHeap_lock              , Mutex  , leaf,        true ); // Used during compilation by VM thread
 224   def(JNIHandleBlockFreeList_lock  , Mutex  , leaf,        true ); // handles are used by VM thread
 225   def(SignatureHandlerLibrary_lock , Mutex  , leaf,        false);
 226   def(SymbolTable_lock             , Mutex  , leaf+2,      true );
 227   def(StringTable_lock             , Mutex  , leaf,        true );
 228   def(ProfilePrint_lock            , Mutex  , leaf,        false); // serial profile printing
 229   def(ExceptionCache_lock          , Mutex  , leaf,        false); // serial profile printing
 230   def(OsrList_lock                 , Mutex  , leaf,        true );
 231   def(Debug1_lock                  , Mutex  , leaf,        true );

 232 #ifndef PRODUCT
 233   def(FullGCALot_lock              , Mutex  , leaf,        false); // a lock to make FullGCALot MT safe
 234 #endif
 235   def(BeforeExit_lock              , Monitor, leaf,        true );
 236   def(PerfDataMemAlloc_lock        , Mutex  , leaf,        true ); // used for allocating PerfData memory for performance data
 237   def(PerfDataManager_lock         , Mutex  , leaf,        true ); // used for synchronized access to PerfDataManager resources
 238 
 239   // CMS_modUnionTable_lock                   leaf
 240   // CMS_bitMap_lock                          leaf + 1
 241   // CMS_freeList_lock                        leaf + 2
 242 
 243   def(Safepoint_lock               , Monitor, safepoint,   true ); // locks SnippetCache_lock/Threads_lock
 244 
 245   def(Threads_lock                 , Monitor, barrier,     true );
 246 
 247   def(VMOperationQueue_lock        , Monitor, nonleaf,     true ); // VM_thread allowed to block on these
 248   def(VMOperationRequest_lock      , Monitor, nonleaf,     true );
 249   def(RetData_lock                 , Mutex  , nonleaf,     false);
 250   def(Terminator_lock              , Monitor, nonleaf,     true );
 251   def(VtableStubs_lock             , Mutex  , nonleaf,     true );
 252   def(Notify_lock                  , Monitor, nonleaf,     true );
 253   def(JNIGlobalHandle_lock         , Mutex  , nonleaf,     true ); // locks JNIHandleBlockFreeList_lock
 254   def(JNICritical_lock             , Monitor, nonleaf,     true ); // used for JNI critical regions
 255   def(AdapterHandlerLibrary_lock   , Mutex  , nonleaf,     true);
 256   if (UseConcMarkSweepGC) {
 257     def(SLT_lock                   , Monitor, nonleaf,     false );
 258                     // used in CMS GC for locking PLL lock
 259   }
 260   def(Heap_lock                    , Monitor, nonleaf+1,   false);
 261   def(JfieldIdCreation_lock        , Mutex  , nonleaf+1,   true ); // jfieldID, Used in VM_Operation
 262   def(MemberNameTable_lock         , Mutex  , nonleaf+1,   false); // Used to protect MemberNameTable
 263 
 264   def(CompiledIC_lock              , Mutex  , nonleaf+2,   false); // locks VtableStubs_lock, InlineCacheBuffer_lock
 265   def(CompileTaskAlloc_lock        , Mutex  , nonleaf+2,   true );
 266   def(CompileStatistics_lock       , Mutex  , nonleaf+2,   false);
 267   def(MultiArray_lock              , Mutex  , nonleaf+2,   false); // locks SymbolTable_lock
 268 
 269   def(JvmtiThreadState_lock        , Mutex  , nonleaf+2,   false); // Used by JvmtiThreadState/JvmtiEventController
 270   def(JvmtiPendingEvent_lock       , Monitor, nonleaf,     false); // Used by JvmtiCodeBlobEvents
 271   def(Management_lock              , Mutex  , nonleaf+2,   false); // used for JVM management
 272 
 273   def(Compile_lock                 , Mutex  , nonleaf+3,   true );
 274   def(MethodData_lock              , Mutex  , nonleaf+3,   false);
 275 
 276   def(MethodCompileQueue_lock      , Monitor, nonleaf+4,   true );
 277   def(Debug2_lock                  , Mutex  , nonleaf+4,   true );
 278   def(Debug3_lock                  , Mutex  , nonleaf+4,   true );
 279   def(ProfileVM_lock               , Monitor, special,   false); // used for profiling of the VMThread
 280   def(CompileThread_lock           , Monitor, nonleaf+5,   false );
 281   def(PeriodicTask_lock            , Monitor, nonleaf+5,   true);

 282   if (WhiteBoxAPI) {
 283     def(Compilation_lock           , Monitor, leaf,        false );
 284   }

 285 #ifdef INCLUDE_TRACE
 286   def(JfrMsg_lock                  , Monitor, leaf,        true);
 287   def(JfrBuffer_lock               , Mutex,   leaf,        true);
 288   def(JfrThreadGroups_lock         , Mutex,   leaf,        true);
 289   def(JfrStream_lock               , Mutex,   nonleaf,     true);
 290   def(JfrStacktrace_lock           , Mutex,   special,     true);
 291 #endif
 292 
 293 #ifndef SUPPORTS_NATIVE_CX8
 294   def(UnsafeJlong_lock             , Mutex,   special,     false);
 295 #endif
 296 }
 297 
 298 GCMutexLocker::GCMutexLocker(Monitor * mutex) {
 299   if (SafepointSynchronize::is_at_safepoint()) {
 300     _locked = false;
 301   } else {
 302     _mutex = mutex;
 303     _locked = true;
 304     _mutex->lock();
 305   }
 306 }
 307 
 308 // Print all mutexes/monitors that are currently owned by a thread; called
 309 // by fatal error handler.
 310 void print_owned_locks_on_error(outputStream* st) {
 311   st->print("VM Mutex/Monitor currently owned by a thread: ");
 312   bool none = true;
 313   for (int i = 0; i < _num_mutex; i++) {
 314      // see if it has an owner
 315      if (_mutex_array[i]->owner() != NULL) {


 150   if (IgnoreLockingAssertions) return;
 151   assert(lock != NULL, "Need non-NULL lock");
 152   if (lock->owned_by_self()) return;
 153   if (SafepointSynchronize::is_at_safepoint()) return;
 154   if (!Universe::is_fully_initialized()) return;
 155   // see if invoker of VM operation owns it
 156   VM_Operation* op = VMThread::vm_operation();
 157   if (op != NULL && op->calling_thread() == lock->owner()) return;
 158   fatal(err_msg("must own lock %s", lock->name()));
 159 }
 160 
 161 // a stronger assertion than the above
 162 void assert_lock_strong(const Monitor * lock) {
 163   if (IgnoreLockingAssertions) return;
 164   assert(lock != NULL, "Need non-NULL lock");
 165   if (lock->owned_by_self()) return;
 166   fatal(err_msg("must own lock %s", lock->name()));
 167 }
 168 #endif
 169 
 170 #define def(var, type, pri, vm_block, safepoint_check_allowed ) {      \
 171 var = new type(Mutex::pri, #var, vm_block, safepoint_check_allowed); \
 172 assert(_num_mutex < MAX_NUM_MUTEX, "increase MAX_NUM_MUTEX");        \
 173 _mutex_array[_num_mutex] = var;                                    \

 174 }
 175 
 176 void mutex_init() {
 177   def(tty_lock                     , Mutex  , event,       true,  Monitor::_safepoint_check_never ); // allow to lock in VM
 178 
 179   def(CGC_lock                     , Monitor, special,     true,  Monitor::_safepoint_check_never ); // coordinate between fore- and background GC
 180   def(STS_lock                     , Monitor, leaf,        true,  Monitor::_safepoint_check_never );
 181 


 182   if (UseConcMarkSweepGC || UseG1GC) {
 183     def(FullGCCount_lock           , Monitor, leaf,        true,  Monitor::_safepoint_check_never ); // in support of ExplicitGCInvokesConcurrent
 184   }
 185   if (UseG1GC) {
 186 
 187     def(CMark_lock                 , Monitor, nonleaf,     true,  Monitor::_safepoint_check_never ); // coordinate concurrent mark thread
 188     def(CMRegionStack_lock         , Mutex,   leaf,        true,  Monitor::_safepoint_check_never );
 189     def(SATB_Q_FL_lock             , Mutex  , special,     true,  Monitor::_safepoint_check_never );
 190     def(SATB_Q_CBL_mon             , Monitor, nonleaf,     true,  Monitor::_safepoint_check_never );
 191     def(Shared_SATB_Q_lock         , Mutex,   nonleaf,     true,  Monitor::_safepoint_check_never );
 192 
 193     def(DirtyCardQ_FL_lock         , Mutex  , special,     true,  Monitor::_safepoint_check_never );
 194     def(DirtyCardQ_CBL_mon         , Monitor, nonleaf,     true,  Monitor::_safepoint_check_never );
 195     def(Shared_DirtyCardQ_lock     , Mutex,   nonleaf,     true,  Monitor::_safepoint_check_never );
 196 
 197     def(FreeList_lock              , Mutex,   leaf     ,   true,  Monitor::_safepoint_check_never );
 198     def(SecondaryFreeList_lock     , Monitor, leaf     ,   true,  Monitor::_safepoint_check_never );
 199     def(OldSets_lock               , Mutex  , leaf     ,   true,  Monitor::_safepoint_check_never );
 200     def(RootRegionScan_lock        , Monitor, leaf     ,   true,  Monitor::_safepoint_check_never );
 201     def(MMUTracker_lock            , Mutex  , leaf     ,   true,  Monitor::_safepoint_check_never );
 202     def(HotCardCache_lock          , Mutex  , special  ,   true,  Monitor::_safepoint_check_never );
 203     def(EvacFailureStack_lock      , Mutex  , nonleaf  ,   true,  Monitor::_safepoint_check_never );
 204     
 205     def(StringDedupQueue_lock      , Monitor, leaf,        true,  Monitor::_safepoint_check_never );
 206     def(StringDedupTable_lock      , Mutex  , leaf,        true,  Monitor::_safepoint_check_never );
 207   }
 208   def(ParGCRareEvent_lock          , Mutex  , leaf     ,   true,  Monitor::_safepoint_check_sometimes);
 209   def(DerivedPointerTableGC_lock   , Mutex,   leaf,        true,  Monitor::_safepoint_check_never );
 210   def(CodeCache_lock               , Mutex  , special,     true,  Monitor::_safepoint_check_never );
 211   def(Interrupt_lock               , Monitor, special,     true,  Monitor::_safepoint_check_never ); // used for interrupt processing
 212   def(RawMonitor_lock              , Mutex,   special,     true,  Monitor::_safepoint_check_never );
 213   def(OopMapCacheAlloc_lock        , Mutex,   leaf,        true,  Monitor::_safepoint_check_always); // used for oop_map_cache allocation.
 214 
 215   def(Patching_lock                , Mutex  , special,     true,  Monitor::_safepoint_check_never ); // used for safepointing and code patching.
 216   def(ObjAllocPost_lock            , Monitor, special,     false, Monitor::_safepoint_check_never );
 217   def(Service_lock                 , Monitor, special,     true,  Monitor::_safepoint_check_never ); // used for service thread operations
 218   def(JmethodIdCreation_lock       , Mutex  , leaf,        true,  Monitor::_safepoint_check_always); // used for creating jmethodIDs.
 219 
 220   def(SystemDictionary_lock        , Monitor, leaf,        true,  Monitor::_safepoint_check_always); // lookups done by VM thread
 221   def(PackageTable_lock            , Mutex  , leaf,        false, Monitor::_safepoint_check_always);
 222   def(InlineCacheBuffer_lock       , Mutex  , leaf,        true,  Monitor::_safepoint_check_always);
 223   def(VMStatistic_lock             , Mutex  , leaf,        false, Monitor::_safepoint_check_always);
 224   def(ExpandHeap_lock              , Mutex  , leaf,        true,  Monitor::_safepoint_check_always); // Used during compilation by VM thread
 225   def(JNIHandleBlockFreeList_lock  , Mutex  , leaf,        true,  Monitor::_safepoint_check_never ); // handles are used by VM thread
 226   def(SignatureHandlerLibrary_lock , Mutex  , leaf,        false, Monitor::_safepoint_check_always);
 227   def(SymbolTable_lock             , Mutex  , leaf+2,      true,  Monitor::_safepoint_check_always);
 228   def(StringTable_lock             , Mutex  , leaf,        true,  Monitor::_safepoint_check_always);
 229   def(ProfilePrint_lock            , Mutex  , leaf,        false, Monitor::_safepoint_check_always); // serial profile printing
 230   def(ExceptionCache_lock          , Mutex  , leaf,        false, Monitor::_safepoint_check_always); // serial profile printing
 231   def(OsrList_lock                 , Mutex  , leaf,        true,  Monitor::_safepoint_check_never );
 232   def(Debug1_lock                  , Mutex  , leaf,        true,  Monitor::_safepoint_check_never );
 233 #ifndef PRODUCT
 234   def(FullGCALot_lock              , Mutex  , leaf,        false, Monitor::_safepoint_check_always); // a lock to make FullGCALot MT safe
 235 #endif
 236   def(BeforeExit_lock              , Monitor, leaf,        true,  Monitor::_safepoint_check_always);
 237   def(PerfDataMemAlloc_lock        , Mutex  , leaf,        true,  Monitor::_safepoint_check_always); // used for allocating PerfData memory for performance data
 238   def(PerfDataManager_lock         , Mutex  , leaf,        true,  Monitor::_safepoint_check_always); // used for synchronized access to PerfDataManager resources
 239 
 240   // CMS_modUnionTable_lock                   leaf
 241    // CMS_bitMap_lock                          leaf 1
 242    // CMS_freeList_lock                        leaf 2
 243 
 244   def(Safepoint_lock               , Monitor, safepoint,   true,  Monitor::_safepoint_check_sometimes); // locks SnippetCache_lock/Threads_lock
 245 
 246   def(Threads_lock                 , Monitor, barrier,     true,  Monitor::_safepoint_check_sometimes);
 247 
 248   def(VMOperationQueue_lock        , Monitor, nonleaf,     true,  Monitor::_safepoint_check_sometimes); // VM_thread allowed to block on these
 249   def(VMOperationRequest_lock      , Monitor, nonleaf,     true,  Monitor::_safepoint_check_sometimes);
 250   def(RetData_lock                 , Mutex  , nonleaf,     false, Monitor::_safepoint_check_always);
 251   def(Terminator_lock              , Monitor, nonleaf,     true,  Monitor::_safepoint_check_sometimes);
 252   def(VtableStubs_lock             , Mutex  , nonleaf,     true,  Monitor::_safepoint_check_always);
 253   def(Notify_lock                  , Monitor, nonleaf,     true,  Monitor::_safepoint_check_always);
 254   def(JNIGlobalHandle_lock         , Mutex  , nonleaf,     true,  Monitor::_safepoint_check_always); // locks JNIHandleBlockFreeList_lock
 255   def(JNICritical_lock             , Monitor, nonleaf,     true,  Monitor::_safepoint_check_always); // used for JNI critical regions
 256   def(AdapterHandlerLibrary_lock   , Mutex  , nonleaf,     true,  Monitor::_safepoint_check_always);
 257   if (UseConcMarkSweepGC) {
 258     def(SLT_lock                   , Monitor, nonleaf,     false, Monitor::_safepoint_check_never );
 259                     // used in CMS GC for locking PLL lock
 260   }
 261 
 262   def(Heap_lock                    , Monitor, nonleaf+1,   false, Monitor::_safepoint_check_sometimes);
 263   def(JfieldIdCreation_lock        , Mutex  , nonleaf+1,   true,  Monitor::_safepoint_check_always); // jfieldID, Used in VM_Operation
 264   def(MemberNameTable_lock         , Mutex  , nonleaf+1,   false, Monitor::_safepoint_check_always); // Used to protect MemberNameTable
 265 
 266   def(CompiledIC_lock              , Mutex  , nonleaf+2,   false, Monitor::_safepoint_check_always); // locks VtableStubs_lock, InlineCacheBuffer_lock
 267   def(CompileTaskAlloc_lock        , Mutex  , nonleaf+2,   true,  Monitor::_safepoint_check_always);
 268   def(CompileStatistics_lock       , Mutex  , nonleaf+2,   false, Monitor::_safepoint_check_always);
 269   def(MultiArray_lock              , Mutex  , nonleaf+2,   false, Monitor::_safepoint_check_always); // locks SymbolTable_lock
 270 
 271   def(JvmtiThreadState_lock        , Mutex  , nonleaf+2,   false, Monitor::_safepoint_check_always); // Used by JvmtiThreadState/JvmtiEventController
 272   def(JvmtiPendingEvent_lock       , Monitor, nonleaf,     false, Monitor::_safepoint_check_never ); // Used by JvmtiCodeBlobEvents
 273   def(Management_lock              , Mutex  , nonleaf+2,   false, Monitor::_safepoint_check_always); // used for JVM management
 274 
 275   def(Compile_lock                 , Mutex  , nonleaf+3,   true,  Monitor::_safepoint_check_sometimes);
 276   def(MethodData_lock              , Mutex  , nonleaf+3,   false, Monitor::_safepoint_check_always);
 277 
 278   def(MethodCompileQueue_lock      , Monitor, nonleaf+4,   true,  Monitor::_safepoint_check_always);
 279   def(Debug2_lock                  , Mutex  , nonleaf+4,   true,  Monitor::_safepoint_check_never );
 280   def(Debug3_lock                  , Mutex  , nonleaf+4,   true,  Monitor::_safepoint_check_never );
 281   def(ProfileVM_lock               , Monitor, special,     false, Monitor::_safepoint_check_never ); // used for profiling of the VMThread
 282   def(CompileThread_lock           , Monitor, nonleaf+5,   false, Monitor::_safepoint_check_always);
 283   def(PeriodicTask_lock            , Monitor, nonleaf+5,   true,  Monitor::_safepoint_check_sometimes);
 284   if (WhiteBoxAPI) {
 285     def(Compilation_lock           , Monitor, leaf,        false, Monitor::_safepoint_check_never );
 286   }
 287  
 288 #ifdef INCLUDE_TRACE
 289   def(JfrMsg_lock                  , Monitor, leaf,        true,  Monitor::_safepoint_check_always);
 290   def(JfrBuffer_lock               , Mutex,   leaf,        true,  Monitor::_safepoint_check_never );
 291   def(JfrThreadGroups_lock         , Mutex,   leaf,        true,  Monitor::_safepoint_check_always);
 292   def(JfrStream_lock               , Mutex,   nonleaf,     true,  Monitor::_safepoint_check_never );
 293   def(JfrStacktrace_lock           , Mutex,   special,     true,  Monitor::_safepoint_check_sometimes);
 294 #endif
 295 



 296 }
 297 
 298 GCMutexLocker::GCMutexLocker(Monitor * mutex) {
 299   if (SafepointSynchronize::is_at_safepoint()) {
 300     _locked = false;
 301   } else {
 302     _mutex = mutex;
 303     _locked = true;
 304     _mutex->lock();
 305   }
 306 }
 307 
 308 // Print all mutexes/monitors that are currently owned by a thread; called
 309 // by fatal error handler.
 310 void print_owned_locks_on_error(outputStream* st) {
 311   st->print("VM Mutex/Monitor currently owned by a thread: ");
 312   bool none = true;
 313   for (int i = 0; i < _num_mutex; i++) {
 314      // see if it has an owner
 315      if (_mutex_array[i]->owner() != NULL) {
src/share/vm/runtime/mutexLocker.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File