8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #ifndef SHARE_RUNTIME_OBJECTMONITOR_INLINE_HPP
26 #define SHARE_RUNTIME_OBJECTMONITOR_INLINE_HPP
27
28 #include "runtime/atomic.hpp"
29
30 inline intptr_t ObjectMonitor::is_entered(TRAPS) const {
31 if (THREAD == _owner || THREAD->is_lock_owned((address) _owner)) {
32 return 1;
33 }
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(&_header, hdr);
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
|
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #ifndef SHARE_RUNTIME_OBJECTMONITOR_INLINE_HPP
26 #define SHARE_RUNTIME_OBJECTMONITOR_INLINE_HPP
27
28 #include "logging/log.hpp"
29 #include "runtime/atomic.hpp"
30
31 inline intptr_t ObjectMonitor::is_entered(TRAPS) const {
32 if (THREAD == _owner || THREAD->is_lock_owned((address) _owner)) {
33 return 1;
34 }
35 return 0;
36 }
37
38 inline markWord ObjectMonitor::header() const {
39 return Atomic::load(&_header);
40 }
41
42 inline volatile markWord* ObjectMonitor::header_addr() {
43 assert((intptr_t)this == (intptr_t)&_header, "sync code expects this");
44 return &_header;
45 }
46
47 inline void ObjectMonitor::set_header(markWord hdr) {
48 Atomic::store(&_header, hdr);
68 _object = NULL;
69 }
70
71 inline void* ObjectMonitor::object() const {
72 return _object;
73 }
74
75 inline void* ObjectMonitor::object_addr() {
76 return (void *)(&_object);
77 }
78
79 inline void ObjectMonitor::set_object(void* obj) {
80 _object = obj;
81 }
82
83 // return number of threads contending for this monitor
84 inline jint ObjectMonitor::contentions() const {
85 return _contentions;
86 }
87
88 // Clear _owner field; current value must match old_value.
89 // If needs_fence is true, we issue a fence() after the release_store().
90 // Otherwise, a storeload() is good enough. See the callers for more info.
91 inline void ObjectMonitor::release_clear_owner_with_barrier(void* old_value,
92 bool needs_fence) {
93 void* prev = _owner;
94 assert(prev == old_value, "unexpected prev owner=" INTPTR_FORMAT
95 ", expected=" INTPTR_FORMAT, p2i(prev), p2i(old_value));
96 Atomic::release_store(&_owner, (void*)NULL);
97 if (needs_fence) {
98 OrderAccess::fence();
99 } else {
100 OrderAccess::storeload();
101 }
102 log_trace(monitorinflation, owner)("release_clear_owner_with_barrier(): mid="
103 INTPTR_FORMAT ", prev=" INTPTR_FORMAT
104 ", needs_fence=%d", p2i(this), p2i(prev),
105 needs_fence);
106 }
107
108 // Simply set _owner field to new_value; current value must match old_value.
109 // (Simple means no memory sync needed.)
110 inline void ObjectMonitor::simply_set_owner_from(void* old_value, void* new_value) {
111 void* prev = _owner;
112 assert(prev == old_value, "unexpected prev owner=" INTPTR_FORMAT
113 ", expected=" INTPTR_FORMAT, p2i(prev), p2i(old_value));
114 _owner = new_value;
115 log_trace(monitorinflation, owner)("simply_set_owner_from(): mid="
116 INTPTR_FORMAT ", prev=" INTPTR_FORMAT
117 ", new=" INTPTR_FORMAT, p2i(this),
118 p2i(prev), p2i(new_value));
119 }
120
121 // Simply set _owner field to self; current value must match basic_lock_p.
122 inline void ObjectMonitor::simply_set_owner_from_BasicLock(void* basic_lock_p, Thread* self) {
123 void* prev = _owner;
124 assert(prev == basic_lock_p, "unexpected prev owner=" INTPTR_FORMAT
125 ", expected=" INTPTR_FORMAT, p2i(prev), p2i(basic_lock_p));
126 // Non-null owner field to non-null owner field is safe without
127 // cmpxchg() as long as all readers can tolerate either flavor.
128 _owner = self;
129 log_trace(monitorinflation, owner)("simply_set_owner_from_BasicLock(): mid="
130 INTPTR_FORMAT ", prev=" INTPTR_FORMAT
131 ", new=" INTPTR_FORMAT ", basic_lock_p="
132 INTPTR_FORMAT, p2i(this), p2i(prev),
133 p2i(self), p2i(basic_lock_p));
134 }
135
136 // Try to set _owner field to new_value if the current value matches
137 // old_value. Otherwise, does not change the _owner field.
138 inline void* ObjectMonitor::try_set_owner_from(void* old_value, void* new_value) {
139 void* prev = Atomic::cmpxchg(&_owner, old_value, new_value);
140 if (prev == old_value) {
141 log_trace(monitorinflation, owner)("try_set_owner_from(): mid="
142 INTPTR_FORMAT ", prev=" INTPTR_FORMAT
143 ", new=" INTPTR_FORMAT, p2i(this),
144 p2i(prev), p2i(new_value));
145 }
146 return prev;
147 }
148
149 #endif // SHARE_RUNTIME_OBJECTMONITOR_INLINE_HPP
|