📄 classfile.doc.html
字号:
<td><a name="9680"></a>
<code>6</code>
<tr><td><a name="9682"></a>
<code>CONSTANT_NameAndType</code>
<td><a name="9684"></a>
<code>12</code>
<tr><td><a name="9686"></a>
<code>CONSTANT_Utf8</code>
<td><a name="9688"></a>
<code>1</code>
</Table><br><br>. 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.
<p><a name="1221"></a>
<h3>4.4.1 <em>CONSTANT_Class</em></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></pre><pre> <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>
<b> tag</b><br><blockquote><a name="1229"></a>
The <code>tag</code> item has the value <code>CONSTANT_Class</code> (<code>7</code>).<p>
</blockquote><a name="8829"></a>
<b> name_index</b><br><blockquote><a name="8830"></a>
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 Java class name <a href="Concepts.doc.html#20389">(§2.8.1)</a> that has been converted to the <code>class</code> file's internal form (<a href="ClassFile.doc.html#14757">§4.2)</a>. <p>
</blockquote><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. In this case, 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="11150"></a>
A valid Java array type descriptor must have 255 or fewer array dimensions.
<p><a name="4723"></a>
<h3>4.4.2 <em>CONSTANT_Fieldref</em>, <em>CONSTANT_Methodref</em>, and <em>CONSTANT_InterfaceMethodref</em></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></pre><pre> <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>
<b> tag</b><br><blockquote><a name="6690"></a>
The <code>tag</code> item of a <code>CONSTANT_Fieldref_info</code> structure has the value <code>CONSTANT_Fieldref</code> (<code>9</code>). <p>
<a name="6698"></a>
The <code>tag</code> item of a <code>CONSTANT_Methodref_info</code> structure has the value <code>CONSTANT_Methodref</code> (<code>10</code>).<p>
<a name="6701"></a>
The <code>tag</code> item of a <code>CONSTANT_InterfaceMethodref_info</code> structure has the value <code>CONSTANT_InterfaceMethodref</code> (<code>11</code>).<p>
</blockquote><a name="1273"></a>
<b> class_index</b><br><blockquote><a name="1274"></a>
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>
<a name="7650"></a>
The <code>class_index</code> item of a <code>CONSTANT_Fieldref_info</code> or 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 that declares the given method.<p>
</blockquote><a name="1276"></a>
<b> name_and_type_index</b><br><blockquote><a name="1277"></a>
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.<p>
<a name="8792"></a>
If the name of the method of a <code>CONSTANT_Methodref_info</code> or <code>CONSTANT_InterfaceMethodref_info</code> begins with a <code>'<'</code> (<code>'u003c'</code>), then the name must be one of the special internal methods <a href="Overview.doc.html#12174">(§3.8)</a>, either <code><init></code> or <code><clinit></code>. In this case, the method must return no value.<p>
</blockquote><a name="8794"></a>
<h3>4.4.3 <em>CONSTANT_String </em></h3>
<a name="21417"></a>
The <code>CONSTANT_String_info</code> structure is used to represent constant objects of the type
<code>java.lang.String</code>:
<p><pre><br><a name="21424"></a> <code>CONSTANT_String_info {
</code></pre><pre> <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>
<b> tag</b><br><blockquote><a name="21647"></a>
The <code>tag</code> item of the <code>CONSTANT_String_info</code> structure has the value <code>CONSTANT_String</code> (<code>8</code>).<p>
</blockquote><a name="6663"></a>
<b> string_index</b><br><blockquote><a name="6664"></a>
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#8794">(§4.4.3)</a> structure representing the sequence of characters to which the <code>java.lang.String</code> object is to be initialized.<p>
</blockquote><a name="21942"></a>
<h3>4.4.4 <i></i><i>CONSTANT_Integer</i> and <i>CONSTANT_Float </i></h3>
<a name="20768"></a>
The <code>CONSTANT_Integer_info</code> and <code>CONSTANT_Float_info</code> structures represent four-byte
numeric (<code>int</code> and <code>float</code>) constants:
<p><pre><br><a name="20560"></a> <code>CONSTANT_Integer_info {
</code></pre><pre> <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>
<b> tag</b><br><blockquote><a name="21652"></a>
The <code>tag</code> item of the <code>CONSTANT_Integer_info</code> structure has the value <code>CONSTANT_Integer</code> (<code>3</code>).<p>
<a name="7297"></a>
The <code>tag</code> item of the <code>CONSTANT_Float_info</code> structure has the value <code>CONSTANT_Float</code> (<code>4</code>).<p>
</blockquote><a name="20502"></a>
<b> bytes</b><br><blockquote><a name="20668"></a>
The <code>bytes</code> item of the <code>CONSTANT_Integer_info</code> structure contains the value of the <code>int</code> constant. The bytes of the value are stored in big-endian (high byte first) order.<p>
<a name="22609"></a>
The <code>bytes</code> item of the <code>CONSTANT_Float_info</code> structure contains the value of the <code>float</code> constant in IEEE 754 floating-point "single format" bit layout. The bytes of the value are stored in big-endian (high byte first) order, and are first converted into an <code>int</code> argument. Then:<p>
<ul>
<a name="22610"></a>
<li>If the argument is <code>0x7f800000</code>, the <code>float</code> value will be positive infinity.
<a name="22611"></a>
<li>If the argument is <code>0xff800000</code>, the <code>float</code> value will be negative infinity.
<a name="22612"></a>
<li>If the argument 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.
<a name="22613"></a>
<li>In all other cases, let <code>s</code>, <code>e</code>, and <code>m</code> be three values that might be computed by
</ul>
</blockquote><pre> <code>int s = ((bytes >> 31) == 0) ? 1 : -1;
</code> <code>int e = ((bytes >> 23) & 0xff);
</code> <code>int m = (e == 0) ?
</code> <code> (bytes & 0x7fffff) << 1 :
</code> <code> (bytes & 0x7fffff) | 0x800000;
</code></pre><blockquote><a name="13707"></a>
Then the <code>float</code> value equals the result of the mathematical expression <br><br><img src="ClassFile.doc.anc.gif">
<br><br>.<p>
</blockquote><a name="1348"></a>
<h3>4.4.5 <em>CONSTANT_Long</em> and <em>CONSTANT_Double </em></h3>
<a name="20772"></a>
The <code>CONSTANT_Long_info</code> and <code>CONSTANT_Double_info</code> represent eight-byte numeric
(<code>long</code> and <code>double</code>) constants:
<p><pre><br><a name="20787"></a> <code>CONSTANT_Long_info {
</code></pre><pre> <code> u1 tag;
</code> <code> u4 high_bytes;
</code> <code> u4 low_bytes;
</code><a name="20790"></a> <code>}
</code><br><br><a name="21702"></a> <code>CONSTANT_Double_info {
</code> <code> u1 tag;
</code> <code> u4 high_bytes;
</code> <code> u4 low_bytes;
</code><a name="21696"></a> <code>}
</code><br></pre><a name="16625"></a>
All eight-byte constants take up two entries in the <code>constant_pool</code> table of the <code>class</code> file, as well as in the in-memory version of the constant pool that is constructed when a <code>class</code> file is read. If a <code>CONSTANT_Long_info</code> or <code>CONSTANT_Double_info</code> structure is the item in the <code>constant_pool</code> table at index n, then the next valid item in the pool is located at index n+2. The <code>constant_pool</code> index n+1 must be considered invalid and must not be used.<a href="#16628"><sup>1</sup></a><p>
<a name="9381"></a>
The items of these structures are as follows:
<p><a name="7309"></a>
<b> tag</b><br><blockquote><a name="7310"></a>
The <code>tag</code> item of the <code>CONSTANT_Long_info</code> structure has the value <code>CONSTANT_Long</code> (<code>5</code>).<p>
<a name="7313"></a>
The <code>tag</code> item of the <code>CONSTANT_Double_info</code> structure has the value <code>CONSTANT_Double</code> (<code>6</code>).<p>
</blockquote><a name="20793"></a>
<b> high_bytes, low_bytes</b><br><blockquote><a name="20794"></a>
The unsigned <code>high_bytes</code> and <code>low_bytes</code> items of the <code>CONSTANT_Long</code> structure together contain the value of the <code>long</code> constant ((<code>long</code>)<code>high_bytes</code> << 32) + <code>low_bytes</code>, where the bytes of each of <code>high_bytes</code> and <code>low_bytes</code> are stored in big-endian (high byte first) order.<p>
<a name="20795"></a>
The <code>high_bytes</code> and <code>low_bytes</code> items of the <code>CONSTANT_Double_info</code> structure contain the <code>double</code> value in IEEE 754 floating-point "double format" bit layout. The bytes of each item are stored in big-endian (high byte first) order. The <code>high_bytes</code> and <code>low_bytes</code> items are first converted into a <code>long</code> argument. Then:<p>
<ul>
<a name="13750"></a>
<li>If the argument is <code>0x7f80000000000000L</code>, the <code>double</code> value will be positive infinity.
<a name="13751"></a>
<li>If the argument is <code>0xff80000000000000L</code>, the <code>double</code> value will be negative infinity.
<a name="13752"></a>
<li>If the argument is in the range <code>0x7ff0000000000001L</code> through <code>0x7fffffffffffffffL</code> or in the range <code>0xfff0000000000001L</code> through <code>0xffffffffffffffffL</code>, the <code>double</code> value will be NaN.
<a name="13753"></a>
<li>In all other cases, let <code>s</code>, <code>e</code>, and <code>m</code> be three values that might be computed from the argument:
</ul>
</blockquote><pre> <code>int s = ((bits >> 63) == 0) ? 1 : -1;
</code> <code>int e = (int)((bits >> 52) & 0x7ffL);
</code> <code>long m = (e == 0) ?
</code> <code> (bits & 0xfffffffffffffL) << 1 :
</code> <code> (bits & 0xfffffffffffffL) | 0x10000000000000L;
</code></pre><blockquote><a name="13772"></a>
Then the floating-point value equals the <code>double</code> value of the mathematical expression <br><br><img src="ClassFile.doc.anc1.gif">
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -