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 inline void ObjectMonitor::release_clear_owner(void* old_value) {
90 DEBUG_ONLY(void* prev = Atomic::load(&_owner);)
91 assert(prev == old_value, "unexpected prev owner=" INTPTR_FORMAT
92 ", expected=" INTPTR_FORMAT, p2i(prev), p2i(old_value));
93 Atomic::release_store(&_owner, (void*)NULL);
94 log_trace(monitorinflation, owner)("release_clear_owner(): mid="
95 INTPTR_FORMAT ", old_value=" INTPTR_FORMAT,
96 p2i(this), p2i(old_value));
97 }
98
99 // Simply set _owner field to new_value; current value must match old_value.
100 // (Simple means no memory sync needed.)
101 inline void ObjectMonitor::set_owner_from(void* old_value, void* new_value) {
102 DEBUG_ONLY(void* prev = Atomic::load(&_owner);)
103 assert(prev == old_value, "unexpected prev owner=" INTPTR_FORMAT
104 ", expected=" INTPTR_FORMAT, p2i(prev), p2i(old_value));
105 Atomic::store(&_owner, new_value);
106 log_trace(monitorinflation, owner)("set_owner_from(): mid="
107 INTPTR_FORMAT ", old_value=" INTPTR_FORMAT
108 ", new_value=" INTPTR_FORMAT, p2i(this),
109 p2i(old_value), p2i(new_value));
110 }
111
112 // Simply set _owner field to self; current value must match basic_lock_p.
113 inline void ObjectMonitor::set_owner_from_BasicLock(void* basic_lock_p, Thread* self) {
114 DEBUG_ONLY(void* prev = Atomic::load(&_owner);)
115 assert(prev == basic_lock_p, "unexpected prev owner=" INTPTR_FORMAT
116 ", expected=" INTPTR_FORMAT, p2i(prev), p2i(basic_lock_p));
117 // Non-null owner field to non-null owner field is safe without
118 // cmpxchg() as long as all readers can tolerate either flavor.
119 Atomic::store(&_owner, self);
120 log_trace(monitorinflation, owner)("set_owner_from_BasicLock(): mid="
121 INTPTR_FORMAT ", basic_lock_p="
122 INTPTR_FORMAT ", new_value=" INTPTR_FORMAT,
123 p2i(this), p2i(basic_lock_p), p2i(self));
124 }
125
126 // Try to set _owner field to new_value if the current value matches
127 // old_value. Otherwise, does not change the _owner field.
128 inline void* ObjectMonitor::try_set_owner_from(void* old_value, void* new_value) {
129 void* prev = Atomic::cmpxchg(&_owner, old_value, new_value);
130 if (prev == old_value) {
131 log_trace(monitorinflation, owner)("try_set_owner_from(): mid="
132 INTPTR_FORMAT ", prev=" INTPTR_FORMAT
133 ", new=" INTPTR_FORMAT, p2i(this),
134 p2i(prev), p2i(new_value));
135 }
136 return prev;
137 }
138
139 #endif // SHARE_RUNTIME_OBJECTMONITOR_INLINE_HPP
|