Java字节码(.class文件)格式详解(一) (二)

2014-11-24 02:33:29 · 作者: · 浏览: 1
uble_info

type

descriptor

remark

u1

tag

CONSTANT_Double(6)

u4

high_bytes

双精度浮点的高四位值

u4

low_bytes

双精度浮点的低四位值

几个特殊值:0x7ff0000000000000L => Double.POSITIVE_INFINITY、

0xfff0000000000000L => Double.NEGATIVE_INFINITY

0x7ff0000000000001L to 0x7fffffffffffffffL => Double.NaN 、

0xfff0000000000001L to 0xffffffffffffffffL => Double.NaN

2.3.6 CONSTANT_String_info

用于记录常量字符串的值(represent constant objects of the type String:)

CONSTANT_String_info

type

descriptor

remark

u1

tag

CONSTANT_String(8)

u2

string_index

constant_pool中的索引,CONSTANT_Utf8_info类型。表示String类型值。

2.3.7 CONSTANT_Fieldref_info

用于记录字段信息(包括类或接口中定义的字段以及代码中使用到的字段)。

CONSTANT_Fieldref_info

type

descriptor

remark

u1

tag

CONSTANT_Fieldref(9)

u2

class_index

constant_pool中的索引,CONSTANT_Class_info类型。记录定义该字段的类或接口。

u2

name_and_type_index

constant_pool中的索引,CONSTANT_NameAndType_info类型。指定类或接口中的字段名(name)和字段描述符(descriptor)。

2.3.8 CONSTANT_Methodref_info

用于记录方法信息(包括类中定义的方法以及代码中使用到的方法)。

CONSTANT_Methodref_info

type

descriptor

remark

u1

tag

CONSTANT_Methodref(10)

u2

class_index

constant_pool中的索引,CONSTANT_Class_info类型。记录定义该方法的类。

u2

name_and_type_index

constant_pool中的索引,CONSTANT_NameAndType_info类型。指定类中 方法名(name)和方法描述符(descriptor)。

2.3.9 CONSTANT_InterfaceMethodref_info

用于记录接口中的方法信息(包括接口中定义的方法以及代码中使用到的方法)。

CONSTANT_InterfaceMethodref_info

type

descriptor

remark

u1

tag

CONSTANT_InterfaceMethodref(11)

u2

class_index

constant_pool中的索引,CONSTANT_Class_info类型。记录定义该方法的接口。

u2

name_and_type_index

constant_pool中的索引,CONSTANT_NameAndType_info类型。指定接口中的方法名(name)和方法描述符(descriptor)。

2.3.10 CONSTANT_NameAndType_info

记录方法或字段的名称(name)和描述符(descriptor)(represent a field or method, without indicating which class or interface type it belongs to:)。

CONSTANT_NameAndType_info

type

descriptor

remark

u1

tag

CONSTANT_NameAndType (12)

u2

name_index

constant_pool中的索引,CONSTANT_Utf8_info类型。指定字段或方法的名称。

u2

descriptor_index

constant_pool中的索引,CONSTANT_utf8_info类型。指定字段或方法的描述符(见附录C

2.3.11 CONSTANT_Utf8_info

记录字符串的值(represent constant string values. String content is encoded in modified UTF-8.)

modifie

d UTF-8 refer to :

http://download.ora

cle.com/javase/1.4.2/docs/api/java/io/DataInputStream.html

CONSTANT_Utf8_info

type

descriptor

remark

u1

tag

CONSTANT_Utf8 (1)

u2

length

bytes所代表

的字符串的长度

u1

bytes[length]

字符串的byte数据,可以通过DataInputStream中的readUtf()方法(实例方法或静态方法读取该二进制的字符串的值。)

2.4 access_flags

指定类或接口的访问权限。

类或接口的访问权限

Flag Name

Value

Remarks

ACC_PUBLIC

0x0001

pubilc,包外可访问。

ACC_FINAL

0x0010

final,不能有子类。

ACC_SUPER

0x0020

用于兼容早期编译器,新编译器都设置该标记,以在使用invokespecial指令时对子类方法做特定处理。

ACC_INTERFACE

0x0200

接口,同时需要设置:ACC_ABSTRACT。不可同时设置:ACC_FINAL、ACC_SUPER、ACC_ENUM

ACC_ABSTRACT

0x0400

抽象类,无法实例化。不可和ACC_FINAL同时设置。

ACC_SYNTHETIC

0x1000

synthetic,由编译器产生,不存在于源代码中。

ACC_ANNOTATION

0x2000

注解类型(annotation),需同时设置:ACC_INTERFACE、ACC_ABSTRACT

ACC_ENUM

0x4000

枚举类型

2.5 this_class

this_class是指向constant pool的索引值,该值必须是CONSTANT_Class_info类型,指定当前字节码定义的类或接口。

2.6 super_class

super_class是指向constant pool的索引值,该值