The structure of a class file

1: magic number: 4 bytes, OxCAFEBABE which can help to recognize a java class file easily
2: minor_version and major_version: 4 bytes
for example,in java 2 platform the major_version is updated from 45 ro 46, and the minor_version depends on specifical platform and its version
3: constant_pool_count and constant_pool:
a constant pool includes the const field assiciated with class and interface. it will keep the titles such as String, final field, class name and method name. the first index of this list is 1, but the index 0 will be added into the contant_pool_count. so if you have 14 items in the pool the contant_pool_count will 15.
every entrance of the contant pool will start with a byte length which is used as a flag pointing out the type of the contant.
 contant pool flag
CONSTANT_Utf8 1 Unicode String
CONSTANT_Integer 3 int
CONSTANT_Float 4 float
CONSTANT_Long 5 long
CONSTANT_Double 6 double
CONSTANT_Class 7 the reference to a class or an interface
CONSTANT_String 8 String value
CONSTANT_Fieldref 9 a field reference
CONSTANT_Methodref10 a method reference in this class
CONSTANT_InterfaceMethodref 11 a method reference defined in a interface
CONSTANT_NameAndType 12 a part reference to a field or method

the contant pool play a important role int the dynamic stage. the JVM will load a reference and analyse for the actual address.

4:access_flags: 2 bytes, it figures out this class file represents a class or a interface and what is its decoration.
ACC_PUBLIC 0X0001 public type class and interface
ACC_FINAL 0X0010 final type class
ACC_SUPER 0X0020 use the new sementeme of invokespecial class and interface
ACC_INTERFACE 0X0200 interface type interface
ACC_ABSTRACT 0X0400 abstract type interface and part of class
5: this_class; 2 bytes, it is a index to the contant pool,which entrance must be CONSTANT_Class_info. such table make up with two items, flag and name_index. the flag is a constant field holding a CONSTANT_Class vlaue. and the the name_index point to a entrance marked with CONSTANT_Utf8_info which is a list.
6:super_class: 2 bytes which point to a entrance in the constant pool containing the describtion of the super class, marked with CONSTANT_Class_info. due to the java.lang.Object class, this field will be set with 0.
7: interfaces_count and interfaces: an array of the interface or extending class a class implement, all the items contain a index to the constant pool. the order of the array depends on the orders of the implements subsentence and extends subsenetence.
8:fields_count and fields:
9:methods_count and methods
10: attributes_count and attributes: there are many attributes and it will appear in many place. for example the arrtibutes item in ClaaFile will contain the information about the class and interface.
ther are two attributes defined by JVM, SourceCode and InnerClasses. they will be contained in the attributes list in the ClassFile list.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值