src/share/vm/runtime/mutex.hpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File hotspot Sdiff src/share/vm/runtime

src/share/vm/runtime/mutex.hpp

Print this page
rev 5732 : [mq]: comments2


  73 #else
  74  #define _LSBINDEX (sizeof(intptr_t)-1)
  75 #endif
  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 is chosen to be 64 to avoid false sharing.
  85 static const int MONITOR_NAME_LEN = 64;
  86 
  87 class Monitor : public CHeapObj<mtInternal> {
  88 
  89  public:
  90   // A special lock: Is a lock where you are guaranteed not to block while you are
  91   // holding it, i.e., no vm operation can happen, taking other locks, etc.
  92   // NOTE: It is critical that the rank 'special' be the lowest (earliest)
  93   // (except for "event"?) for the deadlock dection to work correctly.
  94   // The rank native is only for use in Mutex's created by JVM_RawMonitorCreate,
  95   // which being external to the VM are not subject to deadlock detection.
  96   // The rank safepoint is used only for synchronization in reaching a
  97   // safepoint and leaving a safepoint.  It is only used for the Safepoint_lock
  98   // currently.  While at a safepoint no mutexes of rank safepoint are held
  99   // by any thread.
 100   // The rank named "leaf" is probably historical (and should
 101   // be changed) -- mutexes of this rank aren't really leaf mutexes
 102   // at all.
 103   enum lock_types {
 104        event,
 105        special,
 106        suspend_resume,
 107        leaf        = suspend_resume +   2,
 108        safepoint   = leaf           +  10,
 109        barrier     = safepoint      +   1,
 110        nonleaf     = barrier        +   1,
 111        max_nonleaf = nonleaf        + 900,
 112        native      = max_nonleaf    +   1
 113   };


 224     debug_only(void   set_next(Monitor *next) { _next = next; })
 225   #endif
 226 
 227   void set_owner(Thread* owner) {
 228   #ifndef PRODUCT
 229     set_owner_implementation(owner);
 230     debug_only(void verify_Monitor(Thread* thr));
 231   #else
 232     _owner = owner;
 233   #endif
 234   }
 235 
 236 };
 237 
 238 // Normally we'd expect Monitor to extend Mutex in the sense that a monitor
 239 // constructed from pthreads primitives might extend a mutex by adding
 240 // a condvar and some extra metadata.  In fact this was the case until J2SE7.
 241 //
 242 // Currently, however, the base object is a monitor.  Monitor contains all the
 243 // logic for wait(), notify(), etc.   Mutex extends monitor and restricts the
 244 // visiblity of wait(), notify(), and notify_all().
 245 //
 246 // Another viable alternative would have been to have Monitor extend Mutex and
 247 // implement all the normal mutex and wait()-notify() logic in Mutex base class.
 248 // The wait()-notify() facility would be exposed via special protected member functions
 249 // (e.g., _Wait() and _Notify()) in Mutex.  Monitor would extend Mutex and expose wait()
 250 // as a call to _Wait().  That is, the public wait() would be a wrapper for the protected
 251 // _Wait().
 252 //
 253 // An even better alternative is to simply eliminate Mutex:: and use Monitor:: instead.
 254 // After all, monitors are sufficient for Java-level synchronization.   At one point in time
 255 // there may have been some benefit to having distinct mutexes and monitors, but that time
 256 // has past.
 257 //
 258 // The Mutex/Monitor design parallels that of Java-monitors, being based on
 259 // thread-specific park-unpark platform-specific primitives.
 260 
 261 
 262 class Mutex : public Monitor {      // degenerate Monitor
 263  public:
 264    Mutex (int rank, const char *name, bool allow_vm_block=false);


  73 #else
  74  #define _LSBINDEX (sizeof(intptr_t)-1)
  75 #endif
  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 is chosen to be 64 to avoid false sharing.
  85 static const int MONITOR_NAME_LEN = 64;
  86 
  87 class Monitor : public CHeapObj<mtInternal> {
  88 
  89  public:
  90   // A special lock: Is a lock where you are guaranteed not to block while you are
  91   // holding it, i.e., no vm operation can happen, taking other locks, etc.
  92   // NOTE: It is critical that the rank 'special' be the lowest (earliest)
  93   // (except for "event"?) for the deadlock detection to work correctly.
  94   // The rank native is only for use in Mutex's created by JVM_RawMonitorCreate,
  95   // which being external to the VM are not subject to deadlock detection.
  96   // The rank safepoint is used only for synchronization in reaching a
  97   // safepoint and leaving a safepoint.  It is only used for the Safepoint_lock
  98   // currently.  While at a safepoint no mutexes of rank safepoint are held
  99   // by any thread.
 100   // The rank named "leaf" is probably historical (and should
 101   // be changed) -- mutexes of this rank aren't really leaf mutexes
 102   // at all.
 103   enum lock_types {
 104        event,
 105        special,
 106        suspend_resume,
 107        leaf        = suspend_resume +   2,
 108        safepoint   = leaf           +  10,
 109        barrier     = safepoint      +   1,
 110        nonleaf     = barrier        +   1,
 111        max_nonleaf = nonleaf        + 900,
 112        native      = max_nonleaf    +   1
 113   };


 224     debug_only(void   set_next(Monitor *next) { _next = next; })
 225   #endif
 226 
 227   void set_owner(Thread* owner) {
 228   #ifndef PRODUCT
 229     set_owner_implementation(owner);
 230     debug_only(void verify_Monitor(Thread* thr));
 231   #else
 232     _owner = owner;
 233   #endif
 234   }
 235 
 236 };
 237 
 238 // Normally we'd expect Monitor to extend Mutex in the sense that a monitor
 239 // constructed from pthreads primitives might extend a mutex by adding
 240 // a condvar and some extra metadata.  In fact this was the case until J2SE7.
 241 //
 242 // Currently, however, the base object is a monitor.  Monitor contains all the
 243 // logic for wait(), notify(), etc.   Mutex extends monitor and restricts the
 244 // visibility of wait(), notify(), and notify_all().
 245 //
 246 // Another viable alternative would have been to have Monitor extend Mutex and
 247 // implement all the normal mutex and wait()-notify() logic in Mutex base class.
 248 // The wait()-notify() facility would be exposed via special protected member functions
 249 // (e.g., _Wait() and _Notify()) in Mutex.  Monitor would extend Mutex and expose wait()
 250 // as a call to _Wait().  That is, the public wait() would be a wrapper for the protected
 251 // _Wait().
 252 //
 253 // An even better alternative is to simply eliminate Mutex:: and use Monitor:: instead.
 254 // After all, monitors are sufficient for Java-level synchronization.   At one point in time
 255 // there may have been some benefit to having distinct mutexes and monitors, but that time
 256 // has past.
 257 //
 258 // The Mutex/Monitor design parallels that of Java-monitors, being based on
 259 // thread-specific park-unpark platform-specific primitives.
 260 
 261 
 262 class Mutex : public Monitor {      // degenerate Monitor
 263  public:
 264    Mutex (int rank, const char *name, bool allow_vm_block=false);
src/share/vm/runtime/mutex.hpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File