b130 MethodHandle weirdness?

John Rose john.r.rose at oracle.com
Mon Feb 21 17:52:49 PST 2011


On Feb 21, 2011, at 10:55 AM, Ben Evans wrote:

> Hi,
> 
> I've noticed some oddities with b130 MethodHandles (this is x64 Ubuntu):
> 
>         private void foo() {
>                 System.out.println("Foo!");
>         }

The type of MHTest#foo is ()void only if foo is static.  Otherwise it is (MHTest)void.

>        
>         private void run(String[] args) {
>                 MethodHandle mh;
>                 MethodType desc = MethodType.methodType(void.class);
>                
>             try {
>                 mh = MethodHandles.lookup().findVirtual(getClass(), "foo", desc);
To see what's going on, add this: System.out.println("mh="+mh);
>             } catch (NoAccessException e) {
>                 throw (AssertionError)new AssertionError().initCause(e);
>             }
>            
>             try {
>                         mh.invokeExact();
>                 } catch (Throwable e) {
>                         e.printStackTrace();
>                 }
>         }
> 
> Compiling with javac works fine, but on running:
> 
> bje at bje-desktop:~/projects/java_scratch/src$ java -XX:+UnlockExperimentalVMOptions -XX:+EnableMethodHandles -XX:+EnableInvokeDynamic com/db/java7/test/MHTest
> java.dyn.WrongMethodTypeException: ()V cannot be called as ()V

That's a known bug in the error reporter.  Working on it...

-- John

>         at com.db.java7.test.MHTest.run(MHTest.java:33)
>         at com.db.java7.test.MHTest.main(MHTest.java:42)
> 
> bje at bje-desktop:~/projects/java_scratch/src$ java -version
> java version "1.7.0-ea"
> Java(TM) SE Runtime Environment (build 1.7.0-ea-b130)
> Java HotSpot(TM) 64-Bit Server VM (build 21.0-b02, mixed mode)
> 
> Any ideas?
> 
> Thanks,
> 
> Ben
> _______________________________________________
> mlvm-dev mailing list
> mlvm-dev at openjdk.java.net
> http://mail.openjdk.java.net/mailman/listinfo/mlvm-dev



More information about the mlvm-dev mailing list