Skip to content

Commit

Permalink
机器翻译 - ## 4.4. 常量池
Browse files Browse the repository at this point in the history
  • Loading branch information
renfufei committed Aug 14, 2018
1 parent 0f2ec38 commit d339875
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions tiemao_2017/15_Java_class_File_Format/4.4_The_Constant_Pool.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
## 4.4. The Constant Pool

## 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.

Java虚拟机指令不依赖于运行时的布局类,接口,类实例或数组。相反,指令是指符号信息`constant_pool`议席上就座。

All `constant_pool` table entries have the following general format:

所有`constant_pool`表条目有以下一般格式:

```
cp_info {
u1 tag;
Expand All @@ -12,8 +18,14 @@ cp_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](#jvms-4.4-140). 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.

中的每一项`constant_pool`表必须以字节标签指示的`cp_info`条目。的内容`info`数组的值不同`tag`。列出有效的标签和它们的值(表4.4)(# jvm - 4.4 - 140)。每个标签字节必须紧随其后的是两个或两个以上的字节给特定的信息不变.附加信息的格式随标签值。



**Table 4.4-A. Constant pool tags**

| Constant Type | Value |
Expand Down Expand Up @@ -57,14 +69,25 @@ The items of the `CONSTANT_Class_info` structure are as follows:

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](#jvms-4.3.2)).

arrays也各不相同,因此,opcodes饰品are anewarray * * * * multianewarray宗旨和集体opcode * *纽约“职等”的结论references can经由`CONSTANT_Class_info`结构`constant_pool`表。对于这样的数组类,类的名称是数组类型的描述符((§4.3.2)(# jvms-4.3.2))。

For example, the class name representing the two-dimensional array type `int[][]` is `[[I`, while the class name representing the type `Thread[]` is `[Ljava/lang/Thread;`.

例如,代表二维数组类型的类名`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_info`, `CONSTANT_Methodref_info`, and `CONSTANT_InterfaceMethodref_info` Structures

### 10/24/11。的`CONSTANT_Fieldref_info`,`CONSTANT_Methodref_info`,`CONSTANT_InterfaceMethodref_info`结构

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

字段、方法和接口方法由类似的结构:


```
CONSTANT_Fieldref_info {
u1 tag;
Expand Down Expand Up @@ -170,10 +193,18 @@ CONSTANT_Double_info {

All 8-byte constants take up two entries in the `constant_pool` table of the `class` file. If a `CONSTANT_Long_info` or `CONSTANT_Double_info` structure is the item in the `constant_pool` table at index *n*, then the next usable item in the pool is located at index *n*+2. The `constant_pool` index *n*+1 must be valid but is considered unusable.

所有8字节常数两个条目`constant_pool`表的`class`文件。如果一个`CONSTANT_Long_info``CONSTANT_Double_info`结构中的项`constant_pool`表的索引* n *,然后下一个可用的条目池位于指数* n * + 2。的`constant_pool`指数* n * + 1必须是有效的,但被认为是无法使用。

In retrospect, making 8-byte constants take two constant pool entries was a poor choice.

回想起来,让8字节常数两个常量池条目是一个好的选择。

The items of these structures are as follows:

这些结构的项目如下:



- tag

The `tag` item of the `CONSTANT_Long_info` structure has the value `CONSTANT_Long` (5).The `tag` item of the `CONSTANT_Double_info` structure has the value `CONSTANT_Double` (6).
Expand Down Expand Up @@ -323,14 +354,26 @@ String content is encoded in modified UTF-8. Modified UTF-8 strings are encoded

The bytes of multibyte characters are stored in the `class` file in big-endian (high byte first) order.

多字节字符的字节存储在`class`文件在高位优先(高字节第一)。

There are two differences between this format and the "standard" UTF-8 format. First, the null character `(char)0` is encoded using the 2-byte format rather than the 1-byte format, so that modified UTF-8 strings never have embedded nulls. Second, only the 1-byte, 2-byte, and 3-byte formats of standard UTF-8 are used. The Java Virtual Machine does not recognize the four-byte format of standard UTF-8; it uses its own two-times-three-byte format instead.

有两个这种格式之间的差异和“标准”utf - 8格式。首先,null字符`(char)0`是使用2字节格式进行编码,而不是字节格式,以便修改utf - 8编码的字符串没有嵌入式取消.第二,只有字节,2字节和3字节格式的标准使用utf - 8.Java虚拟机不承认四字节格式标准的utf - 8;它使用自己的two-times-three-byte格式。

For more information regarding the standard UTF-8 format, see Section 3.9 *Unicode Encoding Forms* of *The Unicode Standard, Version 6.0.0*.

关于标准的utf - 8格式的更多信息,参见3.9节* Unicode编码形式* *的Unicode标准,0版本*

### 4.4.8. The `CONSTANT_MethodHandle_info` Structure

### 4.4.8。的`CONSTANT_MethodHandle_info`结构

The `CONSTANT_MethodHandle_info` structure is used to represent a method handle:

`CONSTANT_MethodHandle_info`结构是用来表示一种方法处理:



```
CONSTANT_MethodHandle_info {
u1 tag;
Expand Down Expand Up @@ -378,8 +421,14 @@ The items of the `CONSTANT_MethodType_info` structure are as follows:

### 4.4.10. The `CONSTANT_InvokeDynamic_info` Structure

### 4.4.10。的`CONSTANT_InvokeDynamic_info`结构

The `CONSTANT_InvokeDynamic_info` structure is used by an *invokedynamic* instruction ([§*invokedynamic*](https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-6.html#jvms-6.5.invokedynamic)) to specify a bootstrap method, the dynamic invocation name, the argument and return types of the call, and optionally, a sequence of additional constants called *static arguments* to the bootstrap method.

`CONSTANT_InvokeDynamic_info`结构被一个* * invokedynamic指令((§* invokedynamic *)(https://docs.oracle.com/javase/specs/jvms/se8/html/jvms # jvm - 6.5 - 6. - html.invokedynamic)指定一个引导方法,动态调用的名称,参数和返回类型的调用,并可选地,一系列的附加常量称为* *引导方法静态参数。



```
CONSTANT_InvokeDynamic_info {
u1 tag;
Expand Down

0 comments on commit d339875

Please sign in to comment.