Search code examples
javajvmbytecodejvm-bytecode

What does `at ReturnAddress` mean in JVM?


I'm reading JVMS, §2 The Structure of The Java Virtual Machine.

2.3.3. The returnAddress Type and Values

I have some questions here. What is the returnAddress?

Is returnAddress the address of the previous frame?

Can anyone explain that briefly?

The returnAddress type is used by the Java Virtual Machine's jsr, ret, and jsr_w instructions (§jsr, §ret, §jsr_w)

I saw that returnAddress was instructed jsr,jsr_w,ret using (finally statement for Java), starting from JDK7 virtual machine is not allowed to appear these several instructions (jsr.. ), so does it still have a point of existence?


Solution

  • Is returnAddress the address of the previous frame?

    No, the returnAddress is a position in the current bytecode containing the jsr or jsr_w and ret instructions.

    As the documentation of these instructions describes, it is used to represent the bytecode location right after the jsr or jsr_w instruction, to allow ret to resume at that location.

    I saw that returnAddress was instructed jsr,jsr_w,ret using (finally statement for Java), starting from JDK7 virtual machine is not allowed to appear these several instructions …, so does he still have a point of existence?

    In Java classes with a version of 51 or higher, these instructions may not appear, hence, the code may never deal with values of type returnAddress. Related to this, StackMapTable attributes have no way to denote the type returnAddress.

    Still, as long as JVMs are backward compatible to older class files, returnAddress is a thing.