提交 6a4166d3 编写于 作者: J jrose

6817525: turn on method handle functionality by default for JSR 292

Summary: JVM bug 6817525 requires changes to some JDK unit tests; update test invocation flags and "Indify" snapshot
Reviewed-by: kvn, twisti
上级 33ee9ccf
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
* @bug 6987555 * @bug 6987555
* @summary JSR 292 unboxing to a boolean value fails on big-endian SPARC * @summary JSR 292 unboxing to a boolean value fails on big-endian SPARC
* *
* @run main/othervm -Xint -ea -XX:+UnlockExperimentalVMOptions -XX:+EnableMethodHandles -XX:+EnableInvokeDynamic -XX:+UnlockDiagnosticVMOptions -XX:+VerifyMethodHandles Test6987555 * @run main/othervm -Xint -ea -XX:+UnlockDiagnosticVMOptions -XX:+VerifyMethodHandles Test6987555
*/ */
import java.lang.invoke.*; import java.lang.invoke.*;
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
* @bug 6991596 * @bug 6991596
* @summary JSR 292 unimplemented adapter_opt_i2i and adapter_opt_l2i on SPARC * @summary JSR 292 unimplemented adapter_opt_i2i and adapter_opt_l2i on SPARC
* *
* @run main/othervm -ea -XX:+UnlockExperimentalVMOptions -XX:+EnableMethodHandles -XX:+EnableInvokeDynamic -XX:+UnlockDiagnosticVMOptions -XX:+VerifyMethodHandles Test6991596 * @run main/othervm -ea -XX:+UnlockDiagnosticVMOptions -XX:+VerifyMethodHandles Test6991596
*/ */
import java.lang.invoke.*; import java.lang.invoke.*;
......
...@@ -25,9 +25,9 @@ ...@@ -25,9 +25,9 @@
* @summary smoke test for invokedynamic instructions * @summary smoke test for invokedynamic instructions
* @build indify.Indify * @build indify.Indify
* @compile InvokeDynamicPrintArgs.java * @compile InvokeDynamicPrintArgs.java
* @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+EnableInvokeDynamic * @run main/othervm
* indify.Indify * indify.Indify
* --verify-specifier-count=3 --transitionalJSR292=false * --verify-specifier-count=3
* --expand-properties --classpath ${test.classes} * --expand-properties --classpath ${test.classes}
* --java test.java.lang.invoke.InvokeDynamicPrintArgs --check-output * --java test.java.lang.invoke.InvokeDynamicPrintArgs --check-output
*/ */
...@@ -63,7 +63,8 @@ public class InvokeDynamicPrintArgs { ...@@ -63,7 +63,8 @@ public class InvokeDynamicPrintArgs {
String testClassPath = System.getProperty("build.test.classes.dir"); String testClassPath = System.getProperty("build.test.classes.dir");
if (testClassPath == null) throw new RuntimeException(); if (testClassPath == null) throw new RuntimeException();
String[] args = new String[]{ String[] args = new String[]{
"--verify-specifier-count=3", "--transitionalJSR292=false", "--verify-specifier-count=3",
"--verbose",
"--expand-properties", "--classpath", testClassPath, "--expand-properties", "--classpath", testClassPath,
"--java", "test.java.lang.invoke.InvokeDynamicPrintArgs", "--check-output" "--java", "test.java.lang.invoke.InvokeDynamicPrintArgs", "--check-output"
}; };
...@@ -159,16 +160,14 @@ public class InvokeDynamicPrintArgs { ...@@ -159,16 +160,14 @@ public class InvokeDynamicPrintArgs {
shouldNotCallThis(); shouldNotCallThis();
return ((CallSite) MH_bsm2().invokeGeneric(lookup(), return ((CallSite) MH_bsm2().invokeGeneric(lookup(),
"bar", methodType(void.class, String.class, int.class) "bar", methodType(void.class, String.class, int.class)
, new Object[] { Void.class, "void type!", , Void.class, "void type!", 1, 234.5F, 67.5, (long)89
1, 234.5F, 67.5, (long)89 }
)).dynamicInvoker(); )).dynamicInvoker();
} }
private static MethodHandle INDY_bar2() throws Throwable { private static MethodHandle INDY_bar2() throws Throwable {
shouldNotCallThis(); shouldNotCallThis();
return ((CallSite) MH_bsm2().invokeGeneric(lookup(), return ((CallSite) MH_bsm2().invokeGeneric(lookup(),
"bar2", methodType(void.class, String.class, int.class) "bar2", methodType(void.class, String.class, int.class)
, new Object[] { Void.class, "void type!", , Void.class, "void type!", 1, 234.5F, 67.5, (long)89
1, 234.5F, 67.5, (long)89 }
)).dynamicInvoker(); )).dynamicInvoker();
} }
private static MethodHandle INDY_baz() throws Throwable { private static MethodHandle INDY_baz() throws Throwable {
......
...@@ -25,8 +25,8 @@ ...@@ -25,8 +25,8 @@
/* @test /* @test
* @summary unit tests for java.lang.invoke.MethodHandle.invokeGeneric * @summary unit tests for java.lang.invoke.MethodHandle.invokeGeneric
* @compile -XDallowTransitionalJSR292=no -target 7 InvokeGenericTest.java * @compile -target 7 InvokeGenericTest.java
* @run junit/othervm -XX:+UnlockExperimentalVMOptions -XX:+EnableMethodHandles test.java.lang.invoke.InvokeGenericTest * @run junit/othervm test.java.lang.invoke.InvokeGenericTest
*/ */
package test.java.lang.invoke; package test.java.lang.invoke;
......
...@@ -25,8 +25,8 @@ ...@@ -25,8 +25,8 @@
/* @test /* @test
* @summary example code used in javadoc for java.lang.invoke API * @summary example code used in javadoc for java.lang.invoke API
* @compile -XDallowTransitionalJSR292=no JavaDocExamplesTest.java * @compile JavaDocExamplesTest.java
* @run junit/othervm -XX:+UnlockExperimentalVMOptions -XX:+EnableMethodHandles test.java.lang.invoke.JavaDocExamplesTest * @run junit/othervm test.java.lang.invoke.JavaDocExamplesTest
*/ */
/* /*
...@@ -34,7 +34,6 @@ ...@@ -34,7 +34,6 @@
$ $JAVA7X_HOME/bin/javac -cp $JUNIT4_JAR -d /tmp/Classes \ $ $JAVA7X_HOME/bin/javac -cp $JUNIT4_JAR -d /tmp/Classes \
$DAVINCI/sources/jdk/test/java/lang/invoke/JavaDocExamplesTest.java $DAVINCI/sources/jdk/test/java/lang/invoke/JavaDocExamplesTest.java
$ $JAVA7X_HOME/bin/java -cp $JUNIT4_JAR:/tmp/Classes \ $ $JAVA7X_HOME/bin/java -cp $JUNIT4_JAR:/tmp/Classes \
-XX:+UnlockExperimentalVMOptions -XX:+EnableMethodHandles \
-Dtest.java.lang.invoke.JavaDocExamplesTest.verbosity=1 \ -Dtest.java.lang.invoke.JavaDocExamplesTest.verbosity=1 \
test.java.lang.invoke.JavaDocExamplesTest test.java.lang.invoke.JavaDocExamplesTest
---- ----
......
...@@ -25,8 +25,8 @@ ...@@ -25,8 +25,8 @@
/* @test /* @test
* @summary unit tests for java.lang.invoke.MethodHandles * @summary unit tests for java.lang.invoke.MethodHandles
* @compile -source 7 -target 7 -XDallowTransitionalJSR292=no MethodHandlesTest.java * @compile -source 7 -target 7 MethodHandlesTest.java
* @run junit/othervm -XX:+UnlockExperimentalVMOptions -XX:+EnableMethodHandles test.java.lang.invoke.MethodHandlesTest * @run junit/othervm test.java.lang.invoke.MethodHandlesTest
*/ */
package test.java.lang.invoke; package test.java.lang.invoke;
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
/* @test /* @test
* @summary unit tests for java.lang.invoke.MethodType * @summary unit tests for java.lang.invoke.MethodType
* @compile MethodTypeTest.java * @compile MethodTypeTest.java
* @run junit/othervm -XX:+UnlockExperimentalVMOptions -XX:+EnableMethodHandles test.java.lang.invoke.MethodTypeTest * @run junit/othervm test.java.lang.invoke.MethodTypeTest
*/ */
package test.java.lang.invoke; package test.java.lang.invoke;
......
/* /*
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -89,19 +89,15 @@ import java.util.regex.*; ...@@ -89,19 +89,15 @@ import java.util.regex.*;
$ JAVA_HOME=(some recent OpenJDK 7 build) $ JAVA_HOME=(some recent OpenJDK 7 build)
$ ant $ ant
$ $JAVA_HOME/bin/java -cp build/classes indify.Indify --overwrite --dest build/testout build/classes/indify/Example.class $ $JAVA_HOME/bin/java -cp build/classes indify.Indify --overwrite --dest build/testout build/classes/indify/Example.class
$ $JAVA_HOME/bin/java -XX:+UnlockExperimentalVMOptions -XX:+EnableInvokeDynamic -cp build/classes indify.Example $ $JAVA_HOME/bin/java -cp build/classes indify.Example
MT = (java.lang.Object)java.lang.Object MT = (java.lang.Object)java.lang.Object
MH = adder(int,int)java.lang.Integer MH = adder(int,int)java.lang.Integer
adder(1,2) = 3 adder(1,2) = 3
calling indy: 42 calling indy: 42
$ $JAVA_HOME/bin/java -XX:+UnlockExperimentalVMOptions -XX:+EnableInvokeDynamic -cp build/testout indify.Example $ $JAVA_HOME/bin/java -cp build/testout indify.Example
(same output as above) (same output as above)
* </pre></blockquote> * </pre></blockquote>
* <p> * <p>
* Before OpenJDK build b123, the format of {@code CONSTANT_InvokeDynamic} is in transition,
* and the switch {@code --transitionalJSR292=yes} is recommended.
* It is turned <em>off</em> by default, but users of earlier builds may need to turn it on.
* <p>
* A version of this transformation built on top of <a href="http://asm.ow2.org/">http://asm.ow2.org/</a> would be welcome. * A version of this transformation built on top of <a href="http://asm.ow2.org/">http://asm.ow2.org/</a> would be welcome.
* @author John Rose * @author John Rose
*/ */
...@@ -117,7 +113,6 @@ public class Indify { ...@@ -117,7 +113,6 @@ public class Indify {
public boolean overwrite = false; public boolean overwrite = false;
public boolean quiet = false; public boolean quiet = false;
public boolean verbose = false; public boolean verbose = false;
public boolean transitionalJSR292 = false; // final version is distributed
public boolean all = false; public boolean all = false;
public int verifySpecifierCount = -1; public int verifySpecifierCount = -1;
...@@ -203,9 +198,6 @@ public class Indify { ...@@ -203,9 +198,6 @@ public class Indify {
case "-v": case "--verbose": case "--verbose=": case "-v": case "--verbose": case "--verbose=":
verbose = booleanOption(a2); // more output verbose = booleanOption(a2); // more output
break; break;
case "--transitionalJSR292": case "--transitionalJSR292=":
transitionalJSR292 = booleanOption(a2); // use older invokedynamic format
break;
default: default:
throw new IllegalArgumentException("unrecognized flag: "+a); throw new IllegalArgumentException("unrecognized flag: "+a);
} }
...@@ -330,10 +322,14 @@ public class Indify { ...@@ -330,10 +322,14 @@ public class Indify {
if (resolve) resolveClass(c); if (resolve) resolveClass(c);
return c; return c;
} }
} catch (ClassNotFoundException ex) {
// fall through
} catch (IOException ex) {
// fall through
} catch (Exception ex) { } catch (Exception ex) {
if (ex instanceof IllegalArgumentException) // pass error from reportPatternMethods, etc.
// pass error from reportPatternMethods if (ex instanceof RuntimeException) throw (RuntimeException) ex;
throw (IllegalArgumentException) ex; throw new RuntimeException(ex);
} }
} }
return super.loadClass(name, resolve); return super.loadClass(name, resolve);
...@@ -403,8 +399,7 @@ public class Indify { ...@@ -403,8 +399,7 @@ public class Indify {
if (blab++ == 0 && !quiet) if (blab++ == 0 && !quiet)
System.err.println("patching "+cf.nameString()+"."+m); System.err.println("patching "+cf.nameString()+"."+m);
//if (blab == 1) { for (Instruction j = m.instructions(); j != null; j = j.next()) System.out.println(" |"+j); } //if (blab == 1) { for (Instruction j = m.instructions(); j != null; j = j.next()) System.out.println(" |"+j); }
if (con.tag == CONSTANT_InvokeDynamic || if (con.tag == CONSTANT_InvokeDynamic) {
con.tag == CONSTANT_InvokeDynamic_17) {
// need to patch the following instruction too, // need to patch the following instruction too,
// but there are usually intervening argument pushes too // but there are usually intervening argument pushes too
Instruction i2 = findPop(i); Instruction i2 = findPop(i);
...@@ -566,7 +561,7 @@ public class Indify { ...@@ -566,7 +561,7 @@ public class Indify {
short nt = n12[1]; short nt = n12[1];
char cmark = poolMarks[(char)cl]; char cmark = poolMarks[(char)cl];
if (cmark != 0) { if (cmark != 0) {
mark = cmark; // it is a java.dyn.* or java.lang.* method mark = cmark; // it is a java.lang.invoke.* or java.lang.* method
break; break;
} }
String cls = cf.pool.getString(CONSTANT_Class, cl); String cls = cf.pool.getString(CONSTANT_Class, cl);
...@@ -597,8 +592,6 @@ public class Indify { ...@@ -597,8 +592,6 @@ public class Indify {
if (s.startsWith("MT_")) return 'T'; if (s.startsWith("MT_")) return 'T';
else if (s.startsWith("MH_")) return 'H'; else if (s.startsWith("MH_")) return 'H';
else if (s.startsWith("INDY_")) return 'I'; else if (s.startsWith("INDY_")) return 'I';
else if (transitionalJSR292 &&
s.startsWith("java/dyn/")) return 'D';
else if (s.startsWith("java/lang/invoke/")) return 'D'; else if (s.startsWith("java/lang/invoke/")) return 'D';
else if (s.startsWith("java/lang/")) return 'J'; else if (s.startsWith("java/lang/")) return 'J';
return 0; return 0;
...@@ -623,10 +616,6 @@ public class Indify { ...@@ -623,10 +616,6 @@ public class Indify {
boolean matchType(String descr, String requiredType) { boolean matchType(String descr, String requiredType) {
if (descr.equals(requiredType)) return true; if (descr.equals(requiredType)) return true;
if (transitionalJSR292) {
String oldType = requiredType.replace("Ljava/lang/invoke/", "Ljava/dyn/");
if (descr.equals(oldType)) return true;
}
return false; return false;
} }
...@@ -872,6 +861,7 @@ public class Indify { ...@@ -872,6 +861,7 @@ public class Indify {
continue; continue;
} }
break; break;
case "invoke":
case "invokeGeneric": case "invokeGeneric":
case "invokeWithArguments": case "invokeWithArguments":
if (patternMark != 'I') break decode; if (patternMark != 'I') break decode;
...@@ -1022,7 +1012,7 @@ public class Indify { ...@@ -1022,7 +1012,7 @@ public class Indify {
private Constant makeInvokeDynamicCon(List<Object> args) { private Constant makeInvokeDynamicCon(List<Object> args) {
// E.g.: MH_bsm.invokeGeneric(lookup(), "name", MethodType, "extraArg") // E.g.: MH_bsm.invokeGeneric(lookup(), "name", MethodType, "extraArg")
removeEmptyJVMSlots(args); removeEmptyJVMSlots(args);
if (args.size() != 4 && args.size() != 5) return null; if (args.size() < 4) return null;
int argi = 0; int argi = 0;
short nindex, tindex, ntindex, bsmindex; short nindex, tindex, ntindex, bsmindex;
Object con; Object con;
...@@ -1035,22 +1025,17 @@ public class Indify { ...@@ -1035,22 +1025,17 @@ public class Indify {
tindex = ((Constant)con).itemIndex(); tindex = ((Constant)con).itemIndex();
ntindex = (short) cf.pool.addConstant(CONSTANT_NameAndType, ntindex = (short) cf.pool.addConstant(CONSTANT_NameAndType,
new Short[]{ nindex, tindex }).index; new Short[]{ nindex, tindex }).index;
if (transitionalJSR292) { List<Object> extraArgs = new ArrayList<Object>();
if (argi != args.size()) {
System.err.println("BSM specifier has extra arguments but transitionalJSR292=1");
return null;
}
return cf.pool.addConstant(CONSTANT_InvokeDynamic_17,
new Short[]{ bsmindex, ntindex });
}
List<Object> extraArgs = Collections.emptyList();
if (argi < args.size()) { if (argi < args.size()) {
Object arg = args.get(argi); extraArgs.addAll(args.subList(argi, args.size() - 1));
if (arg instanceof List) Object lastArg = args.get(args.size() - 1);
extraArgs = (List<Object>) arg; if (lastArg instanceof List) {
else List<Object> lastArgs = (List<Object>) lastArg;
extraArgs = Arrays.asList(arg); removeEmptyJVMSlots(lastArgs);
removeEmptyJVMSlots(args); extraArgs.addAll(lastArgs);
} else {
extraArgs.add(lastArg);
}
} }
List<Short> extraArgIndexes = new CountedList<>(Short.class); List<Short> extraArgIndexes = new CountedList<>(Short.class);
for (Object x : extraArgs) { for (Object x : extraArgs) {
...@@ -1062,7 +1047,10 @@ public class Indify { ...@@ -1062,7 +1047,10 @@ public class Indify {
if (x instanceof Double) { num = Double.doubleToRawLongBits((Double)x); numTag = CONSTANT_Double; } if (x instanceof Double) { num = Double.doubleToRawLongBits((Double)x); numTag = CONSTANT_Double; }
if (num != null) x = cf.pool.addConstant(numTag, x); if (num != null) x = cf.pool.addConstant(numTag, x);
} }
if (!(x instanceof Constant)) return null; if (!(x instanceof Constant)) {
System.err.println("warning: unrecognized BSM argument "+x);
return null;
}
extraArgIndexes.add((short) ((Constant)x).index); extraArgIndexes.add((short) ((Constant)x).index);
} }
List<Object[]> specs = bootstrapMethodSpecifiers(true); List<Object[]> specs = bootstrapMethodSpecifiers(true);
...@@ -1359,7 +1347,6 @@ public class Indify { ...@@ -1359,7 +1347,6 @@ public class Indify {
case CONSTANT_Method: case CONSTANT_Method:
case CONSTANT_InterfaceMethod: case CONSTANT_InterfaceMethod:
case CONSTANT_NameAndType: case CONSTANT_NameAndType:
case CONSTANT_InvokeDynamic_17:
case CONSTANT_InvokeDynamic: case CONSTANT_InvokeDynamic:
// read an ordered pair // read an ordered pair
arg = new Short[] { in.readShort(), in.readShort() }; arg = new Short[] { in.readShort(), in.readShort() };
...@@ -1634,7 +1621,6 @@ public class Indify { ...@@ -1634,7 +1621,6 @@ public class Indify {
CONSTANT_NameAndType = 12, CONSTANT_NameAndType = 12,
CONSTANT_MethodHandle = 15, // JSR 292 CONSTANT_MethodHandle = 15, // JSR 292
CONSTANT_MethodType = 16, // JSR 292 CONSTANT_MethodType = 16, // JSR 292
CONSTANT_InvokeDynamic_17 = 17, // JSR 292, only occurs in old class files
CONSTANT_InvokeDynamic = 18; // JSR 292 CONSTANT_InvokeDynamic = 18; // JSR 292
private static final byte private static final byte
REF_getField = 1, REF_getField = 1,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册