📄 instructions2.doc6.html
字号:
<blockquote><a name="316034"></a>Let C<em> </em>be the class of <em>objectref</em>. The actual method to be invoked is selected by the following lookup procedure:</blockquote><p><ul><li>If C contains a declaration for an instance method with the same name and descriptor as the resolved method, then this is the method to be invoked, and the lookup procedure terminates.<p><li>Otherwise, if C has a superclass, this same lookup procedure is performed recursively using the direct superclass of C; the method to be invoked is the result of the recursive invocation of this lookup procedure.<p><li>Otherwise, an <code>AbstractMethodError</code> is raised.</ul><blockquote><a name="187953"></a>If the method is <code>synchronized</code>, the monitor associated with <i>objectref</i> is acquired or reentered.</blockquote><p><blockquote><a name="391024"></a>If the method is not <code>native</code>, the <i>nargs </i>argument values and <i>objectref</i> are popped from the operand stack. A new frame is created on the Java virtual machine stack for the method being invoked. The <i>objectref</i> and the argument values are consecutively made the values of local variables of the new frame, with <i>objectref</i> in local variable <i>0</i>, <i>arg1</i> in local variable <i>1</i> (or, if <i>arg1</i> is of type <code>long</code> or <code>double</code>, in local variables <i>1</i> and <i>2</i>), and so on. Any argument value that is of a floating-point type undergoes value set conversion <a href="Overview.doc.html#33120">(§3.8.3)</a> prior to being stored in a local variable. The new 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.</blockquote><p><blockquote><a name="210740"></a>If the method is <code>native</code> and the platform-dependent code that implements it has not yet been bound <a href="ConstantPool.doc.html#74727">(§5.6)</a> into the Java virtual machine, that is done. The <i>nargs</i> argument values and <i>objectref</i> are popped from the operand stack and are passed as parameters to the code that implements the method. Any argument value that is of a floating-point type undergoes value set conversion <a href="Overview.doc.html#33120">(§3.8.3)</a> prior to being passed as a parameter. The parameters are passed and the code is invoked in an implementation-dependent manner. When the platform-dependent code returns:</blockquote><p><ul><li>If the <code>native</code> method is <code>synchronized</code>, the monitor associated with <i>objectref</i> is released or exited as if by execution of a <i>monitorexit</i> instruction.<p><li>If the <code>native</code> method returns a value, the return value of the platform-dependent code is converted in an implementation-dependent way to the return type of the <code>native</code> method and pushed onto the operand stack.</ul><a name="invokeinterface.Linking"></a><p><b>Linking Exceptions</b><br><blockquote><a name="230485"></a>During resolution of the symbolic reference to the interface method, any of the exceptions documented in <a href="ConstantPool.doc.html#71722">§5.4.3.4</a> can be thrown.</blockquote><p><a name="invokeinterface.Runtime"></a><p><b>Runtime Exceptions</b><br><blockquote><a name="228552"></a>Otherwise, if <i>objectref</i> is <code>null</code>, the <i>invokeinterface</i> instruction throws a <code>NullPointerException</code>. </blockquote><p><blockquote><a name="177889"></a>Otherwise, if the class of <i>objectref</i> does not implement the resolved interface, <i>invokeinterface</i> throws an <code>IncompatibleClassChangeError</code>.</blockquote><p><blockquote><a name="177883"></a>Otherwise, if no method matching the resolved name and descriptor is selected, <i>invokeinterface</i> throws an <code>AbstractMethodError</code>.</blockquote><p><blockquote><a name="475783"></a>Otherwise, if the selected method is not <code>public</code>, <i>invokeinterface</i> throws an <code>IllegalAccessError</code>. </blockquote><p><blockquote><a name="475784"></a>Otherwise, if the selected method is <code>abstract</code>, <i>invokeinterface</i> throws an <code>AbstractMethodError</code>.</blockquote><p><blockquote><a name="496559"></a>Otherwise, if the selected method is <code>native</code> and the code that implements the method cannot be bound, <i>invokeinterface</i> throws an <code>UnsatisfiedLinkError</code>.</blockquote><p><a name="invokeinterface.Notes"></a><p><b>Notes</b><br><blockquote><a name="403926"></a>The <i>count</i> operand of the <i>invokeinterface</i> instruction records a measure of the number of argument values, where an argument value of type <code>long</code> or type <code>double</code> contributes two units to the <i>count</i> value and an argument of any other type contributes one unit. This information can also be derived from the descriptor of the selected method. The redundancy is historical. </blockquote><p><blockquote><a name="264762"></a>The fourth operand byte exists to reserve space for an additional operand used in certain of Sun's implementations, which replace the <i>invokeinterface</i> instruction by a specialized pseudo-instruction at run time. It must be retained for backwards compatibility.</blockquote><p><blockquote><a name="448033"></a>The <i>nargs</i> argument values and <i>objectref</i> are not one-to-one with the first <i>nargs</i> + <i>1</i> local variables. Argument values of types <code>long</code> and <code>double</code> must be stored in two consecutive local variables, thus more than <i>nargs</i> local variables may be required to pass <i>nargs</i> argument values to the invoked method.</blockquote><p><blockquote><a name="448030"></a></blockquote><p><a name="invokespecial"></a><hr><h2>invokespecial</h2><a name="invokespecial.Operation"></a><p><b>Operation</b><br><blockquote><a name="68833"></a>Invoke<strong></strong> instance method; special handling for superclass, private, and instance initialization method invocations<p><Table Border="1"></blockquote><p><b>Format</b><br><blockquote><tr><td><a name="68838"></a> <i>invokespecial</i><td><a name="87568"></a> <tr><td><a name="68840"></a> <i>indexbyte1</i><td><a name="87568"></a> <tr><td><a name="68842"></a> <i>indexbyte2</i><td><a name="87568"></a> </Table><br></blockquote><p><a name="invokespecial.Forms"></a><p><b>Forms</b><br><blockquote><a name="68843"></a><i>invokespecial</i> = 183 (0xb7)</blockquote><p><a name="invokespecial.Operand"></a><p><b>Operand Stack</b><br><blockquote><a name="68844"></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"> ...</blockquote><p><a name="invokespecial.Description"></a><p><b>Description</b><br><blockquote><a name="278683"></a>The unsigned <i>indexbyte1</i> and <i>indexbyte2</i> are used to construct an index into the runtime 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 runtime constant pool item at that index must be a symbolic reference to a method <a href="ConstantPool.doc.html#73272">(§5.1)</a>, which gives the name and descriptor <a href="ClassFile.doc.html#7035">(§4.3.3)</a> of the method as well as a symbolic reference to the class in which the method is to be found. The named method is resolved <a href="ConstantPool.doc.html#86899">(§5.4.3.3)</a>. Finally, if the resolved method is <code>protected</code> <a href="ClassFile.doc.html#1513">(§4.6)</a>, and it is either a member of the current class or a member of a superclass of the current class, then the class of <i>objectref</i> must be either the current class or a subclass of the current class.</blockquote><p><blockquote><a name="437176"></a>Next, the resolved method is selected for invocation unless all of the following conditions are true:</blockquote><p><ul><li>The <code>ACC_SUPER</code> flag (see <a href="ClassFile.doc.html#75734">Table 4.1, "Class access and property modifiers"</a>) is set for the current class.<p><li>The class of the resolved method is a superclass of the current class.<p><li>The resolved method is not an instance initialization method <a href="Overview.doc.html#12174">(§3.9)</a>.</ul><blockquote><a name="280879"></a>If the above conditions are true, the actual method to be invoked is selected by the following lookup procedure. Let C<em> </em>be the direct superclass of the current class:</blockquote><p><ul><li>If C contains a declaration for an instance method with the same name and descriptor as the resolved method, then this method will be invoked. The lookup procedure terminates.<p><li>Otherwise, if C has a superclass, this same lookup procedure is performed recursively using the direct superclass of C. The method to be invoked is the result of the recursive invocation of this lookup procedure.<p><li>Otherwise, an <code>AbstractMethodError</code> is raised.</ul><blockquote><a name="68873"></a>The <i>objectref</i> must be of type <code>reference</code> and must be followed on the operand stack by <i>nargs</i> argument values, where the number, type, and order of the values must be consistent with the descriptor of the selected instance method.</blockquote><p><blockquote><a name="138167"></a>If the method is <code>synchronized</code>, the monitor associated with <i>objectref</i> is acquired or reentered.</blockquote><p><blockquote><a name="236993"></a>If the method is not <code>native</code>, the <i>nargs</i> argument values and <i>objectref</i> are popped from the operand stack. A new frame is created on the Java virtual machine stack for the method being invoked. The <i>objectref</i> and the argument values are consecutively made the values of local variables of the new frame, with <i>objectref</i> in local variable <i>0</i>, <i>arg1</i> in local variable <i>1</i> (or, if <i>arg1</i> is of type <code>long</code> or <code>double</code>, in local variables <i>1</i> and <i>2</i>), and so on. Any argument value that is of a floating-point type undergoes value set conversion <a href="Overview.doc.html#33120">(§3.8.3)</a> prior to being stored in a local variable. The new 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.</blockquote><p><blockquote><a name="236991"></a></blockquote><p><blockquote><a name="205637"></a>If the method is <code>native</code> and the platform-dependent code that implements it has not yet been bound <a href="ConstantPool.doc.html#74727">(§5.6)</a> into the Java virtual machine, that is done. The <i>nargs</i> argument values and <i>objectref</i> are popped from the operand stack and are passed as parameters to the code that implements the method. Any argument value that is of a floating-point type undergoes value set conversion <a href="Overview.doc.html#33120">(§3.8.3)</a> prior to being passed as a parameter. The parameters are passed and the code is invoked in an implementation-dependent manner. When the platform-dependent code returns, the following take place:</blockquote><p><ul><li>If the <code>native</code> method is <code>synchronized</code>, the monitor associated with <i>objectref</i> is released or exited as if by execution of a <i>monitorexit</i> instruction. <p><li>If the <code>native</code> method returns a value, the return value of the platform-dependent code is converted in an implementation-dependent way to the return type of the <code>native</code> method and pushed onto the operand stack.</ul><a name="invokespecial.Linking"></a><p><b>Linking Exceptions</b><br><blockquote><a name="177880"></a>During resolution of the symbolic reference to the method, any of the exceptions pertaining to method resolution documented in <a href="ConstantPool.doc.html#86899">Section 5.4.3.3</a> can be thrown.</blockquote><p><blockquote><a name="437466"></a>Otherwise, if the resolved method is an instance initialization method, and the class in which it is declared is not the class symbolically referenced by the instruction, a <code>NoSuchMethodError</code> is thrown.</blockquote><p><blockquote><a name="68877"></a>Otherwise, if the resolved method is a class (<code>static</code>) method, the <i>invokespecial</i> instruction throws an <code>IncompatibleClassChangeError</code>.</blockquote><p><blockquote><a name="311447"></a>Otherwise, if no method matching the resolved name and descriptor is selected, <i>invokespecial</i> throws an <code>AbstractMethodError</code>.</blockquote><p><blockquote><a name="210995"></a>Otherwise, if the selected method is <code>abstract</code>, <i>invokespecial</i> throws an <code>AbstractMethodError</code>.</blockquote><p><a name="invokespecial.Runtime"></a><p><b>Runtime Exceptions</b><br><blockquote><a name="442232"></a>Otherwise, if <i>objectref</i> is <code>null</code>, the <i>invokespecial</i> instruction throws a <code>NullPointerException</code>.</blockquote><p><blockquote><a name="442233"></a>Otherwise, if the selected method is <code>native</code> and the code that implements the method cannot be bound, <i>invokespecial</i> throws an <code>UnsatisfiedLinkError</code>.</blockquote><p><a name="invokespecial.Notes"></a><p><b>Notes</b><br><blockquote><a name="68888"></a>The difference between the <i>invokespecial</i> and the <i>invokevirtual</i> instructions is that <i>invokevirtual</i> invokes a method based on the class of the object. The <i>invokespecial</i> instruction is used to invoke instance initialization methods <a href="Overview.doc.html#12174">(§3.9)</a> as well as <code>private</code> methods and methods of a superclass of the current class. </blockquote><p><blockquote><a name="68890"></a>The <i>invokespecial</i> instruction was named <i>invokenonvirtual</i> prior to Sun's JDK release 1.0.2.</blockquote><p><blockquote><a name="448025"></a>The <i>nargs</i> argument values and <i>objectref</i> are not one-to-one with the first <i>nargs</i> + <i>1</i> local variables. Argument values of types <code>long</code> and <code>double</code> must be stored in two consecutive local variables, thus more than <i>nargs</i> local variables may be required to pass <i>nargs</i> argument values to the invoked method.</blockquote><p><blockquote><a name="448022"></a></blockquote><p><a name="invokestatic"></a><hr><h2>invokestatic</h2><a name="invokestatic.Operation"></a><p><b>Operation</b><br><blockquote><a name="68901"></a>Invoke a class (<code>static</code>) method<p><Table Border="1"></blockquote><p><b>Format</b><br><blockquote><tr><td><a name="68896"></a> <i>invokestatic</i><td><a name="87568"></a> <tr><td><a name="68898"></a> <i>indexbyte1</i><td><a name="87568"></a> <tr><td><a name="68900"></a> <i>indexbyte2</i><td><a name="87568"></a> </Table><br></blockquote><p><a name="invokestatic.Forms"></a><p><b>Forms</b><br><blockquote><a name="68902"></a><i>invokestatic</i> = 184 (0xb8)</blockquote><p><a name="invokestatic.Operand"></a><p><b>Operand Stack</b><br><blockquote><a name="68903"></a>...<em>, [</em><i>arg1</i><em>, [</em><i>arg2</i><em> </em>...<em>]] </em><img src="chars/arrwdbrt.gif"> ...</blockquote><p><a name="invokestatic.Description"></a><p><b>Description</b><br><blockquote><a name="475919"></a>The unsigned <i>indexbyte1</i> and <i>indexbyte2</i> are used to construct an index into the runtime 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 runtime constant pool item at that index must be a symbolic reference to a method <a href="ConstantPool.doc.html#73272">(§5.1)</a>, which gives the name and descriptor <a href="ClassFile.doc.html#7035">(§4.3.3)</a> of the method as well as a symbolic reference to the class in which the method is to be found. The named method is resolved <a href="ConstantPool.doc.html#86899">(§5.4.3.3)</a>. The method must not be the class or interface initialization method <a href="Overview.doc.html#12174">(§3.9)</a>. It must be <code>static</code>, and therefore cannot be <code>abstract</code>. </blockquote><p><blockquote><a name="422204"></a>On successful resolution of the method, the class that declared the resolved field is initialized <a href="ConstantPool.doc.html#77976">(§5.5)</a> if that class has not already been initialized.</blockquote><p><blockquote><a name="238878"></a>The operand stack must contain <i>nargs</i> argument values, where the number, type, and order of the values must be consistent with the descriptor of the resolved method.</blockquote><p><blockquote><a name="240701"></a>If the method is <code>synchronized</code>, the monitor associated with the resolved class is acquired or reentered.</blockquote><p><blockquote><a name="447990"></a>If the method is not <code>native</code>, the <i>nargs </i>argument values are popped from the operand stack. A new frame is created on the Java virtual machine stack for the method being invoked. The <i>nargs</i> argument values are consecutively made the values of local variables of the new frame, with <i>arg1</i> in local variable <i>0</i> (or, if <i>arg1</i> is of type <code>long</code> or <code>double</code>, in local variables <i>0</i> and <i>1</i>) and so on. Any argument value that is of a floating-point type undergoes value set conversion <a href="Overview.doc.html#33120">(§3.8.3)</a> prior to being stored in a local variable. The new 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.</blockquote><p><blockquote><a name="327007"></a>If the method is <code>native</code> and the platform-dependent code that implements it has not yet been bound <a href="ConstantPool.doc.html#74727">(§5.6)</a> into the Java virtual machine, that is done. The <i>nargs</i> argument values are popped from the operand stack and are passed as parameters to the code that implements the method. Any argument value that is of a floating-point type undergoes value set conversion <a href="Overview.doc.html#33120">(§3.8.3)</a> prior to being passed as a parameter. The parameters are passed and the code is invoked in an implementation-dependent manner. When the platform-dependent code returns, the following take place:</blockquote><p><ul><li>If the <code>native</code> method is <code>synchronized</code>, the monitor associated with the resolved class is released or exited as if by execution of a <i>monitorexit</i> instruction. <p><li>If the <code>native</code> method returns a value, the return value of the platform-dependent code is converted in an implementation-dependent way to the return type of the <code>native</code> method and pushed onto the operand stack.</ul><a name="invokestatic.Linking"></a><p><b>Linking Exceptions</b><br><blockquote><a name="327014"></a>During resolution of the symbolic reference to the method, any of the exceptions pertaining to method resolution documented in <a href="ConstantPool.doc.html#86899">Section 5.4.3.3</a> can be thrown.</blockquote><p><blockquote><a name="444128"></a>Otherwise, if the resolved method is an instance method, the <i>invokestatic</i> instruction throws an <code>IncompatibleClassChangeError</code>.</blockquote><p><a name="invokestatic.Runtime"></a><p><b>Runtime Exceptions</b><br><blockquote><a name="398081"></a>Otherwise, if execution of this <i>invokestatic</i> instruction causes initialization of the referenced class, <i>invokestatic</i> may throw an <code>Error</code> as detailed in <a href="Concepts.doc.html#24237">Section 2.17.5</a>.</blockquote><p><blockquote><a name="399892"></a>Otherwise, if the resolved method is <code>native</code> and the code that implements the method cannot be bound, <i>invokestatic</i> throws an <code>UnsatisfiedLinkError</code>.</blockquote><p><a name="invokestatic.Notes"></a><p><b>Notes</b><br><blockquote><a name="448011"></a>The <i>nargs</i> argument values are not one-to-one with the first <i>nargs</i> local variables. Argument values of types <code>long</code> and <code>double</code> must be stored in two consecutive local variables, thus more than <i>nargs</i> local variables may be required to pass <i>nargs</i> argument values to the invoked method.</blockquote><p><a name="invokevirtual"></a><hr><h2>invokevirtual</h2><a name="invokevirtual.Operation"></a><p><b>Operation</b><br><blockquote><a name="68948"></a>Invoke instance method; dispatch based on class<p><Table Border="1"></blockquote><p><b>Format</b><br><blockquote><tr><td><a name="68943"></a> <i>invokevirtual</i><td><a name="87568"></a> <tr><td><a name="68945"></a> <i>indexbyte1</i><td><a name="87568"></a> <tr><td><a name="68947"></a> <i>indexbyte2</i><td><a name="87568"></a> </Table><br></blockquote><p><a name="invokevirtual.Forms"></a><p><b>Forms</b><br><blockquote><a name="68949"></a><i>invokevirtual</i> = 182 (0xb6)</blockquote><p><a name="invokevirtual.Operand"></a><p><b>Operand Stack</b><br><blockquote><a name="68950"></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"> ...</blockquote><p><a name="invokevirtual.Description"></a><p><b>Description</b><br><blockquote><a name="422216"></a>The unsigned <i>indexbyte1</i> and <i>indexbyte2</i> are used to construct an index into the runtime 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 runtime constant pool item at that index must be a symbolic reference to a method <a href="ConstantPool.doc.html#73272">(§5.1)</a>, which gives the name and descriptor <a href="ClassFile.doc.html#7035">(§4.3.3)</a> of the method as well as a symbolic reference t
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -