< prev index next >

src/hotspot/share/runtime/mutexLocker.cpp

Print this page


   1 /*
   2  * Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *


 172   fatal("must own lock %s", lock->name());
 173 }
 174 
 175 // a weaker assertion than the above
 176 void assert_locked_or_safepoint_weak(const Mutex* lock) {
 177   assert(lock != NULL, "Need non-NULL lock");
 178   if (lock->is_locked()) return;
 179   if (SafepointSynchronize::is_at_safepoint()) return;
 180   if (!Universe::is_fully_initialized()) return;
 181   fatal("must own lock %s", lock->name());
 182 }
 183 
 184 // a stronger assertion than the above
 185 void assert_lock_strong(const Mutex* lock) {
 186   assert(lock != NULL, "Need non-NULL lock");
 187   if (lock->owned_by_self()) return;
 188   fatal("must own lock %s", lock->name());
 189 }
 190 
 191 void assert_locked_or_safepoint_or_handshake(const Mutex* lock, const JavaThread* thread) {
 192   if (Thread::current()->is_VM_thread() && thread->is_vmthread_processing_handshake()) return;
 193   assert_locked_or_safepoint(lock);
 194 }
 195 #endif
 196 
 197 #define def(var, type, pri, vm_block, safepoint_check_allowed ) {      \
 198   var = new type(Mutex::pri, #var, vm_block, Mutex::safepoint_check_allowed); \
 199   assert(_num_mutex < MAX_NUM_MUTEX, "increase MAX_NUM_MUTEX");        \
 200   _mutex_array[_num_mutex++] = var;                                      \
 201 }
 202 
 203 // Using Padded subclasses to prevent false sharing of these global monitors and mutexes.
 204 void mutex_init() {
 205   def(tty_lock                     , PaddedMutex  , tty,         true,  _safepoint_check_never);      // allow to lock in VM
 206 
 207   def(CGC_lock                     , PaddedMonitor, special,     true,  _safepoint_check_never);      // coordinate between fore- and background GC
 208   def(STS_lock                     , PaddedMonitor, leaf,        true,  _safepoint_check_never);
 209 
 210   def(FullGCCount_lock             , PaddedMonitor, leaf,        true,  _safepoint_check_never);      // in support of ExplicitGCInvokesConcurrent
 211   if (UseG1GC) {
 212     def(G1OldGCCount_lock          , PaddedMonitor, leaf,        true,  _safepoint_check_always);


   1 /*
   2  * Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *


 172   fatal("must own lock %s", lock->name());
 173 }
 174 
 175 // a weaker assertion than the above
 176 void assert_locked_or_safepoint_weak(const Mutex* lock) {
 177   assert(lock != NULL, "Need non-NULL lock");
 178   if (lock->is_locked()) return;
 179   if (SafepointSynchronize::is_at_safepoint()) return;
 180   if (!Universe::is_fully_initialized()) return;
 181   fatal("must own lock %s", lock->name());
 182 }
 183 
 184 // a stronger assertion than the above
 185 void assert_lock_strong(const Mutex* lock) {
 186   assert(lock != NULL, "Need non-NULL lock");
 187   if (lock->owned_by_self()) return;
 188   fatal("must own lock %s", lock->name());
 189 }
 190 
 191 void assert_locked_or_safepoint_or_handshake(const Mutex* lock, const JavaThread* thread) {
 192   if (Thread::current() == thread->get_active_handshaker()) return;
 193   assert_locked_or_safepoint(lock);
 194 }
 195 #endif
 196 
 197 #define def(var, type, pri, vm_block, safepoint_check_allowed ) {      \
 198   var = new type(Mutex::pri, #var, vm_block, Mutex::safepoint_check_allowed); \
 199   assert(_num_mutex < MAX_NUM_MUTEX, "increase MAX_NUM_MUTEX");        \
 200   _mutex_array[_num_mutex++] = var;                                      \
 201 }
 202 
 203 // Using Padded subclasses to prevent false sharing of these global monitors and mutexes.
 204 void mutex_init() {
 205   def(tty_lock                     , PaddedMutex  , tty,         true,  _safepoint_check_never);      // allow to lock in VM
 206 
 207   def(CGC_lock                     , PaddedMonitor, special,     true,  _safepoint_check_never);      // coordinate between fore- and background GC
 208   def(STS_lock                     , PaddedMonitor, leaf,        true,  _safepoint_check_never);
 209 
 210   def(FullGCCount_lock             , PaddedMonitor, leaf,        true,  _safepoint_check_never);      // in support of ExplicitGCInvokesConcurrent
 211   if (UseG1GC) {
 212     def(G1OldGCCount_lock          , PaddedMonitor, leaf,        true,  _safepoint_check_always);


< prev index next >