Java Class Format

CLASS FORMAT

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];  
} 
cp_info {
  u1 tag;
  u2 name_index;
}
field_info {
  u2 access_flags; 
  u2 name_index; 
  u2 descriptor_index; 
  u2 attributes_count; 
  attribute_info attributes[attributes_count];
}
method_info {
  u2 access_flags;
  u2 name_index;
  u2 descriptor_index;
  u2 attributes_count;
  attribute_info attributes[attributes_count];
}
attribute_info {
  u2 attribute_name_index;
  u4 attribute_length;
  u1 info[attribute_length];
}

Constant Type

Type Tag
CONSTANT_Utf8 1
CONSTANT_Integer 3
CONSTANT_Float 4
CONSTANT_Long 5
CONSTANT_Double 6
CONSTANT_Class 7
CONSTANT_String 8
CONSTANT_Fieldref 9
CONSTANT_Methodref 10
CONSTANT_InterfaceMethodref 11
CONSTANT_NameAndType 12
CONSTANT_MethodHandle 15
CONSTANT_MethodType 16
CONSTANT_InvokeDynamic 18

Constant Type Info

CONSTANT_Utf8_info {  
   u1 tag;  
   u2 length;  
   u1 bytes[length];  
} 
CONSTANT_Integer_info {  
   u1 tag;  
   u4 bytes;  
} 
CONSTANT_Float_info {  
   u1 tag;  
   u4 bytes;  
} 
CONSTANT_Long_info {  
   u1 tag;  
   u4 high_bytes;  
   u4 low_bytes;  
} 
CONSTANT_Double_info {  
   u1 tag;  
   u4 high_bytes;  
   u4 low_bytes;  
} 
CONSTANT_Class_info {  
   u1 tag;  
   u2 name_index;  
} 
CONSTANT_String_info {  
   u1 tag;  
   u2 string_index;  
} 
CONSTANT_Fieldref_info {  
   u1 tag;  
   u2 class_index;  
   u2 name_and_type_index;  
} 
CONSTANT_Methodref_info {  
   u1 tag;  
   u2 class_index;  
   u2 name_and_type_index;  
} 
CONSTANT_InterfaceMethodref_info {  
   u1 tag;  
   u2 class_index;  
   u2 name_and_type_index;  
} 
CONSTANT_NameAndType_info {  
   u1 tag;  
   u2 name_index;  
   u2 descriptor_index;  
} 
CONSTANT_InvokeDynamic_info {
   u1 tag;
   u2 bootstrap_method_attr_index;
   u2 name_and_type_index;
}

ACCESS_FLAGS

Name Value Desc -
ACC_PUBLIC 0x0001 public类型 所有类型
ACC_FINAL 0x0010 final类型
ACC_SUPER 0x0020 使用新的invokespecial语义 类和接口
ACC_INTERFACE 0x0200 接口类型 接口
ACC_ABSTRACT 0x0400 抽象类型 类和接口
ACC_SYNTHETIC 0x1000 该类不由用户代码生成 所有类型
ACC_ANNOTATION 0x2000 注解类型 注解
ACC_ENUM 0x4000 枚举类型 枚举

你可能感兴趣的:(Java Class Format)