原文链接:

https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.4

Java Virtual Machine instructions do not rely on the run-time layout of classes, interfaces, class instances, or arrays. Instead, instructions refer to symbolic information in the constant_pool table.

JVM虚拟机指令不依赖于类、接口、类实例、或者数组的运行时布局。反而,指令引用在常量池中的符号信息。

All constant_pool table entries have the following general format:

所有常量池表中条目有下面的通用格式:

cp_info {
u1 tag;
u1 info[];
}

Each item in the constant_pool table must begin with a 1-byte tag indicating the kind of cp_info entry. The contents of the info array vary with the value of tag. The valid tags and their values are listed in Table 4.4-A. Each tag byte must be followed by two or more bytes giving information about the specific constant. The format of the additional information varies with the tag value.

在常量表中的每个条目必须以一个字节的标签开始,标识条目的类型。info数组的内容根据tag的值而发生变化。下面的表格列出了所有有效的标记和他们的值。

每个标记类型必须跟随两个或更多字节的信息,标识特定的常量。额外信息的格式随tag的值而变化。

4.4.1. The CONSTANT_Class_info Structure

CONSTANT_Class_info 的结构:

The CONSTANT_Class_info structure is used to represent a class or an interface:

CONSTANT_Class_info结构代表一个类或者一个接口

The items of the CONSTANT_Class_info structure are as follows:

CONSTANT_Class_info 结构的条目如下:

tag

The tag item has the value CONSTANT_Class (7).

tag项的值为CONSTANT_Class (7).

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 a valid binary class or interface name encoded in internal form (§4.2.1).

name_index的值必须是一个有效的constant_pool表中条目的索引。constant_pool表中的该索引对应的项必须是一个CONSTANT_Utf8_info结构,代表一个有效的二进制类或者接口名(内部格式编码)。

Because arrays are objects, the opcodes anewarray and multianewarray - but not the opcode new - can reference array "classes" via CONSTANT_Class_info structures in the constant_pool table. For such array classes, the name of the class is the descriptor of the array type (§4.3.2).

因为数组是对象,操作码anewarray 和multianewarray -但不是操作码new -能够通过本结构体来引用数组类型。对于这样的数组类型,类的名字是数组类型的描述符。

比如,代表二维数组int[][]的类的名字是[[I,代表线程数组Thread[]的类的名字是[Ljava/lang/Thread;

An array type descriptor is valid only if it represents 255 or fewer dimensions.

数组描述符只在数组维数少于255时有效。

 

4.4.2. The CONSTANT_Fieldref_infoCONSTANT_Methodref_info, and CONSTANT_InterfaceMethodref_info Structures

Fields, methods, and interface methods are represented by similar structures:

域,方法和接口方法用类似的结构来代表:

The items of these structures are as follows:

结构体中的条目如下:

tag

The tag item of a CONSTANT_Fieldref_info structure has the value CONSTANT_Fieldref (9).

The tag item of a CONSTANT_Methodref_info structure has the value CONSTANT_Methodref (10).

The tag item of a CONSTANT_InterfaceMethodref_info structure has the valueCONSTANT_InterfaceMethodref (11).

CONSTANT_Fieldref_info 中的tag值为CONSTANT_Fieldref 。

CONSTANT_Methodref_info 中的tag值为CONSTANT_Methodref 。

CONSTANT_InterfaceMethodref_info 中的tag值为valueCONSTANT_InterfaceMethodref

class_index

The value of the class_index item must be a valid index into the constant_pool table. Theconstant_pool entry at that index must be a CONSTANT_Class_info structure (§4.4.1) representing a class or interface type that has the field or method as a member.

The class_index item of a CONSTANT_Methodref_info structure must be a class type, not an interface type.

The class_index item of a CONSTANT_InterfaceMethodref_info structure must be an interface type.

The class_index item of a CONSTANT_Fieldref_info structure may be either a class type or an interface type.

class_index的值必须是常量表中有效的索引。常量表中该索引所指向的条目必须是CONSTANT_Class_info类型的结构体,代表拥有该field或者方法作为其成员的类或接口。

   CONSTANT_Methodref_info中class_index的值必须是class类型,不能是接口。

   CONSTANT_InterfaceMethodref_info 中的class_index必须是接口。

   CONSTANT_Fieldref_info中的class_index可以是接口,也可以是类。

name_and_type_index

  The value of the name_and_type_index item must be a valid index into the constant_pool table. Theconstant_pool entry at that index must be a CONSTANT_NameAndType_info structure (§4.4.6). This constant_pool entry indicates the name and descriptor of the field or method.

  In a CONSTANT_Fieldref_info, the indicated descriptor must be a field descriptor (§4.3.2). Otherwise, the indicated descriptor must be a method descriptor (§4.3.3).

  If the name of the method of a CONSTANT_Methodref_info structure begins with a '<' ('\u003c'), then the name must be the special name <init>, representing an instance initialization method (§2.9). The return type of such a method must be void.

  name_and_type_index 的值必须是常量表中的有效索引。其值必须是CONSTANT_NameAndType_info结构体。这个条目标识字段或者方法的名字和描述符。

  在CONSTANT_Fieldref_info中,指示的描述符必须是一个字段描述符。否则,必须是一个方法描述符。

  如果CONSTANT_Methodref_info 的方法名字以'<' 开头,那么这个名字一定是<init>,代表对象的初始化方法。返回值必须为void。

4.4.3. The CONSTANT_String_info Structure

The CONSTANT_String_info structure is used to represent constant objects of the type String:

CONSTANT_String_info 结构体用来代表字符串常量:

The items of the CONSTANT_String_info structure are as follows:

tag

The tag item of the CONSTANT_String_info structure has the value CONSTANT_String (8).

tag值为CONSTANT_String

string_index

The value of the string_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 the sequence of Unicode code points to which the String object is to be initialized.

值必须为常量表有效索引。必须是一个CONSTANT_Utf8_info 结构体,代表unicode序列,指向将被初始化的String对象

翻译:JVM虚拟机规范1.7中的运行时常量池部分(一)的更多相关文章

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

    本篇为JVM虚拟机规范1.7中的运行时常量池部分系列的第二篇. 4.4.4. The CONSTANT_Integer_info and CONSTANT_Float_info Structures ...

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

    4.4.7. The CONSTANT_Utf8_info Structure The CONSTANT_Utf8_info structure is used to represent consta ...

  3. 类的加载,链接和初始化——1运行时常量池(来自于java虚拟机规范英文版本+本人的翻译和理解)

    加载(loading):通过一个特定的名字,找到类或接口的二进制表示,并通过这个二进制表示创建一个类或接口的过程. 链接:是获取类或接口并把它结合到JVM的运行时状态中,以让类或接口可以被执行 初始化 ...

  4. 深入理解JVM虚拟机:(一)Java运行时数据区域

    概述 JVM是Java语言的精髓所在,因为它Java语言实现了跨平台运行,以及自动内存管理机制等,本文将从概念上介绍JVM内存的各个区域,说明个区域的作用. JVM运行时数据区模型 Java虚拟机在执 ...

  5. JVM笔记3-java内存区域之运行时常量池

    1.运行时常量池属于线程共享区中的方法区. 2.运行时常量池用于编译期生成的各种自变量,符号引用,这部分内用将在类加载后接入方法区的运行时常量池中存放. 看如下代码所示,如图: public clas ...

  6. 对JVM运行时常量池的一些理解

    1.JVM运行时常量池在内存的方法区中(在jdk8中,移除了方法区) 2.JVM运行时常量池中的内容主要是从各个类型的class文件的常量池中获取,对于字符串常量,可以调用intern方法人为添加,而 ...

  7. JVM详解之:运行时常量池

    目录 简介 class文件中的常量池 运行时常量池 静态常量详解 String常量 数字常量 符号引用详解 String Pool字符串常量池 总结 简介 JVM在运行的时候会对class文件进行加载 ...

  8. 运行时常量池中的符号引用/String.intern() /ldc指令

    运行时常量池,之前放在方法区(永久代)中,1.8之后被转移到元空间,放到了native memory中. 具体的数据结构是:(看对象的内存布局,句柄访问还是对象头中保存指向类的元数据的指针,这里以对象 ...

  9. JVM 常量池、运行时常量池、字符串常量池

    常量池: 即class文件常量池,是class文件的一部分,用于保存编译时确定的数据. 保存的内容如下图: D:\java\test\out\production\test>javap -ver ...

随机推荐

  1. Django基础(二):环境配置

    前戏 WEB框架简介 具体介绍Django之前,必须先介绍WEB框架等概念. web框架: 别人已经设定好的一个web网站模板,你学习它的规则,然后“填空”或“修改”成你自己需要的样子. 一般web框 ...

  2. 教你快速打造PHP MVC框架

    简介 MVC框架在现在的开发中相当流行,不论你使用的是JAVA,C#,PHP或者IOS,你肯定都会选择一款框架.虽然不能保证100%的开发语言都会使用框架,但是在PHP社区当中拥有最多数量的MVC框架 ...

  3. 利用sfc文件构建网络渗透

      收集哈希 SCF(Shell命令文件)文件可用于执行一组有限的操作,例如显示Windows桌面或打开Windows资源管理器,这并不是什么新鲜事.然而,一个SCF文件可以用来访问一个特定的UNC路 ...

  4. JAVA-基础语法篇

    JAVA-基础语法篇 一.     基础语法: 对大小写敏感 类名的首字母大写 方法名首字母小写,后面用驼峰发命名 源文件名和类名要相同 主方法入口: public static void main( ...

  5. 转发—Android开发常用的插件及工具

    作者:蓝之风 出处:http://www.cnblogs.com/vaiyanzi/ Android开发常用的插件及工具 1.GitHub,这个不管是做安卓还是其他,只要是开发就必上的网站,也是天朝没 ...

  6. Mac下安装virtualenv, 并在PyCharm中使用

    今天在安装一个leader写的package的时候,同事建议安装到虚拟环境中,再在PyCharm里使用该虚拟环境即可.此处记录下经过: 开发Python应用的时候,有时会遇到不同的Python应用依赖 ...

  7. python全栈学习--day4

    列表 说明:列表是python中的基础数据类型之一,它是以[]括起来,每个元素以逗号隔开,而且他里面可以存放各种数据类型比如:   1 li = ['alex',123,Ture,(1,2,3,'wu ...

  8. alpha-咸鱼冲刺day2-紫仪

    总汇链接 一,合照 emmmmm.自然是没有的. 二,项目燃尽图 三,项目进展 今天并没有什么进展,弄了好久好像也只研究出怎么把JS的功能块插入进去.html的信息提交这些还不知道要怎么弄. 四,问题 ...

  9. 团队开发---”我爱淘“校园二手书店 NABC分析

    本项目特点之一:可预订 N:对于一些抢手的书可以提前预定,避免学生买不到书 A:网上下单,通过手机便捷购物 B:使得订书更加方便快捷 C:二手书摊.网上书店 团队成员:杨广鑫.郭健豪.李明.郑涛

  10. 软件工程第三次作业-结对作业NO.1

    第一次结对作业 结对人员: 潘伟靖 170320077 张 松 170320079 方案分析 我们对所供的资料进行分析,如下: 从提供的资料可以看出,需要解决的问题以及满足的需求主要有两类目标用户,各 ...