---
spec: JVMS
title: "The Java Virtual Machine Specification"
edition: "Java SE 13 Edition"
java_version: 13
chapter: "Chapter 4. The class File Format"
section: "4.10.1.9.monitorenter"
heading: "monitorenter, monitorexit"
parent: "4.10.1.9. Type Checking Instructions"
source: https://docs.oracle.com/javase/specs/jvms/se13/html/jvms-4.html#jvms-4.10.1.9.monitorenter
id: "4.10.1.9.monitorenter"
url: https://jvm.obfuscated.software/jvms/se13/4.10.1.9.monitorenter.html
raw: https://jvm.obfuscated.software/jvms/se13/4.10.1.9.monitorenter.md
---

# monitorenter, monitorexit

A *monitorenter* instruction is type safe iff one can validly pop a type matching `reference` off the incoming operand stack yielding the outgoing type state.

```
instructionIsTypeSafe(monitorenter, _Environment, _Offset, StackFrame,
                      NextStackFrame, ExceptionStackFrame) :-
    canPop(StackFrame, [reference], NextStackFrame),
    exceptionStackFrame(StackFrame, ExceptionStackFrame).
```

A *monitorexit* instruction is type safe iff the equivalent *monitorenter* instruction is type safe.

```
instructionHasEquivalentTypeRule(monitorexit, monitorenter).
```
