ClassFile { u4 magic; u2 minor_version; u2 major_version; u2 constant_pool_count; cp_info constant_pool[constant_pool_count-1]; u2 access_flags; u2 this_class; u2 super_class; u2 interfaces_count; u2 interfaces[interfaces_count]; u2 fields_count; field_info fields[fields_count]; u2 methods_count; method_info methods[methods_count]; u2 attributes_count; attribute_info attributes[attributes_count]; }
Constant Type Value CONSTANT_Class7 CONSTANT_Fieldref9 CONSTANT_Methodref10 CONSTANT_InterfaceMethodref11 CONSTANT_String8 CONSTANT_Integer3 CONSTANT_Float4 CONSTANT_Long5 CONSTANT_Double6 CONSTANT_NameAndType12 CONSTANT_Utf81 CONSTANT_MethodHandle15 CONSTANT_MethodType16 CONSTANT_InvokeDynamic18
每个类型,后面的字节数不一样
1 2 3 4
CONSTANT_Class_info { u1 tag; u2 name_index; }
access_flags
表示类或者接口的访问信息
Class access and property modifiers
1 2 3 4 5 6 7 8 9 10 11
Flag Name Value Interpretation ACC_PUBLIC 0x0001 Declared public; may be accessed from outside its package. ACC_FINAL 0x0010 Declared final; no subclasses allowed. ACC_SUPER 0x0020 Treat superclassmethods specially when invoked by the invokespecial instruction. ACC_INTERFACE 0x0200 Is an interface, not a class. ACC_ABSTRACT 0x0400 Declared abstract; must not be instantiated. ACC_SYNTHETIC 0x1000 Declared synthetic; not present in the source code. ACC_ANNOTATION 0x2000 Declared as an annotation type. ACC_ENUM 0x4000 Declared as an enum type.
this_class
表示类的常量池索引,指向常量池中CONSTANT_Class_info的常量
super_class
表示超类的索引,指向常量池中CONSTANT_Class_info的常量
interface_counts及interface[interface_counts]
表示接口的数量及它里面每一项都指向常量池中CONSTANT_Class_info常量
fields_count 及 field_info fields[fields_count]
表示类的实例变量和类变量的数量及字段表的信息。
1 2 3 4 5 6 7
field_info { u2 access_flags; u2 name_index; u2 descriptor_index; u2 attributes_count; attribute_info attributes[attributes_count]; }