Local Variable Array in JVM stack

Local Variable Array in JVM stack

Unlike static method, for non-static method the first local varaible is always this. For example, here is a piece of code:

1
2
3
4
5
6
7
8
9
10
11
public class LocalVariableDemo {

public static void staticFoo() {
int i = 1;
}

public void foo() {
int i = 1;
}

}

And we compile this file into class file and then disassemble the class file:

local_variable_array

As shown, in the static method staticFoo, JVM stores the constant 1 into local varaible array at index 0, while in the non-static method foo, it stores at index 1. The value at index 0 is this, which means this foo method belongs to one certain instance.