174 // acting as proxies for Threads.
175
176 ObjectWaiter* volatile _cxq; // LL of recently-arrived threads blocked on entry.
177 Thread* volatile _succ; // Heir presumptive thread - used for futile wakeup throttling
178 Thread* volatile _Responsible;
179
180 volatile int _Spinner; // for exit->spinner handoff optimization
181 volatile int _SpinDuration;
182
183 volatile jint _contentions; // Number of active contentions in enter(). It is used by is_busy()
184 // along with other fields to determine if an ObjectMonitor can be
185 // deflated. See ObjectSynchronizer::deflate_monitor() and
186 // ObjectSynchronizer::deflate_monitor_using_JT().
187 protected:
188 ObjectWaiter* volatile _WaitSet; // LL of threads wait()ing on the monitor
189 volatile jint _waiters; // number of waiting threads
190 private:
191 volatile int _WaitSetLock; // protects Wait Queue - simple spinlock
192
193 public:
194 volatile int visit_marker;
195 static void Initialize();
196
197 // Only perform a PerfData operation if the PerfData object has been
198 // allocated and if the PerfDataManager has not freed the PerfData
199 // objects which can happen at normal VM shutdown.
200 //
201 #define OM_PERFDATA_OP(f, op_str) \
202 do { \
203 if (ObjectMonitor::_sync_ ## f != NULL && \
204 PerfDataManager::has_PerfData()) { \
205 ObjectMonitor::_sync_ ## f->op_str; \
206 } \
207 } while (0)
208
209 static PerfCounter * _sync_ContendedLockAttempts;
210 static PerfCounter * _sync_FutileWakeups;
211 static PerfCounter * _sync_Parks;
212 static PerfCounter * _sync_Notifications;
213 static PerfCounter * _sync_Inflations;
214 static PerfCounter * _sync_Deflations;
215 static PerfLongVariable * _sync_MonExtant;
216
217 static int Knob_SpinLimit;
218
219 void* operator new (size_t size) throw();
220 void* operator new[] (size_t size) throw();
221 void operator delete(void* p);
222 void operator delete[] (void* p);
223
224 // TODO-FIXME: the "offset" routines should return a type of off_t instead of int ...
225 // ByteSize would also be an appropriate type.
226 static int header_offset_in_bytes() { return offset_of(ObjectMonitor, _header); }
227 static int object_offset_in_bytes() { return offset_of(ObjectMonitor, _object); }
228 static int owner_offset_in_bytes() { return offset_of(ObjectMonitor, _owner); }
229 static int recursions_offset_in_bytes() { return offset_of(ObjectMonitor, _recursions); }
230 static int cxq_offset_in_bytes() { return offset_of(ObjectMonitor, _cxq); }
231 static int succ_offset_in_bytes() { return offset_of(ObjectMonitor, _succ); }
232 static int EntryList_offset_in_bytes() { return offset_of(ObjectMonitor, _EntryList); }
233
234 // ObjectMonitor references can be ORed with markWord::monitor_value
235 // as part of the ObjectMonitor tagging mechanism. When we combine an
236 // ObjectMonitor reference with an offset, we need to remove the tag
237 // value in order to generate the proper address.
238 //
239 // We can either adjust the ObjectMonitor reference and then add the
240 // offset or we can adjust the offset that is added to the ObjectMonitor
241 // reference. The latter avoids an AGI (Address Generation Interlock)
242 // stall so the helper macro adjusts the offset value that is returned
243 // to the ObjectMonitor reference manipulation code:
244 //
245 #define OM_OFFSET_NO_MONITOR_VALUE_TAG(f) \
246 ((ObjectMonitor::f ## _offset_in_bytes()) - markWord::monitor_value)
247
248 markWord header() const;
255 // _ref_count is for indicating that the ObjectMonitor* is in
256 // use which is orthogonal to whether the ObjectMonitor itself
257 // is in use for a locking operation.
258 intptr_t ret_code = _contentions | _waiters | intptr_t(_cxq) | intptr_t(_EntryList);
259 if (!AsyncDeflateIdleMonitors) {
260 ret_code |= intptr_t(_owner);
261 } else {
262 if (_owner != DEFLATER_MARKER) {
263 ret_code |= intptr_t(_owner);
264 }
265 }
266 return ret_code;
267 }
268 const char* is_busy_to_string(stringStream* ss);
269
270 intptr_t is_entered(Thread* current) const;
271
272 void* owner() const; // Returns NULL if DEFLATER_MARKER is observed.
273 // Returns true if owner field == DEFLATER_MARKER and false otherwise.
274 bool owner_is_DEFLATER_MARKER();
275 void set_owner(void* owner);
276
277 jint waiters() const;
278
279 jint contentions() const;
280 intptr_t recursions() const { return _recursions; }
281
282 // JVM/TI GetObjectMonitorUsage() needs this:
283 ObjectWaiter* first_waiter() { return _WaitSet; }
284 ObjectWaiter* next_waiter(ObjectWaiter* o) { return o->_next; }
285 Thread* thread_of_waiter(ObjectWaiter* o) { return o->_thread; }
286
287 protected:
288 // We don't typically expect or want the ctors or dtors to run.
289 // normal ObjectMonitors are type-stable and immortal.
290 ObjectMonitor() { ::memset((void*)this, 0, sizeof(*this)); }
291
292 ~ObjectMonitor() {
293 // TODO: Add asserts ...
294 // _cxq == 0 _succ == NULL _owner == NULL _waiters == 0
295 // _contentions == 0 _EntryList == NULL etc
322 bool is_active() const;
323 bool is_old() const;
324 bool is_new() const;
325 void dec_ref_count();
326 void inc_ref_count();
327 jint ref_count() const;
328
329 // Returns true if the specified thread owns the ObjectMonitor. Otherwise
330 // returns false and throws IllegalMonitorStateException (IMSE).
331 bool check_owner(Thread* THREAD);
332 void clear();
333 void clear_using_JT();
334
335 void enter(TRAPS);
336 void exit(bool not_suspended, TRAPS);
337 void wait(jlong millis, bool interruptable, TRAPS);
338 void notify(TRAPS);
339 void notifyAll(TRAPS);
340
341 void print() const;
342 void print_on(outputStream* st) const;
343
344 // Use the following at your own risk
345 intptr_t complete_exit(TRAPS);
346 void reenter(intptr_t recursions, TRAPS);
347
348 private:
349 void AddWaiter(ObjectWaiter* waiter);
350 void INotify(Thread* self);
351 ObjectWaiter* DequeueWaiter();
352 void DequeueSpecificWaiter(ObjectWaiter* waiter);
353 void EnterI(TRAPS);
354 void ReenterI(Thread* self, ObjectWaiter* self_node);
355 void UnlinkAfterAcquire(Thread* self, ObjectWaiter* self_node);
356 int TryLock(Thread* self);
357 int NotRunnable(Thread* self, Thread* Owner);
358 int TrySpin(Thread* self);
359 void ExitEpilog(Thread* self, ObjectWaiter* Wakee);
360 bool ExitSuspendEquivalent(JavaThread* self);
361 void install_displaced_markword_in_object(const oop obj);
|
174 // acting as proxies for Threads.
175
176 ObjectWaiter* volatile _cxq; // LL of recently-arrived threads blocked on entry.
177 Thread* volatile _succ; // Heir presumptive thread - used for futile wakeup throttling
178 Thread* volatile _Responsible;
179
180 volatile int _Spinner; // for exit->spinner handoff optimization
181 volatile int _SpinDuration;
182
183 volatile jint _contentions; // Number of active contentions in enter(). It is used by is_busy()
184 // along with other fields to determine if an ObjectMonitor can be
185 // deflated. See ObjectSynchronizer::deflate_monitor() and
186 // ObjectSynchronizer::deflate_monitor_using_JT().
187 protected:
188 ObjectWaiter* volatile _WaitSet; // LL of threads wait()ing on the monitor
189 volatile jint _waiters; // number of waiting threads
190 private:
191 volatile int _WaitSetLock; // protects Wait Queue - simple spinlock
192
193 public:
194 static void Initialize();
195
196 // Only perform a PerfData operation if the PerfData object has been
197 // allocated and if the PerfDataManager has not freed the PerfData
198 // objects which can happen at normal VM shutdown.
199 //
200 #define OM_PERFDATA_OP(f, op_str) \
201 do { \
202 if (ObjectMonitor::_sync_ ## f != NULL && \
203 PerfDataManager::has_PerfData()) { \
204 ObjectMonitor::_sync_ ## f->op_str; \
205 } \
206 } while (0)
207
208 static PerfCounter * _sync_ContendedLockAttempts;
209 static PerfCounter * _sync_FutileWakeups;
210 static PerfCounter * _sync_Parks;
211 static PerfCounter * _sync_Notifications;
212 static PerfCounter * _sync_Inflations;
213 static PerfCounter * _sync_Deflations;
214 static PerfLongVariable * _sync_MonExtant;
215
216 static int Knob_SpinLimit;
217
218 void* operator new (size_t size) throw();
219 void* operator new[] (size_t size) throw();
220 void operator delete(void* p);
221 void operator delete[] (void* p);
222
223 // TODO-FIXME: the "offset" routines should return a type of off_t instead of int ...
224 // ByteSize would also be an appropriate type.
225 static int header_offset_in_bytes() { return offset_of(ObjectMonitor, _header); }
226 static int object_offset_in_bytes() { return offset_of(ObjectMonitor, _object); }
227 static int owner_offset_in_bytes() { return offset_of(ObjectMonitor, _owner); }
228 static int ref_count_offset_in_bytes() { return offset_of(ObjectMonitor, _ref_count); }
229 static int recursions_offset_in_bytes() { return offset_of(ObjectMonitor, _recursions); }
230 static int cxq_offset_in_bytes() { return offset_of(ObjectMonitor, _cxq); }
231 static int succ_offset_in_bytes() { return offset_of(ObjectMonitor, _succ); }
232 static int EntryList_offset_in_bytes() { return offset_of(ObjectMonitor, _EntryList); }
233
234 // ObjectMonitor references can be ORed with markWord::monitor_value
235 // as part of the ObjectMonitor tagging mechanism. When we combine an
236 // ObjectMonitor reference with an offset, we need to remove the tag
237 // value in order to generate the proper address.
238 //
239 // We can either adjust the ObjectMonitor reference and then add the
240 // offset or we can adjust the offset that is added to the ObjectMonitor
241 // reference. The latter avoids an AGI (Address Generation Interlock)
242 // stall so the helper macro adjusts the offset value that is returned
243 // to the ObjectMonitor reference manipulation code:
244 //
245 #define OM_OFFSET_NO_MONITOR_VALUE_TAG(f) \
246 ((ObjectMonitor::f ## _offset_in_bytes()) - markWord::monitor_value)
247
248 markWord header() const;
255 // _ref_count is for indicating that the ObjectMonitor* is in
256 // use which is orthogonal to whether the ObjectMonitor itself
257 // is in use for a locking operation.
258 intptr_t ret_code = _contentions | _waiters | intptr_t(_cxq) | intptr_t(_EntryList);
259 if (!AsyncDeflateIdleMonitors) {
260 ret_code |= intptr_t(_owner);
261 } else {
262 if (_owner != DEFLATER_MARKER) {
263 ret_code |= intptr_t(_owner);
264 }
265 }
266 return ret_code;
267 }
268 const char* is_busy_to_string(stringStream* ss);
269
270 intptr_t is_entered(Thread* current) const;
271
272 void* owner() const; // Returns NULL if DEFLATER_MARKER is observed.
273 // Returns true if owner field == DEFLATER_MARKER and false otherwise.
274 bool owner_is_DEFLATER_MARKER();
275 // Set _owner field to new_value; current value must match old_value.
276 void set_owner_from(void* new_value, void* old_value);
277 // Set _owner field to new_value; current value must match old_value1 or old_value2.
278 void set_owner_from(void* new_value, void* old_value1, void* old_value2);
279 // Set _owner field to self; current value must match basic_lock_p.
280 void set_owner_from_BasicLock(Thread* self, void* basic_lock_p);
281 // Try to set _owner field to new_value if the current value matches
282 // old_value. Otherwise, does not change the _owner field.
283 void* try_set_owner_from(void* new_value, void* old_value);
284
285 jint waiters() const;
286
287 jint contentions() const;
288 intptr_t recursions() const { return _recursions; }
289
290 // JVM/TI GetObjectMonitorUsage() needs this:
291 ObjectWaiter* first_waiter() { return _WaitSet; }
292 ObjectWaiter* next_waiter(ObjectWaiter* o) { return o->_next; }
293 Thread* thread_of_waiter(ObjectWaiter* o) { return o->_thread; }
294
295 protected:
296 // We don't typically expect or want the ctors or dtors to run.
297 // normal ObjectMonitors are type-stable and immortal.
298 ObjectMonitor() { ::memset((void*)this, 0, sizeof(*this)); }
299
300 ~ObjectMonitor() {
301 // TODO: Add asserts ...
302 // _cxq == 0 _succ == NULL _owner == NULL _waiters == 0
303 // _contentions == 0 _EntryList == NULL etc
330 bool is_active() const;
331 bool is_old() const;
332 bool is_new() const;
333 void dec_ref_count();
334 void inc_ref_count();
335 jint ref_count() const;
336
337 // Returns true if the specified thread owns the ObjectMonitor. Otherwise
338 // returns false and throws IllegalMonitorStateException (IMSE).
339 bool check_owner(Thread* THREAD);
340 void clear();
341 void clear_using_JT();
342
343 void enter(TRAPS);
344 void exit(bool not_suspended, TRAPS);
345 void wait(jlong millis, bool interruptable, TRAPS);
346 void notify(TRAPS);
347 void notifyAll(TRAPS);
348
349 void print() const;
350 void print_debug_style_on(outputStream* st) const;
351 void print_on(outputStream* st) const;
352
353 // Use the following at your own risk
354 intptr_t complete_exit(TRAPS);
355 void reenter(intptr_t recursions, TRAPS);
356
357 private:
358 void AddWaiter(ObjectWaiter* waiter);
359 void INotify(Thread* self);
360 ObjectWaiter* DequeueWaiter();
361 void DequeueSpecificWaiter(ObjectWaiter* waiter);
362 void EnterI(TRAPS);
363 void ReenterI(Thread* self, ObjectWaiter* self_node);
364 void UnlinkAfterAcquire(Thread* self, ObjectWaiter* self_node);
365 int TryLock(Thread* self);
366 int NotRunnable(Thread* self, Thread* Owner);
367 int TrySpin(Thread* self);
368 void ExitEpilog(Thread* self, ObjectWaiter* Wakee);
369 bool ExitSuspendEquivalent(JavaThread* self);
370 void install_displaced_markword_in_object(const oop obj);
|