45 }
46
47 inline void ObjectMonitor::set_header(markWord hdr) {
48 Atomic::store(&_header, hdr);
49 }
50
51 inline jint ObjectMonitor::waiters() const {
52 return _waiters;
53 }
54
55 // Returns NULL if DEFLATER_MARKER is observed.
56 inline void* ObjectMonitor::owner() const {
57 void* owner = _owner;
58 return owner != DEFLATER_MARKER ? owner : NULL;
59 }
60
61 // Returns true if owner field == DEFLATER_MARKER and false otherwise.
62 // This accessor is called when we really need to know if the owner
63 // field == DEFLATER_MARKER and any non-NULL value won't do the trick.
64 inline bool ObjectMonitor::owner_is_DEFLATER_MARKER() {
65 return _owner == DEFLATER_MARKER;
66 }
67
68 // Returns true if 'this' is being async deflated and false otherwise.
69 inline bool ObjectMonitor::is_being_async_deflated() {
70 return owner_is_DEFLATER_MARKER() && contentions() < 0;
71 }
72
73 inline void ObjectMonitor::clear() {
74 assert(Atomic::load(&_header).value() != 0, "must be non-zero");
75 assert(_owner == NULL, "must be NULL: owner=" INTPTR_FORMAT, p2i(_owner));
76
77 Atomic::store(&_header, markWord::zero());
78
79 clear_using_JT();
80 }
81
82 inline void ObjectMonitor::clear_using_JT() {
83 // Unlike other *_using_JT() functions, we cannot assert
84 // AsyncDeflateIdleMonitors or Thread::current()->is_Java_thread()
85 // because clear() calls this function for the rest of its checks.
86
87 if (AsyncDeflateIdleMonitors) {
88 // Async deflation protocol uses the header, owner and contentions
89 // fields. While the ObjectMonitor being deflated is on the global free
90 // list, we leave those three fields alone; owner == DEFLATER_MARKER
91 // and contentions < 0 will force any racing threads to retry. The
92 // header field is used by install_displaced_markword_in_object()
93 // to restore the object's header so we cannot check its value here.
94 guarantee(_owner == NULL || _owner == DEFLATER_MARKER,
95 "must be NULL or DEFLATER_MARKER: owner=" INTPTR_FORMAT,
96 p2i(_owner));
97 }
98 assert(contentions() <= 0, "must not be positive: contentions=%d", contentions());
99 assert(_waiters == 0, "must be 0: waiters=%d", _waiters);
100 assert(_recursions == 0, "must be 0: recursions=" INTX_FORMAT, _recursions);
101 assert(_object != NULL, "must be non-NULL");
102
103 set_allocation_state(Free);
104 _object = NULL;
105 }
106
107 inline void* ObjectMonitor::object() const {
108 return _object;
109 }
110
111 inline void* ObjectMonitor::object_addr() {
112 return (void *)(&_object);
113 }
114
115 inline void ObjectMonitor::set_object(void* obj) {
116 _object = obj;
117 }
118
119 // Return number of threads contending for this monitor.
120 inline jint ObjectMonitor::contentions() const {
121 return Atomic::load(&_contentions);
122 }
123
124 // Clear _owner field; current value must match old_value.
125 inline void ObjectMonitor::release_clear_owner(void* old_value) {
126 void* prev = Atomic::load(&_owner);
127 ADIM_guarantee(prev == old_value, "unexpected prev owner=" INTPTR_FORMAT
128 ", expected=" INTPTR_FORMAT, p2i(prev), p2i(old_value));
129 Atomic::release_store(&_owner, (void*)NULL);
130 log_trace(monitorinflation, owner)("release_clear_owner(): mid="
131 INTPTR_FORMAT ", old_value=" INTPTR_FORMAT,
132 p2i(this), p2i(old_value));
133 }
134
135 // Simply set _owner field to new_value; current value must match old_value.
136 // (Simple means no memory sync needed.)
137 inline void ObjectMonitor::set_owner_from(void* old_value, void* new_value) {
138 void* prev = Atomic::load(&_owner);
139 ADIM_guarantee(prev == old_value, "unexpected prev owner=" INTPTR_FORMAT
140 ", expected=" INTPTR_FORMAT, p2i(prev), p2i(old_value));
141 Atomic::store(&_owner, new_value);
142 log_trace(monitorinflation, owner)("set_owner_from(): mid="
143 INTPTR_FORMAT ", old_value=" INTPTR_FORMAT
|
45 }
46
47 inline void ObjectMonitor::set_header(markWord hdr) {
48 Atomic::store(&_header, hdr);
49 }
50
51 inline jint ObjectMonitor::waiters() const {
52 return _waiters;
53 }
54
55 // Returns NULL if DEFLATER_MARKER is observed.
56 inline void* ObjectMonitor::owner() const {
57 void* owner = _owner;
58 return owner != DEFLATER_MARKER ? owner : NULL;
59 }
60
61 // Returns true if owner field == DEFLATER_MARKER and false otherwise.
62 // This accessor is called when we really need to know if the owner
63 // field == DEFLATER_MARKER and any non-NULL value won't do the trick.
64 inline bool ObjectMonitor::owner_is_DEFLATER_MARKER() {
65 return Atomic::load(&_owner) == DEFLATER_MARKER;
66 }
67
68 // Returns true if 'this' is being async deflated and false otherwise.
69 inline bool ObjectMonitor::is_being_async_deflated() {
70 return AsyncDeflateIdleMonitors && owner_is_DEFLATER_MARKER() && contentions() < 0;
71 }
72
73 inline void ObjectMonitor::clear() {
74 assert(Atomic::load(&_header).value() != 0, "must be non-zero");
75 assert(_owner == NULL, "must be NULL: owner=" INTPTR_FORMAT, p2i(_owner));
76
77 Atomic::store(&_header, markWord::zero());
78
79 clear_common();
80 }
81
82 inline void ObjectMonitor::clear_common() {
83 if (AsyncDeflateIdleMonitors) {
84 // Async deflation protocol uses the header, owner and contentions
85 // fields. While the ObjectMonitor being deflated is on the global free
86 // list, we leave those three fields alone; owner == DEFLATER_MARKER
87 // and contentions < 0 will force any racing threads to retry. The
88 // header field is used by install_displaced_markword_in_object()
89 // to restore the object's header so we cannot check its value here.
90 guarantee(_owner == NULL || _owner == DEFLATER_MARKER,
91 "must be NULL or DEFLATER_MARKER: owner=" INTPTR_FORMAT,
92 p2i(_owner));
93 }
94 assert(contentions() <= 0, "must not be positive: contentions=%d", contentions());
95 assert(_waiters == 0, "must be 0: waiters=%d", _waiters);
96 assert(_recursions == 0, "must be 0: recursions=" INTX_FORMAT, _recursions);
97 assert(_object != NULL, "must be non-NULL");
98
99 set_allocation_state(Free);
100 _object = NULL;
101 }
102
103 inline void* ObjectMonitor::object() const {
104 return _object;
105 }
106
107 inline void* ObjectMonitor::object_addr() {
108 return (void *)(&_object);
109 }
110
111 inline void ObjectMonitor::set_object(void* obj) {
112 _object = obj;
113 }
114
115 // Return number of threads contending for this monitor.
116 inline jint ObjectMonitor::contentions() const {
117 return Atomic::load(&_contentions);
118 }
119
120 // Add value to the contentions field.
121 inline void ObjectMonitor::add_to_contentions(jint value) {
122 Atomic::add(&_contentions, value);
123 }
124
125 // Clear _owner field; current value must match old_value.
126 inline void ObjectMonitor::release_clear_owner(void* old_value) {
127 void* prev = Atomic::load(&_owner);
128 ADIM_guarantee(prev == old_value, "unexpected prev owner=" INTPTR_FORMAT
129 ", expected=" INTPTR_FORMAT, p2i(prev), p2i(old_value));
130 Atomic::release_store(&_owner, (void*)NULL);
131 log_trace(monitorinflation, owner)("release_clear_owner(): mid="
132 INTPTR_FORMAT ", old_value=" INTPTR_FORMAT,
133 p2i(this), p2i(old_value));
134 }
135
136 // Simply set _owner field to new_value; current value must match old_value.
137 // (Simple means no memory sync needed.)
138 inline void ObjectMonitor::set_owner_from(void* old_value, void* new_value) {
139 void* prev = Atomic::load(&_owner);
140 ADIM_guarantee(prev == old_value, "unexpected prev owner=" INTPTR_FORMAT
141 ", expected=" INTPTR_FORMAT, p2i(prev), p2i(old_value));
142 Atomic::store(&_owner, new_value);
143 log_trace(monitorinflation, owner)("set_owner_from(): mid="
144 INTPTR_FORMAT ", old_value=" INTPTR_FORMAT
|