深入理解JVM(四)
第6章 类文件结构
1. 任何一个Class文件都对应唯一一个类或者接口。但反之不一定成立。(类和接口也可以通过类加载器直接生成)。
2.Class中文件字节序为大端。(大端:高低低高)(Intel的x86是小端)
3.每个Class文件开头4个字节叫魔数,Class是0xCAFEBABE。(恶心心。 话说当年看廖雪峰讲Win创建txt开头的4个东西估计也是这个。
4.Class文件格式
类型 | 名称 | 数量 |
---|---|---|
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 | attribute_count | 1 |
attribute_info | attributes | attributes_count |
5.常量池
a) 字面量:String final变量
b) 符号引用:类和接口的全限定名, 字段的名称和描述符,方法的名称和描述符
6.Java程序如果定义了超过64KB英文字符的变量或方法名,将会无法编译。
第6章 类文件结构
1. 任何一个Class文件都对应唯一一个类或者接口。但反之不一定成立。(类和接口也可以通过类加载器直接生成)。
2.Class中文件字节序为大端。(大端:高低低高)(Intel的x86是小端)
3.每个Class文件开头4个字节叫魔数,Class是0xCAFEBABE。(恶心心。 话说当年看廖雪峰讲Win创建txt开头的4个东西估计也是这个。
4.Class文件格式
类型 | 名称 | 数量 |
---|---|---|
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 | attribute_count | 1 |
attribute_info | attributes | attributes_count |
5.常量池
a) 字面量:String final变量
b) 符号引用:类和接口的全限定名, 字段的名称和描述符,方法的名称和描述符