Navigation: Overview - Part A - Part B - Part C - Part D - Part E - Part F - Part G - Part H - Part J
Sections: JVMS-4.6 - JVMS-4.9.1 - JVMS-5.4.3.3 - JVMS-5.4.3.4 - JVMS-6.5.invokeinterface - JVMS-6.5.invokespecial - JVMS-6.5.invokestatic - JVMS-6.5.invokevirtual
Version 0.6.2. Copyright © 2012 Oracle America, Inc. Legal Notice.
Changes to the Java Virtual Machine are necessary to support the implementation of default methods. Methods declared in interface class files need not be declared abstract
, and thus can carry a Code
attribute. Methods declared in interface class files may also be private
or static
. The rules for method resolution and invocation (via invokeinterface
, invokespecial
, invokestatic
, and invokevirtual
) are enhanced to support execution of code in interfaces.
Compare JVMS 4.6
...
Methods of classes may set any of the flags in Table 4.20. However, a specific method of a class may have at most one of its ACC_PRIVATE
, ACC_PROTECTED
, and ACC_PUBLIC
flags set (8.4.3). [jvms-4.6-200-A.5]
Methods of interfaces may set any of the flags in Table 4.5 except ACC_PROTECTED
, ACC_FINAL
, ACC_NATIVE
, and ACC_SYNCHRONIZED
(9.4); they must have exactly one of the ACC_PUBLIC
or ACC_PRIVATE
flags set. [jsr335-4.6-200-A.10]
An interface method in a class file whose version number is not 52.0 or above must have its ACC_ABSTRACT
and ACC_PUBLIC
flags set they may have their . [jvms-4.6-200-A.6]
ACC_VARARGS
, ACC_BRIDGE
, and ACC_SYNTHETIC
flags set and must not have any of the other flags in Table 4.5 set (9.4)
If a specific method of a class or interface has its ACC_ABSTRACT
flag set, it must not have any of its ACC_FINAL
, ACC_NATIVE
, ACC_PRIVATE
, ACC_STATIC
, ACC_STRICT
, or ACC_SYNCHRONIZED
flags set (8.4.3.1, 8.4.3.3, 8.4.3.4). [jsr335-4.6-200-A.11]
...
Discussion and motivation:
Interface methods prior to version 52.0 must beabstract
, and thus must not beprivate
,static
, orstrictfp
; they are also prohibited from havingCode
attributes (4.7.3). In version 52.0, an interface method may be non-abstract and thus is free to use these flags and have aCode
attribute.
Compare JVMS 4.9.1
...
The static constraints on the operands of instructions in the code
array are as follows:
...
invokevirtual
invokespecial
, and invokestatic
constant_pool
table. The constant pool entry referenced by that index must be of type CONSTANT_Methodref
.
invokespecial
and invokestatic
instruction must represent a valid index into the constant_pool
table. The constant pool entry referenced by that index must be either of type CONSTANT_Methodref
or of type CONSTANT_InterfaceMethodref
.
...
Compare JVMS 5.4.3.3
To resolve an unresolved symbolic reference from D to a method in a class C, the symbolic reference to C given by the method reference is first resolved (5.4.3.1). Therefore, any exception that can be thrown as a result of failure of resolution of a class reference can be thrown as a result of method resolution. If the reference to C can be successfully resolved, exceptions relating to the resolution of the method reference itself can be thrown. [jvms-5.4.3.3-100]
When resolving a method reference: [jvms-5.4.3.3-200]
IncompatibleClassChangeError
. [jvms-5.4.3.3-200-A-1]
abstract
most-specific matching method, this is the referenced method and method lookup succeeds. [jsr335-5.4.3.3-200-C5]
abstract
most-specific matching methods, method resolution throws an IncompatibleClassChangeError
. [jsr335-5.4.3.3-200-C6]
abstract
most-specific matching method (possibly more than one), this is the referenced method and method lookup succeeds. [jsr335-5.4.3.3-200-C7]
If method lookup fails, method resolution throws a NoSuchMethodError
. [jvms-5.4.3.3-210-A]
If method lookup succeeds and the method is abstract
, but C is not abstract
, method resolution throws an AbstractMethodError
. [jvms-5.4.3.3-210-B]
Otherwise, if the referenced method is not accessible (5.4.4) to D, method resolution throws an IllegalAccessError
. [jvms-5.4.3.3-210-C]
...
Compare JVMS 5.4.3.4
To resolve an unresolved symbolic reference from D to an interface method in an interface C, the symbolic reference to C given by the interface method reference is first resolved (5.4.3.1). Therefore, any exception that can be thrown as a result of failure of resolution of an interface reference can be thrown as a result of interface method resolution. If the reference to C can be successfully resolved, exceptions relating to the resolution of the method reference itself can be thrown. [jvms-5.4.3.4-100]
When resolving an interface method reference: [jvms-5.4.3.4-200]
IncompatibleClassChangeError
. [jvms-5.4.3.4-200-A]
If method lookup fails, method resolution throws a NoSuchMethodError
. Otherwise, if the referenced method is not accessible (5.4.4) to D, method resolution throws an IllegalAccessError
. [jsr335-5.4.3.4-210]
Given a referenced method, let ... [jvms-5.4.3.4-200-C]
...
Compare JVMS 6.5.invokeinterface
...
Let C be the class of objectref. The actual method to be invoked is selected by the following lookup procedure: [jvms-6.5.invokeinterface.desc-200]
abstract
most-specific matching method, this is the method to be invoked. [jsr335-6.5.invokeinterface.desc-200-D3]
abstract
most-specific matching methods, an IncompatibleClassChangeError
is raised. [jsr335-6.5.invokeinterface.desc-200-D4]
AbstractMethodError
is raised. [jvms-6.5.invokeinterface.desc-200-C]
...
During resolution of the symbolic reference to the interface method, any of the exceptions pertaining to interface method resolution (JVMS-5.4.3.4) can be thrown. [jvms-6.5.invokeinterface.linking-100]
Otherwise, if the resolved method is a static
method, the invokeinterface
instruction throws an IncompatibleClassChangeError
. [jsr335-6.5.invokeinterface.linking-20]
...
Compare JVMS 6.5.invokespecial
...
The unsigned indexbyte1 and indexbyte2 are used to construct an index into the runtime constant pool of the current class (2.6), where the value of the index is (indexbyte1 << 8) | indexbyte2. The runtime constant pool item at that index must be a symbolic reference to a method or an interface method (5.1), which gives the name and descriptor (4.3.3) of the method as well as a symbolic reference to the class or interface in which the method is to be found. The named method is resolved (5.4.3.3). Finally, if the resolved method is protected
(4.6), and it is a member of a superclass of the current class, and the method is not declared in the same runtime package (5.3) as the current class, then the class of objectref must be either the current class or a subclass of the current class. [jvms-6.5.invokespecial.desc-100]
...
Compare JVMS 6.5.invokestatic
...
The unsigned indexbyte1 and indexbyte2 are used to construct an index into the runtime constant pool of the current class (2.6), where the value of the index is (indexbyte1 << 8) | indexbyte2. The runtime constant pool item at that index must be a symbolic reference to a method or an interface method (5.1), which gives the name and descriptor (4.3.3) of the method as well as a symbolic reference to the class or interface in which the method is to be found. The named method is resolved (5.4.3.3). The resolved method must not be an instance initialization method (2.9) or the a class or interface initialization method (2.9). It must be static
, and therefore cannot be abstract
. If the resolved method is declared in an interface, that interface must be the one named by the symbolic reference. [jvms-6.5.invokestatic.desc-100]
On successful resolution of the method, the class or interface that declared the resolved method is initialized (5.5) if that class or interface has not already been initialized. [jvms-6.5.invokestatic.desc-110]
...
Otherwise, if the resolved method is an instance method, the invokestatic instruction throws an IncompatibleClassChangeError
. [jvms-6.5.invokestatic.linking-110]
Otherwise, if the resolved method is declared in an interface other than the class or interface named by the method reference, the invokestatic instruction throws an IncompatibleClassChangeError
. [jsr335-6.5.invokestatic.linking-20]
Otherwise, if execution of this invokestatic instruction causes initialization of the referenced class or interface, invokestatic may throw an Error
as detailed in 5.5. [jvms-6.5.invokestatic.runtime-100]
...
Compare JVMS 6.5.invokevirtual
...
The unsigned indexbyte1 and indexbyte2 are used to construct an index into the runtime constant pool of the current class (2.6), where the value of the index is (indexbyte1 << 8) | indexbyte2. The runtime constant pool item at that index must be a symbolic reference to a method (5.1), which gives the name and descriptor (4.3.3) 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 (5.4.3.3). The resolved method must not be an instance initialization method (2.9) or the a class or interface initialization method (2.9). Finally, if the resolved method is protected
(4.6), and it is a member of a superclass of the current class, and the method is not declared in the same runtime package (5.3) as the current class, then the class of objectref must be either the current class or a subclass of the current class. [jvms-6.5.invokevirtual.desc-100]
If the resolved method is not signature polymorphic (2.9), then the invokevirtual instruction proceeds as follows. [jvms-6.5.invokevirtual.desc-200]
Let C be the class of objectref. The actual method to be invoked is selected by the following lookup procedure: [jvms-6.5.invokevirtual.desc-210]
AbstractMethodError
is raised. [jvms-6.5.invokevirtual.desc-210-C]
abstract
most-specific matching method, this is the method to be invoked. [jsr335-6.5.invokevirtual.desc-210-Y33]
abstract
most-specific matching methods, an IncompatibleClassChangeError
is raised. [jsr335-6.5.invokevirtual.desc-210-Y34]
AbstractMethodError
is raised. [jsr335-6.5.invokevirtual.desc-210-Y35]
...
Otherwise, if the resolved method is not signature polymorphic: [jvms-6.5.invokevirtual.runtime-110]
IncompatibleClassChangeError
. [jsr335-6.5.invokevirtual.runtime-110-D]
AbstractMethodError
. [jvms-6.5.invokevirtual.runtime-110-A]
public
, invokevirtual throws an IllegalAccessError
. [jsr335-6.5.invokevirtual.runtime-110-E]
abstract
, invokevirtual throws an AbstractMethodError
. [jvms-6.5.invokevirtual.runtime-110-B]
native
... [jvms-6.5.invokevirtual.runtime-110-C]
...