< prev index next >

src/share/vm/runtime/objectMonitor.hpp

Print this page




  38 class ObjectWaiter : public StackObj {
  39  public:
  40   enum TStates { TS_UNDEF, TS_READY, TS_RUN, TS_WAIT, TS_ENTER, TS_CXQ } ;
  41   enum Sorted  { PREPEND, APPEND, SORTED } ;
  42   ObjectWaiter * volatile _next;
  43   ObjectWaiter * volatile _prev;
  44   Thread*       _thread;
  45   jlong         _notifier_tid;
  46   ParkEvent *   _event;
  47   volatile int  _notified ;
  48   volatile TStates TState ;
  49   Sorted        _Sorted ;           // List placement disposition
  50   bool          _active ;           // Contention monitoring is enabled
  51  public:
  52   ObjectWaiter(Thread* thread);
  53 
  54   void wait_reenter_begin(ObjectMonitor *mon);
  55   void wait_reenter_end(ObjectMonitor *mon);
  56 };
  57 
  58 // forward declaration to avoid include tracing.hpp
  59 class EventJavaMonitorWait;
  60 
  61 // WARNING:
  62 //   This is a very sensitive and fragile class. DO NOT make any
  63 // change unless you are fully aware of the underlying semantics.
  64 
  65 //   This class can not inherit from any other class, because I have
  66 // to let the displaced header be the very first word. Otherwise I
  67 // have to let markOop include this file, which would export the
  68 // monitor data structure to everywhere.
  69 //
  70 // The ObjectMonitor class is used to implement JavaMonitors which have
  71 // transformed from the lightweight structure of the thread stack to a
  72 // heavy weight lock due to contention
  73 
  74 // It is also used as RawMonitor by the JVMTI
  75 
  76 
  77 class ObjectMonitor {
  78  public:
  79   enum {
  80     OM_OK,                    // no error


 207   intptr_t  complete_exit(TRAPS);
 208   void      reenter(intptr_t recursions, TRAPS);
 209 
 210  private:
 211   void      AddWaiter (ObjectWaiter * waiter) ;
 212   static    void DeferredInitialize();
 213 
 214   ObjectWaiter * DequeueWaiter () ;
 215   void      DequeueSpecificWaiter (ObjectWaiter * waiter) ;
 216   void      EnterI (TRAPS) ;
 217   void      ReenterI (Thread * Self, ObjectWaiter * SelfNode) ;
 218   void      UnlinkAfterAcquire (Thread * Self, ObjectWaiter * SelfNode) ;
 219   int       TryLock (Thread * Self) ;
 220   int       NotRunnable (Thread * Self, Thread * Owner) ;
 221   int       TrySpin_Fixed (Thread * Self) ;
 222   int       TrySpin_VaryFrequency (Thread * Self) ;
 223   int       TrySpin_VaryDuration  (Thread * Self) ;
 224   void      ctAsserts () ;
 225   void      ExitEpilog (Thread * Self, ObjectWaiter * Wakee) ;
 226   bool      ExitSuspendEquivalent (JavaThread * Self) ;
 227   void      post_monitor_wait_event(EventJavaMonitorWait * event,
 228                                                    jlong notifier_tid,
 229                                                    jlong timeout,
 230                                                    bool timedout);
 231 
 232  private:
 233   friend class ObjectSynchronizer;
 234   friend class ObjectWaiter;
 235   friend class VMStructs;
 236 
 237   // WARNING: this must be the very first word of ObjectMonitor
 238   // This means this class can't use any virtual member functions.
 239 
 240   volatile markOop   _header;       // displaced object header word - mark
 241   void*     volatile _object;       // backward object pointer - strong root
 242 
 243   double SharingPad [1] ;           // temp to reduce false sharing
 244 
 245   // All the following fields must be machine word aligned
 246   // The VM assumes write ordering wrt these fields, which can be
 247   // read from other threads.
 248 
 249  protected:                         // protected for jvmtiRawMonitor
 250   void *  volatile _owner;          // pointer to owning thread OR BasicLock




  38 class ObjectWaiter : public StackObj {
  39  public:
  40   enum TStates { TS_UNDEF, TS_READY, TS_RUN, TS_WAIT, TS_ENTER, TS_CXQ } ;
  41   enum Sorted  { PREPEND, APPEND, SORTED } ;
  42   ObjectWaiter * volatile _next;
  43   ObjectWaiter * volatile _prev;
  44   Thread*       _thread;
  45   jlong         _notifier_tid;
  46   ParkEvent *   _event;
  47   volatile int  _notified ;
  48   volatile TStates TState ;
  49   Sorted        _Sorted ;           // List placement disposition
  50   bool          _active ;           // Contention monitoring is enabled
  51  public:
  52   ObjectWaiter(Thread* thread);
  53 
  54   void wait_reenter_begin(ObjectMonitor *mon);
  55   void wait_reenter_end(ObjectMonitor *mon);
  56 };
  57 



  58 // WARNING:
  59 //   This is a very sensitive and fragile class. DO NOT make any
  60 // change unless you are fully aware of the underlying semantics.
  61 
  62 //   This class can not inherit from any other class, because I have
  63 // to let the displaced header be the very first word. Otherwise I
  64 // have to let markOop include this file, which would export the
  65 // monitor data structure to everywhere.
  66 //
  67 // The ObjectMonitor class is used to implement JavaMonitors which have
  68 // transformed from the lightweight structure of the thread stack to a
  69 // heavy weight lock due to contention
  70 
  71 // It is also used as RawMonitor by the JVMTI
  72 
  73 
  74 class ObjectMonitor {
  75  public:
  76   enum {
  77     OM_OK,                    // no error


 204   intptr_t  complete_exit(TRAPS);
 205   void      reenter(intptr_t recursions, TRAPS);
 206 
 207  private:
 208   void      AddWaiter (ObjectWaiter * waiter) ;
 209   static    void DeferredInitialize();
 210 
 211   ObjectWaiter * DequeueWaiter () ;
 212   void      DequeueSpecificWaiter (ObjectWaiter * waiter) ;
 213   void      EnterI (TRAPS) ;
 214   void      ReenterI (Thread * Self, ObjectWaiter * SelfNode) ;
 215   void      UnlinkAfterAcquire (Thread * Self, ObjectWaiter * SelfNode) ;
 216   int       TryLock (Thread * Self) ;
 217   int       NotRunnable (Thread * Self, Thread * Owner) ;
 218   int       TrySpin_Fixed (Thread * Self) ;
 219   int       TrySpin_VaryFrequency (Thread * Self) ;
 220   int       TrySpin_VaryDuration  (Thread * Self) ;
 221   void      ctAsserts () ;
 222   void      ExitEpilog (Thread * Self, ObjectWaiter * Wakee) ;
 223   bool      ExitSuspendEquivalent (JavaThread * Self) ;




 224 
 225  private:
 226   friend class ObjectSynchronizer;
 227   friend class ObjectWaiter;
 228   friend class VMStructs;
 229 
 230   // WARNING: this must be the very first word of ObjectMonitor
 231   // This means this class can't use any virtual member functions.
 232 
 233   volatile markOop   _header;       // displaced object header word - mark
 234   void*     volatile _object;       // backward object pointer - strong root
 235 
 236   double SharingPad [1] ;           // temp to reduce false sharing
 237 
 238   // All the following fields must be machine word aligned
 239   // The VM assumes write ordering wrt these fields, which can be
 240   // read from other threads.
 241 
 242  protected:                         // protected for jvmtiRawMonitor
 243   void *  volatile _owner;          // pointer to owning thread OR BasicLock


< prev index next >