Why does a reference in the JVM not take two stack slots

Viewed 36

Looking at the JVM 15 specification (first two sections here), I see that

  • reference, int, and float take only one local variable slot and one stack slot
  • long and double, take 2 slots

Everything in the spec points suggests a slot is 32-bits wide. If this is the case, how can a reference work when the JVM heap is very large? Isn't 32-bits just not enough to address potentially massive heaps? Even if the minimum size of a JVM object 16 bytes, 32-bits would run out of references around a ~70GB heap.


What I've "tried" checked

Just to check that above is still true on my locally installed 64-bit Java, here's a sample Java class, compiled with javac -target 8 me/alec/Tester.java

package me.alec;

public final class Tester {
  public void intArgMethod(int intArg) { }
  public void longArgMethod(long longArg) { }
  public void referenceArgMethod(Tester referenceArg) { }
}

Here's a snippet of the output from javap -v me.alec.Tester. Note that a the referenceArgMethod local size is the same as referenceIntMethod and less than referenceLongMethod (the extra +1 for all methods is due to the this reference argument).

  public void intArgMethod(int);
    descriptor: (I)V
    flags: ACC_PUBLIC
    Code:
      stack=0, locals=2, args_size=2
         0: return
      LineNumberTable:
        line 4: 0

  public void longArgMethod(long);
    descriptor: (J)V
    flags: ACC_PUBLIC
    Code:
      stack=0, locals=3, args_size=2
         0: return
      LineNumberTable:
        line 5: 0

  public void referenceArgMethod(me.alec.Tester);
    descriptor: (Lme/alec/Tester;)V
    flags: ACC_PUBLIC
    Code:
      stack=0, locals=2, args_size=2
         0: return
      LineNumberTable:
        line 6: 0
0 Answers
Related