代码改变世界

Java字节码

2020-08-17 17:51  Tony、  阅读(168)  评论(0编辑  收藏  举报
package com.my;

public interface IMy01 {
    int say01();
}
package com.my;

public interface IMy02 {
    String say02();
}
package com.my;

/**
 * Hello world!
 */
public class App04 implements IMy01, IMy02 {
    private int id;
    private int age;

    public void func() {
    }

    public void func2() {
    }

    @Override
    public int say01() {
        return 0;
    }

    @Override
    public String say02() {
        return "say02";
    }
}

两个插件

 

 

最终生成的字节码

CA FE BA BE 00 00 00 34 00 1E 0A 00 04 00 19 08 
00 15 07 00 1A 07 00 1B 07 00 1C 07 00 1D 01 00 
02 69 64 01 00 01 49 01 00 03 61 67 65 01 00 06 
3C 69 6E 69 74 3E 01 00 03 28 29 56 01 00 04 43 
6F 64 65 01 00 0F 4C 69 6E 65 4E 75 6D 62 65 72 
54 61 62 6C 65 01 00 12 4C 6F 63 61 6C 56 61 72 
69 61 62 6C 65 54 61 62 6C 65 01 00 04 74 68 69 
73 01 00 0E 4C 63 6F 6D 2F 6D 79 2F 41 70 70 30 
34 3B 01 00 04 66 75 6E 63 01 00 05 66 75 6E 63 
32 01 00 05 73 61 79 30 31 01 00 03 28 29 49 01 
00 05 73 61 79 30 32 01 00 14 28 29 4C 6A 61 76 
61 2F 6C 61 6E 67 2F 53 74 72 69 6E 67 3B 01 00 
0A 53 6F 75 72 63 65 46 69 6C 65 01 00 0A 41 70 
70 30 34 2E 6A 61 76 61 0C 00 0A 00 0B 01 00 0C 
63 6F 6D 2F 6D 79 2F 41 70 70 30 34 01 00 10 6A 
61 76 61 2F 6C 61 6E 67 2F 4F 62 6A 65 63 74 01 
00 0C 63 6F 6D 2F 6D 79 2F 49 4D 79 30 31 01 00 
0C 63 6F 6D 2F 6D 79 2F 49 4D 79 30 32 00 21 00 
03 00 04 00 02 00 05 00 06 00 02 00 02 00 07 00 
08 00 00 00 02 00 09 00 08 00 00 00 05 00 01 00 
0A 00 0B 00 01 00 0C 00 00 00 2F 00 01 00 01 00 
00 00 05 2A B7 00 01 B1 00 00 00 02 00 0D 00 00 
00 06 00 01 00 00 00 06 00 0E 00 00 00 0C 00 01 
00 00 00 05 00 0F 00 10 00 00 00 01 00 11 00 0B 
00 01 00 0C 00 00 00 2B 00 00 00 01 00 00 00 01 
B1 00 00 00 02 00 0D 00 00 00 06 00 01 00 00 00 
0B 00 0E 00 00 00 0C 00 01 00 00 00 01 00 0F 00 
10 00 00 00 01 00 12 00 0B 00 01 00 0C 00 00 00 
2B 00 00 00 01 00 00 00 01 B1 00 00 00 02 00 0D 
00 00 00 06 00 01 00 00 00 0E 00 0E 00 00 00 0C 
00 01 00 00 00 01 00 0F 00 10 00 00 00 01 00 13 
00 14 00 01 00 0C 00 00 00 2C 00 01 00 01 00 00 
00 02 03 AC 00 00 00 02 00 0D 00 00 00 06 00 01 
00 00 00 12 00 0E 00 00 00 0C 00 01 00 00 00 02 
00 0F 00 10 00 00 00 01 00 15 00 16 00 01 00 0C 
00 00 00 2D 00 01 00 01 00 00 00 03 12 02 B0 00 
00 00 02 00 0D 00 00 00 06 00 01 00 00 00 17 00 
0E 00 00 00 0C 00 01 00 00 00 03 00 0F 00 10 00 
00 00 01 00 17 00 00 00 02 00 18

字节码解读

 

 

 

字节码存储数据的顺序

magic 魔术 4u
minor_version 小版本 2u
major_version 大版本 2u
constant_pool_count 常量池数量 2u
constant_pool 常量池  不确定,通过计算获得
AccessFlags 2u
this_Class 2u
super_calss 2u
interfaces_count 2u
interfaces 不确定,通过计算获得
fields_count 2u
fields 不确定,通过计算获得
methods_count 2u
method_info 不确定,通过计算获得
attribute_count 2u
attribute

字节码常量池的数据类型的结构表

 

 

 上面的表中描述了11中数据类型的结构,其实在jdk1.7之后又增加了3种(CONSTANT_MethodHandle_info,CONSTANT_MethodType_info以及CONSTANT_InvokeDynamic_info)。这样算起来一共是14种。