Nestmates with invokespecial
Manoj Palat
manoj.palat at in.ibm.com
Fri Apr 5 05:51:44 UTC 2019
Hi Alex, Dan, all,
Consider the following code:
class X {
public class Y{
private void foo() {
System.out.println("Hello");
}
}
public class Z1 extends Y {
public class Z2 {
void bar() {
Z1.super.foo(); // This call }
}
}
public static void main(String[] args) {
new X().new Z1().new Z2().bar();
}
}
Consider the call Z1.super.foo(); At ecj, for 11+, currently we do not
create synthetic accessor methods for private nestmate members; instead,
emit “invokespecial” since both Y and Z2 are nestmates – the relevant
portion of the byte code is shown below:
void bar();
descriptor: ()V
flags: (0x0000)
Code:
stack=1, locals=1, args_size=1
0: aload_0
1: getfield #10 // Field this$1:LX$Z1;
4: invokespecial #20 // Method X$Y.foo:()V
7: return
Run with any of the latest Java versions (I used the latest Java 12 as
well); the following error is thrown:
Exception in thread "main" java.lang.VerifyError: Bad invokespecial
instruction: current class isn't assignable to reference class.
Exception Details:
Location:
X$Z1$Z2.bar()V @4: invokespecial
Reason:
Error exists in the bytecode
Bytecode:
0000000: 2ab4 000a b700 14b1
at X.main(X.java:14)
Is this a problem in verification of invokespecial, where the nestmates are
not considered? Or are we supposed to go via synthetic emulation for
qualified super class private methods even if they are nestmates?
Note: at JVMS 11 - 4.9.2, under invokespecial, I don’t see the nestmates
referred to, although the corresponding bug
https://bugs.openjdk.java.net/browse/JDK-8177020 mentions that the
“proposed changes” include the addition of “With nestmates it may also
name a method of a nestmate's class. “ to section 4.9.2. Any reason(s) for
the omission of this condition?
Regards,
Manoj.
Eclipse Java Dev, IBM.
More information about the jls-jvms-spec-comments
mailing list