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