src/hotspot/share/runtime/objectMonitor.hpp
changeset 58488 165b193b30dd
parent 57906 e17f768b3b71
child 58679 9c3209ff7550
child 59156 14fa9e70ae71
equal deleted inserted replaced
58487:43f63f904bbc 58488:165b193b30dd
    41 // See next_waiter(), first_waiter(), etc.
    41 // See next_waiter(), first_waiter(), etc.
    42 
    42 
    43 class ObjectWaiter : public StackObj {
    43 class ObjectWaiter : public StackObj {
    44  public:
    44  public:
    45   enum TStates { TS_UNDEF, TS_READY, TS_RUN, TS_WAIT, TS_ENTER, TS_CXQ };
    45   enum TStates { TS_UNDEF, TS_READY, TS_RUN, TS_WAIT, TS_ENTER, TS_CXQ };
    46   enum Sorted  { PREPEND, APPEND, SORTED };
       
    47   ObjectWaiter* volatile _next;
    46   ObjectWaiter* volatile _next;
    48   ObjectWaiter* volatile _prev;
    47   ObjectWaiter* volatile _prev;
    49   Thread*       _thread;
    48   Thread*       _thread;
    50   jlong         _notifier_tid;
    49   jlong         _notifier_tid;
    51   ParkEvent *   _event;
    50   ParkEvent *   _event;
    52   volatile int  _notified;
    51   volatile int  _notified;
    53   volatile TStates TState;
    52   volatile TStates TState;
    54   Sorted        _Sorted;           // List placement disposition
       
    55   bool          _active;           // Contention monitoring is enabled
    53   bool          _active;           // Contention monitoring is enabled
    56  public:
    54  public:
    57   ObjectWaiter(Thread* thread);
    55   ObjectWaiter(Thread* thread);
    58 
    56 
    59   void wait_reenter_begin(ObjectMonitor *mon);
    57   void wait_reenter_begin(ObjectMonitor *mon);
    65 // inflated into an ObjectMonitor. This inflation is typically due to
    63 // inflated into an ObjectMonitor. This inflation is typically due to
    66 // contention or use of Object.wait().
    64 // contention or use of Object.wait().
    67 //
    65 //
    68 // WARNING: This is a very sensitive and fragile class. DO NOT make any
    66 // WARNING: This is a very sensitive and fragile class. DO NOT make any
    69 // changes unless you are fully aware of the underlying semantics.
    67 // changes unless you are fully aware of the underlying semantics.
    70 //
       
    71 // Class JvmtiRawMonitor currently inherits from ObjectMonitor so
       
    72 // changes in this class must be careful to not break JvmtiRawMonitor.
       
    73 // These two subsystems should be separated.
       
    74 //
    68 //
    75 // ObjectMonitor Layout Overview/Highlights/Restrictions:
    69 // ObjectMonitor Layout Overview/Highlights/Restrictions:
    76 //
    70 //
    77 // - The _header field must be at offset 0 because the displaced header
    71 // - The _header field must be at offset 0 because the displaced header
    78 //   from markWord is stored there. We do not want markWord.hpp to include
    72 //   from markWord is stored there. We do not want markWord.hpp to include
   125 //   - The _recursions field should be of type int, or int32_t but not
   119 //   - The _recursions field should be of type int, or int32_t but not
   126 //     intptr_t. There's no reason to use a 64-bit type for this field
   120 //     intptr_t. There's no reason to use a 64-bit type for this field
   127 //     in a 64-bit JVM.
   121 //     in a 64-bit JVM.
   128 
   122 
   129 class ObjectMonitor {
   123 class ObjectMonitor {
   130  public:
       
   131   enum {
       
   132     OM_OK,                    // no error
       
   133     OM_SYSTEM_ERROR,          // operating system error
       
   134     OM_ILLEGAL_MONITOR_STATE, // IllegalMonitorStateException
       
   135     OM_INTERRUPTED,           // Thread.interrupt()
       
   136     OM_TIMED_OUT              // Object.wait() timed out
       
   137   };
       
   138 
       
   139  private:
       
   140   friend class ObjectSynchronizer;
   124   friend class ObjectSynchronizer;
   141   friend class ObjectWaiter;
   125   friend class ObjectWaiter;
   142   friend class VMStructs;
   126   friend class VMStructs;
   143   JVMCI_ONLY(friend class JVMCIVMStructs;)
   127   JVMCI_ONLY(friend class JVMCIVMStructs;)
   144 
   128 
   156   // _next_om shares _header's cache line for pre-monitor list historical
   140   // _next_om shares _header's cache line for pre-monitor list historical
   157   // reasons. _next_om only changes if the next ObjectMonitor is deflated.
   141   // reasons. _next_om only changes if the next ObjectMonitor is deflated.
   158   DEFINE_PAD_MINUS_SIZE(0, DEFAULT_CACHE_LINE_SIZE,
   142   DEFINE_PAD_MINUS_SIZE(0, DEFAULT_CACHE_LINE_SIZE,
   159                         sizeof(volatile markWord) + sizeof(void* volatile) +
   143                         sizeof(volatile markWord) + sizeof(void* volatile) +
   160                         sizeof(ObjectMonitor *));
   144                         sizeof(ObjectMonitor *));
   161  protected:                         // protected for JvmtiRawMonitor
       
   162   void* volatile _owner;            // pointer to owning thread OR BasicLock
   145   void* volatile _owner;            // pointer to owning thread OR BasicLock
   163  private:
       
   164   volatile jlong _previous_owner_tid;  // thread id of the previous owner of the monitor
   146   volatile jlong _previous_owner_tid;  // thread id of the previous owner of the monitor
   165  protected:                         // protected for JvmtiRawMonitor
       
   166   volatile intptr_t _recursions;    // recursion count, 0 for first entry
   147   volatile intptr_t _recursions;    // recursion count, 0 for first entry
   167   ObjectWaiter* volatile _EntryList;  // Threads blocked on entry or reentry.
   148   ObjectWaiter* volatile _EntryList;  // Threads blocked on entry or reentry.
   168                                       // The list is actually composed of WaitNodes,
   149                                       // The list is actually composed of WaitNodes,
   169                                       // acting as proxies for Threads.
   150                                       // acting as proxies for Threads.
   170  private:
   151 
   171   ObjectWaiter* volatile _cxq;      // LL of recently-arrived threads blocked on entry.
   152   ObjectWaiter* volatile _cxq;      // LL of recently-arrived threads blocked on entry.
   172   Thread* volatile _succ;           // Heir presumptive thread - used for futile wakeup throttling
   153   Thread* volatile _succ;           // Heir presumptive thread - used for futile wakeup throttling
   173   Thread* volatile _Responsible;
   154   Thread* volatile _Responsible;
   174 
   155 
   175   volatile int _Spinner;            // for exit->spinner handoff optimization
   156   volatile int _Spinner;            // for exit->spinner handoff optimization