-1

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?

Holger
  • 285,553
  • 42
  • 434
  • 765
user9214779
  • 309
  • 2
  • 8
  • 2
    Why are you linking to section 2.11.8? Is that relevant for your question? – Erwin Bolwidt Sep 02 '19 at 08:15
  • 1
    Section 2.3.3 (that you refer to with its heading) has a description of the `returnAddress` type. What is it that you don't understand about it? "The returnAddress type is used by the Java Virtual Machine's jsr, ret, and jsr_w instructions (§jsr, §ret, §jsr_w). The values of the returnAddress type are pointers to the opcodes of Java Virtual Machine instructions. Unlike the numeric primitive types, the returnAddress type does not correspond to any Java programming language type and cannot be modified by the running program." – Erwin Bolwidt Sep 02 '19 at 08:16
  • See also: [What Java compilers use the jsr instruction, and what for?](https://stackoverflow.com/questions/21150154/what-java-compilers-use-the-jsr-instruction-and-what-for) – Erwin Bolwidt Sep 02 '19 at 08:21
  • @ErwinBolwidt I'm sorry,i changed it now. – user9214779 Sep 02 '19 at 08:26
  • @ErwinBolwidt I added some information about my question – user9214779 Sep 02 '19 at 08:31

1 Answers1

4

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.

Community
  • 1
  • 1
Holger
  • 285,553
  • 42
  • 434
  • 765
  • Thank a lots。 You mentioned that if it makes sense for backward compatibility。 then in other words,If our bytecode versions are all 1.7 +, then the `returnADDRESS` is useless, right? – user9214779 Dec 09 '19 at 03:54
  • 1
    Correct, for bytecode targeting Java 7+, there will be no use of the returnaddress type. – Holger Dec 09 '19 at 09:19