Constant pool resolution of class file

Definition:

  • Literal quantity and reference: in the class file, all symbol values (which should be interpreted from the perspective of compilation principle) are not pure field variable values.

    • For example: private final int a = 10; (constant: variable name a, integer:10)

      • #28 = NameAndType #10:#11
      • #10 = Utf8 a
      • #11 = Utf8 I
    • The symbol in compilation principle, which is used for existing symbols and symbols that may be externally referenced in the file runtime

      • Fully qualified name of class and interface
      • Name and descriptor of the field
      • Method name and descriptor
      • Field value of final tag

View command

javap: decompile and view. class file
Usage: javap < Options > < classes >

Possible options include:

  -Help -- help -? Output this usage message

  -Version version information

  -V - verbose output additional information

  -l output line number and local variable table

  -Public shows only public classes and members

  -Protected shows protected / public classes and members

  -package shows packages / protected / public classes and members (default)

  -P - private shows all classes and members

  -c disassembly of code

  -s output internal type signature

  -sysinfo displays the system information of the class being processed (path, size, date, MD5 hash)

  -constants shows the final constant

  -Classpath < Path > specifies where to find user class files

  -CP < Path > specifies where to find user class files

  -Bootclasspath < Path > overwrites the location of the boot class file

case

.java file
package com.fxl.fight2.service;

public class ClassTest {

	private final int a = 11;
	private int b = 11;
	private int c = 10;
	private UserDto u1 = new UserDto();
}


Javap-v decompile file
Classfile /C:/Users/ssHss/Desktop/JVM/class/ClassTest.class
  Last modified 2018-3-3; size 541 bytes
  MD5 checksum ba4f2da1b37c1def6459f2639e6a8a7f
  Compiled from "ClassTest.java"
public class com.fxl.fight2.service.ClassTest
  minor version: 0  "Sub version number"
  major version: 51 "Main version number"
  flags: ACC_PUBLIC, ACC_SUPER
Constant pool:  "Constant pool"
   "index" = "type"        "value(Data value,index Size)"   "annotation"
   #1 = Methodref          #9.#27         // java/lang/Object."<init>":()V
   #2 = Fieldref           #8.#28         // com/fxl/fight2/service/ClassTest.a:I
   #3 = Fieldref           #8.#29         // com/fxl/fight2/service/ClassTest.b:I
   #4 = Fieldref           #8.#30         // com/fxl/fight2/service/ClassTest.c:I
   #5 = Class              #31            // com/fxl/fight2/service/UserDto
   #6 = Methodref          #5.#27         // com/fxl/fight2/service/UserDto."<init>":()V
   #7 = Fieldref           #8.#32         // com/fxl/fight2/service/ClassTest.u1:Lcom/fxl/fight2/service/UserDto;
   #8 = Class              #33            // com/fxl/fight2/service/ClassTest
   #9 = Class              #34            // java/lang/Object
  #10 = Utf8               a
  #11 = Utf8               I
  #12 = Utf8               ConstantValue
  #13 = Integer            11
  #14 = Utf8               b
  #15 = Utf8               c
  #16 = Utf8               u1
  #17 = Utf8               Lcom/fxl/fight2/service/UserDto;

  #18 = utf8 < init > ". Class file initialization required characters"
  #19 = utf8() V ". Class file initialization required characters"
  
  #20 = Utf8               Code
  #21 = Utf8               LineNumberTable
  #22 = Utf8               LocalVariableTable
  #23 = Utf8               this
  #24 = Utf8               Lcom/fxl/fight2/service/ClassTest;
  #25 = Utf8               SourceFile
  #26 = Utf8               ClassTest.java
  
  #27 = NameAndType        #18:#19 / / "< init >": () V "initial"
  #28 = NameAndType        #10:#11        // a:I
  #29 = NameAndType        #14:#11        // b:I
  #30 = NameAndType        #15:#11        // c:I
  
  #31 = utf8 com/fxl/fight2/service/UserDto "index = 31: store string content: com/fxl/fight2/service/UserDto"
  #32 = NameAndType        #16:#17        // u1:Lcom/fxl/fight2/service/UserDto;
  #33 = utf8 com/fxl/fight2/service/ClassTest "index = 33: store string content: com/fxl/fight2/service/ClassTest"
  #34 = utf8 Java / Lang / object "index = 34: store string content: com/fxl/fight2/service/Object"
  "instructions"
{
  public com.fxl.fight2.service.ClassTest();
    descriptor: ()V
    flags: ACC_PUBLIC
    Code:
      stack=3, locals=1, args_size=1
         0: aload_0
         1: invokespecial #1                  // Method java/lang/Object."<init>":()V
         
         4: aload_0
         5: bipush        11    "cover final Embellishment, directly expressed in 11"
         7: putfield      #2                  // Field a:I
         
        10: aload_0
        11: bipush        11        "Not being final Decorated, but static Embellishment, directly expressed in 11"
        13: putfield      #3                  // Field b:I
        
        16: aload_0
        17: bipush        10    "It's not decorated. It's expressed in 11"
        19: putfield      #4                  // Field c:I
        
        22: aload_0
        23: new           #5                  // class com/fxl/fight2/service/UserDto
        26: dup
        27: invokespecial #6                  // Method com/fxl/fight2/service/UserDto."<init>":()V
        30: putfield      #7                  // Field u1:Lcom/fxl/fight2/service/UserDto;
        
        33: return
        
      LineNumberTable:
        line 3: 0
        line 5: 4
        line 6: 10
        line 7: 16
        line 8: 22
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
            0      34     0  this   Lcom/fxl/fight2/service/ClassTest;
}
SourceFile: "ClassTest.java"

Tags: Java jvm

Posted on Tue, 31 Mar 2020 01:08:56 -0700 by Plex