`

JVM学习笔记-特殊字符串(Special Strings)

阅读更多

 

Special Strings 特殊字符串

The symbolic references contained in the constant pool involve three special kinds of strings: fully qualified names, simple names, and descriptors. All symbolic references include the fully qualified name of a class or interface. Symbolic references to fields include a simple field name and field descriptor in addition to a fully qualified type name. Symbolic references to methods include a simple method name and method descriptor in addition to a fully qualified name.

常量池中容纳的符号引用包括三种特殊的字符串:全限定名、简单名称和描述符。所有的符号引用都包括类或者接口的全限定名。字段的符号引用除了全限定类型名之外,还包括简单字段名和字段描述符。方法的符号引用除了全限定类型名之外,还包括简单方法名和方法描述符。

 

The same special strings are used to describe the class or interface that is defined by the class file. The class or interface name, the superclass name (if any), and the names of any superinterfaces are all given as fully qualified names. For each field declared by the class or interface, the constant pool contains a simple name and field descriptor. For each method declared by the class or interface, the constant pool contains a simple name and method descriptor.

在符号引用中使用的特殊字符串也同样用来描述被class文件定义的类或者接口。例如,定义过的类或者接口会有一个全限定名。对于每一个在类或者接口中声明的字段,常量池中都会有一个简单名称和字段描述符。对于每一个在类或者接口中声明的方法,常量池中都会有一个简单名称和方法描述符。

Fully Qualified Names 全限定名

 

Whenever constant pool entries refer to classes and interfaces, they give the fully qualified name of the class or interface. In the class file, fully qualified names have their dots replaced with slashes. For example, the representation of the fully qualified name of java.lang.Object in the class file is java/lang/Object. The fully qualified name of java.util.Hashtable in the class file is java/util/Hashtable.

当常量池入口指向类或者接口时,它们给出该类或者接口的全限定名。在class文件中,全限定名中的点用斜线取代了。例如,在class文件中,java.lang.Object的全限定名表示为java/lang/Object;在class文件中,java.util.Hashtable的全限定名表示为java/util/Hashtable。

Simple Names 简单名称

 

The names of fields and methods appear in constant pool entries as simple (not fully qualified) names. For example, a constant pool entry that refers to the String toString() method of class java.lang.Object would give its method name as "toString". A constant pool entry that refers to the java.io.PrintStream out field of class java.lang.System would specify the field name simply as "out".

字段名和方法名以简单名称(非全限定名)形式出现在常量池入口中。例如,一个指向类java.lang.Object所属方法StringtoString()的常量池入口有一个形如“toStirng”的方法名。一个指向类java.lang.System所属字段java.io.PrintStream.out的常量池入口有个以形如”out”的字段名。

Descriptors 描述符

 

Symbolic references to fields and methods include a descriptor string in addition to a fully qualified class or interface name and a simple field or method name. A field descriptor gives the fieldís type. A method descriptor gives the methodís return type and the number and types of the methodís parameters.

除了类(或接口)的全限定名和简单字段(或方法)名,指向字段和方法的符号引用还包括描述符字符串。字段的描述符给出了字段的类型;方法描述符给出了方法的返回值和方法参数的数量、类型以及顺序。

 

Field and method descriptors are defined by the context free grammar shown below. Nonterminals of this grammar, such as FieldType, are shown in italic font. Terminals, such as B or V, are shown in fixed width font. The asterisk character (*) stands for zero or more occurrences of the item that precedes it placed side by side (with no intervening white space).

 

字段和方法的描述符由如下所示的上下文无关语法定义。该语法中非终结符号用斜体字标出,如FieldType;终结符号使用等宽度字体标出,如B或V;星号代表紧接在它前面的符号(中间没有空格)将会出现0次或者多次。

 

 

 

FieldDescriptor:

 

FieldType


ComponentType:

 

FieldType

 

FieldType:

 

BaseType

ObjectType

ArrayType

 

BaseType:

 

B

C

D

F

I

J

S

Z

 

ObjectType:

 

L<classname>;

 

ArrayType:

 

[ ComponentType

 

ParameterDescriptor:

 

FieldType

 

MethodDescriptor:

 

( ParameterDescriptor* ) ReturnDescriptor

 

ReturnDescriptor:

 

FieldType

V

The meaning of each of the BaseType terminals is shown in Table 6-5. The V terminal represents methods that return void.

 

Table 6-5. BaseType terminals

Terminal Type
B byte
C char
D double
F float
I int
J long
S short
Z boolean

Some examples of field descriptors are shown in Table 6-6.

Table 6-6. Examples of field descriptors

Descriptor Field Declaration
I int i;
[[J long[][] windingRoad;
[Ljava/lang/Object; java.lang.Object[] stuff;
Ljava/util/Hashtable; java.util.Hashtable ht;
[[[Z boolean[][][] isReady;

Some examples of method descriptors are shown in Table 6-7. Note that method descriptors don't include the hidden this parameter passed as the first argument to all instance methods.

Table 6-7. Examples of method descriptors

Descriptor Method Declaration
()I int getSize();
()Ljava/lang/String; String toString();
([Ljava/lang/String;)V void main(String[] args);
()V void wait()
(JI)V void wait(long timeout, int nanos)
(ZILjava/lang/String;II)Z boolean regionMatches(boolean ignoreCase, int toOffset, String other, int ooffset, int len);
([BII)I int read(byte[] b, int off, int len);

 

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics