aoqi@0: /* aoqi@0: * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: * aoqi@0: */ aoqi@0: aoqi@0: #ifndef SHARE_VM_RUNTIME_OBJECTMONITOR_INLINE_HPP aoqi@0: #define SHARE_VM_RUNTIME_OBJECTMONITOR_INLINE_HPP aoqi@0: aoqi@0: inline intptr_t ObjectMonitor::is_entered(TRAPS) const { aoqi@0: if (THREAD == _owner || THREAD->is_lock_owned((address) _owner)) { aoqi@0: return 1; aoqi@0: } aoqi@0: return 0; aoqi@0: } aoqi@0: aoqi@0: inline markOop ObjectMonitor::header() const { aoqi@0: return _header; aoqi@0: } aoqi@0: aoqi@0: inline void ObjectMonitor::set_header(markOop hdr) { aoqi@0: _header = hdr; aoqi@0: } aoqi@0: aoqi@0: inline intptr_t ObjectMonitor::count() const { aoqi@0: return _count; aoqi@0: } aoqi@0: aoqi@0: inline void ObjectMonitor::set_count(intptr_t count) { aoqi@0: _count= count; aoqi@0: } aoqi@0: aoqi@0: inline intptr_t ObjectMonitor::waiters() const { aoqi@0: return _waiters; aoqi@0: } aoqi@0: aoqi@0: inline void* ObjectMonitor::owner() const { aoqi@0: return _owner; aoqi@0: } aoqi@0: aoqi@0: inline void ObjectMonitor::clear() { aoqi@0: assert(_header, "Fatal logic error in ObjectMonitor header!"); aoqi@0: assert(_count == 0, "Fatal logic error in ObjectMonitor count!"); aoqi@0: assert(_waiters == 0, "Fatal logic error in ObjectMonitor waiters!"); aoqi@0: assert(_recursions == 0, "Fatal logic error in ObjectMonitor recursions!"); aoqi@0: assert(_object, "Fatal logic error in ObjectMonitor object!"); aoqi@0: assert(_owner == 0, "Fatal logic error in ObjectMonitor owner!"); aoqi@0: aoqi@0: _header = NULL; aoqi@0: _object = NULL; aoqi@0: } aoqi@0: aoqi@0: aoqi@0: inline void* ObjectMonitor::object() const { aoqi@0: return _object; aoqi@0: } aoqi@0: aoqi@0: inline void* ObjectMonitor::object_addr() { aoqi@0: return (void *)(&_object); aoqi@0: } aoqi@0: aoqi@0: inline void ObjectMonitor::set_object(void* obj) { aoqi@0: _object = obj; aoqi@0: } aoqi@0: aoqi@0: inline bool ObjectMonitor::check(TRAPS) { aoqi@0: if (THREAD != _owner) { aoqi@0: if (THREAD->is_lock_owned((address) _owner)) { aoqi@0: _owner = THREAD; // regain ownership of inflated monitor aoqi@0: OwnerIsThread = 1 ; aoqi@0: assert (_recursions == 0, "invariant") ; aoqi@0: } else { aoqi@0: check_slow(THREAD); aoqi@0: return false; aoqi@0: } aoqi@0: } aoqi@0: return true; aoqi@0: } aoqi@0: aoqi@0: aoqi@0: // return number of threads contending for this monitor aoqi@0: inline intptr_t ObjectMonitor::contentions() const { aoqi@0: return _count; aoqi@0: } aoqi@0: aoqi@0: // Do NOT set _count = 0. There is a race such that _count could aoqi@0: // be set while inflating prior to setting _owner aoqi@0: // Just use Atomic::inc/dec and assert 0 when monitor put on free list aoqi@0: inline void ObjectMonitor::set_owner(void* owner) { aoqi@0: _owner = owner; aoqi@0: _recursions = 0; aoqi@0: } aoqi@0: aoqi@0: aoqi@0: #endif // SHARE_VM_RUNTIME_OBJECTMONITOR_INLINE_HPP