changeset 52:f8ba90f78b93

meth-ing: final version
author jrose
date Sat, 01 May 2010 18:22:32 -0700
parents 30b47eb3dafb
children 423e18903e43
files meth-ing-6939134.patch
diffstat 1 files changed, 124 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/meth-ing-6939134.patch	Mon Apr 26 11:50:50 2010 +0200
+++ b/meth-ing-6939134.patch	Sat May 01 18:22:32 2010 -0700
@@ -1,7 +1,8 @@
 6939134: JSR 292 adjustments to method handle invocation
 Summary: split MethodHandle.invoke into invokeExact and invokeGeneric
-Mark the special signature-polymorpic methods and classes with @PolymorphicSignature.
-Reviewed-by: twisti(?)
+Reviewed-by: twisti
+
+Mark the special signature-polymorphic methods and classes with @PolymorphicSignature.
 
 The JSR 292 EG has decided to split MethodHandle.invoke into two
 methods, invokeExact and invokeGeneric.  Adjust javac so that it uses
@@ -29,6 +30,20 @@
      /** Modifier masks.
       */
      public static final int
+diff --git a/src/share/classes/com/sun/tools/javac/code/Source.java b/src/share/classes/com/sun/tools/javac/code/Source.java
+--- a/src/share/classes/com/sun/tools/javac/code/Source.java
++++ b/src/share/classes/com/sun/tools/javac/code/Source.java
+@@ -168,6 +168,10 @@
+     public boolean allowStringsInSwitch() {
+         return compareTo(JDK1_7) >= 0;
+     }
++    // JSR 292: recognize @PolymorphicSignature on java/dyn names
++    public boolean allowPolymorphicSignature() {
++        return compareTo(JDK1_7) >= 0;
++    }
+     public static SourceVersion toSourceVersion(Source source) {
+         switch(source) {
+         case JDK1_2:
 diff --git a/src/share/classes/com/sun/tools/javac/code/Symtab.java b/src/share/classes/com/sun/tools/javac/code/Symtab.java
 --- a/src/share/classes/com/sun/tools/javac/code/Symtab.java
 +++ b/src/share/classes/com/sun/tools/javac/code/Symtab.java
@@ -86,7 +101,26 @@
 diff --git a/src/share/classes/com/sun/tools/javac/comp/Attr.java b/src/share/classes/com/sun/tools/javac/comp/Attr.java
 --- a/src/share/classes/com/sun/tools/javac/comp/Attr.java
 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java
-@@ -1387,9 +1387,15 @@
+@@ -120,7 +120,6 @@
+         relax = (options.get("-retrofit") != null ||
+                  options.get("-relax") != null);
+         useBeforeDeclarationWarning = options.get("useBeforeDeclarationWarning") != null;
+-        allowInvokedynamic = options.get("invokedynamic") != null;
+         enableSunApiLintControl = options.get("enableSunApiLintControl") != null;
+     }
+ 
+@@ -153,10 +152,6 @@
+      */
+     boolean allowAnonOuterThis;
+ 
+-    /** Switch: allow invokedynamic syntax
+-     */
+-    boolean allowInvokedynamic;
+-
+     /**
+      * Switch: warn about use of variable before declaration?
+      * RFE: 6425594
+@@ -1387,9 +1382,15 @@
              // as a special case, MethodHandle.<T>invoke(abc) and InvokeDynamic.<T>foo(abc)
              // has type <T>, and T can be a primitive type.
              if (tree.meth.getTag() == JCTree.SELECT && !typeargtypes.isEmpty()) {
@@ -123,6 +157,24 @@
 diff --git a/src/share/classes/com/sun/tools/javac/comp/Resolve.java b/src/share/classes/com/sun/tools/javac/comp/Resolve.java
 --- a/src/share/classes/com/sun/tools/javac/comp/Resolve.java
 +++ b/src/share/classes/com/sun/tools/javac/comp/Resolve.java
+@@ -67,7 +67,7 @@
+     JCDiagnostic.Factory diags;
+     public final boolean boxingEnabled; // = source.allowBoxing();
+     public final boolean varargsEnabled; // = source.allowVarargs();
+-    public final boolean allowInvokedynamic; // = options.get("invokedynamic");
++    public final boolean allowPolymorphicSignature;
+     private final boolean debugResolve;
+ 
+     public static Resolve instance(Context context) {
+@@ -105,7 +105,7 @@
+         varargsEnabled = source.allowVarargs();
+         Options options = Options.instance(context);
+         debugResolve = options.get("debugresolve") != null;
+-        allowInvokedynamic = options.get("invokedynamic") != null;
++        allowPolymorphicSignature = source.allowPolymorphicSignature() || options.get("invokedynamic") != null;
+     }
+ 
+     /** error symbols, which are returned when resolution fails
 @@ -301,6 +301,7 @@
                          boolean useVarargs,
                          Warner warn)
@@ -135,32 +187,33 @@
          if (sym.kind == ERR) return bestSoFar;
          if (!sym.isInheritedIn(site.tsym, types)) return bestSoFar;
          assert sym.kind < AMBIGUOUS;
-+        if ((sym.flags() & POLYMORPHIC_SIGNATURE) != 0) {
++        if ((sym.flags() & POLYMORPHIC_SIGNATURE) != 0 && allowPolymorphicSignature) {
 +            assert(site.tag == CLASS);
 +            // Never match a MethodHandle.invoke directly.
 +            if (useVarargs | allowBoxing | operator)
 +                return bestSoFar;
 +            // Supply an exactly-typed implicit method instead.
-+            sym = findImplicitMethod(env, sym.owner.type, sym.name, (MethodSymbol) sym, argtypes, typeargtypes);
++            sym = findPolymorphicSignatureInstance(env, sym.owner.type, sym.name, (MethodSymbol) sym, argtypes, typeargtypes);
 +        }
          try {
              if (rawInstantiate(env, site, sym, argtypes, typeargtypes,
                                 allowBoxing, useVarargs, Warner.noWarnings) == null) {
-@@ -745,6 +754,13 @@
+@@ -745,6 +754,14 @@
                        boolean allowBoxing,
                        boolean useVarargs,
                        boolean operator) {
 +        Symbol bestSoFar = methodNotFound;
 +        if ((site.tsym.flags() & POLYMORPHIC_SIGNATURE) != 0 &&
++            allowPolymorphicSignature &&
 +            site.tag == CLASS &&
 +            !(useVarargs | allowBoxing | operator)) {
 +            // supply an exactly-typed implicit method in java.dyn.InvokeDynamic
-+            bestSoFar = findImplicitMethod(env, site, name, null, argtypes, typeargtypes);
++            bestSoFar = findPolymorphicSignatureInstance(env, site, name, null, argtypes, typeargtypes);
 +        }
          return findMethod(env,
                            site,
                            name,
-@@ -752,7 +768,7 @@
+@@ -752,7 +769,7 @@
                            typeargtypes,
                            site.tsym.type,
                            true,
@@ -169,24 +222,32 @@
                            allowBoxing,
                            useVarargs,
                            operator);
-@@ -897,10 +913,11 @@
-     Symbol findImplicitMethod(Env<AttrContext> env,
-                               Type site,
-                               Name name,
-+                              MethodSymbol spMethod,  // sig. poly. method or null if none
-                               List<Type> argtypes,
-                               List<Type> typeargtypes) {
-         assert allowInvokedynamic;
+@@ -894,13 +911,14 @@
+      *  @param argtypes  The method's value arguments.
+      *  @param typeargtypes The method's type arguments
+      */
+-    Symbol findImplicitMethod(Env<AttrContext> env,
+-                              Type site,
+-                              Name name,
+-                              List<Type> argtypes,
+-                              List<Type> typeargtypes) {
+-        assert allowInvokedynamic;
 -        assert site == syms.invokeDynamicType || (site == syms.methodHandleType && name == names.invoke);
++    Symbol findPolymorphicSignatureInstance(Env<AttrContext> env,
++                                            Type site,
++                                            Name name,
++                                            MethodSymbol spMethod,  // sig. poly. method or null if none
++                                            List<Type> argtypes,
++                                            List<Type> typeargtypes) {
++        assert allowPolymorphicSignature;
 +        //assert site == syms.invokeDynamicType || site == syms.methodHandleType : site;
          ClassSymbol c = (ClassSymbol) site.tsym;
          Scope implicit = c.members().next;
          if (implicit == null) {
-@@ -915,12 +932,23 @@
+@@ -915,12 +933,22 @@
                  return methodNotFound;
          }
          List<Type> paramtypes = Type.map(argtypes, implicitArgType);
-+        
 +        long flags;
 +        List<Type> exType;
 +        if (spMethod != null) {
@@ -227,7 +288,7 @@
 diff --git a/src/share/classes/com/sun/tools/javac/jvm/ClassReader.java b/src/share/classes/com/sun/tools/javac/jvm/ClassReader.java
 --- a/src/share/classes/com/sun/tools/javac/jvm/ClassReader.java
 +++ b/src/share/classes/com/sun/tools/javac/jvm/ClassReader.java
-@@ -1099,6 +1099,12 @@
+@@ -1098,6 +1098,12 @@
                  }
              },
  
@@ -257,6 +318,31 @@
          return acount;
      }
  
+diff --git a/src/share/classes/com/sun/tools/javac/jvm/Gen.java b/src/share/classes/com/sun/tools/javac/jvm/Gen.java
+--- a/src/share/classes/com/sun/tools/javac/jvm/Gen.java
++++ b/src/share/classes/com/sun/tools/javac/jvm/Gen.java
+@@ -121,7 +121,7 @@
+             : options.get("-g:vars") != null;
+         genCrt = options.get("-Xjcov") != null;
+         debugCode = options.get("debugcode") != null;
+-        allowInvokedynamic = options.get("invokedynamic") != null;
++        allowInvokedynamic = target.hasInvokedynamic() || options.get("invokedynamic") != null;
+ 
+         generateIproxies =
+             target.requiresIproxy() ||
+diff --git a/src/share/classes/com/sun/tools/javac/main/Main.java b/src/share/classes/com/sun/tools/javac/main/Main.java
+--- a/src/share/classes/com/sun/tools/javac/main/Main.java
++++ b/src/share/classes/com/sun/tools/javac/main/Main.java
+@@ -278,9 +278,6 @@
+                 }
+             }
+         }
+-        if (target.hasInvokedynamic()) {
+-            options.put("invokedynamic",  "invokedynamic");
+-        }
+         return filenames.toList();
+     }
+     // where
 diff --git a/src/share/classes/com/sun/tools/javac/util/Names.java b/src/share/classes/com/sun/tools/javac/util/Names.java
 --- a/src/share/classes/com/sun/tools/javac/util/Names.java
 +++ b/src/share/classes/com/sun/tools/javac/util/Names.java
@@ -292,10 +378,27 @@
  
          TYPE = fromString("TYPE");
          TYPE_USE = fromString("TYPE_USE");
+diff --git a/test/tools/javac/meth/InvokeDyn.java b/test/tools/javac/meth/InvokeDyn.java
+--- a/test/tools/javac/meth/InvokeDyn.java
++++ b/test/tools/javac/meth/InvokeDyn.java
+@@ -47,7 +47,7 @@
+ import java.dyn.InvokeDynamic;
+ 
+ public class InvokeDyn {
+-    void test() {
++    void test() throws Throwable {
+         Object x = "hello";
+         InvokeDynamic.greet(x, "world", 123);
+         InvokeDynamic.greet(x, "mundus", 456);
 diff --git a/test/tools/javac/meth/InvokeMH.java b/test/tools/javac/meth/InvokeMH.java
 --- a/test/tools/javac/meth/InvokeMH.java
 +++ b/test/tools/javac/meth/InvokeMH.java
-@@ -52,24 +52,52 @@
+@@ -48,28 +48,56 @@
+     void test(MethodHandle mh_SiO,
+               MethodHandle mh_vS,
+               MethodHandle mh_vi,
+-              MethodHandle mh_vv) {
++              MethodHandle mh_vv) throws Throwable {
          Object o; String s; int i;  // for return type testing
  
          // next five must have sig = (String,int)Object
@@ -335,7 +438,7 @@
 +    void testGen(MethodHandle mh_SiO,
 +                 MethodHandle mh_vS,
 +                 MethodHandle mh_vi,
-+                 MethodHandle mh_vv) {
++                 MethodHandle mh_vv) throws Throwable {
 +        Object o; String s; int i;  // for return type testing
 +
 +        // next five must have sig = (*,*)*