103 // - Adjacent ObjectMonitors should be separated by enough space to avoid
104 // false sharing. This is handled by the ObjectMonitor allocation code
105 // in synchronizer.cpp. Also see TEST_VM(SynchronizerTest, sanity) gtest.
106 //
107 // Futures notes:
108 // - Separating _owner from the <remaining_fields> by enough space to
109 // avoid false sharing might be profitable. Given
110 // http://blogs.oracle.com/dave/entry/cas_and_cache_trivia_invalidate
111 // we know that the CAS in monitorenter will invalidate the line
112 // underlying _owner. We want to avoid an L1 data cache miss on that
113 // same line for monitorexit. Putting these <remaining_fields>:
114 // _recursions, _EntryList, _cxq, and _succ, all of which may be
115 // fetched in the inflated unlock path, on a different cache line
116 // would make them immune to CAS-based invalidation from the _owner
117 // field.
118 //
119 // - The _recursions field should be of type int, or int32_t but not
120 // intptr_t. There's no reason to use a 64-bit type for this field
121 // in a 64-bit JVM.
122
123 class ObjectMonitor {
124 friend class ObjectSynchronizer;
125 friend class ObjectWaiter;
126 friend class VMStructs;
127 JVMCI_ONLY(friend class JVMCIVMStructs;)
128
129 // The sync code expects the header field to be at offset zero (0).
130 // Enforced by the assert() in header_addr().
131 volatile markWord _header; // displaced object header word - mark
132 void* volatile _object; // backward object pointer - strong root
133 public:
134 ObjectMonitor* _next_om; // Next ObjectMonitor* linkage
135 private:
136 // Separate _header and _owner on different cache lines since both can
137 // have busy multi-threaded access. _header and _object are set at
138 // initial inflation and _object doesn't change until deflation so
139 // _object is a good choice to share the cache line with _header.
140 // _next_om shares _header's cache line for pre-monitor list historical
141 // reasons. _next_om only changes if the next ObjectMonitor is deflated.
142 DEFINE_PAD_MINUS_SIZE(0, DEFAULT_CACHE_LINE_SIZE,
143 sizeof(volatile markWord) + sizeof(void* volatile) +
144 sizeof(ObjectMonitor *));
145 void* volatile _owner; // pointer to owning thread OR BasicLock
146 volatile jlong _previous_owner_tid; // thread id of the previous owner of the monitor
147 volatile intx _recursions; // recursion count, 0 for first entry
148 ObjectWaiter* volatile _EntryList; // Threads blocked on entry or reentry.
149 // The list is actually composed of WaitNodes,
150 // acting as proxies for Threads.
151
152 ObjectWaiter* volatile _cxq; // LL of recently-arrived threads blocked on entry.
153 Thread* volatile _succ; // Heir presumptive thread - used for futile wakeup throttling
154 Thread* volatile _Responsible;
155
156 volatile int _Spinner; // for exit->spinner handoff optimization
157 volatile int _SpinDuration;
158
159 volatile jint _contentions; // Number of active contentions in enter(). It is used by is_busy()
160 // along with other fields to determine if an ObjectMonitor can be
161 // deflated. See ObjectSynchronizer::deflate_monitor().
162 protected:
|
103 // - Adjacent ObjectMonitors should be separated by enough space to avoid
104 // false sharing. This is handled by the ObjectMonitor allocation code
105 // in synchronizer.cpp. Also see TEST_VM(SynchronizerTest, sanity) gtest.
106 //
107 // Futures notes:
108 // - Separating _owner from the <remaining_fields> by enough space to
109 // avoid false sharing might be profitable. Given
110 // http://blogs.oracle.com/dave/entry/cas_and_cache_trivia_invalidate
111 // we know that the CAS in monitorenter will invalidate the line
112 // underlying _owner. We want to avoid an L1 data cache miss on that
113 // same line for monitorexit. Putting these <remaining_fields>:
114 // _recursions, _EntryList, _cxq, and _succ, all of which may be
115 // fetched in the inflated unlock path, on a different cache line
116 // would make them immune to CAS-based invalidation from the _owner
117 // field.
118 //
119 // - The _recursions field should be of type int, or int32_t but not
120 // intptr_t. There's no reason to use a 64-bit type for this field
121 // in a 64-bit JVM.
122
123 #ifndef OM_CACHE_LINE_SIZE
124 // Use DEFAULT_CACHE_LINE_SIZE if not already specified for
125 // the current build platform.
126 #define OM_CACHE_LINE_SIZE DEFAULT_CACHE_LINE_SIZE
127 #endif
128
129 class ObjectMonitor {
130 friend class ObjectSynchronizer;
131 friend class ObjectWaiter;
132 friend class VMStructs;
133 JVMCI_ONLY(friend class JVMCIVMStructs;)
134
135 // The sync code expects the header field to be at offset zero (0).
136 // Enforced by the assert() in header_addr().
137 volatile markWord _header; // displaced object header word - mark
138 void* volatile _object; // backward object pointer - strong root
139 public:
140 ObjectMonitor* _next_om; // Next ObjectMonitor* linkage
141 private:
142 // Separate _header and _owner on different cache lines since both can
143 // have busy multi-threaded access. _header and _object are set at
144 // initial inflation and _object doesn't change until deflation so
145 // _object is a good choice to share the cache line with _header.
146 // _next_om shares _header's cache line for pre-monitor list historical
147 // reasons. _next_om only changes if the next ObjectMonitor is deflated.
148 DEFINE_PAD_MINUS_SIZE(0, OM_CACHE_LINE_SIZE,
149 sizeof(volatile markWord) + sizeof(void* volatile) +
150 sizeof(ObjectMonitor *));
151 void* volatile _owner; // pointer to owning thread OR BasicLock
152 volatile jlong _previous_owner_tid; // thread id of the previous owner of the monitor
153 volatile intx _recursions; // recursion count, 0 for first entry
154 ObjectWaiter* volatile _EntryList; // Threads blocked on entry or reentry.
155 // The list is actually composed of WaitNodes,
156 // acting as proxies for Threads.
157
158 ObjectWaiter* volatile _cxq; // LL of recently-arrived threads blocked on entry.
159 Thread* volatile _succ; // Heir presumptive thread - used for futile wakeup throttling
160 Thread* volatile _Responsible;
161
162 volatile int _Spinner; // for exit->spinner handoff optimization
163 volatile int _SpinDuration;
164
165 volatile jint _contentions; // Number of active contentions in enter(). It is used by is_busy()
166 // along with other fields to determine if an ObjectMonitor can be
167 // deflated. See ObjectSynchronizer::deflate_monitor().
168 protected:
|