JVM Knowledge

ireturn

Raw .md Oracle

Operation

Return int from method

Format

ireturn

Forms

ireturn = 172 (0xac)

Operand Stack

..., value →

[empty]

Description

The current method must have return type boolean, byte, char, short, or int. The value must be of type int. If the current method is a synchronized method, the monitor entered or reentered on invocation of the method is updated and possibly exited as if by execution of a monitorexit instruction (§monitorexit) in the current thread. If no exception is thrown, value is popped from the operand stack of the current frame (§2.6) and pushed onto the operand stack of the frame of the invoker. Any other values on the operand stack of the current method are discarded.

Prior to pushing value onto the operand stack of the frame of the invoker, it may have to be converted. If the return type of the invoked method was byte, char, or short, then value is converted from int to the return type as if by execution of i2b, i2c, or i2s, respectively. If the return type of the invoked method was boolean, then value is narrowed from int to boolean by taking the bitwise AND of value and 1.

The interpreter then returns control to the invoker of the method, reinstating the frame of the invoker.

Run-time Exceptions

If the Java Virtual Machine implementation does not enforce the rules on structured locking described in §2.11.10, then if the current method is a synchronized method and the current thread is not the owner of the monitor entered or reentered on invocation of the method, ireturn throws an IllegalMonitorStateException. This can happen, for example, if a synchronized method contains a monitorexit instruction, but no monitorenter instruction, on the object on which the method is synchronized.

Otherwise, if the Java Virtual Machine implementation enforces the rules on structured locking described in §2.11.10 and if the first of those rules is violated during invocation of the current method, then ireturn throws an IllegalMonitorStateException.