38
39 inline volatile markOop* ObjectMonitor::header_addr() {
40 assert((intptr_t)this == (intptr_t)&_header, "sync code expects this");
41 return &_header;
42 }
43
44 inline void ObjectMonitor::set_header(markOop hdr) {
45 _header = hdr;
46 }
47
48 inline jint ObjectMonitor::waiters() const {
49 return _waiters;
50 }
51
52 // Returns NULL if DEFLATER_MARKER is observed.
53 inline void* ObjectMonitor::owner() const {
54 void* owner = _owner;
55 return owner != DEFLATER_MARKER ? owner : NULL;
56 }
57
58 inline void ObjectMonitor::clear() {
59 assert(_header != NULL, "must be non-NULL");
60 assert(_owner == NULL, "must be NULL: owner=" INTPTR_FORMAT, p2i(_owner));
61 assert(_ref_count == 0, "must be 0: ref_count=%d", _ref_count);
62
63 _header = NULL;
64
65 clear_using_JT();
66 }
67
68 inline void ObjectMonitor::clear_using_JT() {
69 // Unlike other *_using_JT() functions, we cannot assert
70 // AsyncDeflateIdleMonitors or Thread::current()->is_Java_thread()
71 // because clear() calls this function for the rest of its checks.
72
73 if (AsyncDeflateIdleMonitors) {
74 // Async deflation protocol uses the header, owner and ref_count
75 // fields. While the ObjectMonitor being deflated is on the global free
76 // list, we leave those three fields alone; owner == DEFLATER_MARKER
77 // and ref_count < 0 will force any racing threads to retry. The
78 // header field is used by install_displaced_markword_in_object()
79 // in the last part of the deflation protocol so we cannot check
80 // its value here.
81 guarantee(_owner == NULL || _owner == DEFLATER_MARKER,
82 "must be NULL or DEFLATER_MARKER: owner=" INTPTR_FORMAT,
83 p2i(_owner));
84 guarantee(_ref_count <= 0, "must be <= 0: ref_count=%d", _ref_count);
85 }
86 assert(_contentions == 0, "must be 0: contentions=%d", _contentions);
87 assert(_waiters == 0, "must be 0: waiters=%d", _waiters);
88 assert(_recursions == 0, "must be 0: recursions=" INTPTR_FORMAT, _recursions);
89 assert(_object != NULL, "must be non-NULL");
90
91 set_allocation_state(Free);
92 _object = NULL;
93 }
94
95 inline void* ObjectMonitor::object() const {
96 return _object;
97 }
98
99 inline void* ObjectMonitor::object_addr() {
100 return (void *)(&_object);
101 }
102
103 inline void ObjectMonitor::set_object(void* obj) {
104 _object = obj;
138 return _allocation_state == Free;
139 }
140
141 inline bool ObjectMonitor::is_active() const {
142 return !is_free();
143 }
144
145 inline bool ObjectMonitor::is_old() const {
146 return _allocation_state == Old;
147 }
148
149 inline bool ObjectMonitor::is_new() const {
150 return _allocation_state == New;
151 }
152
153 inline void ObjectMonitor::dec_ref_count() {
154 // The decrement only needs to be MO_ACQ_REL since the reference
155 // counter is volatile.
156 Atomic::dec(&_ref_count);
157 // Can be negative as part of async deflation protocol.
158 guarantee(AsyncDeflateIdleMonitors || _ref_count >= 0,
159 "sanity check: ref_count=%d", _ref_count);
160 }
161
162 inline void ObjectMonitor::inc_ref_count() {
163 // The increment needs to be MO_SEQ_CST so that the reference
164 // counter update is seen as soon as possible in a race with the
165 // async deflation protocol.
166 Atomic::inc(&_ref_count);
167 // Can be negative as part of async deflation protocol.
168 guarantee(AsyncDeflateIdleMonitors || _ref_count > 0,
169 "sanity check: ref_count=%d", _ref_count);
170 }
171
172 inline jint ObjectMonitor::ref_count() const {
173 return OrderAccess::load_acquire(&_ref_count);
174 }
175
176 #endif // SHARE_RUNTIME_OBJECTMONITOR_INLINE_HPP
|
38
39 inline volatile markOop* ObjectMonitor::header_addr() {
40 assert((intptr_t)this == (intptr_t)&_header, "sync code expects this");
41 return &_header;
42 }
43
44 inline void ObjectMonitor::set_header(markOop hdr) {
45 _header = hdr;
46 }
47
48 inline jint ObjectMonitor::waiters() const {
49 return _waiters;
50 }
51
52 // Returns NULL if DEFLATER_MARKER is observed.
53 inline void* ObjectMonitor::owner() const {
54 void* owner = _owner;
55 return owner != DEFLATER_MARKER ? owner : NULL;
56 }
57
58 // Returns true if owner field == DEFLATER_MARKER and false otherwise.
59 // This accessor is called when we really need to know if the owner
60 // field == DEFLATER_MARKER and any non-NULL value won't do the trick.
61 inline bool ObjectMonitor::owner_is_DEFLATER_MARKER() {
62 return OrderAccess::load_acquire(&_owner) == DEFLATER_MARKER;
63 }
64
65 inline void ObjectMonitor::clear() {
66 assert(_header != NULL, "must be non-NULL");
67 assert(_owner == NULL, "must be NULL: owner=" INTPTR_FORMAT, p2i(_owner));
68 assert(ref_count() == 0, "must be 0: ref_count=%d", ref_count());
69
70 _header = NULL;
71
72 clear_using_JT();
73 }
74
75 inline void ObjectMonitor::clear_using_JT() {
76 // Unlike other *_using_JT() functions, we cannot assert
77 // AsyncDeflateIdleMonitors or Thread::current()->is_Java_thread()
78 // because clear() calls this function for the rest of its checks.
79
80 if (AsyncDeflateIdleMonitors) {
81 // Async deflation protocol uses the header, owner and ref_count
82 // fields. While the ObjectMonitor being deflated is on the global free
83 // list, we leave those three fields alone; owner == DEFLATER_MARKER
84 // and ref_count < 0 will force any racing threads to retry. The
85 // header field is used by install_displaced_markword_in_object()
86 // in the last part of the deflation protocol so we cannot check
87 // its value here.
88 guarantee(_owner == NULL || _owner == DEFLATER_MARKER,
89 "must be NULL or DEFLATER_MARKER: owner=" INTPTR_FORMAT,
90 p2i(_owner));
91 guarantee(ref_count() <= 0, "must be <= 0: ref_count=%d", ref_count());
92 }
93 assert(_contentions == 0, "must be 0: contentions=%d", _contentions);
94 assert(_waiters == 0, "must be 0: waiters=%d", _waiters);
95 assert(_recursions == 0, "must be 0: recursions=" INTPTR_FORMAT, _recursions);
96 assert(_object != NULL, "must be non-NULL");
97
98 set_allocation_state(Free);
99 _object = NULL;
100 }
101
102 inline void* ObjectMonitor::object() const {
103 return _object;
104 }
105
106 inline void* ObjectMonitor::object_addr() {
107 return (void *)(&_object);
108 }
109
110 inline void ObjectMonitor::set_object(void* obj) {
111 _object = obj;
145 return _allocation_state == Free;
146 }
147
148 inline bool ObjectMonitor::is_active() const {
149 return !is_free();
150 }
151
152 inline bool ObjectMonitor::is_old() const {
153 return _allocation_state == Old;
154 }
155
156 inline bool ObjectMonitor::is_new() const {
157 return _allocation_state == New;
158 }
159
160 inline void ObjectMonitor::dec_ref_count() {
161 // The decrement only needs to be MO_ACQ_REL since the reference
162 // counter is volatile.
163 Atomic::dec(&_ref_count);
164 // Can be negative as part of async deflation protocol.
165 ADIM_guarantee(AsyncDeflateIdleMonitors || ref_count() >= 0,
166 "sanity check: ref_count=%d", ref_count());
167 }
168
169 inline void ObjectMonitor::inc_ref_count() {
170 // The increment needs to be MO_SEQ_CST so that the reference
171 // counter update is seen as soon as possible in a race with the
172 // async deflation protocol.
173 Atomic::inc(&_ref_count);
174 // Can be negative as part of async deflation protocol.
175 ADIM_guarantee(AsyncDeflateIdleMonitors || ref_count() > 0,
176 "sanity check: ref_count=%d", ref_count());
177 }
178
179 inline jint ObjectMonitor::ref_count() const {
180 return OrderAccess::load_acquire(&_ref_count);
181 }
182
183 #endif // SHARE_RUNTIME_OBJECTMONITOR_INLINE_HPP
|