CA FE BA BE # magic
00 00 # minor-version
00 34 # major-version 52-jdk8
00 16 # constant_pool_count 常量池个数 22
---- 常量池
#01
0A 十进制10 CONSTANT_Methodref_info tag u2
00 04 #04 u2
00 12 #18 u2
#02
09 CONSTANT_Fieldref_info tag u2
00 03 #03 u2
00 13 #19 u2
#03
07 CONSTANT_Class_info tag u2
00 14 #20 u2
#04
07 CONSTANT_Class_info tag u2
00 15 #21 u2
#05
01 CONSTANT_Uft8_info tag u2
00 01 #utf8 字符串占用字节数 当前为1 u2
6D #当前字节值 m
#06
01 CONSTANT_Uft8_info tag u2
00 01 #utf8 字符串占用字节数 当前为1 u2
49 #当前值 I
#07
01 CONSTANT_Uft8_info tag u2
00 06 #utf8 字符串占用字节数 当前为6 u2
3C 69 6E 69 74 3E #当前值 <init>
#08
01 CONSTANT_Uft8_info tag u2
00 03 utf8 #字符串占用字节数 当前为3 u2
28 29 56 #当前值 ()V
#09
01 CONSTANT_Uft8_info tag u2
00 04 #utf8 字符串占用字节数 当前为4 u2
43 6F 64 65 #当前值为Code
#10
01 CONSTANT_Uft8_info tag u2
00 0F #utf8 字符串占用字节数 当前为15 u2
4C 69 6E 65 4E 75 6D 62 65 72 54 61 62 6C 65 #当前值为 LineNumberTable
#11
01 CONSTANT_Uft8_info tag u2
00 12 #utf8 字符串占用字节数 当前为18 u2
4C 6F 63 61 6C 56 61 72 69 61 62 6C 65 54 61 62 6C 65 #值:LocalVeriableTable
#12
01 CONSTANT_Uft8_info tag u2
00 04 #长度:4, u2
74 68 69 73 #值: this
#13
01 CONSTANT_Uft8_info tag u2
00 0B #值:11 u2
4C 54 65 73 74 43 6C 61 73 73 3B #值:LTestClass
#14
01 CONSTANT_Uft8_info tag u2
00 03 #值为3 u2
69 6E 63 #值: inc
#15
01 CONSTANT_Uft8_info tag u2
00 03 #值为3 u2
28 29 49 #值 ()I
#16
01 CONSTANT_Uft8_info tag u2
00 0A #值:10 u2
53 6F 75 72 63 65 46 69 6C 65 值:SourceFile
#17
01 CONSTANT_Uft8_info tag u2
00 0E #值:14 u2
54 65 73 74 43 6C 61 73 73 2E 6A 61 76 61 #TestClass.java
#18
0C CONSTANT_NameAndType_info tag u2
00 07 #07
00 08 #08
#19
0C CONSTANT_NameAndType_info tag u2
00 05 #05
00 06 #06
#20
01 CONSTANT_Uft8_info tag u2
00 09 #长度:9
54 65 73 74 43 6C 61 73 73 #值:TestClass
#21
01 CONSTANT_Uft8_info tag u2
00 10 #长度16
6A 61 76 61 2F 6C 61 6E 67 2F 4F 62 6A 65 63 74 #值 java/lang/Object
----
#access_flags
00 21 #表示公有的类 允许invokespecial字节码指令
# this class 指向 #03 TestClass
00 03
# super class 指向04 java/lang/Object
00 04
# interface_count 0 u2
00 00
#fields_count 1 u2
00 01
---- fields
00 02 #access_flag private
00 05 #name_index #05 m
00 06 #descriptor_index #06 I 表示int
00 00 #attributes_count 0
# methods_count 2
00 02
---- methods
#method[0]
00 01 #access_flag public
00 07 #name_index #07 <init> 表示构造方法
00 08 #descriptor_index 08 ()V 返回值为void
00 01 #attributes_count 1
00 09 #09 Code
00 00 00 2F #attribute length 47
00 01 #max_stack 1 操作该方法栈深度不操作 1
00 01 #max_locals 局部变量表需要的存储空间 1
00 00 00 05 # code_length 字节码指令长度
2A B7 00 01 B1 #2A aload_0 将第一个引用类型本地变量推送至栈顶 B7 invokespecial 调用超类构造方法, 实例初始化方法,私有方法 ,指向 #1的变量 java/lang/Object <init> (),V B1 return 从当前方法返回void
00 00 #exception_table_length 需要处理的异常
00 02 # 属性数量
---- 属性1
00 0A #10 常量 LineTableNumber
00 00 00 06 # 属性长度为6
00 01 # lineTableInfo长度 1
00 00 # 字节码行号
00 01 # 源代码行号 1
---- 属性2
00 0B #11 常量 LocalVeriableTable
00 00 00 0C # 属性长度 12
00 01 #LocalVeriableTable 长度
00 00 #局部变量生命周期开始偏移量
00 05 # 局部变量的生命周期开始的作用范围覆盖长度 5
00 0C #name_index #12 this
00 0D #descriptor_index 13
00 00 #局部变量在栈帧局部变量表中Slot的位置
#method[1]
00 01 #access_flag public
00 0E #name_index #14 inc
00 0F #descriptor_index #15 ()I
00 01 #attributes_count 1
00 09 #09 Code
00 00 00 31 #attribute length 49
00 02 # max_stack 2 最大栈深度为 2
00 01 # max_locals 局部变量表需要的存储空间 1
00 00 00 07 #字节码指令长度 7
2A B4 00 02 04 60 AC # 2A aload_0 b4 getfield 获取指定类的实例域,并将其值压入栈顶 #0002 TestClass.m.I iconst_1 将1推到栈顶 #60 iadd 两个int相加压入栈顶 #AC ireturn 返回int型
00 00 #exception_table_length 需处理异常数
00 02 #属性数量
---- 属性1
00 0A # LineNumberTable
00 00 00 06 #属性长度为6
00 01 #lineTableInfo 1
00 00 # 字节码行号
00 04 #源代码行号 04
00 0B #11 常量 LocalVeriableTable
00 00 00 0C # 属性长度 12
00 01 #LocalVeriableTable 长度
00 00 # 属性生命周期开始偏移量
00 07 # 局部变量的生命周期开始的作用范围覆盖长度 7
00 0C #name_index #12 this
00 0D #descriptor_index #13 值:LTestClass
00 00 #局部变量在栈帧局部变量表中Slot的位置
# 属性
00 01
00 10 #16 SourceFile
00 00 00 02 #attribute_length 2
00 11 #值为:TestClass.java
一个简单的class文件分析
于 2024-02-19 16:39:25 首次发布
![](https://img-home.csdnimg.cn/images/20240611030827.png)