Contents | Prev | Next | Index

monitorenter

The monitorenter instruction may be used with a monitorexit instruction to implement a Java synchronized block. The monitorenter instruction is not used in the implementation of synchronized methods, although it provides equivalent semantics; monitor entry on invocation of a synchronized method is handled implicitly by the Java Virtual Machine's method invocation instructions. See §7.14, in "Compiling for the Java Virtual Machine," for more information on the use of the monitorenter and monitorexit instructions.

The association of a monitor with an object may be managed in various ways that are beyond the scope of this specification. For instance, the monitor may be allocated and deallocated at the same time as the object. Alternatively, it may be dynamically allocated at the time when a thread attempts to gain exclusive access to the object and freed at some later time when no thread remains in the monitor for the object.

The synchronization constructs of the Java Language require support for operations on monitors besides entry and exit, including waiting on a monitor (Object.wait) and notifying other threads waiting in a monitor (Object.notify and Object.notifyAll). These operations are supported in the standard package java.lang, supplied with the Java Virtual Machine. No explicit support for these operations appears in the instruction set of the Java Virtual Machine.


Contents | Prev | Next | Index

Java Virtual Machine Specification (HTML generated by dkramer on February 25, 1997)
Copyright © 1996 Sun Microsystems, Inc. All rights reserved
Please send any comments or corrections to doug.kramer@sun.com