--- old/src/share/vm/classfile/classLoaderData.cpp 2014-11-06 12:39:38.425875000 -0800 +++ new/src/share/vm/classfile/classLoaderData.cpp 2014-11-06 12:39:37.489907000 -0800 @@ -82,7 +82,8 @@ _metaspace(NULL), _unloading(false), _klasses(NULL), _claimed(0), _jmethod_ids(NULL), _handles(NULL), _deallocate_list(NULL), _next(NULL), _dependencies(dependencies), - _metaspace_lock(new Mutex(Monitor::leaf+1, "Metaspace allocation lock", true)) { + _metaspace_lock(new Mutex(Monitor::leaf+1, "Metaspace allocation lock", true, + Monitor::_safepoint_check_never)) { // empty } --- old/src/os/linux/vm/osThread_linux.cpp 2014-11-06 12:39:38.399725000 -0800 +++ new/src/os/linux/vm/osThread_linux.cpp 2014-11-06 12:39:37.481458000 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2014, 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 @@ -39,7 +39,8 @@ sigemptyset(&_caller_sigmask); - _startThread_lock = new Monitor(Mutex::event, "startThread_lock", true); + _startThread_lock = new Monitor(Mutex::event, "startThread_lock", true, + Monitor::_safepoint_check_never); assert(_startThread_lock !=NULL, "check"); } --- old/src/os/aix/vm/osThread_aix.cpp 2014-11-06 12:39:38.437913000 -0800 +++ new/src/os/aix/vm/osThread_aix.cpp 2014-11-06 12:39:37.516714000 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved. * Copyright 2012, 2013 SAP AG. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * @@ -45,7 +45,8 @@ sigemptyset(&_caller_sigmask); - _startThread_lock = new Monitor(Mutex::event, "startThread_lock", true); + _startThread_lock = new Monitor(Mutex::event, "startThread_lock", true, + Monitor::_safepoint_check_never); assert(_startThread_lock !=NULL, "check"); } --- old/src/os/bsd/vm/osThread_bsd.cpp 2014-11-06 12:39:38.422201000 -0800 +++ new/src/os/bsd/vm/osThread_bsd.cpp 2014-11-06 12:39:37.504021000 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2014, 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 @@ -43,7 +43,8 @@ sigemptyset(&_caller_sigmask); - _startThread_lock = new Monitor(Mutex::event, "startThread_lock", true); + _startThread_lock = new Monitor(Mutex::event, "startThread_lock", true, + Monitor::_safepoint_check_never); assert(_startThread_lock !=NULL, "check"); } --- old/src/share/vm/gc_implementation/g1/concurrentG1RefineThread.cpp 2014-11-06 12:39:38.449950000 -0800 +++ new/src/share/vm/gc_implementation/g1/concurrentG1RefineThread.cpp 2014-11-06 12:39:37.496852000 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 2014, 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 @@ -52,7 +52,8 @@ // The 0th worker in notified by mutator threads and has a special monitor. // The last worker is used for young gen rset size sampling. if (worker_id > 0) { - _monitor = new Monitor(Mutex::nonleaf, "Refinement monitor", true); + _monitor = new Monitor(Mutex::nonleaf, "Refinement monitor", true, + Monitor::_safepoint_check_never); } else { _monitor = DirtyCardQ_CBL_mon; } --- old/src/share/vm/gc_implementation/parallelScavenge/gcTaskManager.cpp 2014-11-06 12:39:38.449667000 -0800 +++ new/src/share/vm/gc_implementation/parallelScavenge/gcTaskManager.cpp 2014-11-06 12:39:37.526157000 -0800 @@ -400,7 +400,8 @@ assert(workers() != 0, "no workers"); _monitor = new Monitor(Mutex::barrier, // rank "GCTaskManager monitor", // name - Mutex::_allow_vm_block_flag); // allow_vm_block + Mutex::_allow_vm_block_flag, // allow_vm_block + Monitor::_safepoint_check_never); // The queue for the GCTaskManager must be a CHeapObj. GCTaskQueue* unsynchronized_queue = GCTaskQueue::create_on_c_heap(); _queue = SynchronizedGCTaskQueue::create(unsynchronized_queue, lock()); @@ -1125,8 +1126,9 @@ } else { result = new Monitor(Mutex::barrier, // rank "MonitorSupply monitor", // name - Mutex::_allow_vm_block_flag); // allow_vm_block - } + Mutex::_allow_vm_block_flag, // allow_vm_block + Monitor::_safepoint_check_never); + } guarantee(result != NULL, "shouldn't return NULL"); assert(!result->is_locked(), "shouldn't be locked"); // release lock(). --- old/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp 2014-11-06 12:39:38.448825000 -0800 +++ new/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp 2014-11-06 12:39:37.520028000 -0800 @@ -83,9 +83,11 @@ // Note: this requires that CFLspace c'tors // are called serially in the order in which the locks are // are acquired in the program text. This is true today. - _freelistLock(_lockRank--, "CompactibleFreeListSpace._lock", true), + _freelistLock(_lockRank--, "CompactibleFreeListSpace._lock", true, + Monitor::_safepoint_check_sometimes), _parDictionaryAllocLock(Mutex::leaf - 1, // == rank(ExpandHeap_lock) - 1 - "CompactibleFreeListSpace._dict_par_lock", true), + "CompactibleFreeListSpace._dict_par_lock", true, + Monitor::_safepoint_check_never), _rescan_task_size(CardTableModRefBS::card_size_in_words * BitsPerWord * CMSRescanMultiple), _marking_task_size(CardTableModRefBS::card_size_in_words * BitsPerWord * @@ -153,8 +155,7 @@ if (CollectedHeap::use_parallel_gc_threads()) { for (size_t i = IndexSetStart; i < IndexSetSize; i += IndexSetStride) { _indexedFreeListParLocks[i] = new Mutex(Mutex::leaf - 1, // == ExpandHeap_lock - 1 - "a freelist par lock", - true); + "freelist par lock", true, Mutex::_safepoint_check_sometimes); DEBUG_ONLY( _indexedFreeList[i].set_protecting_lock(_indexedFreeListParLocks[i]); ) --- old/src/share/vm/gc_implementation/g1/heapRegionRemSet.cpp 2014-11-06 12:39:38.454650000 -0800 +++ new/src/share/vm/gc_implementation/g1/heapRegionRemSet.cpp 2014-11-06 12:39:37.496716000 -0800 @@ -840,7 +840,7 @@ HeapRegionRemSet::HeapRegionRemSet(G1BlockOffsetSharedArray* bosa, HeapRegion* hr) : _bosa(bosa), - _m(Mutex::leaf, FormatBuffer<128>("HeapRegionRemSet lock #%u", hr->hrm_index()), true), + _m(Mutex::leaf, FormatBuffer<128>("HeapRegionRemSet lock #%u", hr->hrm_index()), true, Monitor::_safepoint_check_never), _code_roots(), _other_regions(hr, &_m), _iter_state(Unclaimed), _iter_claimed(0) { reset_for_par_iteration(); } --- old/src/share/vm/gc_implementation/shared/concurrentGCThread.cpp 2014-11-06 12:39:38.476778000 -0800 +++ new/src/share/vm/gc_implementation/shared/concurrentGCThread.cpp 2014-11-06 12:39:37.528257000 -0800 @@ -88,7 +88,8 @@ SurrogateLockerThread::SurrogateLockerThread() : JavaThread(&_sltLoop), - _monitor(Mutex::nonleaf, "SLTMonitor"), + _monitor(Mutex::nonleaf, "SLTMonitor", false, + Monitor::_safepoint_check_sometimes), _buffer(empty) {} --- old/src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepGeneration.hpp 2014-11-06 12:39:38.435779000 -0800 +++ new/src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepGeneration.hpp 2014-11-06 12:39:37.497060000 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 2014, 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 @@ -188,7 +188,8 @@ public: CMSMarkStack(): - _par_lock(Mutex::event, "CMSMarkStack._par_lock", true), + _par_lock(Mutex::event, "CMSMarkStack._par_lock", true, + Monitor::_safepoint_check_never), _hit_limit(0), _failed_double(0) {} --- old/src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepGeneration.cpp 2014-11-06 12:39:38.475016000 -0800 +++ new/src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepGeneration.cpp 2014-11-06 12:39:37.524187000 -0800 @@ -6630,8 +6630,9 @@ CMSBitMap::CMSBitMap(int shifter, int mutex_rank, const char* mutex_name): _bm(), _shifter(shifter), - _lock(mutex_rank >= 0 ? new Mutex(mutex_rank, mutex_name, true) : NULL) -{ + _lock(mutex_rank >= 0 ? new Mutex(mutex_rank, mutex_name, true , + Monitor::_safepoint_check_never) : NULL) +{ _bmStartWord = 0; _bmWordSize = 0; } --- old/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp 2014-11-06 12:39:38.515923000 -0800 +++ new/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp 2014-11-06 12:39:37.514670000 -0800 @@ -5024,7 +5024,7 @@ } }; -Monitor* G1CodeCacheUnloadingTask::_lock = new Monitor(Mutex::leaf, "Code Cache Unload lock"); +Monitor* G1CodeCacheUnloadingTask::_lock = new Monitor(Mutex::leaf, "Code Cache Unload lock", false, Monitor::_safepoint_check_never); class G1KlassCleaningTask : public StackObj { BoolObjectClosure* _is_alive; --- old/src/share/vm/runtime/mutex.hpp 2014-11-06 12:39:42.221894000 -0800 +++ new/src/share/vm/runtime/mutex.hpp 2014-11-06 12:39:41.209852000 -0800 @@ -154,6 +154,24 @@ _as_suspend_equivalent_flag = true }; + // Locks can be acquired with or without safepoint check. + // MutexLockerEx checks these flags when acquiring a lock + // to ensure consistent checking for each lock. + // A few existing locks will sometimes have a safepoint check and + // sometimes not, but these locks are set up in such a way to avoid deadlocks. + enum SafepointCheckRequired { + _safepoint_check_never, // Monitors with this value will cause errors + // when acquired with a safepoint check. + _safepoint_check_sometimes, // Certain locks are called sometimes with and + // sometimes without safepoint checks. These + // locks will not produce errors when acquired + // by a MutexLockerEx. + _safepoint_check_always // Causes error if acquired by MutexLockerEx + // without safepoint check. + }; + + NOT_PRODUCT(SafepointCheckRequired _safepoint_check_required;) + enum WaitResults { CONDVAR_EVENT, // Wait returned because of condition variable notification INTERRUPT_EVENT, // Wait returned because waiting thread was interrupted @@ -175,7 +193,8 @@ Monitor() ; public: - Monitor(int rank, const char *name, bool allow_vm_block=false); + Monitor(int rank, const char *name, bool allow_vm_block=false, + SafepointCheckRequired safepoint_check_required= _safepoint_check_always); ~Monitor(); // Wait until monitor is notified (or times out). @@ -261,7 +280,8 @@ class Mutex : public Monitor { // degenerate Monitor public: - Mutex (int rank, const char *name, bool allow_vm_block=false); + Mutex (int rank, const char *name, bool allow_vm_block=false, + SafepointCheckRequired safepoint_check_required = _safepoint_check_always); ~Mutex () ; private: bool notify () { ShouldNotReachHere(); return false; } --- old/src/share/vm/runtime/mutexLocker.cpp 2014-11-06 12:39:42.256095000 -0800 +++ new/src/share/vm/runtime/mutexLocker.cpp 2014-11-06 12:39:41.250560000 -0800 @@ -163,128 +163,127 @@ } #endif -#define def(var, type, pri, vm_block) { \ - var = new type(Mutex::pri, #var, vm_block); \ - assert(_num_mutex < MAX_NUM_MUTEX, \ - "increase MAX_NUM_MUTEX"); \ - _mutex_array[_num_mutex++] = var; \ +#define def(var, type, pri, vm_block, safepoint_check_allowed ) { \ + var = new type(Mutex::pri, #var, vm_block,safepoint_check_allowed); \ + assert(_num_mutex < MAX_NUM_MUTEX, "increase MAX_NUM_MUTEX"); \ + _mutex_array[_num_mutex++] = var; \ } void mutex_init() { - def(tty_lock , Mutex , event, true ); // allow to lock in VM + def(tty_lock , Mutex , event, true, Monitor::_safepoint_check_never ); // allow to lock in VM - def(CGC_lock , Monitor, special, true ); // coordinate between fore- and background GC - def(STS_lock , Monitor, leaf, true ); + def(CGC_lock , Monitor, special, true, Monitor::_safepoint_check_never ); // coordinate between fore- and background GC + def(STS_lock , Monitor, leaf, true, Monitor::_safepoint_check_never ); if (UseConcMarkSweepGC) { - def(iCMS_lock , Monitor, special, true ); // CMS incremental mode start/stop notification + def(iCMS_lock , Monitor, special, true, Monitor::_safepoint_check_never ); // CMS incremental mode start/stop notification } if (UseConcMarkSweepGC || UseG1GC) { - def(FullGCCount_lock , Monitor, leaf, true ); // in support of ExplicitGCInvokesConcurrent + def(FullGCCount_lock , Monitor, leaf, true, Monitor::_safepoint_check_never ); // in support of ExplicitGCInvokesConcurrent } if (UseG1GC) { - def(CMark_lock , Monitor, nonleaf, true ); // coordinate concurrent mark thread - def(CMRegionStack_lock , Mutex, leaf, true ); - def(SATB_Q_FL_lock , Mutex , special, true ); - def(SATB_Q_CBL_mon , Monitor, nonleaf, true ); - def(Shared_SATB_Q_lock , Mutex, nonleaf, true ); - - def(DirtyCardQ_FL_lock , Mutex , special, true ); - def(DirtyCardQ_CBL_mon , Monitor, nonleaf, true ); - def(Shared_DirtyCardQ_lock , Mutex, nonleaf, true ); - - def(FreeList_lock , Mutex, leaf , true ); - def(SecondaryFreeList_lock , Monitor, leaf , true ); - def(OldSets_lock , Mutex , leaf , true ); - def(RootRegionScan_lock , Monitor, leaf , true ); - def(MMUTracker_lock , Mutex , leaf , true ); - def(HotCardCache_lock , Mutex , special , true ); - def(EvacFailureStack_lock , Mutex , nonleaf , true ); - - def(StringDedupQueue_lock , Monitor, leaf, true ); - def(StringDedupTable_lock , Mutex , leaf, true ); - } - def(ParGCRareEvent_lock , Mutex , leaf , true ); - def(DerivedPointerTableGC_lock , Mutex, leaf, true ); - def(CodeCache_lock , Mutex , special, true ); - def(Interrupt_lock , Monitor, special, true ); // used for interrupt processing - def(RawMonitor_lock , Mutex, special, true ); - def(OopMapCacheAlloc_lock , Mutex, leaf, true ); // used for oop_map_cache allocation. - - def(Patching_lock , Mutex , special, true ); // used for safepointing and code patching. - def(ObjAllocPost_lock , Monitor, special, false); - def(Service_lock , Monitor, special, true ); // used for service thread operations - def(JmethodIdCreation_lock , Mutex , leaf, true ); // used for creating jmethodIDs. - - def(SystemDictionary_lock , Monitor, leaf, true ); // lookups done by VM thread - def(PackageTable_lock , Mutex , leaf, false); - def(InlineCacheBuffer_lock , Mutex , leaf, true ); - def(VMStatistic_lock , Mutex , leaf, false); - def(ExpandHeap_lock , Mutex , leaf, true ); // Used during compilation by VM thread - def(JNIHandleBlockFreeList_lock , Mutex , leaf, true ); // handles are used by VM thread - def(SignatureHandlerLibrary_lock , Mutex , leaf, false); - def(SymbolTable_lock , Mutex , leaf+2, true ); - def(StringTable_lock , Mutex , leaf, true ); - def(ProfilePrint_lock , Mutex , leaf, false); // serial profile printing - def(ExceptionCache_lock , Mutex , leaf, false); // serial profile printing - def(OsrList_lock , Mutex , leaf, true ); - def(Debug1_lock , Mutex , leaf, true ); + def(CMark_lock , Monitor, nonleaf, true, Monitor::_safepoint_check_never ); // coordinate concurrent mark thread + def(CMRegionStack_lock , Mutex, leaf, true, Monitor::_safepoint_check_never ); + def(SATB_Q_FL_lock , Mutex , special, true, Monitor::_safepoint_check_never ); + def(SATB_Q_CBL_mon , Monitor, nonleaf, true, Monitor::_safepoint_check_never ); + def(Shared_SATB_Q_lock , Mutex, nonleaf, true, Monitor::_safepoint_check_never ); + + def(DirtyCardQ_FL_lock , Mutex , special, true, Monitor::_safepoint_check_never ); + def(DirtyCardQ_CBL_mon , Monitor, nonleaf, true, Monitor::_safepoint_check_never ); + def(Shared_DirtyCardQ_lock , Mutex, nonleaf, true, Monitor::_safepoint_check_never ); + + def(FreeList_lock , Mutex, leaf , true, Monitor::_safepoint_check_never ); + def(SecondaryFreeList_lock , Monitor, leaf , true, Monitor::_safepoint_check_never ); + def(OldSets_lock , Mutex , leaf , true, Monitor::_safepoint_check_never ); + def(RootRegionScan_lock , Monitor, leaf , true, Monitor::_safepoint_check_never ); + def(MMUTracker_lock , Mutex , leaf , true, Monitor::_safepoint_check_never ); + def(HotCardCache_lock , Mutex , special , true, Monitor::_safepoint_check_never ); + def(EvacFailureStack_lock , Mutex , nonleaf , true, Monitor::_safepoint_check_never ); + + def(StringDedupQueue_lock , Monitor, leaf, true, Monitor::_safepoint_check_never ); + def(StringDedupTable_lock , Mutex , leaf, true, Monitor::_safepoint_check_never ); + } + def(ParGCRareEvent_lock , Mutex , leaf , true, Monitor::_safepoint_check_sometimes); + def(DerivedPointerTableGC_lock , Mutex, leaf, true, Monitor::_safepoint_check_never ); + def(CodeCache_lock , Mutex , special, true, Monitor::_safepoint_check_never ); + def(Interrupt_lock , Monitor, special, true, Monitor::_safepoint_check_never ); // used for interrupt processing + def(RawMonitor_lock , Mutex, special, true, Monitor::_safepoint_check_never ); + def(OopMapCacheAlloc_lock , Mutex, leaf, true, Monitor::_safepoint_check_always); // used for oop_map_cache allocation. + + def(Patching_lock , Mutex , special, true, Monitor::_safepoint_check_never ); // used for safepointing and code patching. + def(ObjAllocPost_lock , Monitor, special, false, Monitor::_safepoint_check_never ); + def(Service_lock , Monitor, special, true, Monitor::_safepoint_check_never ); // used for service thread operations + def(JmethodIdCreation_lock , Mutex , leaf, true, Monitor::_safepoint_check_always); // used for creating jmethodIDs. + + def(SystemDictionary_lock , Monitor, leaf, true, Monitor::_safepoint_check_always); // lookups done by VM thread + def(PackageTable_lock , Mutex , leaf, false, Monitor::_safepoint_check_always); + def(InlineCacheBuffer_lock , Mutex , leaf, true, Monitor::_safepoint_check_always); + def(VMStatistic_lock , Mutex , leaf, false, Monitor::_safepoint_check_always); + def(ExpandHeap_lock , Mutex , leaf, true, Monitor::_safepoint_check_always); // Used during compilation by VM thread + def(JNIHandleBlockFreeList_lock , Mutex , leaf, true, Monitor::_safepoint_check_never ); // handles are used by VM thread + def(SignatureHandlerLibrary_lock , Mutex , leaf, false, Monitor::_safepoint_check_always); + def(SymbolTable_lock , Mutex , leaf+2, true, Monitor::_safepoint_check_always); + def(StringTable_lock , Mutex , leaf, true, Monitor::_safepoint_check_always); + def(ProfilePrint_lock , Mutex , leaf, false, Monitor::_safepoint_check_always); // serial profile printing + def(ExceptionCache_lock , Mutex , leaf, false, Monitor::_safepoint_check_always); // serial profile printing + def(OsrList_lock , Mutex , leaf, true, Monitor::_safepoint_check_never ); + def(Debug1_lock , Mutex , leaf, true, Monitor::_safepoint_check_never ); #ifndef PRODUCT - def(FullGCALot_lock , Mutex , leaf, false); // a lock to make FullGCALot MT safe + def(FullGCALot_lock , Mutex , leaf, false, Monitor::_safepoint_check_always); // a lock to make FullGCALot MT safe #endif - def(BeforeExit_lock , Monitor, leaf, true ); - def(PerfDataMemAlloc_lock , Mutex , leaf, true ); // used for allocating PerfData memory for performance data - def(PerfDataManager_lock , Mutex , leaf, true ); // used for synchronized access to PerfDataManager resources + def(BeforeExit_lock , Monitor, leaf, true, Monitor::_safepoint_check_always); + def(PerfDataMemAlloc_lock , Mutex , leaf, true, Monitor::_safepoint_check_always); // used for allocating PerfData memory for performance data + def(PerfDataManager_lock , Mutex , leaf, true, Monitor::_safepoint_check_always); // used for synchronized access to PerfDataManager resources // CMS_modUnionTable_lock leaf // CMS_bitMap_lock leaf + 1 // CMS_freeList_lock leaf + 2 - def(Safepoint_lock , Monitor, safepoint, true ); // locks SnippetCache_lock/Threads_lock + def(Safepoint_lock , Monitor, safepoint, true, Monitor::_safepoint_check_sometimes); // locks SnippetCache_lock/Threads_lock - def(Threads_lock , Monitor, barrier, true ); + def(Threads_lock , Monitor, barrier, true, Monitor::_safepoint_check_sometimes); - def(VMOperationQueue_lock , Monitor, nonleaf, true ); // VM_thread allowed to block on these - def(VMOperationRequest_lock , Monitor, nonleaf, true ); - def(RetData_lock , Mutex , nonleaf, false); - def(Terminator_lock , Monitor, nonleaf, true ); - def(VtableStubs_lock , Mutex , nonleaf, true ); - def(Notify_lock , Monitor, nonleaf, true ); - def(JNIGlobalHandle_lock , Mutex , nonleaf, true ); // locks JNIHandleBlockFreeList_lock - def(JNICritical_lock , Monitor, nonleaf, true ); // used for JNI critical regions - def(AdapterHandlerLibrary_lock , Mutex , nonleaf, true); + def(VMOperationQueue_lock , Monitor, nonleaf, true, Monitor::_safepoint_check_sometimes); // VM_thread allowed to block on these + def(VMOperationRequest_lock , Monitor, nonleaf, true, Monitor::_safepoint_check_sometimes); + def(RetData_lock , Mutex , nonleaf, false, Monitor::_safepoint_check_always); + def(Terminator_lock , Monitor, nonleaf, true, Monitor::_safepoint_check_sometimes); + def(VtableStubs_lock , Mutex , nonleaf, true, Monitor::_safepoint_check_always); + def(Notify_lock , Monitor, nonleaf, true, Monitor::_safepoint_check_always); + def(JNIGlobalHandle_lock , Mutex , nonleaf, true, Monitor::_safepoint_check_always); // locks JNIHandleBlockFreeList_lock + def(JNICritical_lock , Monitor, nonleaf, true, Monitor::_safepoint_check_always); // used for JNI critical regions + def(AdapterHandlerLibrary_lock , Mutex , nonleaf, true, Monitor::_safepoint_check_always); if (UseConcMarkSweepGC) { - def(SLT_lock , Monitor, nonleaf, false ); + def(SLT_lock , Monitor, nonleaf, false, Monitor::_safepoint_check_never ); // used in CMS GC for locking PLL lock } - def(Heap_lock , Monitor, nonleaf+1, false); - def(JfieldIdCreation_lock , Mutex , nonleaf+1, true ); // jfieldID, Used in VM_Operation - def(MemberNameTable_lock , Mutex , nonleaf+1, false); // Used to protect MemberNameTable - - def(CompiledIC_lock , Mutex , nonleaf+2, false); // locks VtableStubs_lock, InlineCacheBuffer_lock - def(CompileTaskAlloc_lock , Mutex , nonleaf+2, true ); - def(CompileStatistics_lock , Mutex , nonleaf+2, false); - def(MultiArray_lock , Mutex , nonleaf+2, false); // locks SymbolTable_lock - - def(JvmtiThreadState_lock , Mutex , nonleaf+2, false); // Used by JvmtiThreadState/JvmtiEventController - def(JvmtiPendingEvent_lock , Monitor, nonleaf, false); // Used by JvmtiCodeBlobEvents - def(Management_lock , Mutex , nonleaf+2, false); // used for JVM management - - def(Compile_lock , Mutex , nonleaf+3, true ); - def(MethodData_lock , Mutex , nonleaf+3, false); - - def(MethodCompileQueue_lock , Monitor, nonleaf+4, true ); - def(Debug2_lock , Mutex , nonleaf+4, true ); - def(Debug3_lock , Mutex , nonleaf+4, true ); - def(ProfileVM_lock , Monitor, special, false); // used for profiling of the VMThread - def(CompileThread_lock , Monitor, nonleaf+5, false ); - def(PeriodicTask_lock , Monitor, nonleaf+5, true); + def(Heap_lock , Monitor, nonleaf+1, false, Monitor::_safepoint_check_sometimes); + def(JfieldIdCreation_lock , Mutex , nonleaf+1, true, Monitor::_safepoint_check_always); // jfieldID, Used in VM_Operation + def(MemberNameTable_lock , Mutex , nonleaf+1, false, Monitor::_safepoint_check_always); // Used to protect MemberNameTable + + def(CompiledIC_lock , Mutex , nonleaf+2, false, Monitor::_safepoint_check_always); // locks VtableStubs_lock, InlineCacheBuffer_lock + def(CompileTaskAlloc_lock , Mutex , nonleaf+2, true, Monitor::_safepoint_check_always); + def(CompileStatistics_lock , Mutex , nonleaf+2, false, Monitor::_safepoint_check_always); + def(MultiArray_lock , Mutex , nonleaf+2, false, Monitor::_safepoint_check_always); // locks SymbolTable_lock + + def(JvmtiThreadState_lock , Mutex , nonleaf+2, false, Monitor::_safepoint_check_always); // Used by JvmtiThreadState/JvmtiEventController + def(JvmtiPendingEvent_lock , Monitor, nonleaf, false, Monitor::_safepoint_check_never ); // Used by JvmtiCodeBlobEvents + def(Management_lock , Mutex , nonleaf+2, false, Monitor::_safepoint_check_always); // used for JVM management + + def(Compile_lock , Mutex , nonleaf+3, true, Monitor::_safepoint_check_sometimes); + def(MethodData_lock , Mutex , nonleaf+3, false, Monitor::_safepoint_check_always); + + def(MethodCompileQueue_lock , Monitor, nonleaf+4, true, Monitor::_safepoint_check_always); + def(Debug2_lock , Mutex , nonleaf+4, true, Monitor::_safepoint_check_never ); + def(Debug3_lock , Mutex , nonleaf+4, true, Monitor::_safepoint_check_never ); + def(ProfileVM_lock , Monitor, special, false, Monitor::_safepoint_check_never ); // used for profiling of the VMThread + def(CompileThread_lock , Monitor, nonleaf+5, false, Monitor::_safepoint_check_always); + def(PeriodicTask_lock , Monitor, nonleaf+5, true, Monitor::_safepoint_check_sometimes); #ifdef INCLUDE_TRACE - def(JfrMsg_lock , Monitor, leaf, true); - def(JfrBuffer_lock , Mutex, leaf, true); - def(JfrThreadGroups_lock , Mutex, leaf, true); - def(JfrStream_lock , Mutex, nonleaf, true); - def(JfrStacktrace_lock , Mutex, special, true); + def(JfrMsg_lock , Monitor, leaf, true, Monitor::_safepoint_check_always); + def(JfrBuffer_lock , Mutex, leaf, true, Monitor::_safepoint_check_never ); + def(JfrThreadGroups_lock , Mutex, leaf, true, Monitor::_safepoint_check_always); + def(JfrStream_lock , Mutex, nonleaf, true, Monitor::_safepoint_check_never ); + def(JfrStacktrace_lock , Mutex, special, true, Monitor::_safepoint_check_sometimes); #endif } --- old/src/share/vm/runtime/thread.cpp 2014-11-06 12:39:42.314713000 -0800 +++ new/src/share/vm/runtime/thread.cpp 2014-11-06 12:39:41.269380000 -0800 @@ -227,7 +227,8 @@ _visited_for_critical_count = false; #endif - _SR_lock = new Monitor(Mutex::suspend_resume, "SR_lock", true); + _SR_lock = new Monitor(Mutex::suspend_resume, "SR_lock", true, + Monitor::_safepoint_check_sometimes); _suspend_flags = 0; // thread-specific hashCode stream generator state - Marsaglia shift-xor form --- old/src/share/vm/runtime/mutex.cpp 2014-11-06 12:39:42.238072000 -0800 +++ new/src/share/vm/runtime/mutex.cpp 2014-11-06 12:39:41.225669000 -0800 @@ -895,6 +895,11 @@ // of Mutex-Monitor and instead directly address the underlying design flaw. void Monitor::lock(Thread * Self) { + //Ensure that the Monitor requires/allows safepoint checks. + assert(this->_safepoint_check_required != Monitor::_safepoint_check_never, + err_msg("This lock should never have a safepoint check: %s", + this->name())); + #ifdef CHECK_UNHANDLED_OOPS // Clear unhandled oops so we get a crash right away. Only clear for non-vm // or GC threads. @@ -953,6 +958,10 @@ // thread state set to be in VM, the safepoint synchronization code will deadlock! void Monitor::lock_without_safepoint_check(Thread * Self) { + //Ensure that the Monitor does not require or allow safepoint checks. + assert(this->_safepoint_check_required != Monitor::_safepoint_check_always, + err_msg("This lock should always have a safepoint check: %s", + this->name())); assert(_owner != Self, "invariant"); ILock(Self); assert(_owner == NULL, "invariant"); @@ -1168,11 +1177,13 @@ Monitor::Monitor() { ClearMonitor(this); } -Monitor::Monitor(int Rank, const char * name, bool allow_vm_block) { +Monitor::Monitor(int Rank, const char * name, bool allow_vm_block, + SafepointCheckRequired safepoint_check_required) { ClearMonitor(this, name); #ifdef ASSERT _allow_vm_block = allow_vm_block; _rank = Rank; + NOT_PRODUCT(_safepoint_check_required = safepoint_check_required;) #endif } @@ -1180,11 +1191,13 @@ assert((UNS(_owner)|UNS(_LockWord.FullWord)|UNS(_EntryList)|UNS(_WaitSet)|UNS(_OnDeck)) == 0, ""); } -Mutex::Mutex(int Rank, const char * name, bool allow_vm_block) { +Mutex::Mutex(int Rank, const char * name, bool allow_vm_block, + SafepointCheckRequired safepoint_check_required) { ClearMonitor((Monitor *) this, name); #ifdef ASSERT _allow_vm_block = allow_vm_block; _rank = Rank; + NOT_PRODUCT(_safepoint_check_required = safepoint_check_required;) #endif } --- old/src/share/vm/runtime/vm_operations.cpp 2014-11-06 12:39:42.267162000 -0800 +++ new/src/share/vm/runtime/vm_operations.cpp 2014-11-06 12:39:41.245151000 -0800 @@ -388,7 +388,8 @@ assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint already"); Thread * thr_cur = ThreadLocalStorage::get_thread_slow(); - Monitor timer(Mutex::leaf, "VM_Exit timer", true); + Monitor timer(Mutex::leaf, "VM_Exit timer", true, + Monitor::_safepoint_check_never); // Compiler threads need longer wait because they can access VM data directly // while in native. If they are active and some structures being used are --- old/src/share/vm/memory/metaspace.cpp 2014-11-06 12:39:42.253681000 -0800 +++ new/src/share/vm/memory/metaspace.cpp 2014-11-06 12:39:41.201547000 -0800 @@ -791,7 +791,8 @@ Mutex* const SpaceManager::_expand_lock = new Mutex(SpaceManager::_expand_lock_rank, SpaceManager::_expand_lock_name, - Mutex::_allow_vm_block_flag); + Mutex::_allow_vm_block_flag, + Monitor::_safepoint_check_never); void VirtualSpaceNode::inc_container_count() { assert_lock_strong(SpaceManager::expand_lock()); --- old/src/share/vm/memory/sharedHeap.cpp 2014-11-06 12:39:42.452976000 -0800 +++ new/src/share/vm/memory/sharedHeap.cpp 2014-11-06 12:39:41.463693000 -0800 @@ -156,7 +156,7 @@ } } -Monitor* SharedHeap::StrongRootsScope::_lock = new Monitor(Mutex::leaf, "StrongRootsScope lock", false); +Monitor* SharedHeap::StrongRootsScope::_lock = new Monitor(Mutex::leaf, "StrongRootsScope lock", false, Monitor::_safepoint_check_never); void SharedHeap::StrongRootsScope::mark_worker_done_with_threads(uint n_workers) { // The Thread work barrier is only needed by G1 Class Unloading. --- old/src/share/vm/prims/whitebox.cpp 2014-11-06 12:39:42.512501000 -0800 +++ new/src/share/vm/prims/whitebox.cpp 2014-11-06 12:39:41.506397000 -0800 @@ -876,6 +876,13 @@ return (jlong) MetaspaceGC::capacity_until_GC(); WB_END +WB_ENTRY(void, WB_AssertMatchingSafepointCalls(JNIEnv* env, jobject o, jboolean mutexSafepointValue, jboolean attemptedNoSafepointValue)) + Monitor::SafepointCheckRequired sfpt_check_required = mutexSafepointValue ? + Monitor::_safepoint_check_always : + Monitor::_safepoint_check_never; + MutexLockerEx ml(new Mutex(Mutex::leaf, "SFPT_Test_lock", true, sfpt_check_required), + attemptedNoSafepointValue == JNI_TRUE ); +WB_END //Some convenience methods to deal with objects from java int WhiteBox::offset_for_field(const char* field_name, oop object, Symbol* signature_symbol) { @@ -1055,6 +1062,7 @@ (void*)&WB_GetNMethod }, {CC"getThreadStackSize", CC"()J", (void*)&WB_GetThreadStackSize }, {CC"getThreadRemainingStackSize", CC"()J", (void*)&WB_GetThreadRemainingStackSize }, + {CC"assertMatchingSafepointCalls", CC"(ZZ)V", (void*)&WB_AssertMatchingSafepointCalls }, }; #undef CC --- old/src/share/vm/runtime/vmThread.cpp 2014-11-06 12:39:42.507049000 -0800 +++ new/src/share/vm/runtime/vmThread.cpp 2014-11-06 12:39:41.529169000 -0800 @@ -214,7 +214,7 @@ _vm_queue = new VMOperationQueue(); guarantee(_vm_queue != NULL, "just checking"); - _terminate_lock = new Monitor(Mutex::safepoint, "VMThread::_terminate_lock", true); + _terminate_lock = new Monitor(Mutex::safepoint, "VMThread::_terminate_lock", true, Monitor::_safepoint_check_never); if (UsePerfData) { // jvmstat performance counters --- old/src/share/vm/services/diagnosticFramework.cpp 2014-11-06 12:39:42.505511000 -0800 +++ new/src/share/vm/services/diagnosticFramework.cpp 2014-11-06 12:39:41.514989000 -0800 @@ -488,7 +488,7 @@ } } -Mutex* DCmdFactory::_dcmdFactory_lock = new Mutex(Mutex::leaf, "DCmdFactory", true); +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) { --- old/src/share/vm/runtime/mutexLocker.hpp 2014-11-06 12:39:42.799886000 -0800 +++ new/src/share/vm/runtime/mutexLocker.hpp 2014-11-06 12:39:41.825094000 -0800 @@ -206,13 +206,13 @@ if (_mutex != NULL) { assert(mutex->rank() > Mutex::special || no_safepoint_check, "Mutexes with rank special or lower should not do safepoint checks"); + if (no_safepoint_check) _mutex->lock_without_safepoint_check(); else _mutex->lock(); } } - ~MutexLockerEx() { if (_mutex != NULL) { _mutex->unlock(); --- old/src/share/vm/services/memoryManager.cpp 2014-11-06 12:39:43.759932000 -0800 +++ new/src/share/vm/services/memoryManager.cpp 2014-11-06 12:39:42.675873000 -0800 @@ -198,7 +198,8 @@ GCMemoryManager::GCMemoryManager() : MemoryManager() { _num_collections = 0; _last_gc_stat = NULL; - _last_gc_lock = new Mutex(Mutex::leaf, "_last_gc_lock", true); + _last_gc_lock = new Mutex(Mutex::leaf, "_last_gc_lock", true, + Monitor::_safepoint_check_never); _current_gc_stat = NULL; _num_gc_threads = 1; _notification_enabled = false; --- old/src/share/vm/utilities/decoder.cpp 2014-11-06 12:39:46.110679000 -0800 +++ new/src/share/vm/utilities/decoder.cpp 2014-11-06 12:39:45.521494000 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2014, 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 @@ -42,7 +42,9 @@ AbstractDecoder* Decoder::_error_handler_decoder = NULL; NullDecoder Decoder::_do_nothing_decoder; Mutex* Decoder::_shared_decoder_lock = new Mutex(Mutex::native, - "SharedDecoderLock"); + "SharedDecoderLock", + false, + Monitor::_safepoint_check_never); AbstractDecoder* Decoder::get_shared_instance() { assert(_shared_decoder_lock != NULL && _shared_decoder_lock->owned_by_self(), --- old/test/testlibrary/whitebox/sun/hotspot/WhiteBox.java 2014-11-06 12:39:46.160323000 -0800 +++ new/test/testlibrary/whitebox/sun/hotspot/WhiteBox.java 2014-11-06 12:39:45.547987000 -0800 @@ -205,4 +205,7 @@ .findAny() .orElse(null); } + + //Safepoint Checking + public native void assertMatchingSafepointCalls(boolean mutexSafepointValue, boolean attemptedNoSafepointValue); } --- old/src/share/vm/utilities/workgroup.cpp 2014-11-06 12:39:46.308986000 -0800 +++ new/src/share/vm/utilities/workgroup.cpp 2014-11-06 12:39:45.688930000 -0800 @@ -46,7 +46,8 @@ // Other initialization. _monitor = new Monitor(/* priority */ Mutex::leaf, /* name */ "WorkGroup monitor", - /* allow_vm_block */ are_GC_task_threads); + /* allow_vm_block */ are_GC_task_threads, + Monitor::_safepoint_check_sometimes); assert(monitor() != NULL, "Failed to allocate monitor"); _terminate = false; _task = NULL; @@ -378,12 +379,13 @@ // *** WorkGangBarrierSync WorkGangBarrierSync::WorkGangBarrierSync() - : _monitor(Mutex::safepoint, "work gang barrier sync", true), + : _monitor(Mutex::safepoint, "work gang barrier sync", true, + Monitor::_safepoint_check_never), _n_workers(0), _n_completed(0), _should_reset(false), _aborted(false) { } WorkGangBarrierSync::WorkGangBarrierSync(uint n_workers, const char* name) - : _monitor(Mutex::safepoint, name, true), + : _monitor(Mutex::safepoint, name, true, Monitor::_safepoint_check_never), _n_workers(n_workers), _n_completed(0), _should_reset(false), _aborted(false) { } --- old/src/share/vm/utilities/events.hpp 2014-11-06 12:39:46.303623000 -0800 +++ new/src/share/vm/utilities/events.hpp 2014-11-06 12:39:45.685927000 -0800 @@ -90,7 +90,7 @@ _length(length), _count(0), _index(0), - _mutex(Mutex::event, name) { + _mutex(Mutex::event, name, false, Monitor::_safepoint_check_never) { _records = new EventRecord[length]; }