Understanding of slot in jvm

Understanding of slot in jvm

  • The storage of parameter values ​​always starts at index0 of the local variable array and ends at the index of array length-1.
  • Local variable table, the most basic storage unit is slot (variable slot)
  • The local variable table stores various basic data types (8 types), reference types (reference), and returnAddress type variables that can be known at compile time.
  • In the local variable table, the 32-bit type only occupies one slot (including the returnAddress type), and the 64-bit type (long and double) occupies two slots.
    • Byte, short, char are converted to int before storage, boolean is also converted to int, 0 means false, and non-zero means true.
    • Long and double occupy two slots.
  • JVM will assign an access index to each slot in the local variable table, through this index, you can successfully access the local variable value specified in the local variable table
  • When an instance method is called, its method parameters and local variables defined in the method body will be copied to each slot in the local variable table in order
  • If you need to access a 64-bit local variable value in the local variable table, you only need to use the previous index . (For example: access long or double type variables)
  • If the current frame is created by the constructor or instance method, the object reference this will be stored in the slot with index 0 , and the remaining parameters will continue to be arranged in the order of the parameter list.

Insert picture description here

The code is demonstrated as follows:

package com.lbl.LocalVariables;

import java.util.Date;

public class LocalVariablesSoltTest {
    
    
    int count = 0;

    //关于slot的使用理解
    public void test01() {
    
    
        count = 1;
    }

    //this在index0处
    public void test02(){
    
    
        Date date = new Date();
        String s="lbl";
        System.out.println(s+date);
    }

    //double占两个slot
    public void test03(){
    
    
        Date date = new Date();
        double d=2.3;
        String s="lbl";
        System.out.println(s+date);
    }

}

Illustration:

test01:

Insert picture description here

test02:

Insert picture description here

test03:

Insert picture description here

Guess you like

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