📄 quick2.doc3.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html>
<head>
<title>VM Spec </title>
</head>
<body BGCOLOR=#eeeeff text=#000000 LINK=#0000ff VLINK=#000077 ALINK=#ff0000>
<table width=600><tr>
<td><a href="Copyright.doc.html">Contents</a> | <a href="Quick2.doc2.html">Prev</a> | <a href="Quick2.doc4.html">Next</a> | <a href="Lindholm.INDEX.html">Index</a></td><td align=right><i><i>The Java<sup><font size=-2>TM</font></sup> Virtual Machine Specification</i></i></td>
</tr></table>
<hr><br>
<a name="instanceof_quick"></a>
<h2>instanceof_quick</h2>
<a name="instanceof_quick.Operation"></a>
<b>Operation</b><br>
<a name="5311"></a>
<p>
<Table Border="0">
<tr><td><a name="5306"></a>
<i>instanceof_quick</i>
<td><a name="423"></a>
<tr><td><a name="5308"></a>
<i>indexbyte1</i>
<td><a name="430"></a>
<tr><td><a name="5310"></a>
<i>indexbyte2</i>
<td><a name="437"></a>
</Table>
Determine if object is of given type<p>
<a name="instanceof_quick.Forms"></a>
<b>Forms</b><br>
<a name="12455"></a>
<i>instanceof_quick</i> = 225 (0xe1)<p>
<a name="instanceof_quick.Stack"></a>
<b>Stack</b><br>
<a name="5312"></a>
..., <i>objectref</i><em> </em><img src="chars/arrwdbrt.gif"> ..., <i>result</i><p>
<a name="instanceof_quick.Description"></a>
<b>Description</b><br>
<a name="8113"></a>
The <i>objectref</i>, which must be of type <code>reference</code>, is popped from the operand stack. The unsigned <i>indexbyte1</i> and <i>indexbyte2</i> are used to construct an index into the constant pool of the current class <a href="Overview.doc.html#17257">(§3.6)</a>, where the value of the index is (<i>indexbyte1</i> << 8) | <i>indexbyte2</i>. The class at that index of the constant pool must have already been successfully resolved and may be a class, array, or interface.<p>
<a name="18712"></a>
If <i>objectref</i> is not <code>null</code> and is an instance of the resolved class, array, or interface, the <i>instanceof_quick</i> instruction pushes an <code>int</code> <i>result</i> of <i>1</i> as an int on the operand stack. Otherwise, it pushes an <code>int</code> <i>result</i> of <i>0</i>.<p>
<a name="18713"></a>
The following rules are used to determine whether an <i>objectref</i> that is not <code>null</code> is an instance of the resolved type: If S is the class of the object referred to by <i>objectref</i> and T is the resolved class, array, or instance type, <i>instanceof_quick</i> determines whether <i>objectref</i> is an instance of T as follows:<p>
<ul><a name="11862"></a>
<li>If S is an ordinary (non-array) class, then:
<ul>
<a name="11866"></a>
<li>If T is a class type, then S must be the same class <a href="Concepts.doc.html#20389">(§2.8.1)</a> as T, or a subclass of T.
<a name="11870"></a>
<li>If T is an interface type, then S must implement <a href="Concepts.doc.html#16432">(§2.13)</a> interface T.
<a name="22108"></a>
instanceof_quick (cont.) instanceof_quick (cont.)<p>
</ul>
<a name="11871"></a>
<li>If S is a class representing the array type SC<code>[]</code>, that is, an array of components of type SC, then:
<ul>
<a name="11875"></a>
<li>If T is a class type, then T must be <code>Object</code> <a href="Concepts.doc.html#27433">(§2.4.6)</a>.
<a name="11876"></a>
<li>If T is an array type TC<code>[]</code>, that is, an array of components of type TC, then one of the following must be true:
<ul>
<a name="11880"></a>
<li>TC and SC are the same primitive type <a href="Concepts.doc.html#19511">(§2.4.1)</a>.
<a name="11884"></a>
<li>TC and SC are reference types <a href="Concepts.doc.html#25376">(§2.4.5)</a> and type SC can be cast to TC by these runtime rules.
</ul>
</ul>
</ul><a name="8134"></a>
S cannot be an interface type, because there are no instances of interfaces, only instances of classes and arrays.<p>
<a name="instanceof_quick.Notes"></a>
<b>Notes</b><br>
<a name="5318"></a>
The opcode of this instruction was originally <i>instanceof</i>. The operands of the <i>instanceof</i> instruction are not modified.<p>
<a name="5243"></a>
invokeinterface_quick invokeinterface_quick<p>
<a name="instanceof_quick.Operation"></a>
<b>Operation</b><br>
<a name="5257"></a>
Invoke interface method<p>
<Table Border="0">
<tr><td><a name="5248"></a>
<i>invokeinterface_quick</i>
<td><a name="182"></a>
<tr><td><a name="5250"></a>
<i>idbyte1</i>
<td><a name="189"></a>
<tr><td><a name="5252"></a>
<i>idbyte2</i>
<td><a name="196"></a>
<tr><td><a name="5254"></a>
<i>nargs</i>
<td><a name="203"></a>
<tr><td><a name="5256"></a>
<i>guess</i>
<td><a name="210"></a>
</Table>
<p>
<a name="instanceof_quick.Forms"></a>
<b>Forms</b><br>
<a name="12456"></a>
<i>invokeinterface_quick</i> = 218 (0xda)<p>
<a name="instanceof_quick.Stack"></a>
<b>Stack</b><br>
<a name="5258"></a>
...<em>, </em><i>objectref</i><em>, [</em><i>arg1</i><em>, [</em><i>arg2</i><em> </em>...<em>]] </em><img src="chars/arrwdbrt.gif"> ...<p>
<a name="instanceof_quick.Description"></a>
<b>Description</b><br>
<a name="11638"></a>
The unsigned <i>idbyte1</i> and <i>idbyte2</i> are used to construct an identifier for the name and descriptor <a href="ClassFile.doc.html#7035">(§4.3.3)</a> of the desired method, where the value of the identifier is (<i>idbyte1</i> << 8) | <i>idbyte2</i>. <p>
<a name="11642"></a>
The <i>nargs</i> operand is an unsigned byte which must not be zero. The <i>objectref</i> must be of type <code>reference</code> and must be followed on the operands stack by <i>nargs</i> - 1 words of arguments. The method table of the class of the type of <i>objectref</i> is determined. If <i>objectref</i> is an array type, then the method table of class <code>Object</code> is used.<p>
<a name="11615"></a>
The unsigned <i>guess</i> is used to index into the method table. If there is a method at index <i>guess</i>, and if its identifier is identical to the constructed identifier, then that method is selected. Otherwise, the method table is searched for a method whose identifier is identical to the constructed identifier. If one is found, the current value of <i>guess</i> is overwritten by that index.<p>
<a name="11655"></a>
The result of the search is a method table entry, which includes a direct reference to the code for the interface method and the method's modifier information ((see <a href="ClassFile.doc.html#12725">Table 4.4, "Method access and modifier flags"</a>). The method table entry must be that of a <code>public</code> method.<p>
<a name="22116"></a>
invokeinterface_quick (cont.) invokeinterface_quick (cont.)<p>
<a name="18526"></a>
If the method is <code>synchronized</code>, the monitor associated with <i>objectref</i> is acquired.<p>
<a name="18527"></a>
If the method is not <code>native</code>, the <i>nargs </i>- 1 words of arguments and <i>objectref</i> are popped from the operand stack. A new stack frame is created for the method being invoked, and <i>objectref</i> and the words of arguments are made the values of its first <i>nargs</i> local variables, with <i>objectref</i> in local variable <i>0</i>, <i>arg1</i> in local variable <i>1</i>, and so on. The new stack frame is then made current, and the Java Virtual Machine <code>pc</code> is set to the opcode of the first instruction of the method to be invoked. Execution continues with the first instruction of the method.<p>
<a name="18528"></a>
If the method is <code>native</code> and the platform-dependent code that implements it has not yet been loaded and linked into the Java Virtual Machine, that is done. The <i>nargs </i>- 1 words of arguments and <i>objectref</i> are popped from the operand stack; the code that implements the method is invoked in an implementation-dependent manner.<p>
<a name="instanceof_quick.Linking"></a>
<b>Linking Exceptions</b><br>
<a name="12075"></a>
If no method matching the resolved name and descriptor can be found in the class of <i>objectref</i>, <i>invokeinterface_quick</i> throws an <code>IncompatibleClassChangeError</code>.<p>
<a name="11782"></a>
Otherwise, if the selected method is a class (<code>static</code>) method, the <i>invokeinterface_quick</i> instruction throws an <code>IncompatibleClassChangeError</code>.<p>
<a name="11783"></a>
Otherwise, if the selected method is not <code>public</code>, the <i>in-vokeinterface_quick</i> instruction throws an <code>IllegalAccess-Error</code>.<p>
<a name="12163"></a>
Otherwise, if the selected method is <code>abstract</code>, <i>invoke-interface_quick</i> throws an <code>AbstractMethodError</code>.<p>
<a name="12164"></a>
Otherwise, if the selected method is <code>native</code> and the code that implements the method cannot be loaded or linked, <i>invoke-interface_quick </i>throws an <code>UnsatisfiedLinkError</code>.<p>
<a name="22168"></a>
invokeinterface_quick (cont.) invokeinterface_quick (cont.)<p>
<a name="instanceof_quick.Runtime"></a>
<b>Runtime Exception</b><br>
<a name="5268"></a>
Otherwise, if <i>objectref</i> is <code>null</code>, the <i>invokeinterface_quick</i> instruction throws a <code>NullPointerException</code>. <p>
<a name="instanceof_quick.Notes"></a>
<b>Notes</b><br>
<a name="5270"></a>
The opcode of this instruction was originally <i>invokeinterface</i>. The initial value of <i>guess</i> is 0, the operand value supplied by <i>invokeinterface</i>. The identifiers being compared and stored in the <i>invokeinterface_quick</i> instruction encode a method name and descriptor as a 16-bit quantity that can be compared quickly. The details of the encoding are implementation-specific. The bytes of the identifier for the method being invoked, <i>idbyte1</i> and <i>idbyte2</i>, replace the original constant pool index bytes. The identifier can be calculated when each method is loaded, or at run time. The value of the <i>nargs</i> operand is not modified.<p>
<a name="12207"></a>
invokenonvirtual_quick invokenonvirtual_quick<p>
<a name="instanceof_quick.Operation"></a>
<b>Operation</b><br>
<a name="12217"></a>
Invoke an instance initialization method or a private method, dispatching based on compile-time type<p>
<Table Border="0">
<tr><td><a name="12212"></a>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -