objectMonitor.inline.hpp revision 1798:fa83ab460c54
1249261Sdim/*
2249261Sdim * Copyright (c) 1998, 2005, Oracle and/or its affiliates. All rights reserved.
3249261Sdim * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4249261Sdim *
5249261Sdim * This code is free software; you can redistribute it and/or modify it
6249261Sdim * under the terms of the GNU General Public License version 2 only, as
7249261Sdim * published by the Free Software Foundation.
8249261Sdim *
9249261Sdim * This code is distributed in the hope that it will be useful, but WITHOUT
10249261Sdim * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11249261Sdim * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12249261Sdim * version 2 for more details (a copy is included in the LICENSE file that
13249261Sdim * accompanied this code).
14249261Sdim *
15249261Sdim * You should have received a copy of the GNU General Public License version
16249261Sdim * 2 along with this work; if not, write to the Free Software Foundation,
17249261Sdim * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18249261Sdim *
19249261Sdim * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20249261Sdim * or visit www.oracle.com if you need additional information or have any
21249261Sdim * questions.
22249261Sdim *
23249261Sdim */
24263509Sdim
25263509Sdiminline intptr_t ObjectMonitor::is_entered(TRAPS) const {
26263509Sdim  if (THREAD == _owner || THREAD->is_lock_owned((address) _owner)) {
27263509Sdim    return 1;
28263509Sdim  }
29263509Sdim  return 0;
30263509Sdim}
31263509Sdim
32263509Sdiminline markOop ObjectMonitor::header() const {
33263509Sdim  return _header;
34263509Sdim}
35249261Sdim
36249261Sdiminline void ObjectMonitor::set_header(markOop hdr) {
37249261Sdim  _header = hdr;
38249261Sdim}
39249261Sdim
40249261Sdiminline intptr_t ObjectMonitor::count() const {
41249261Sdim  return _count;
42249261Sdim}
43249261Sdim
44249261Sdiminline void ObjectMonitor::set_count(intptr_t count) {
45249261Sdim  _count= count;
46249261Sdim}
47249261Sdim
48249261Sdiminline intptr_t ObjectMonitor::waiters() const {
49249261Sdim  return _waiters;
50263509Sdim}
51249261Sdim
52249261Sdiminline void* ObjectMonitor::owner() const {
53249261Sdim  return _owner;
54249261Sdim}
55249261Sdim
56249261Sdiminline void ObjectMonitor::clear() {
57249261Sdim  assert(_header, "Fatal logic error in ObjectMonitor header!");
58249261Sdim  assert(_count == 0, "Fatal logic error in ObjectMonitor count!");
59263509Sdim  assert(_waiters == 0, "Fatal logic error in ObjectMonitor waiters!");
60249261Sdim  assert(_recursions == 0, "Fatal logic error in ObjectMonitor recursions!");
61252723Sdim  assert(_object, "Fatal logic error in ObjectMonitor object!");
62252723Sdim  assert(_owner == 0, "Fatal logic error in ObjectMonitor owner!");
63263509Sdim
64249261Sdim  _header = NULL;
65249261Sdim  _object = NULL;
66249261Sdim}
67249261Sdim
68249261Sdim
69249261Sdiminline void* ObjectMonitor::object() const {
70249261Sdim  return _object;
71249261Sdim}
72249261Sdim
73249261Sdiminline void* ObjectMonitor::object_addr() {
74252723Sdim  return (void *)(&_object);
75249261Sdim}
76249261Sdim
77263509Sdiminline void ObjectMonitor::set_object(void* obj) {
78249261Sdim  _object = obj;
79249261Sdim}
80249261Sdim
81249261Sdiminline bool ObjectMonitor::check(TRAPS) {
82249261Sdim  if (THREAD != _owner) {
83263509Sdim    if (THREAD->is_lock_owned((address) _owner)) {
84249261Sdim      _owner = THREAD;  // regain ownership of inflated monitor
85249261Sdim      OwnerIsThread = 1 ;
86249261Sdim      assert (_recursions == 0, "invariant") ;
87263509Sdim    } else {
88263509Sdim      check_slow(THREAD);
89263509Sdim      return false;
90263509Sdim    }
91263509Sdim  }
92263509Sdim  return true;
93263509Sdim}
94249261Sdim
95263509Sdim
96249261Sdim// return number of threads contending for this monitor
97263509Sdiminline intptr_t ObjectMonitor::contentions() const {
98263509Sdim  return _count;
99263509Sdim}
100263509Sdim
101263509Sdiminline void ObjectMonitor::set_owner(void* owner) {
102263509Sdim  _owner = owner;
103263509Sdim  _recursions = 0;
104263509Sdim  _count = 0;
105263509Sdim}
106249261Sdim
107249261Sdim