Site Tools

Sidebar

Smart Card Solution

User Manual

JavaCard API Samples

Java Card Specification

Knowledge Sharing

javacard:jcvm:7.5.54_invokeinterface

7.5.54 invokeinterface

Invoke interface method

Format

invokeinterface

nargs

indexbyte1

indexbyte2

method

Forms

invokeinterface = 142 (0x8e)

Stack

…, objectref, [arg1, [arg2 …]] → …

Description

The unsigned indexbyte1 and indexbyte2 are used to construct an index into the constant pool of the current package ( Section 3.5, Frames), where the value of the index is (indexbyte1 « 8) | indexbyte2. The constant pool item at that index must be of type CONSTANT_Classref ( Section 6.7.1, CONSTANT_Classref), a reference to an interface class. The specified interface is resolved.

The nargs operand is an unsigned byte that must not be zero.

The method operand is an unsigned byte that is the interface method token for the method to be invoked. The interface method must not be or an instance initialization method.

The objectref must be of type reference and must be followed on the operand stack by nargs - 1 words of arguments. The number of words of arguments and the type and order of the values they represent must be consistent with those of the selected interface method.

The interface table of the class of the type of objectref is determined. If objectref is an array type, then the interface table of class Object ( Section 2.2.2.4, Classes) is used. The interface table is searched for the resolved interface. The result of the search is a table that is used to map the method token to a index.

The index is an unsigned byte that is used as an index into the method table of the class of the type of objectref. If the objectref is an array type, then the method table of class Object is used. The table entry at that index includes a direct reference to the method's code and modifier information.

The nargs - 1 words of arguments and objectref are popped from the operand stack. A new stack frame is created for the method being invoked, and objectref and the arguments are made the values of its first nargs words of local variables, with objectref in local variable 0, arg1 in local variable 1, and so on. The new stack frame is then made current, and the Java Card virtual machine pc is set to the opcode of the first instruction of the method to be invoked. Execution continues with the first instruction of the method.

Runtime Exception

If objectref is null, the invokeinterface instruction throws a NullPointerException.

Notes

In some circumstances, the invokeinterface instruction may throw a SecurityException if the current context ( Section 3.4, Contexts) is not the context ( Section 3.4, Contexts) of the object referenced by objectref. The exact circumstances when the exception will be thrown are specified in Chapter 6 of the Runtime Environment Specification, Java Card Platform, Version 2.2.2. If the current context is not the object's context and the Java Card RE permits invocation of the method, the invokeinterface instruction will cause a context switch ( Section 3.4, Contexts) to the object's context before invoking the method, and will cause a return context switch to the previous context when the invoked method returns.

javacard/jcvm/7.5.54_invokeinterface.txt · Last modified: 2017/05/13 04:09 (external edit)