# monitor-enter

## Purpose

Acquire the monitor for the indicated object.

## Details

Op & Format | Mnemonic / Syntax | Arguments
--- | --- | ---
1d 11x | monitor-enter vAA | `A:` reference-bearing register (8 bits)

## Constraints

- A must be a valid register index for the current stack frame.
- Register vA must contain a reference to an object.

## Behavior

- An attempt is made for the current thread to acquire the monitor of the indicated object. Various results are possible:
  - If the monitor is not owned by any thread at this point, then the current thread becomes owner of the monitor. The entry count of the indicated object is set to 1.
  - Otherwise, if the monitor is owned by the same thread that attempts the acquiration, then the entry count of the indicated object is increased by 1.
  - Otherwise the monitor is owned by a different thread. The current thread sleeps until the monitor of the object is released. Once that happens, a new attempt to acquire the monitor is made, as described here. There is no guarantee that the second attempt (or any subsequent attempt) will be successful.

## Exceptions

- NullPointerException if vA is null.
- IllegalMonitorStateException if the entry count exceeds an (implementation-dependent) upper bound for recursive monitor entries. Note that it is unlikely this bound is ever hit, since for most implementations the call stack will overflow before.