📄 classfile.doc.html
字号:
All <code>constant_pool</code> table entries have the following general format:<p><pre><br><a name="9604"></a> <code>cp_info {</code> <code> u1 tag;</code> <code> u1 info[];</code><a name="9689"></a> <code>}</code><br></pre><a name="86988"></a>Each item in the <code>constant_pool</code> table must begin with a 1-byte tag indicating the kind of <code>cp_info</code> entry. The contents of the <code>info</code> array vary with the value of <code>tag</code>. The valid tags and their values are listed in <a href="ClassFile.doc.html#87125">Table 4.3</a>. Each tag byte must be followed by two or more bytes giving information about the specific constant. The formatof the additional information varies with the tag value.<p><Table Border="1"><tr><th><b><i>Constant Type</i></b><th><b><i>Value</i></b><tr><td><a name="87125"></a><code>CONSTANT_Class</code><td><a name="87127"></a><code>7</code><tr><td><a name="87129"></a><code>CONSTANT_Fieldref</code><td><a name="87131"></a><code>9</code><tr><td><a name="87133"></a><code>CONSTANT_Methodref</code><td><a name="87135"></a><code>10</code><tr><td><a name="87137"></a><code>CONSTANT_InterfaceMethodref</code><td><a name="87139"></a><code>11</code><tr><td><a name="87141"></a><code>CONSTANT_String</code><td><a name="87143"></a><code>8</code><tr><td><a name="87145"></a><code>CONSTANT_Integer</code><td><a name="87147"></a><code>3</code><tr><td><a name="87149"></a><code>CONSTANT_Float</code><td><a name="87151"></a><code>4</code><tr><td><a name="87153"></a><code>CONSTANT_Long</code><td><a name="87155"></a><code>5</code><tr><td><a name="87157"></a><code>CONSTANT_Double</code><td><a name="87159"></a><code>6</code><tr><td><a name="87161"></a><code>CONSTANT_NameAndType</code><td><a name="87163"></a><code>12</code><tr><td><a name="87165"></a><code>CONSTANT_Utf8</code><td><a name="87167"></a><code>1</code></Table><br><br><p><a name="1221"></a><h3>4.4.1 The <code>CONSTANT_Class_info</code> Structure</h3><a name="1222"></a>The <code>CONSTANT_Class_info</code> structure is used to represent a class or an interface:<p><pre><br><a name="1223"></a> <code>CONSTANT_Class_info {</code> <code> u1 tag;</code> <code> u2 name_index;</code><a name="1226"></a> <code>}</code><br></pre><a name="9357"></a>The items of the <code>CONSTANT_Class_info</code> structure are the following:<p><a name="1228"></a><dl><dt><code>tag</code><dd> The <code>tag</code> item has the value <code>CONSTANT_Class</code> (<code>7</code>).<p><a name="8829"></a><dt><code>name_index</code><dd> The value of the <code>name_index</code> item must be a valid index into the <code>constant_pool</code> table. The <code>constant_pool</code> entry at that index must be a <code>CONSTANT_Utf8_info</code> <a href="ClassFile.doc.html#7963">(§4.4.7)</a> structure representing a valid fully qualified class or interface name <a href="Concepts.doc.html#20389">(§2.8.1)</a> encoded in internal form (<a href="ClassFile.doc.html#14757">§4.2)</a>. <p></dl><a name="84853"></a> <p><a name="1232"></a>Because arrays are objects, the opcodes <i>anewarray</i> and <i>multianewarray</i> can reference array "classes" via <code>CONSTANT_Class_info</code> <a href="ClassFile.doc.html#1221">(§4.4.1)</a> structures in the <code>constant_pool</code> table. For such array classes, the name of the class is the descriptor of the array type. For example, the class name representing a two-dimensional <code>int</code> array type<p><pre> <code>int[][] </code></pre><a name="1234"></a>is <p><pre> <code>[[I</code></pre><a name="1237"></a>The class name representing the type array of class <code>Thread</code><p><pre> <code>Thread[] </code></pre><a name="1239"></a>is <p><pre> <code>[Ljava/lang/Thread;</code></pre><a name="42039"></a>An array type descriptor is valid only if it represents 255 or fewer dimensions.<p><a name="42041"></a><h3>4.4.2 The <code>CONSTANT_Fieldref_info</code>, <code>CONSTANT_Methodref_info</code>, and <code>CONSTANT_InterfaceMethodref_info</code> Structures</h3><a name="1253"></a>Fields, methods, and interface methods are represented by similar structures:<p><pre><br><a name="1254"></a> <code>CONSTANT_Fieldref_info {</code> <code> u1 tag;</code> <code> u2 class_index;</code> <code> u2 name_and_type_index;</code><a name="1258"></a> <code>}</code><br><br><a name="1260"></a> <code>CONSTANT_Methodref_info {</code> <code> u1 tag;</code> <code> u2 class_index;</code> <code> u2 name_and_type_index;</code><a name="1264"></a> <code>}</code><br><br><a name="1266"></a> <code>CONSTANT_InterfaceMethodref_info {</code> <code> u1 tag;</code> <code> u2 class_index;</code> <code> u2 name_and_type_index;</code><a name="1270"></a> <code>}</code><br></pre><a name="9360"></a>The items of these structures are as follows:<p><a name="6689"></a><dl><dt><code>tag</code><dd>The <code>tag</code> item of a <code>CONSTANT_Fieldref_info</code> structure has the value <code>CONSTANT_Fieldref</code> (<code>9</code>). <p>The <code>tag</code> item of a <code>CONSTANT_Methodref_info</code> structure has the value <code>CONSTANT_Methodref</code> (<code>10</code>).<p>The <code>tag</code> item of a <code>CONSTANT_InterfaceMethodref_info</code> structure has the value <code>CONSTANT_InterfaceMethodref</code> (<code>11</code>).<p><a name="1273"></a><dt><code>class_index</code><dd> The value of the <code>class_index</code> item must be a valid index into the <code>constant_pool</code> table. The <code>constant_pool</code> entry at that index must be a <code>CONSTANT_Class_info</code> <a href="ClassFile.doc.html#1221">(§4.4.1)</a> structure representing the class or interface type that contains the declaration of the field or method.<p>The <code>class_index</code> item of a <code>CONSTANT_Methodref_info</code> structure must be a class type, not an interface type. The <code>class_index</code> item of a <code>CONSTANT_InterfaceMethodref_info</code> structure must be an interface type. The <code>class_index</code> item of a <code>CONSTANT_Fieldref_info</code> structure may be either a class type or an interface type. <p><a name="1276"></a><dt><code>name_and_type_index</code><dd> The value of the <code>name_and_type_index</code> item must be a valid index into the <code>constant_pool</code> table. The <code>constant_pool</code> entry at that index must be a <code>CONSTANT_NameAndType_info</code> <a href="ClassFile.doc.html#1327">(§4.4.6)</a> structure. This <code>constant_pool</code> entry indicates the name and descriptor of the field or method. In a <code>CONSTANT_Fieldref_info</code> the indicated descriptor must be a field descriptor <a href="ClassFile.doc.html#14152">(§4.3.2)</a>. Otherwise, the indicated descriptor must be a method descriptor <a href="ClassFile.doc.html#7035">(§4.3.3)</a>.<p>If the name of the method of a <code>CONSTANT_Methodref_info</code> structure begins with a<code>' <'</code> (<code>'\u003c'</code>), then the name must be the special name <code><init></code>, representing an instance initialization method <a href="Overview.doc.html#12174">(§3.9)</a>. Such a method must return no value. <p></dl><a name="29297"></a><h3>4.4.3 The <code>CONSTANT_String_info</code> Structure</h3><a name="21417"></a>The <code>CONSTANT_String_info</code> structure is used to represent constant objects of the type <code>String</code>:<p><pre><br><a name="21424"></a> <code>CONSTANT_String_info {</code> <code> u1 tag;</code> <code> u2 string_index;</code><a name="21426"></a> <code>}</code><br></pre><a name="9366"></a>The items of the <code>CONSTANT_String_info</code> structure are as follows:<p><a name="21646"></a><dl><dt><code>tag</code></b><br><a name="21647"></a><dd> The <code>tag</code> item of the <code>CONSTANT_String_info</code> structure has the value <code>CONSTANT_String</code> (<code>8</code>).<p><a name="6663"></a><dt><code>string_index</code></b><br><a name="6664"></a><dd> The value of the <code>string_index</code> item must be a valid index into the <code>constant_pool</code> table. The <code>constant_pool</code> entry at that index must be a <code>CONSTANT_Utf8_info</code> <a href="ClassFile.doc.html#7963">(§4.4.7)</a> structure representing the sequence of characters to which the <code>String</code> object is to be initialized.<p><a name="21942"></a></dl><h3>4.4.4 The <code>CONSTANT_Integer_info</code> and <code>CONSTANT_Float_info</code> Structures </h3><a name="20768"></a>The <code>CONSTANT_Integer_info</code> and <code>CONSTANT_Float_info</code> structures represent 4-byte numeric (<code>int</code> and <code>float</code>) constants:<p><pre><br><a name="20560"></a> <code>CONSTANT_Integer_info {</code> <code> u1 tag;</code> <code> u4 bytes;</code><a name="20497"></a> <code>}</code><br><br><a name="20499"></a> <code>CONSTANT_Float_info {</code> <code> u1 tag;</code> <code> u4 bytes;</code><a name="9373"></a> <code>}</code><br></pre><a name="9376"></a>The items of these structures are as follows:<p><a name="9375"></a><dl><dt><code>tag</code><dd> The <code>tag</code> item of the <code>CONSTANT_Integer_info</code> structure has the value <code>CONSTANT_Integer</code> (<code>3</code>).<p>The <code>tag</code> item of the <code>CONSTANT_Float_info</code> structure has the value <code>CONSTANT_Float</code> (<code>4</code>).<p><a name="20502"></a><dt><code>bytes</code><dd> The <code>bytes</code> item of the <code>CONSTANT_Integer_info</code> structure represents the value of the <code>int</code> constant. The bytes of the value are stored in big-endian (high byte first) order.<p>The <code>bytes</code> item of the <code>CONSTANT_Float_info</code> structure represents the value of the <code>float</code> constant in IEEE 754 floating-point single format <a href="Overview.doc.html#28147">(§3.3.2)</a>. The bytes of the single format representation are stored in big-endian (high byte first) order. <p>The value represented by the <code>CONSTANT_Float_info</code> structure is determined as follows. The bytes of the value are first converted into an <code>int</code> constant bits. Then:<p><ul><li>If bits is <code>0x7f800000</code>, the <code>float</code> value will be positive infinity.<li>If bits is <code>0xff800000</code>, the <code>float</code> value will be negative infinity.<li>If bits is in the range <code>0x7f800001</code> through <code>0x7fffffff</code> or in the range <code>0xff800001</code> through <code>0xffffffff</code>, the <code>float</code> value will be NaN. <li>In all other cases, let <code>s</code>, <code>e</code>, and <code>m</code> be three values that might be computed from <em>bits</em>:</ul><pre> <code> int s = ((</code>bits<code> >> 31) == 0) ? 1 : -1;</code> <code> int e = ((</code>bits<code> >> 23) & 0xff);</code> <code> int m = (e == 0) ?</code> <code> (</code>bits<code> & 0x7fffff) << 1 :</code> <code> (</code>bits<code> & 0x7fffff) | 0x800000;</code>Then the <code>float</code> value equals the result of the mathematical expression <code>s·m·2<sup>e-150</sup></code>.</ul></pre><a name="1348"></a><h3>4.4.5 The <code>CONSTANT_Long_info</code> and <code>CONSTANT_Double_info</code> Structures</h3><a name="20772"></a>The <code>CONSTANT_Long_info</code> and <code>CONSTANT_Double_info</code> represent 8-byte numeric (<code>long</code> and <code>double</code>) constants:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -