翻译:JVM虚拟机规范1.7中的运行时常量池部分(二)

时间:2022-10-25 06:36:44

本篇为JVM虚拟机规范1.7中的运行时常量池部分系列的第二篇。

4.4.4. The CONSTANT_Integer_info and CONSTANT_Float_info Structures

The CONSTANT_Integer_info and CONSTANT_Float_info structures represent 4-byte numeric (int and float) constants:

代表4字节的数字常量,如int和float:

翻译:JVM虚拟机规范1.7中的运行时常量池部分(二)

The items of these structures are as follows:

tag

The tag item of the CONSTANT_Integer_info structure has the value CONSTANT_Integer (3).

The tag item of the CONSTANT_Float_info structure has the value CONSTANT_Float (4).

类型分别必须为CONSTANT_Integer和CONSTANT_Float

bytes

The bytes item of the CONSTANT_Integer_info structure represents the value of the int constant. The bytes of the value are stored in big-endian (high byte first) order.

The bytes item of the CONSTANT_Float_info structure represents the value of the float constant in IEEE 754 floating-point single format (§2.3.2). The bytes of the single format representation are stored in big-endian (high byte first) order.

The value represented by the CONSTANT_Float_info structure is determined as follows. The bytes of the value are first converted into an int constant bits. Then:

  • If bits is 0x7f800000, the float value will be positive infinity.

  • If bits is 0xff800000, the float value will be negative infinity.

  • If bits is in the range 0x7f800001 through 0x7fffffff or in the range 0xff800001 through 0xffffffff, the float value will be NaN.

       In all other cases, let se, and m be three values that might be computed from bits:

      翻译:JVM虚拟机规范1.7中的运行时常量池部分(二)

    bytes在CONSTANT_Integer_info 中代表int常量的值。大端序(高字节在前)存储

    bytes在CONSTANT_Float_info 中代表以IEEE 754 浮点数格式存储的float常量。大端序存储。

CONSTANT_Float_info结构体的内容按照如下规则。bytes的值首先被转换为int常量比特,然后:

    如果bits是0x7f800000,那么浮点值为正无穷。

    如果bits是0xff800000,那么浮点值为负无穷。

     如果bits是在0x7f800001 到0x7fffffff或者0xff800001到0xffffffff,值为NaN。

    其他情况,参考上图算出s,e,m,则值为 s · m · 2e-150.

4.4.5. The CONSTANT_Long_info and CONSTANT_Double_info Structures

看看它的存储结构体:

翻译:JVM虚拟机规范1.7中的运行时常量池部分(二)

其余和int和float差不多,只是变成了两个4字节来存储。

4.4.6. The CONSTANT_NameAndType_info Structure

The CONSTANT_NameAndType_info structure is used to represent a field or method, without indicating which class or interface type it belongs to:

  代表一个字段或者方法,没标识属于哪个类或者接口:

翻译:JVM虚拟机规范1.7中的运行时常量池部分(二)

The items of the CONSTANT_NameAndType_info structure are as follows:

条目如下:

tag

The tag item of the CONSTANT_NameAndType_info structure has the value CONSTANT_NameAndType (12).

tag值为CONSTANT_NameAndType

name_index

The value of the name_index item must be a valid index into the constant_pool table. The constant_pool entry at that index must be a CONSTANT_Utf8_info structure (§4.4.7) representing either the special method name <init> (§2.9) or a valid unqualified name denoting a field or method (§4.2.2).

name_index项必须为有效索引项。必须指向CONSTANT_Utf8_info 结构体,代表特殊方法名,如<init>或者一个有效的相对名标识字段或方法。

descriptor_index

The value of the descriptor_index item must be a valid index into the constant_pool table. The constant_pool entry at that index must be a CONSTANT_Utf8_info structure (§4.4.7) representing a valid field descriptor or method descriptor (§4.3.2§4.3.3).

   值必须为有效索引。必须指向CONSTANT_Utf8_info ,代表有效的字段描述符或者方法描述符。(应该是一个域前面的那些:private,static,final之类的修饰符吧)