Basic Knowledge Points and Examples of java Local Variable Table

  • 2021-10-11 18:37:07
  • OfStack

Description

1. Local variable table is also called local variable array or local variable table. It is defined as an array, which is mainly used to store method parameters and define local variables in methods. These data types include various basic data types, object references and returnAddress types.

2. Because the local variable table is the thread private data built on the thread stack, there is no data security problem.

Instances


private static int count=0;
public static void recursion(int a,int b,int c){
long l1=12;
short sl=1;
byte b1=1;
String s="1";
System.out.println("count="+count);
count++;
recursion(1,2,3);
}
public static void recursion(){
System.out.println("count="+count);
count++;
recursion();
}

Expansion of basic knowledge points:

The local variable table (Local Variable Table) is a set of variable value storage spaces for storing method parameters and local variables defined inside the method. When the Java program is compiled into an Class file, the maximum capacity of the list of local variables that the method needs to allocate is determined in the max_locals data entry of the Code property of the method.

The capacity of the local variable table is divided into variable slots (Variable Slot, Hereinafter referred to as Slot) is the smallest unit, The virtual machine specification does not specify the memory space that an Slot should occupy. It's just very guiding to say that each Slot should be able to store one data of boolean, byte, char, short, int, float, reference or returnAddress type. These eight data types can be stored in 32 bits or less of physical memory, but this description is somewhat different from explicitly stating that "each Slot occupies 32 bits of memory space", which allows the length of Slot to vary with different processors, operating systems or virtual machines. As long as you ensure that even if you use 64-bit physical memory space to implement an Slot in a 64-bit virtual machine, the virtual machine still needs to use alignment and padding to make Slot look the same as 1 in a 32-bit virtual machine.


Related articles: