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