attribute_info attributes[attributes_count];表示的是当前class文件的所有属性,attribute_info是一个非常复杂的数据结构,存储着各种属性信息。
attribute_info数据结构:
attribute_info {u2 attribute_name_index;u4 attribute_length;u1 info[attribute_length];}
u2 attribute_name_index;表示的是属性名称索引,读取attribute_name_index值所在常量池中的名称可以得到属性名称。
Java15属性表:
| 属性名称 | 章节 |
|---|---|
| ConstantValue Attribute | §4.7.2 |
| Code Attribute | §4.7.3 |
| StackMapTable Attribute | §4.7.4 |
| Exceptions Attribute | §4.7.5 |
| InnerClasses Attribute | §4.7.6 |
| EnclosingMethod Attribute | §4.7.7 |
| Synthetic Attribute | §4.7.8 |
| Signature Attribute | §4.7.9 |
| SourceFile Attribute | §4.7.10 |
| SourceDebugExtension Attribute | §4.7.11 |
| LineNumberTable Attribute | §4.7.12 |
| LocalVariableTable Attribute | §4.7.13 |
| LocalVariableTypeTable Attribute | §4.7.14 |
| Deprecated Attribute | §4.7.15 |
| RuntimeVisibleAnnotations Attribute | §4.7.16 |
|---|---|
| RuntimeInvisibleAnnotations Attribute | §4.7.17 |
| RuntimeVisibleParameterAnnotations Attribute | §4.7.18 |
| RuntimeInvisibleParameterAnnotations Attribute | §4.7.19 |
| RuntimeVisibleTypeAnnotations Attribute | §4.7.20 |
| RuntimeInvisibleTypeAnnotations Attribute | §4.7.21 |
| AnnotationDefault Attribute | §4.7.22 |
| BootstrapMethods Attribute | §4.7.23 |
| MethodParameters Attribute | §4.7.24 |
| Module Attribute | §4.7.25 |
| ModulePackages Attribute | §4.7.26 |
| ModuleMainClass Attribute | §4.7.27 |
| NestHost Attribute | §4.7.28 |
| NestMembers Attribute | §4.7.29 |
属性对象
属性表是动态的,新的JDK版本可能会添加新的属性值。每一种属性的数据结构都不相同,所以读取到属性名称后还需要根据属性的类型解析不同属性表中的值。比如Code Attribute中存储了类方法的异常表、字节码指令集、属性信息等重要信息。
