JVM Knowledge

ret

Raw .md Oracle

Operation

Return from subroutine

Format

ret
index

Forms

ret = 169 (0xa9)

Operand Stack

No change

Description

The index is an unsigned byte between 0 and 255, inclusive. The local variable at index in the current frame (§2.6) must contain a value of type returnAddress. The contents of the local variable are written into the Java Virtual Machine's pc register, and execution continues there.

Notes

Note that jsr (§jsr) pushes the address onto the operand stack and ret gets it out of a local variable. This asymmetry is intentional.

In Oracle's implementation of a compiler for the Java programming language prior to Java SE 6, the ret instruction was used with the jsr and jsr_w instructions (§jsr, §jsr_w) in the implementation of the finally clause (§3.13, §4.10.2.5).

The ret instruction should not be confused with the return instruction (§return). A return instruction returns control from a method to its invoker, without passing any value back to the invoker.

The ret opcode can be used in conjunction with the wide instruction (§wide) to access a local variable using a two-byte unsigned index.