1 /*
2 * Copyright (c) 1998, 2019, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
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
is_entered(TRAPS) const30 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
header() const37 inline markWord ObjectMonitor::header() const {
38 return Atomic::load(&_header);
39 }
40
header_addr()41 inline volatile markWord* ObjectMonitor::header_addr() {
42 assert((intptr_t)this == (intptr_t)&_header, "sync code expects this");
43 return &_header;
44 }
45
set_header(markWord hdr)46 inline void ObjectMonitor::set_header(markWord hdr) {
47 Atomic::store(&_header, hdr);
48 }
49
waiters() const50 inline jint ObjectMonitor::waiters() const {
51 return _waiters;
52 }
53
owner() const54 inline void* ObjectMonitor::owner() const {
55 return _owner;
56 }
57
clear()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=" INTX_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(&_header, markWord::zero());
67 _object = NULL;
68 }
69
object() const70 inline void* ObjectMonitor::object() const {
71 return _object;
72 }
73
object_addr()74 inline void* ObjectMonitor::object_addr() {
75 return (void *)(&_object);
76 }
77
set_object(void * obj)78 inline void ObjectMonitor::set_object(void* obj) {
79 _object = obj;
80 }
81
82 // return number of threads contending for this monitor
contentions() const83 inline jint ObjectMonitor::contentions() const {
84 return _contentions;
85 }
86
set_owner(void * owner)87 inline void ObjectMonitor::set_owner(void* owner) {
88 _owner = owner;
89 }
90
91 #endif // SHARE_RUNTIME_OBJECTMONITOR_INLINE_HPP
92