monitorexit 0xc3
Pops an object and unlocks its monitor.
- Opcode
0xc3(195)- Family
- Monitors
- Operands
- none
- Length
- 1 byte
- Operand stack
…, objectref → …- Can throw
NullPointerException,IllegalMonitorStateException
What it does
Unlocks the object's monitor (decrements its count). javac emits two for every synchronized block: one on the normal way out, and one in an exception handler that catches anything, unlocks, and rethrows. The handler also covers itself, so the monitor is released even if the unlock is interrupted.
How often javac uses it
In JDK 25.0.5's java.base module, monitorexit appears 2,147 times in 244 of its 7,391 classes: 0.11% of all instructions, the 84th most common of 194 opcodes in use. Some of the methods that use it: java.io.BufferedReader.read, java.io.BufferedWriter.flushBuffer, java.io.CharArrayReader.read, java.io.CharArrayWriter.write.
Examples
From the sample classes, compiled by javac 25 with -g. Each Java line is shown above the bytecode it compiled to; monitorexit is highlighted.
void increment() in Sync, compiled by javac 25void bump() in Switches, compiled by javac 25Related instructions
monitorenter Pops an object and locks its monitor (start of synchronized).athrow Throws the exception on top of the stack.
Specification: JVMS §6.5, monitorexit (Java SE 25).