JDK-8006267 : InterfaceMethod_ref should allow invokestatic and invokespecial
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: runtime
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2013-01-15
  • Updated: 2014-06-26
  • Resolved: 2013-04-18
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8 Other
8Fixed hs25Fixed
Related Reports
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Sub Tasks
JDK-8012961 :  
JDK-8013875 :  
Description
Per the lambda spec, hotspot now allows interface methods to be static.  
Per the upcoming version (0.6.2) of the lambda spec, these static interface methods are InterfaceMethod_ref.  Currently, classFileParser.cpp disallows invokestatic (and invokespecial) calls to InterfaceMethod_ref.  Thus these methods cannot be called.

Below describes the spec:

...keep the current restrictions on Methodref_info, and the instruction arguments will be expected as follows:

invokevirtual(Methodref_info)
invokeinterface(InterfaceMethoref_info)
invokespecial(Methodref_info or InterfaceMethodref_info)
invokestatic(Methodref_info or InterfaceMethodref_info)

-----
Please find attached a proposed patch to accomplish this.  It is unknown if restrictions will need to be put elsewhere in the VM to compensate for this widening.


Comments
It was my understanding that static interface methods are now deferred to Java 9, or at least post Java 8 ?
09-03-2013

None of the above examples include static methods. Those can be declared directly in Java source: ----- interface I { static int m() { return 12; } } class Test { public static void main(String... args) { System.out.println(I.m()); }} ----- Also worth noting that class files generated by something other than javac may generate arbitrary private methods in the interface, invokable via invokespecial. (In contrast, javac only uses them to encode lambdas, I think.)
08-03-2013

And here are two more tests Robert Field and Dan Smith have provided me - for the record class PS implements I { public static void main(String[] args) { System.err.printf("pow: %s\n", (new PS()).thing().f(0.5)); } } interface I { default FI thing() { return (x) -> x * x; } } interface FI { Double f(Double x); } ========== interface Dog { default void bark() { System.out.println("Woof"); } } class Foo implements Dog { public Foo() { Dog.super.bark(); } }
06-03-2013

Example one: private static interface method interface I { default void m() { Runnable r = ()-> { System.out.println("Hello"); }; //the plan is to generate a private static synthetic method for translating this lambda away } } Example two: private instance interface method interface Sup { default void m() { } } interface I extends Sup { default m() { Runnable r = ()-> { Sup.super.m() }; //the plan is to generate a private instance synthetic method for translating this lambda away } }
06-03-2013

It appears that changes also need be made to java.lang.invoke.* classes to facilitate the proposed change. Not sure if this effect was also considered while proposing the change.
21-02-2013

There will need to be a separate bug for the JDK changes. I'm wondering if core reflection also needs to be updated to handle these new kinds of methods?
21-02-2013