src/share/vm/runtime/mutexLocker.cpp

Print this page
rev 4773 : 8005849: JEP 167: Event-Based JVM Tracing
Reviewed-by: acorn, coleenp, sla
Contributed-by: Karen Kinnear <karen.kinnear@oracle.com>, Bengt Rutisson <bengt.rutisson@oracle.com>, Calvin Cheung <calvin.cheung@oracle.com>, Erik Gahlin <erik.gahlin@oracle.com>, Erik Helin <erik.helin@oracle.com>, Jesper Wilhelmsson <jesper.wilhelmsson@oracle.com>, Keith McGuigan <keith.mcguigan@oracle.com>, Mattias Tobiasson <mattias.tobiasson@oracle.com>, Markus Gronlund <markus.gronlund@oracle.com>, Mikael Auno <mikael.auno@oracle.com>, Nils Eliasson <nils.eliasson@oracle.com>, Nils Loodin <nils.loodin@oracle.com>, Rickard Backman <rickard.backman@oracle.com>, Staffan Larsen <staffan.larsen@oracle.com>, Stefan Karlsson <stefan.karlsson@oracle.com>, Yekaterina Kantserova <yekaterina.kantserova@oracle.com>
   1 /*
   2  * Copyright (c) 1997, 2012, 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  *


 253   def(Heap_lock                    , Monitor, nonleaf+1,   false);
 254   def(JfieldIdCreation_lock        , Mutex  , nonleaf+1,   true ); // jfieldID, Used in VM_Operation
 255   def(JNICachedItableIndex_lock    , Mutex  , nonleaf+1,   false); // Used to cache an itable index during JNI invoke
 256   def(MemberNameTable_lock         , Mutex  , nonleaf+1,   false); // Used to protect MemberNameTable
 257 
 258   def(CompiledIC_lock              , Mutex  , nonleaf+2,   false); // locks VtableStubs_lock, InlineCacheBuffer_lock
 259   def(CompileTaskAlloc_lock        , Mutex  , nonleaf+2,   true );
 260   def(CompileStatistics_lock       , Mutex  , nonleaf+2,   false);
 261   def(MultiArray_lock              , Mutex  , nonleaf+2,   false); // locks SymbolTable_lock
 262 
 263   def(JvmtiThreadState_lock        , Mutex  , nonleaf+2,   false); // Used by JvmtiThreadState/JvmtiEventController
 264   def(JvmtiPendingEvent_lock       , Monitor, nonleaf,     false); // Used by JvmtiCodeBlobEvents
 265   def(Management_lock              , Mutex  , nonleaf+2,   false); // used for JVM management
 266 
 267   def(Compile_lock                 , Mutex  , nonleaf+3,   true );
 268   def(MethodData_lock              , Mutex  , nonleaf+3,   false);
 269 
 270   def(MethodCompileQueue_lock      , Monitor, nonleaf+4,   true );
 271   def(Debug2_lock                  , Mutex  , nonleaf+4,   true );
 272   def(Debug3_lock                  , Mutex  , nonleaf+4,   true );
 273   def(ProfileVM_lock               , Monitor, nonleaf+4,   false); // used for profiling of the VMThread
 274   def(CompileThread_lock           , Monitor, nonleaf+5,   false );
 275 
 276   def(JfrQuery_lock                , Monitor, nonleaf,     true);  // JFR locks, keep these in consecutive order
 277   def(JfrMsg_lock                  , Monitor, nonleaf+2,   true);
 278   def(JfrBuffer_lock               , Mutex,   nonleaf+3,   true);
 279   def(JfrStream_lock               , Mutex,   nonleaf+4,   true);
 280   def(PeriodicTask_lock            , Monitor, nonleaf+5,   true);
 281 }
 282 
 283 GCMutexLocker::GCMutexLocker(Monitor * mutex) {
 284   if (SafepointSynchronize::is_at_safepoint()) {
 285     _locked = false;
 286   } else {
 287     _mutex = mutex;
 288     _locked = true;
 289     _mutex->lock();
 290   }
 291 }
 292 
 293 // Print all mutexes/monitors that are currently owned by a thread; called
 294 // by fatal error handler.
 295 void print_owned_locks_on_error(outputStream* st) {
 296   st->print("VM Mutex/Monitor currently owned by a thread: ");
 297   bool none = true;
 298   for (int i = 0; i < _num_mutex; i++) {
 299      // see if it has an owner
   1 /*
   2  * Copyright (c) 1997, 2013, 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  *


 253   def(Heap_lock                    , Monitor, nonleaf+1,   false);
 254   def(JfieldIdCreation_lock        , Mutex  , nonleaf+1,   true ); // jfieldID, Used in VM_Operation
 255   def(JNICachedItableIndex_lock    , Mutex  , nonleaf+1,   false); // Used to cache an itable index during JNI invoke
 256   def(MemberNameTable_lock         , Mutex  , nonleaf+1,   false); // Used to protect MemberNameTable
 257 
 258   def(CompiledIC_lock              , Mutex  , nonleaf+2,   false); // locks VtableStubs_lock, InlineCacheBuffer_lock
 259   def(CompileTaskAlloc_lock        , Mutex  , nonleaf+2,   true );
 260   def(CompileStatistics_lock       , Mutex  , nonleaf+2,   false);
 261   def(MultiArray_lock              , Mutex  , nonleaf+2,   false); // locks SymbolTable_lock
 262 
 263   def(JvmtiThreadState_lock        , Mutex  , nonleaf+2,   false); // Used by JvmtiThreadState/JvmtiEventController
 264   def(JvmtiPendingEvent_lock       , Monitor, nonleaf,     false); // Used by JvmtiCodeBlobEvents
 265   def(Management_lock              , Mutex  , nonleaf+2,   false); // used for JVM management
 266 
 267   def(Compile_lock                 , Mutex  , nonleaf+3,   true );
 268   def(MethodData_lock              , Mutex  , nonleaf+3,   false);
 269 
 270   def(MethodCompileQueue_lock      , Monitor, nonleaf+4,   true );
 271   def(Debug2_lock                  , Mutex  , nonleaf+4,   true );
 272   def(Debug3_lock                  , Mutex  , nonleaf+4,   true );
 273   def(ProfileVM_lock               , Monitor, special,   false); // used for profiling of the VMThread
 274   def(CompileThread_lock           , Monitor, nonleaf+5,   false );
 275 
 276   def(JfrMsg_lock                  , Monitor, leaf,        true);
 277   def(JfrBuffer_lock               , Mutex,   nonleaf+1,   true);
 278   def(JfrStream_lock               , Mutex,   nonleaf+2,   true);

 279   def(PeriodicTask_lock            , Monitor, nonleaf+5,   true);
 280 }
 281 
 282 GCMutexLocker::GCMutexLocker(Monitor * mutex) {
 283   if (SafepointSynchronize::is_at_safepoint()) {
 284     _locked = false;
 285   } else {
 286     _mutex = mutex;
 287     _locked = true;
 288     _mutex->lock();
 289   }
 290 }
 291 
 292 // Print all mutexes/monitors that are currently owned by a thread; called
 293 // by fatal error handler.
 294 void print_owned_locks_on_error(outputStream* st) {
 295   st->print("VM Mutex/Monitor currently owned by a thread: ");
 296   bool none = true;
 297   for (int i = 0; i < _num_mutex; i++) {
 298      // see if it has an owner