Contents | Prev | Next | IndexThe JavaTM Virtual Machine Specification


A B C D F G I J L M N P R S T W

ret

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 (§3.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

The ret instruction is used with jsr or jsr_w instructions in the implementation of the finally clauses of the Java programming language (see Section 7.13, "Compiling finally"). Note that jsr pushes the address onto the operand stack and ret gets it out of a local variable. This asymmetry is intentional.

The ret instruction should not be confused with the return instruction. 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 to access a local variable using a two-byte unsigned index.


return

Operation

Return void from method

Format

return

Forms

return = 177 (0xb1)

Operand Stack

... [empty]

Description

The current method must have return type void. If the current method is a synchronized method, the monitor acquired or reentered on invocation of the method is released or exited (respectively) as if by execution of a monitorexit instruction. If no exception is thrown, any values on the operand stack of the current frame (§3.6) are discarded.

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

Runtime Exceptions

If the current method is a synchronized method and the current thread is not the owner of the monitor acquired or reentered on invocation of the method, return 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 virtual machine implementation enforces the rules on structured use of locks described in Section 8.13 and if the first of those rules is violated during invocation of the current method, then return throws an IllegalMonitorStateException.


Contents | Prev | Next | Index

The JavaTM Virtual Machine Specification
Copyright © 1999 Sun Microsystems, Inc. All rights reserved
Please send any comments or corrections to jvm@java.sun.com