Symbolic reference and direct reference of java virtual machine

  In java, a java class will be compiled into a class file. At compile time, the java class does not know the actual memory address of the referenced class, so it can only use symbolic references instead. For example, the org.simple.People class refers to the org.simple.Tool class. The People class does not know the actual memory address of the Tool class at compile time, so it can only use the symbol org.simple.Tool (hypothetical) to represent the address of the Tool class. When the class loader loads the People class, the actual memory address of the Tool class can be obtained through the virtual machine, so the symbol org.simple.Tool can be replaced with the actual memory address of the Tool class, and the address can be directly referenced.

Summary: The JVM handles direct references and symbolic references differently. You can see that when a symbolic reference is used, the JVM will use StringBuilder to complete the addition of strings, and when a direct reference is made, it will use String directly; direct references are always better than symbols. The reference efficiency is faster, but it is impossible to use all direct references in practical application development. To improve the performance, you can consider writing your program according to the thinking of a virtual machine.

1.0 Direct quote:

public class StringAndStringBuilder{
   public static void main(String[] args){    
       System.out.println ("s=" + "asdfa");
   }
}

2.0 Symbolic references:

public class StringAndStringBuilder{
   public static void main(String[] args){    
      String s="asdfa";
        System.out.println ("s=" + s);
   }
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326153771&siteId=291194637