< prev index next >

src/share/vm/runtime/mutex.hpp

Print this page
rev 13131 : [mq]: G1LockOrderProblems
   1 /*
   2  * Copyright (c) 1998, 2016, 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  *


  76 
  77 class ParkEvent ;
  78 
  79 // See orderAccess.hpp.  We assume throughout the VM that mutex lock and
  80 // try_lock do fence-lock-acquire, and that unlock does a release-unlock,
  81 // *in that order*.  If their implementations change such that these
  82 // assumptions are violated, a whole lot of code will break.
  83 
  84 // The default length of monitor name was originally chosen to be 64 to avoid
  85 // false sharing. Now, PaddedMonitor is available for this purpose.
  86 // TODO: Check if _name[MONITOR_NAME_LEN] should better get replaced by const char*.
  87 static const int MONITOR_NAME_LEN = 64;
  88 
  89 class Monitor : public CHeapObj<mtInternal> {
  90 
  91  public:
  92   // A special lock: Is a lock where you are guaranteed not to block while you are
  93   // holding it, i.e., no vm operation can happen, taking other locks, etc.
  94   // NOTE: It is critical that the rank 'special' be the lowest (earliest)
  95   // (except for "event"?) for the deadlock detection to work correctly.




  96   // The rank native is only for use in Mutex's created by JVM_RawMonitorCreate,
  97   // which being external to the VM are not subject to deadlock detection.
  98   // The rank safepoint is used only for synchronization in reaching a
  99   // safepoint and leaving a safepoint.  It is only used for the Safepoint_lock
 100   // currently.  While at a safepoint no mutexes of rank safepoint are held
 101   // by any thread.
 102   // The rank named "leaf" is probably historical (and should
 103   // be changed) -- mutexes of this rank aren't really leaf mutexes
 104   // at all.
 105   enum lock_types {
 106        event,
 107        special,

 108        suspend_resume,
 109        leaf        = suspend_resume +   2,
 110        safepoint   = leaf           +  10,
 111        barrier     = safepoint      +   1,
 112        nonleaf     = barrier        +   1,
 113        max_nonleaf = nonleaf        + 900,
 114        native      = max_nonleaf    +   1
 115   };
 116 
 117   // The WaitSet and EntryList linked lists are composed of ParkEvents.
 118   // I use ParkEvent instead of threads as ParkEvents are immortal and
 119   // type-stable, meaning we can safely unpark() a possibly stale
 120   // list element in the unlock()-path.
 121 
 122  protected:                              // Monitor-Mutex metadata
 123   SplitWord _LockWord ;                  // Contention queue (cxq) colocated with Lock-byte
 124   enum LockWordBits { _LBIT=1 } ;
 125   Thread * volatile _owner;              // The owner of the lock
 126                                          // Consider sequestering _owner on its own $line
 127                                          // to aid future synchronization mechanisms.


   1 /*
   2  * Copyright (c) 1998, 2017, 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  *


  76 
  77 class ParkEvent ;
  78 
  79 // See orderAccess.hpp.  We assume throughout the VM that mutex lock and
  80 // try_lock do fence-lock-acquire, and that unlock does a release-unlock,
  81 // *in that order*.  If their implementations change such that these
  82 // assumptions are violated, a whole lot of code will break.
  83 
  84 // The default length of monitor name was originally chosen to be 64 to avoid
  85 // false sharing. Now, PaddedMonitor is available for this purpose.
  86 // TODO: Check if _name[MONITOR_NAME_LEN] should better get replaced by const char*.
  87 static const int MONITOR_NAME_LEN = 64;
  88 
  89 class Monitor : public CHeapObj<mtInternal> {
  90 
  91  public:
  92   // A special lock: Is a lock where you are guaranteed not to block while you are
  93   // holding it, i.e., no vm operation can happen, taking other locks, etc.
  94   // NOTE: It is critical that the rank 'special' be the lowest (earliest)
  95   // (except for "event"?) for the deadlock detection to work correctly.
  96   // The rank access is reserved for locks that may be required to perform
  97   // memory accesses that require special GC barriers, such as SATB barriers.
  98   // Since memory accesses should be able to be performed pretty much anywhere
  99   // in the code, that wannts being more special than the "special" rank.
 100   // The rank native is only for use in Mutex's created by JVM_RawMonitorCreate,
 101   // which being external to the VM are not subject to deadlock detection.
 102   // The rank safepoint is used only for synchronization in reaching a
 103   // safepoint and leaving a safepoint.  It is only used for the Safepoint_lock
 104   // currently.  While at a safepoint no mutexes of rank safepoint are held
 105   // by any thread.
 106   // The rank named "leaf" is probably historical (and should
 107   // be changed) -- mutexes of this rank aren't really leaf mutexes
 108   // at all.
 109   enum lock_types {
 110        event,
 111        access      = event          +   1,
 112        special     = access         +   3,
 113        suspend_resume,
 114        leaf        = suspend_resume +   2,
 115        safepoint   = leaf           +  10,
 116        barrier     = safepoint      +   1,
 117        nonleaf     = barrier        +   1,
 118        max_nonleaf = nonleaf        + 900,
 119        native      = max_nonleaf    +   1
 120   };
 121 
 122   // The WaitSet and EntryList linked lists are composed of ParkEvents.
 123   // I use ParkEvent instead of threads as ParkEvents are immortal and
 124   // type-stable, meaning we can safely unpark() a possibly stale
 125   // list element in the unlock()-path.
 126 
 127  protected:                              // Monitor-Mutex metadata
 128   SplitWord _LockWord ;                  // Contention queue (cxq) colocated with Lock-byte
 129   enum LockWordBits { _LBIT=1 } ;
 130   Thread * volatile _owner;              // The owner of the lock
 131                                          // Consider sequestering _owner on its own $line
 132                                          // to aid future synchronization mechanisms.


< prev index next >