Symbolic references in Java
I've been playing java reflection and reflection these days Class format I'm learning the LDC command
In the JVM specification, I find that I don't understand the term: symbolic reference. I have the following problems
What does that mean? > Where does it work? > In which case does the LDC instruction load symbol references? > Is there any code corresponding to this action in Java?
Solution
It will be helpful if you quote some articles that cause you trouble Since you don't, I'll guess what you may quote from the LDC document:
This reference has a link to another part of the JVM specification (5.1), which describes the runtime constant pool:
This means that the runtime constant pool contains some information about the symbolic form of the class: as a text value
Therefore, when LDC gives a "symbolic reference" to a class, it is given constant in the constant pool_ Class_ Index of info structure If you look at the definition of this structure, you will see that it contains a reference to the class name and is also saved in the constant pool
TL; Dr: a symbolic reference is a string that can be used to retrieve an actual object
An example:
if (obj.getClass() == String.class) { // do something }
Become the following bytecode:
aload_1 invokevirtual #21; //Method java/lang/Object.getClass:()Ljava/lang/Class; ldc #25; //class java/lang/String if_acmpne 20
In this case, the LDC operation refers to a class stored in symbolic form When the JVM executes this opcode, it will use a symbolic reference to identify the actual class in the current class loader and return a reference to the class instance