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 | public class LocalVariableDemo { |
And we compile this file into class file and then disassemble the class file:
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.