6939196: method handle signatures off the boot class path get linkage errors

http://cr.openjdk.java.net/~jrose/6939196/hs-webrev.00/
http://cr.openjdk.java.net/~jrose/6939196/jdk-webrev.00/

The bugtraq description is copied below.

- Adjust MethodType lookup logic to search off the BCP, but not to cache those 
results.
- Pass accessing class where it needs to be seen.
- A SignatureStream idiom "as_klass" for class lookup has been refactored.

Please review the JDK changes along with the JVM changes.  They are very simple:
- Remove workaround from MethodHandleImpl lookup code
- Add JUnit regression test to MethodHandlesTest

-- John

P.S.  Here is the description from bugtraq.

The following test program throws an error on the marked line.  The problem is 
a weakness in the current JSR 292 Reference Implementation logic for resolving 
MethodTypes that mention types not on the boot class path.

The workaround, therefore, is to load your entire JSR 292 application using 
-Xbootclasspath/a:myapp.jar.

import java.dyn.*;
import static java.dyn.MethodHandles.*;
import static java.dyn.MethodType.*;

public class BCPBug {
   // Local class which appears in method signature;
   static class Example { }
   static void bcpTypesOnly(Object x) { System.out.println("bcpTypesOnly"); }
   static void hasUserType(Example x) { System.out.println("hasUserType"); }

   public static void main(String... av) throws Throwable {
       Lookup lookup = lookup();
       MethodHandle bcpTypesOnly = lookup.findStatic(lookup.lookupClass(), 
"bcpTypesOnly", methodType(void.class, Object.class));
       MethodHandle hasUserType  = lookup.findStatic(lookup.lookupClass(), 
"hasUserType",  methodType(void.class, Example.class));

       bcpTypesOnly.<void>invokeExact((Object)null);
       hasUserType.<void>invokeExact((Example)null); // throws 
NoClassDefFoundError on BCPBug$Example
   }
}

/* Run:
$ $JAVA7X_HOME/bin/javac -d . BCPBug.java
$ $JAVA7X_HOME/bin/java -XX:+UnlockExperimentalVMOptions 
-XX:+EnableMethodHandles -cp . BCPBug
bcpTypesOnly
Exception in thread "main" java.lang.NoClassDefFoundError: BCPBug$Example
        at BCPBug.main(BCPBug.java:17)
*/

_______________________________________________
mlvm-dev mailing list
mlvm-dev@openjdk.java.net
http://mail.openjdk.java.net/mailman/listinfo/mlvm-dev

Reply via email to