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() {
310 // _contentions == 0 EntryList == NULL
311 // _recursions == 0 _WaitSet == NULL
312 DEBUG_ONLY(stringStream ss;)
313 assert((is_busy() | _recursions) == 0, "freeing in-use monitor: %s, "
314 "recursions=" INTX_FORMAT, is_busy_to_string(&ss), _recursions);
315 _succ = NULL;
316 _EntryList = NULL;
317 _cxq = NULL;
318 _WaitSet = NULL;
319 _recursions = 0;
320 }
321
322 public:
323
324 void* object() const;
325 void* object_addr();
326 void set_object(void* obj);
327 void set_allocation_state(AllocationState s);
328 AllocationState allocation_state() const;
329 bool is_free() const;
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;
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);
371 };
372
373 // A helper object for managing an ObjectMonitor*'s ref_count. There
374 // are special safety considerations when async deflation is used.
375 class ObjectMonitorHandle : public StackObj {
376 private:
377 ObjectMonitor* _om_ptr;
378 public:
379 ObjectMonitorHandle() { _om_ptr = NULL; }
380 ~ObjectMonitorHandle();
381
382 ObjectMonitor* om_ptr() const { return _om_ptr; }
383 // Save the ObjectMonitor* associated with the specified markWord and
384 // increment the ref_count.
385 bool save_om_ptr(oop object, markWord mark);
386
387 // For internal used by ObjectSynchronizer::monitors_iterate().
388 ObjectMonitorHandle(ObjectMonitor* _om_ptr);
389 // For internal use by ObjectSynchronizer::inflate().
390 void set_om_ptr(ObjectMonitor* om_ptr);
391 };
392
393 // Macro to use guarantee() for more strict AsyncDeflateIdleMonitors
394 // checks and assert() otherwise.
395 #define ADIM_guarantee(p, ...) \
396 do { \
397 if (AsyncDeflateIdleMonitors) { \
398 guarantee(p, __VA_ARGS__); \
399 } else { \
400 assert(p, __VA_ARGS__); \
401 } \
402 } while (0)
403
404 #endif // SHARE_RUNTIME_OBJECTMONITOR_HPP
|
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 // Simply set _owner field to new_value; current value must match old_value.
278 void simply_set_owner_from(void* new_value, void* old_value);
279 // Simply set _owner field to new_value; current value must match old_value1 or old_value2.
280 void simply_set_owner_from(void* new_value, void* old_value1, void* old_value2);
281 // Simply set _owner field to self; current value must match basic_lock_p.
282 void simply_set_owner_from_BasicLock(Thread* self, void* basic_lock_p);
283 // Try to set _owner field to new_value if the current value matches
284 // old_value. Otherwise, does not change the _owner field.
285 void* try_set_owner_from(void* new_value, void* old_value);
286
287 jint waiters() const;
288
289 jint contentions() const;
290 intptr_t recursions() const { return _recursions; }
291
292 // JVM/TI GetObjectMonitorUsage() needs this:
293 ObjectWaiter* first_waiter() { return _WaitSet; }
294 ObjectWaiter* next_waiter(ObjectWaiter* o) { return o->_next; }
295 Thread* thread_of_waiter(ObjectWaiter* o) { return o->_thread; }
296
297 protected:
298 // We don't typically expect or want the ctors or dtors to run.
299 // normal ObjectMonitors are type-stable and immortal.
300 ObjectMonitor() { ::memset((void*)this, 0, sizeof(*this)); }
301
302 ~ObjectMonitor() {
312 // _contentions == 0 EntryList == NULL
313 // _recursions == 0 _WaitSet == NULL
314 DEBUG_ONLY(stringStream ss;)
315 assert((is_busy() | _recursions) == 0, "freeing in-use monitor: %s, "
316 "recursions=" INTX_FORMAT, is_busy_to_string(&ss), _recursions);
317 _succ = NULL;
318 _EntryList = NULL;
319 _cxq = NULL;
320 _WaitSet = NULL;
321 _recursions = 0;
322 }
323
324 public:
325
326 void* object() const;
327 void* object_addr();
328 void set_object(void* obj);
329 void set_allocation_state(AllocationState s);
330 AllocationState allocation_state() const;
331 bool is_free() const;
332 bool is_old() const;
333 bool is_new() const;
334 void dec_ref_count();
335 void inc_ref_count();
336 jint ref_count() const;
337
338 // Returns true if the specified thread owns the ObjectMonitor. Otherwise
339 // returns false and throws IllegalMonitorStateException (IMSE).
340 bool check_owner(Thread* THREAD);
341 void clear();
342 void clear_using_JT();
343
344 void enter(TRAPS);
345 void exit(bool not_suspended, TRAPS);
346 void wait(jlong millis, bool interruptable, TRAPS);
347 void notify(TRAPS);
348 void notifyAll(TRAPS);
349
350 void print() const;
351 void print_debug_style_on(outputStream* st) const;
367 int NotRunnable(Thread* self, Thread* Owner);
368 int TrySpin(Thread* self);
369 void ExitEpilog(Thread* self, ObjectWaiter* Wakee);
370 bool ExitSuspendEquivalent(JavaThread* self);
371 void install_displaced_markword_in_object(const oop obj);
372 };
373
374 // A helper object for managing an ObjectMonitor*'s ref_count. There
375 // are special safety considerations when async deflation is used.
376 class ObjectMonitorHandle : public StackObj {
377 private:
378 ObjectMonitor* _om_ptr;
379 public:
380 ObjectMonitorHandle() { _om_ptr = NULL; }
381 ~ObjectMonitorHandle();
382
383 ObjectMonitor* om_ptr() const { return _om_ptr; }
384 // Save the ObjectMonitor* associated with the specified markWord and
385 // increment the ref_count.
386 bool save_om_ptr(oop object, markWord mark);
387 // Save the specified ObjectMonitor* if safe and increment the ref_count.
388 bool set_om_ptr_if_safe(ObjectMonitor* om_ptr);
389 // Unset the _om_ptr field and decrement the ref_count.
390 void unset_om_ptr();
391
392 // For internal use by ObjectSynchronizer::inflate().
393 void set_om_ptr(ObjectMonitor* om_ptr);
394 };
395
396 // Macro to use guarantee() for more strict AsyncDeflateIdleMonitors
397 // checks and assert() otherwise.
398 #define ADIM_guarantee(p, ...) \
399 do { \
400 if (AsyncDeflateIdleMonitors) { \
401 guarantee(p, __VA_ARGS__); \
402 } else { \
403 assert(p, __VA_ARGS__); \
404 } \
405 } while (0)
406
407 #endif // SHARE_RUNTIME_OBJECTMONITOR_HPP
|