JVM实探-class文件格式(2)

本贴主要详解field_info结构和attribute_info,而attribute_info在后续的menthod_info也有涉及。

11、字段表

fields[],描述当前类或接口声明的所有字段,但不包括从父类或父接口继承的部分。field_info接口如下:

field_info {
    u2 access_flags;   #定义字段被访问权限和基础属性的掩码标志
    u2 name_index;     #对应常量池索引值所属的项为CONSTANT_Utf8_info结构
    u2 descriptor_index; #对应常量池索引值所属的项为CONSTANT_Utf8_info结构
    u2 attributes_count;  #表示当前字段的附加属性的数量
    attribute_info attributes[attributes_count]; #attribute结构
}

其中,attribute_info结构为

attribute_info {
    u2 attribute_name_index;
    u4 attribute_length;
    u1 info[attribute_length];
}

同一个Class文件中不会有两个字段(field)同时具有相同的字段名和描述符。

属性(Attributes)在Class文件格式中的ClassFile结构、field_info结构,method_info结构和Code_attribute结构中都有使用。

任意属性对常量池的索引项必须是CONSTANT_Class_info结构,表示当前属性的名字,attribute_length项的值给出了跟随其后的字节的长度,有些属性因Class文件格式规范所需,已被预先定义好,如下表格,详细属性名的介绍参考:属性名详解

属性名Java SEClass 文件
ConstantValue1.0.245.3
Code1.0.245.3
StackMapTable650.0
Exceptions1.0.245.3
InnerClasses1.145.3
EnclosingMethod5.049.0
Synthetic1.145.3
Signature5.049.0
SourceFile1.0.245.3
SourceDebugExtension5.049.0
LineNumberTable1.0.245.3
LocalVariableTable1.0.245.3
LocalVariableTypeTable5.049.0
Deprecated1.145.3
RuntimeVisibleAnnotations5.049.0
RuntimeInvisibleAnnotations5.049.0
RuntimeVisibleParameterAnnotations5.049.0
RuntimeInvisibleParameterAnnotations5.049.0
AnnotationDefault5.049.0
BootstrapMethods751.0

12、方法计数器

methods_count,表示当前class文件methods[]数组的成员个数,每一项都是method_info结构。

13、方法表

methods[],表示当前类或接口中某方法的完整描述,如果method_info的access_flag项既没有设置ACC_NATIVE标志也没有设置ACC_ABSTRACT标志,那么它对应的方法体就应当可以被java虚拟机直接从当前类加载,而不需要引用其他类。只描述当前类或接口中声明的方法,不包括父类或父接口继承的方法。

14、属性计数器

attributes_count,表示attributes表的成员个数,每一项都是attribute_info结构。

15、属性表

attributes[],在JAVA SE7中,Class文件结构中的attributes表的项包含下列定义的属性。

InnerClasses、EnclosingMethod、Synthetic、Signature、SourceFile、SourceDebugExtension、Deprecated、RuntimeVisibleAnnotations、RuntimeInvisibleAnnotations、BootstrapMethods。对于支持Class文件格式版本号为49.0或更高的java虚拟机实现,必须正确识别并读取attributes表中的Signature、RuntimeVisibleAnnotations和RuntimeInvisibleAnnotations属性。对于51.0或更高的java虚拟机实现,必须正确识别并读取BootstrapMethods属性。
 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值