HelloWorld字节码解析

HelloWorld字节码解析

源程序

package com.example.peggy.test;

public class HelloWorld {
    public static void main(String[] args) {
        System.out.println(" HelloWorld");
    }
}

字节码信息

E:\JavaCode\VueDome\target\classes\com\example\peggy\test>javap -v HelloWorld.class
    //类文件地址
Classfile /E:/JavaCode/VueDome/target/classes/com/example/peggy/test/HelloWorld.class
    //类文件最后一次修改的时间
  Last modified 2022-10-26; size 579 bytes
  MD5 checksum f812202db4a4098393c11989f340df9f
      //class 类文件编译的来源
  Compiled from "HelloWorld.java"
      //类的访问修饰符 报名 类名
public class com.example.peggy.test.HelloWorld
  minor version: 0
      //使用的是1.8版本 (52代表1.8)
  major version: 52
       //类的访问修饰符  父类
  flags: ACC_PUBLIC, ACC_SUPER
      //常量池地址
Constant pool:
   #1 = Methodref          #6.#20         // java/lang/Object."<init>":()V
   #2 = Fieldref           #21.#22        // java/lang/System.out:Ljava/io/PrintStream;
   #3 = String             #23            //  HelloWorld
   #4 = Methodref          #24.#25        // java/io/PrintStream.println:(Ljava/lang/String;)V
   #5 = Class              #26            // com/example/peggy/test/HelloWorld
   #6 = Class              #27            // java/lang/Object
   #7 = Utf8               <init>
   #8 = Utf8               ()V
   #9 = Utf8               Code
  #10 = Utf8               LineNumberTable
  #11 = Utf8               LocalVariableTable
  #12 = Utf8               this
  #13 = Utf8               Lcom/example/peggy/test/HelloWorld;
  #14 = Utf8               main
  #15 = Utf8               ([Ljava/lang/String;)V
  #16 = Utf8               args
  #17 = Utf8               [Ljava/lang/String;
  #18 = Utf8               SourceFile
  #19 = Utf8               HelloWorld.java
  #20 = NameAndType        #7:#8          // "<init>":()V
  #21 = Class              #28            // java/lang/System
  #22 = NameAndType        #29:#30        // out:Ljava/io/PrintStream;
  #23 = Utf8                HelloWorld
  #24 = Class              #31            // java/io/PrintStream
  #25 = NameAndType        #32:#33        // println:(Ljava/lang/String;)V
  #26 = Utf8               com/example/peggy/test/HelloWorld
  #27 = Utf8               java/lang/Object
  #28 = Utf8               java/lang/System
  #29 = Utf8               out
  #30 = Utf8               Ljava/io/PrintStream;
  #31 = Utf8               java/io/PrintStream
  #32 = Utf8               println
  #33 = Utf8               (Ljava/lang/String;)V
{
    //类的方法定义
    //构造方法
  public com.example.peggy.test.HelloWorld();
    descriptor: ()V
        //public类型方法
    flags: ACC_PUBLIC
    Code:
      stack=1, locals=1, args_size=1
         0: aload_0
         1: invokespecial #1                  // Method java/lang/Object."<init>":()V
         4: return
      LineNumberTable:
        line 3: 0
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
            0       5     0  this   Lcom/example/peggy/test/HelloWorld;
	//main方法            方法的参数类型
  public static void main(java.lang.String[]);
    descriptor: ([Ljava/lang/String;)V
    flags: ACC_PUBLIC, ACC_STATIC
      //虚拟机的指令
    Code:
      stack=2, locals=1, args_size=1
           /*
           #2 = Fieldref           #21.#22        // java/lang/System.out:Ljava/io/PrintStream;
           #21 = Class              #28            // java/lang/System
  		   #22 = NameAndType        #29:#30        // out:Ljava/io/PrintStream;
  		   
  		   #28 = Utf8               java/lang/System
           #29 = Utf8               out
           
           #30 = Utf8               Ljava/io/PrintStream;
           */
         0: getstatic     #2                  // Field java/lang/System.out:Ljava/io/PrintStream;
            /*
            #2 = Fieldref           #21.#22        // java/lang/System.out:Ljava/io/PrintStream;
            
            #21 = Class              #28            // java/lang/System
            #22 = NameAndType        #29:#30        // out:Ljava/io/PrintStream;
            
            #28 = Utf8               java/lang/System
  			#29 = Utf8               out
  			#30 = Utf8               Ljava/io/PrintStream;
            */
         3: ldc           #3                  // String  HelloWorld
            /*
            #3 = String             #23            //  HelloWorld
            #23 = Utf8                HelloWorld
            */
         5: invokevirtual #4                  // Method java/io/PrintStream.println:(Ljava/lang/String;)V
         8: return
      LineNumberTable:
        line 5: 0
        line 6: 8
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
            0       9     0  args   [Ljava/lang/String;
}
SourceFile: "HelloWorld.java"

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值