src/share/vm/runtime/mutexLocker.hpp

Thu, 24 May 2018 20:03:11 +0800

author
aoqi
date
Thu, 24 May 2018 20:03:11 +0800
changeset 8868
91ddc23482a4
parent 7994
04ff2f6cd0eb
child 9756
2be326848943
permissions
-rw-r--r--

Increase MaxHeapSize for better performance on MIPS

aoqi@0 1 /*
redestad@7653 2 * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #ifndef SHARE_VM_RUNTIME_MUTEXLOCKER_HPP
aoqi@0 26 #define SHARE_VM_RUNTIME_MUTEXLOCKER_HPP
aoqi@0 27
aoqi@0 28 #include "memory/allocation.hpp"
aoqi@0 29 #include "runtime/mutex.hpp"
aoqi@0 30 #ifdef TARGET_OS_FAMILY_linux
aoqi@0 31 # include "os_linux.inline.hpp"
aoqi@0 32 #endif
aoqi@0 33 #ifdef TARGET_OS_FAMILY_solaris
aoqi@0 34 # include "os_solaris.inline.hpp"
aoqi@0 35 #endif
aoqi@0 36 #ifdef TARGET_OS_FAMILY_windows
aoqi@0 37 # include "os_windows.inline.hpp"
aoqi@0 38 #endif
aoqi@0 39 #ifdef TARGET_OS_FAMILY_aix
aoqi@0 40 # include "os_aix.inline.hpp"
aoqi@0 41 #endif
aoqi@0 42 #ifdef TARGET_OS_FAMILY_bsd
aoqi@0 43 # include "os_bsd.inline.hpp"
aoqi@0 44 #endif
aoqi@0 45
aoqi@0 46 // Mutexes used in the VM.
aoqi@0 47
aoqi@0 48 extern Mutex* Patching_lock; // a lock used to guard code patching of compiled code
aoqi@0 49 extern Monitor* SystemDictionary_lock; // a lock on the system dictonary
aoqi@0 50 extern Mutex* PackageTable_lock; // a lock on the class loader package table
aoqi@0 51 extern Mutex* CompiledIC_lock; // a lock used to guard compiled IC patching and access
aoqi@0 52 extern Mutex* InlineCacheBuffer_lock; // a lock used to guard the InlineCacheBuffer
aoqi@0 53 extern Mutex* VMStatistic_lock; // a lock used to guard statistics count increment
aoqi@0 54 extern Mutex* JNIGlobalHandle_lock; // a lock on creating JNI global handles
aoqi@0 55 extern Mutex* JNIHandleBlockFreeList_lock; // a lock on the JNI handle block free list
aoqi@0 56 extern Mutex* MemberNameTable_lock; // a lock on the MemberNameTable updates
aoqi@0 57 extern Mutex* JmethodIdCreation_lock; // a lock on creating JNI method identifiers
aoqi@0 58 extern Mutex* JfieldIdCreation_lock; // a lock on creating JNI static field identifiers
aoqi@0 59 extern Monitor* JNICritical_lock; // a lock used while entering and exiting JNI critical regions, allows GC to sometimes get in
aoqi@0 60 extern Mutex* JvmtiThreadState_lock; // a lock on modification of JVMTI thread data
aoqi@0 61 extern Monitor* JvmtiPendingEvent_lock; // a lock on the JVMTI pending events list
aoqi@0 62 extern Monitor* Heap_lock; // a lock on the heap
aoqi@0 63 extern Mutex* ExpandHeap_lock; // a lock on expanding the heap
aoqi@0 64 extern Mutex* AdapterHandlerLibrary_lock; // a lock on the AdapterHandlerLibrary
aoqi@0 65 extern Mutex* SignatureHandlerLibrary_lock; // a lock on the SignatureHandlerLibrary
aoqi@0 66 extern Mutex* VtableStubs_lock; // a lock on the VtableStubs
aoqi@0 67 extern Mutex* SymbolTable_lock; // a lock on the symbol table
aoqi@0 68 extern Mutex* StringTable_lock; // a lock on the interned string table
aoqi@0 69 extern Monitor* StringDedupQueue_lock; // a lock on the string deduplication queue
aoqi@0 70 extern Mutex* StringDedupTable_lock; // a lock on the string deduplication table
aoqi@0 71 extern Mutex* CodeCache_lock; // a lock on the CodeCache, rank is special, use MutexLockerEx
aoqi@0 72 extern Mutex* MethodData_lock; // a lock on installation of method data
aoqi@0 73 extern Mutex* RetData_lock; // a lock on installation of RetData inside method data
aoqi@0 74 extern Mutex* DerivedPointerTableGC_lock; // a lock to protect the derived pointer table
aoqi@0 75 extern Monitor* VMOperationQueue_lock; // a lock on queue of vm_operations waiting to execute
aoqi@0 76 extern Monitor* VMOperationRequest_lock; // a lock on Threads waiting for a vm_operation to terminate
aoqi@0 77 extern Monitor* Safepoint_lock; // a lock used by the safepoint abstraction
aoqi@0 78 extern Monitor* Threads_lock; // a lock on the Threads table of active Java threads
aoqi@0 79 // (also used by Safepoints too to block threads creation/destruction)
aoqi@0 80 extern Monitor* CGC_lock; // used for coordination between
aoqi@0 81 // fore- & background GC threads.
pliden@6906 82 extern Monitor* STS_lock; // used for joining/leaving SuspendibleThreadSet.
aoqi@0 83 extern Monitor* SLT_lock; // used in CMS GC for acquiring PLL
aoqi@0 84 extern Monitor* iCMS_lock; // CMS incremental mode start/stop notification
aoqi@0 85 extern Monitor* FullGCCount_lock; // in support of "concurrent" full gc
aoqi@0 86 extern Monitor* CMark_lock; // used for concurrent mark thread coordination
aoqi@0 87 extern Mutex* CMRegionStack_lock; // used for protecting accesses to the CM region stack
aoqi@0 88 extern Mutex* SATB_Q_FL_lock; // Protects SATB Q
aoqi@0 89 // buffer free list.
aoqi@0 90 extern Monitor* SATB_Q_CBL_mon; // Protects SATB Q
aoqi@0 91 // completed buffer queue.
aoqi@0 92 extern Mutex* Shared_SATB_Q_lock; // Lock protecting SATB
aoqi@0 93 // queue shared by
aoqi@0 94 // non-Java threads.
aoqi@0 95
aoqi@0 96 extern Mutex* DirtyCardQ_FL_lock; // Protects dirty card Q
aoqi@0 97 // buffer free list.
aoqi@0 98 extern Monitor* DirtyCardQ_CBL_mon; // Protects dirty card Q
aoqi@0 99 // completed buffer queue.
aoqi@0 100 extern Mutex* Shared_DirtyCardQ_lock; // Lock protecting dirty card
aoqi@0 101 // queue shared by
aoqi@0 102 // non-Java threads.
aoqi@0 103 // (see option ExplicitGCInvokesConcurrent)
aoqi@0 104 extern Mutex* ParGCRareEvent_lock; // Synchronizes various (rare) parallel GC ops.
aoqi@0 105 extern Mutex* EvacFailureStack_lock; // guards the evac failure scan stack
aoqi@0 106 extern Mutex* Compile_lock; // a lock held when Compilation is updating code (used to block CodeCache traversal, CHA updates, etc)
aoqi@0 107 extern Monitor* MethodCompileQueue_lock; // a lock held when method compilations are enqueued, dequeued
aoqi@0 108 extern Monitor* CompileThread_lock; // a lock held by compile threads during compilation system initialization
aoqi@0 109 extern Mutex* CompileTaskAlloc_lock; // a lock held when CompileTasks are allocated
aoqi@0 110 extern Mutex* CompileStatistics_lock; // a lock held when updating compilation statistics
aoqi@0 111 extern Mutex* MultiArray_lock; // a lock used to guard allocation of multi-dim arrays
aoqi@0 112 extern Monitor* Terminator_lock; // a lock used to guard termination of the vm
aoqi@0 113 extern Monitor* BeforeExit_lock; // a lock used to guard cleanups and shutdown hooks
aoqi@0 114 extern Monitor* Notify_lock; // a lock used to synchronize the start-up of the vm
aoqi@0 115 extern Monitor* Interrupt_lock; // a lock used for condition variable mediated interrupt processing
aoqi@0 116 extern Monitor* ProfileVM_lock; // a lock used for profiling the VMThread
aoqi@0 117 extern Mutex* ProfilePrint_lock; // a lock used to serialize the printing of profiles
aoqi@0 118 extern Mutex* ExceptionCache_lock; // a lock used to synchronize exception cache updates
aoqi@0 119 extern Mutex* OsrList_lock; // a lock used to serialize access to OSR queues
aoqi@0 120
aoqi@0 121 #ifndef PRODUCT
aoqi@0 122 extern Mutex* FullGCALot_lock; // a lock to make FullGCALot MT safe
aoqi@0 123 #endif // PRODUCT
aoqi@0 124 extern Mutex* Debug1_lock; // A bunch of pre-allocated locks that can be used for tracing
aoqi@0 125 extern Mutex* Debug2_lock; // down synchronization related bugs!
aoqi@0 126 extern Mutex* Debug3_lock;
aoqi@0 127
aoqi@0 128 extern Mutex* RawMonitor_lock;
aoqi@0 129 extern Mutex* PerfDataMemAlloc_lock; // a lock on the allocator for PerfData memory for performance data
aoqi@0 130 extern Mutex* PerfDataManager_lock; // a long on access to PerfDataManager resources
aoqi@0 131 extern Mutex* ParkerFreeList_lock;
aoqi@0 132 extern Mutex* OopMapCacheAlloc_lock; // protects allocation of oop_map caches
aoqi@0 133
aoqi@0 134 extern Mutex* FreeList_lock; // protects the free region list during safepoints
aoqi@0 135 extern Monitor* SecondaryFreeList_lock; // protects the secondary free region list
aoqi@0 136 extern Mutex* OldSets_lock; // protects the old region sets
aoqi@0 137 extern Monitor* RootRegionScan_lock; // used to notify that the CM threads have finished scanning the IM snapshot regions
aoqi@0 138 extern Mutex* MMUTracker_lock; // protects the MMU
aoqi@0 139 // tracker data structures
aoqi@0 140
aoqi@0 141 extern Mutex* Management_lock; // a lock used to serialize JVM management
aoqi@0 142 extern Monitor* Service_lock; // a lock used for service thread operation
aoqi@0 143 extern Monitor* PeriodicTask_lock; // protects the periodic task structure
aoqi@0 144
aoqi@0 145 #ifdef INCLUDE_TRACE
aoqi@0 146 extern Mutex* JfrStacktrace_lock; // used to guard access to the JFR stacktrace table
aoqi@0 147 extern Monitor* JfrMsg_lock; // protects JFR messaging
aoqi@0 148 extern Mutex* JfrBuffer_lock; // protects JFR buffer operations
aoqi@0 149 extern Mutex* JfrStream_lock; // protects JFR stream access
aoqi@0 150 extern Mutex* JfrThreadGroups_lock; // protects JFR access to Thread Groups
aoqi@0 151 #endif
aoqi@0 152
dholmes@7547 153 #ifndef SUPPORTS_NATIVE_CX8
dholmes@7547 154 extern Mutex* UnsafeJlong_lock; // provides Unsafe atomic updates to jlongs on platforms that don't support cx8
dholmes@7547 155 #endif
dholmes@7547 156
aoqi@0 157 // A MutexLocker provides mutual exclusion with respect to a given mutex
aoqi@0 158 // for the scope which contains the locker. The lock is an OS lock, not
aoqi@0 159 // an object lock, and the two do not interoperate. Do not use Mutex-based
aoqi@0 160 // locks to lock on Java objects, because they will not be respected if a
aoqi@0 161 // that object is locked using the Java locking mechanism.
aoqi@0 162 //
aoqi@0 163 // NOTE WELL!!
aoqi@0 164 //
aoqi@0 165 // See orderAccess.hpp. We assume throughout the VM that MutexLocker's
aoqi@0 166 // and friends constructors do a fence, a lock and an acquire *in that
aoqi@0 167 // order*. And that their destructors do a release and unlock, in *that*
aoqi@0 168 // order. If their implementations change such that these assumptions
aoqi@0 169 // are violated, a whole lot of code will break.
aoqi@0 170
aoqi@0 171 // Print all mutexes/monitors that are currently owned by a thread; called
aoqi@0 172 // by fatal error handler.
aoqi@0 173 void print_owned_locks_on_error(outputStream* st);
aoqi@0 174
aoqi@0 175 char *lock_name(Mutex *mutex);
aoqi@0 176
aoqi@0 177 class MutexLocker: StackObj {
aoqi@0 178 private:
aoqi@0 179 Monitor * _mutex;
aoqi@0 180 public:
aoqi@0 181 MutexLocker(Monitor * mutex) {
aoqi@0 182 assert(mutex->rank() != Mutex::special,
aoqi@0 183 "Special ranked mutex should only use MutexLockerEx");
aoqi@0 184 _mutex = mutex;
aoqi@0 185 _mutex->lock();
aoqi@0 186 }
aoqi@0 187
aoqi@0 188 // Overloaded constructor passing current thread
aoqi@0 189 MutexLocker(Monitor * mutex, Thread *thread) {
aoqi@0 190 assert(mutex->rank() != Mutex::special,
aoqi@0 191 "Special ranked mutex should only use MutexLockerEx");
aoqi@0 192 _mutex = mutex;
aoqi@0 193 _mutex->lock(thread);
aoqi@0 194 }
aoqi@0 195
aoqi@0 196 ~MutexLocker() {
aoqi@0 197 _mutex->unlock();
aoqi@0 198 }
aoqi@0 199
aoqi@0 200 };
aoqi@0 201
aoqi@0 202 // for debugging: check that we're already owning this lock (or are at a safepoint)
aoqi@0 203 #ifdef ASSERT
aoqi@0 204 void assert_locked_or_safepoint(const Monitor * lock);
aoqi@0 205 void assert_lock_strong(const Monitor * lock);
aoqi@0 206 #else
aoqi@0 207 #define assert_locked_or_safepoint(lock)
aoqi@0 208 #define assert_lock_strong(lock)
aoqi@0 209 #endif
aoqi@0 210
aoqi@0 211 // A MutexLockerEx behaves like a MutexLocker when its constructor is
aoqi@0 212 // called with a Mutex. Unlike a MutexLocker, its constructor can also be
aoqi@0 213 // called with NULL, in which case the MutexLockerEx is a no-op. There
aoqi@0 214 // is also a corresponding MutexUnlockerEx. We want to keep the
aoqi@0 215 // basic MutexLocker as fast as possible. MutexLockerEx can also lock
aoqi@0 216 // without safepoint check.
aoqi@0 217
aoqi@0 218 class MutexLockerEx: public StackObj {
aoqi@0 219 private:
aoqi@0 220 Monitor * _mutex;
aoqi@0 221 public:
aoqi@0 222 MutexLockerEx(Monitor * mutex, bool no_safepoint_check = !Mutex::_no_safepoint_check_flag) {
aoqi@0 223 _mutex = mutex;
aoqi@0 224 if (_mutex != NULL) {
aoqi@0 225 assert(mutex->rank() > Mutex::special || no_safepoint_check,
aoqi@0 226 "Mutexes with rank special or lower should not do safepoint checks");
aoqi@0 227 if (no_safepoint_check)
aoqi@0 228 _mutex->lock_without_safepoint_check();
aoqi@0 229 else
aoqi@0 230 _mutex->lock();
aoqi@0 231 }
aoqi@0 232 }
aoqi@0 233
aoqi@0 234 ~MutexLockerEx() {
aoqi@0 235 if (_mutex != NULL) {
aoqi@0 236 _mutex->unlock();
aoqi@0 237 }
aoqi@0 238 }
aoqi@0 239 };
aoqi@0 240
aoqi@0 241 // A MonitorLockerEx is like a MutexLockerEx above, except it takes
aoqi@0 242 // a possibly null Monitor, and allows wait/notify as well which are
aoqi@0 243 // delegated to the underlying Monitor.
aoqi@0 244
aoqi@0 245 class MonitorLockerEx: public MutexLockerEx {
aoqi@0 246 private:
aoqi@0 247 Monitor * _monitor;
aoqi@0 248 public:
aoqi@0 249 MonitorLockerEx(Monitor* monitor,
aoqi@0 250 bool no_safepoint_check = !Mutex::_no_safepoint_check_flag):
aoqi@0 251 MutexLockerEx(monitor, no_safepoint_check),
aoqi@0 252 _monitor(monitor) {
aoqi@0 253 // Superclass constructor did locking
aoqi@0 254 }
aoqi@0 255
aoqi@0 256 ~MonitorLockerEx() {
aoqi@0 257 #ifdef ASSERT
aoqi@0 258 if (_monitor != NULL) {
aoqi@0 259 assert_lock_strong(_monitor);
aoqi@0 260 }
aoqi@0 261 #endif // ASSERT
aoqi@0 262 // Superclass destructor will do unlocking
aoqi@0 263 }
aoqi@0 264
aoqi@0 265 bool wait(bool no_safepoint_check = !Mutex::_no_safepoint_check_flag,
aoqi@0 266 long timeout = 0,
aoqi@0 267 bool as_suspend_equivalent = !Mutex::_as_suspend_equivalent_flag) {
aoqi@0 268 if (_monitor != NULL) {
aoqi@0 269 return _monitor->wait(no_safepoint_check, timeout, as_suspend_equivalent);
aoqi@0 270 }
aoqi@0 271 return false;
aoqi@0 272 }
aoqi@0 273
aoqi@0 274 bool notify_all() {
aoqi@0 275 if (_monitor != NULL) {
aoqi@0 276 return _monitor->notify_all();
aoqi@0 277 }
aoqi@0 278 return true;
aoqi@0 279 }
aoqi@0 280
aoqi@0 281 bool notify() {
aoqi@0 282 if (_monitor != NULL) {
aoqi@0 283 return _monitor->notify();
aoqi@0 284 }
aoqi@0 285 return true;
aoqi@0 286 }
aoqi@0 287 };
aoqi@0 288
aoqi@0 289
aoqi@0 290
aoqi@0 291 // A GCMutexLocker is usually initialized with a mutex that is
aoqi@0 292 // automatically acquired in order to do GC. The function that
aoqi@0 293 // synchronizes using a GCMutexLocker may be called both during and between
aoqi@0 294 // GC's. Thus, it must acquire the mutex if GC is not in progress, but not
aoqi@0 295 // if GC is in progress (since the mutex is already held on its behalf.)
aoqi@0 296
aoqi@0 297 class GCMutexLocker: public StackObj {
aoqi@0 298 private:
aoqi@0 299 Monitor * _mutex;
aoqi@0 300 bool _locked;
aoqi@0 301 public:
aoqi@0 302 GCMutexLocker(Monitor * mutex);
aoqi@0 303 ~GCMutexLocker() { if (_locked) _mutex->unlock(); }
aoqi@0 304 };
aoqi@0 305
aoqi@0 306
aoqi@0 307
aoqi@0 308 // A MutexUnlocker temporarily exits a previously
aoqi@0 309 // entered mutex for the scope which contains the unlocker.
aoqi@0 310
aoqi@0 311 class MutexUnlocker: StackObj {
aoqi@0 312 private:
aoqi@0 313 Monitor * _mutex;
aoqi@0 314
aoqi@0 315 public:
aoqi@0 316 MutexUnlocker(Monitor * mutex) {
aoqi@0 317 _mutex = mutex;
aoqi@0 318 _mutex->unlock();
aoqi@0 319 }
aoqi@0 320
aoqi@0 321 ~MutexUnlocker() {
aoqi@0 322 _mutex->lock();
aoqi@0 323 }
aoqi@0 324 };
aoqi@0 325
aoqi@0 326 // A MutexUnlockerEx temporarily exits a previously
aoqi@0 327 // entered mutex for the scope which contains the unlocker.
aoqi@0 328
aoqi@0 329 class MutexUnlockerEx: StackObj {
aoqi@0 330 private:
aoqi@0 331 Monitor * _mutex;
aoqi@0 332 bool _no_safepoint_check;
aoqi@0 333
aoqi@0 334 public:
aoqi@0 335 MutexUnlockerEx(Monitor * mutex, bool no_safepoint_check = !Mutex::_no_safepoint_check_flag) {
aoqi@0 336 _mutex = mutex;
aoqi@0 337 _no_safepoint_check = no_safepoint_check;
aoqi@0 338 _mutex->unlock();
aoqi@0 339 }
aoqi@0 340
aoqi@0 341 ~MutexUnlockerEx() {
aoqi@0 342 if (_no_safepoint_check == Mutex::_no_safepoint_check_flag) {
aoqi@0 343 _mutex->lock_without_safepoint_check();
aoqi@0 344 } else {
aoqi@0 345 _mutex->lock();
aoqi@0 346 }
aoqi@0 347 }
aoqi@0 348 };
aoqi@0 349
aoqi@0 350 #ifndef PRODUCT
aoqi@0 351 //
aoqi@0 352 // A special MutexLocker that allows:
aoqi@0 353 // - reentrant locking
aoqi@0 354 // - locking out of order
aoqi@0 355 //
aoqi@0 356 // Only too be used for verify code, where we can relaxe out dead-lock
aoqi@0 357 // dection code a bit (unsafe, but probably ok). This code is NEVER to
aoqi@0 358 // be included in a product version.
aoqi@0 359 //
aoqi@0 360 class VerifyMutexLocker: StackObj {
aoqi@0 361 private:
aoqi@0 362 Monitor * _mutex;
aoqi@0 363 bool _reentrant;
aoqi@0 364 public:
aoqi@0 365 VerifyMutexLocker(Monitor * mutex) {
aoqi@0 366 _mutex = mutex;
aoqi@0 367 _reentrant = mutex->owned_by_self();
aoqi@0 368 if (!_reentrant) {
aoqi@0 369 // We temp. diable strict safepoint checking, while we require the lock
aoqi@0 370 FlagSetting fs(StrictSafepointChecks, false);
aoqi@0 371 _mutex->lock();
aoqi@0 372 }
aoqi@0 373 }
aoqi@0 374
aoqi@0 375 ~VerifyMutexLocker() {
aoqi@0 376 if (!_reentrant) {
aoqi@0 377 _mutex->unlock();
aoqi@0 378 }
aoqi@0 379 }
aoqi@0 380 };
aoqi@0 381
aoqi@0 382 #endif
aoqi@0 383
aoqi@0 384 #endif // SHARE_VM_RUNTIME_MUTEXLOCKER_HPP

mercurial