Class类文件结构
Class文件是一组以8位字节为基础单位的二进制流,各个数据项严格按照顺序紧凑地排列在Class文件之中,中间没有添加任何分隔符。Class文件格式采用一种类似于语言结构体的伪结构来存储数据,这种伪结构中只有两种数据类型:无符号数(u)和表(_info)。
组成
类型 | 名称 | 说明 | 数量 |
---|---|---|---|
u4 | magic | 魔数 | 1 |
u2 | minor_version | 次版本号 | 1 |
u2 | major_version | 主版本号 | 1 |
u2 | constant_pool_count | 常量池容量计数器 | 1 |
cp_info | constant_pool | 常量池 | constant_pool_count-1 |
u2 | access_flags | 访问标志 | 1 |
u2 | this_class | 类索引 | 1 |
u2 | super_class | 父类索引 | 1 |
u2 | interfaces_count | 接口个数计数器 | 1 |
u2 | interfaces | 接口集合 | interfaces_count |
u2 | fields_count | 字段个数计数器 | 1 |
field_info | fields | 字段集合 | fields_count |
u2 | methods_count | 方法个数计数器 | 1 |
method_info | methods | 方法集合 | methods_count |
u2 | attributes_count | 属性个数计数器 | 1 |
attribute_info | attributes | 属性集合 | attributes_count |