/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
#include "oops/markOop.hpp"
#include "runtime/basicLock.hpp"
#include "runtime/handles.hpp"
#include "runtime/perfData.hpp"
class ObjectMonitor;
friend class VMStructs;
public:
typedef enum {
// exit must be implemented non-blocking, since the compiler cannot easily handle
// deoptimization at monitor exit. Hence, it does not take a Handle argument.
// This is full version of monitor enter and exit. I choose not
// to use enter() and exit() in order to make sure user be ware
// of the performance and semantics difference. They are normally
// used by ObjectLocker etc. The interpreter and compiler use
// assembly copies of these routines. Please keep them synchornized.
//
// attempt_rebias flag is used by UseBiasedLocking implementation
// WARNING: They are ONLY used to handle the slow cases. They should
// only be used when the fast cases failed. Use of these functions
// without previous fast case check may cause fatal error.
// Internally they will use heavy weight monitor.
// Handle all interpreter, compiler and jni cases
// Special internal-use-only method for use by JVM infrastructure
// that needs to wait() on a java-level object but that can't risk
// throwing unexpected InterruptedExecutionExceptions.
// used by classloading to free classloader object lock,
// wait on an internal lock, and reclaim original lock
// with original recursion count
// thread-specific and global objectMonitor free list accessors
// Inflate light weight monitor to heavy weight monitor
// This version is only for internal use
// Returns the identity hash value for an oop
// NOTE: It may cause monitor inflation
// java.lang.Thread support
// JNI detach support
static void release_monitors_owned_by_thread(TRAPS);
static void monitors_iterate(MonitorClosure* m);
// GC: we current use aggressive monitor deflation policy
// Basically we deflate all monitors that are not busy.
// An adaptive profile-based deflation policy could be used if needed
static void deflate_idle_monitors();
static void oops_do(OopClosure* f);
// debugging
static void trace_locking(Handle obj, bool is_compiled, bool is_method, bool is_locking) PRODUCT_RETURN;
private:
static ObjectMonitor * volatile gOmInUseList; // for moribund thread, so monitors they inflated still get scanned
static int gOmInUseCount;
};
// ObjectLocker enforced balanced locking and can never thrown an
// IllegalMonitorStateException. However, a pending exception may
// have to pass through, and we must also be able to deal with
// asynchronous exceptions. The caller is responsible for checking
// the threads pending exception if needed.
// doLock was added to support classloading with UnsyncloadClass which
// requires flag based choice of locking the classloader lock.
private:
public:
~ObjectLocker();
// Monitor behavior
// complete_exit gives up lock completely, returning recursion count
// reenter reclaims lock with original recursion count
};
#endif // SHARE_VM_RUNTIME_SYNCHRONIZER_HPP