JVM local variable table (Local Variables)

JVM local variable table (Local Variables)

  • Local variable table is also called local variable array or local variable table
  • Defined as a numeric array, mainly used to store method parameters and local variables defined in the method body . These data types include various basic data types, object references, and returnAddress types.
  • Since the local variable table is built on the thread’s stack and is the thread’s private data, there is no data security problem
  • The required capacity of the local variable table is determined during the compile time and saved in the maximum local variables data item of the Code attribute of the method. The size of the local variable table is not changed during the running of the method.
  • **The number of nested method calls is determined by the size of the stack. ** Generally speaking, ** the larger the stack, the more nested method calls. **For a function, the more parameters and local variables it has, the larger the local variable table will be, and the larger its stack frame will be, so as to meet the needs of increasing the information passed by the method call. In turn, function calls will occupy more stack space, resulting in fewer nested calls.
  • The variables in the local variable table are only valid in the current method call . When the method is executed, the virtual machine completes the transfer process of parameter values ​​to the parameter variable list by using the local variable table. When the method call ends, the local variable table will be destroyed as the method stack frame is destroyed.

The code demonstration case is as follows:

package com.lbl.LocalVariables;

public class LocalVariablesTest {
    
    
    private int count=0;

    public static void main(String[] args) {
    
    
        LocalVariablesTest test = new LocalVariablesTest();
        int num=10;
        test.test1();
    }

    public void test1(){
    
    
        System.out.println("test1....run");
    }
}

The Maximum local variables can be seen by jclasslib in IDEA:

Insert picture description here

Insert picture description here

Guess you like

Origin blog.csdn.net/qq_37924905/article/details/108740436