< prev index next >

src/hotspot/share/runtime/mutex.hpp

Print this page
rev 52886 : imported patch new_rank


  70 class ParkEvent ;
  71 
  72 // See orderAccess.hpp.  We assume throughout the VM that mutex lock and
  73 // try_lock do fence-lock-acquire, and that unlock does a release-unlock,
  74 // *in that order*.  If their implementations change such that these
  75 // assumptions are violated, a whole lot of code will break.
  76 
  77 // The default length of monitor name was originally chosen to be 64 to avoid
  78 // false sharing. Now, PaddedMonitor is available for this purpose.
  79 // TODO: Check if _name[MONITOR_NAME_LEN] should better get replaced by const char*.
  80 static const int MONITOR_NAME_LEN = 64;
  81 
  82 class Monitor : public CHeapObj<mtInternal> {
  83 
  84  public:
  85   // A special lock: Is a lock where you are guaranteed not to block while you are
  86   // holding it, i.e., no vm operation can happen, taking other (blocking) locks, etc.
  87   // The rank 'access' is similar to 'special' and has the same restrictions on usage.
  88   // It is reserved for locks that may be required in order to perform memory accesses
  89   // that require special barriers, e.g. SATB GC barriers, that in turn uses locks.


  90   // Since memory accesses should be able to be performed pretty much anywhere
  91   // in the code, that requires locks required for performing accesses being
  92   // inherently a bit more special than even locks of the 'special' rank.
  93   // NOTE: It is critical that the rank 'special' be the lowest (earliest)
  94   // (except for "event" and "access") for the deadlock detection to work correctly.
  95   // The rank native is only for use in Mutex's created by JVM_RawMonitorCreate,
  96   // which being external to the VM are not subject to deadlock detection.
  97   // The rank safepoint is used only for synchronization in reaching a
  98   // safepoint and leaving a safepoint.  It is only used for the Safepoint_lock
  99   // currently.  While at a safepoint no mutexes of rank safepoint are held
 100   // by any thread.
 101   // The rank named "leaf" is probably historical (and should
 102   // be changed) -- mutexes of this rank aren't really leaf mutexes
 103   // at all.
 104   enum lock_types {
 105        event,
 106        access         = event          +   1,
 107        special        = access         +   2,

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


 219   // Lock without safepoint check. Should ONLY be used by safepoint code and other code
 220   // that is guaranteed not to block while running inside the VM.
 221   void lock_without_safepoint_check();
 222   void lock_without_safepoint_check (Thread * Self) ;
 223 
 224   // Current owner - not not MT-safe. Can only be used to guarantee that
 225   // the current running thread owns the lock
 226   Thread* owner() const         { return _owner; }
 227   bool owned_by_self() const;
 228 
 229   // Support for JVM_RawMonitorEnter & JVM_RawMonitorExit. These can be called by
 230   // non-Java thread. (We should really have a RawMonitor abstraction)
 231   void jvm_raw_lock();
 232   void jvm_raw_unlock();
 233   const char *name() const                  { return _name; }
 234 
 235   void print_on_error(outputStream* st) const;
 236 
 237   #ifndef PRODUCT
 238     void print_on(outputStream* st) const;
 239     void print() const                      { print_on(tty); }
 240     DEBUG_ONLY(int    rank() const          { return _rank; })
 241     bool   allow_vm_block()                 { return _allow_vm_block; }
 242 
 243     DEBUG_ONLY(Monitor *next()  const         { return _next; })
 244     DEBUG_ONLY(void   set_next(Monitor *next) { _next = next; })
 245   #endif
 246 
 247   void set_owner(Thread* owner) {
 248   #ifndef PRODUCT
 249     set_owner_implementation(owner);
 250     DEBUG_ONLY(void verify_Monitor(Thread* thr);)
 251   #else
 252     _owner = owner;
 253   #endif
 254   }
 255 
 256 };
 257 
 258 class PaddedMonitor : public Monitor {
 259   enum {




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


 222   // Lock without safepoint check. Should ONLY be used by safepoint code and other code
 223   // that is guaranteed not to block while running inside the VM.
 224   void lock_without_safepoint_check();
 225   void lock_without_safepoint_check (Thread * Self) ;
 226 
 227   // Current owner - not not MT-safe. Can only be used to guarantee that
 228   // the current running thread owns the lock
 229   Thread* owner() const         { return _owner; }
 230   bool owned_by_self() const;
 231 
 232   // Support for JVM_RawMonitorEnter & JVM_RawMonitorExit. These can be called by
 233   // non-Java thread. (We should really have a RawMonitor abstraction)
 234   void jvm_raw_lock();
 235   void jvm_raw_unlock();
 236   const char *name() const                  { return _name; }
 237 
 238   void print_on_error(outputStream* st) const;
 239 
 240   #ifndef PRODUCT
 241     void print_on(outputStream* st) const;
 242     void print() const                      { print_on(::tty); }
 243     DEBUG_ONLY(int    rank() const          { return _rank; })
 244     bool   allow_vm_block()                 { return _allow_vm_block; }
 245 
 246     DEBUG_ONLY(Monitor *next()  const         { return _next; })
 247     DEBUG_ONLY(void   set_next(Monitor *next) { _next = next; })
 248   #endif
 249 
 250   void set_owner(Thread* owner) {
 251   #ifndef PRODUCT
 252     set_owner_implementation(owner);
 253     DEBUG_ONLY(void verify_Monitor(Thread* thr);)
 254   #else
 255     _owner = owner;
 256   #endif
 257   }
 258 
 259 };
 260 
 261 class PaddedMonitor : public Monitor {
 262   enum {


< prev index next >