changeset 65:32f7d51f44ee

meth-edrfix: now builds java.dyn code under -XDallowTransitionalJSR292=no
author jrose
date Thu, 12 Aug 2010 17:44:35 -0700
parents e25df59bd472
children 921d71c53d7f
files meth-edrfix.patch
diffstat 1 files changed, 55 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/meth-edrfix.patch	Thu Aug 12 15:34:33 2010 -0700
+++ b/meth-edrfix.patch	Thu Aug 12 17:44:35 2010 -0700
@@ -14,7 +14,7 @@
  
      public void visitExec(JCExpressionStatement tree) {
          attribExpr(tree.expr, env);
-+        pushTargetType(syms.voidType, tree.expr);
++        tree.expr = pushTargetType(syms.voidType, tree.expr);
          result = null;
      }
  
@@ -56,11 +56,11 @@
                  chk.checkRefTypes(tree.typeargs, typeargtypes);
              }
  
-@@ -1949,12 +1949,34 @@
+@@ -1949,12 +1949,50 @@
          Type clazztype = attribType(tree.clazz, env);
          chk.validate(tree.clazz, env);
          Type exprtype = attribExpr(tree.expr, env, Infer.anyPoly);
-+        pushTargetType(clazztype, tree.expr);
++        tree.expr = pushTargetType(clazztype, tree.expr);
          Type owntype = chk.checkCastable(tree.expr.pos(), exprtype, clazztype);
          if (exprtype.constValue() != null)
              owntype = cfolder.coerce(exprtype, owntype);
@@ -68,8 +68,20 @@
      }
  
 +    // A cast or occurrence as an expression statement can affect the linkage of some method calls.
-+    void pushTargetType(Type targetType, JCExpression expr) {
++    JCExpression pushTargetType(Type targetType, JCExpression expr) {
 +        // JSR 292:  Link some calls according to return type as indicated by a cast.
++        JCExpression transformedExpr = expr;
++        JCTypeCast enclosingCast = null;
++        if (targetType.isPrimitive() && expr.getTag() == JCTree.TYPECAST) {
++            enclosingCast = (JCTypeCast)expr;
++            if (types.boxedClass(targetType) == enclosingCast.type.tsym) {
++                System.out.println("*** found prim cast "+expr);
++                expr = enclosingCast.expr;
++                // If the expr in turn is a MH.invoke expression,
++                // we will change (int)(Integer)MH.invoke(...) to (int)MH.invoke(...),
++                // with a linkage change to return the int directly.
++            }
++        }
 +        if (expr.getTag() == JCTree.APPLY) {
 +            JCExpression meth = ((JCMethodInvocation)expr).meth;
 +            if (meth.getTag() == JCTree.SELECT) {
@@ -83,9 +95,13 @@
 +                    if (!rs.isPolymorphicSignatureInstance(newSym))
 +                        throw new AssertionError("can't split poly sym: "+sym);
 +                    methsel.sym = newSym;
++                    expr.type = targetType;
++                    transformedExpr = expr;
 +                }
 +            }
 +        }
++        if (enclosingCast != null && expr == enclosingCast.expr)  System.out.println("*** but failed to match"+expr);
++        return transformedExpr;
 +    }
 +
      public void visitTypeTest(JCInstanceOf tree) {
@@ -117,16 +133,15 @@
      }
  
      /** error symbols, which are returned when resolution fails
-@@ -301,7 +306,7 @@
+@@ -301,7 +306,6 @@
                          boolean useVarargs,
                          Warner warn)
          throws Infer.InferenceException {
 -        assert ((m.flags() & (POLYMORPHIC_SIGNATURE|HYPOTHETICAL)) != POLYMORPHIC_SIGNATURE);
-+        assert !isPolymorphicSignatureGeneric(m);
          if (useVarargs && (m.flags() & VARARGS) == 0) return null;
          Type mt = types.memberType(site, m);
  
-@@ -578,13 +583,16 @@
+@@ -578,13 +582,16 @@
          if (sym.kind == ERR) return bestSoFar;
          if (!sym.isInheritedIn(site.tsym, types)) return bestSoFar;
          assert sym.kind < AMBIGUOUS;
@@ -145,7 +160,7 @@
          }
          try {
              if (rawInstantiate(env, site, sym, argtypes, typeargtypes,
-@@ -757,12 +765,14 @@
+@@ -757,12 +764,14 @@
                        boolean useVarargs,
                        boolean operator) {
          Symbol bestSoFar = methodNotFound;
@@ -163,7 +178,7 @@
          }
          return findMethod(env,
                            site,
-@@ -908,43 +918,35 @@
+@@ -908,43 +917,35 @@
      /** Find or create an implicit method of exactly the given type (after erasure).
       *  Searches in a side table, not the main scope of the site.
       *  This emulates the lookup process required by JSR 292 in JVM.
@@ -218,7 +233,7 @@
              exType = List.of(syms.throwableType);
              flags = PUBLIC | STATIC;
          }
-@@ -972,7 +974,7 @@
+@@ -972,7 +973,7 @@
          }
          assert argumentsAcceptable(argtypes, types.memberType(site, m).getParameterTypes(),
                                     false, false, Warner.noWarnings);
@@ -227,7 +242,7 @@
          return m;
      }
      //where
-@@ -989,6 +991,26 @@
+@@ -989,6 +990,26 @@
              return argType;
          }
  
@@ -254,7 +269,7 @@
      /** Load toplevel or member class with given fully qualified name and
       *  verify that it is accessible.
       *  @param env       The current environment.
-@@ -1367,6 +1389,14 @@
+@@ -1367,6 +1388,14 @@
              methodResolutionCache.put(steps.head, sym);
              steps = steps.tail;
          }
@@ -269,7 +284,7 @@
          if (sym.kind >= AMBIGUOUS) {//if nothing is found return the 'first' error
              MethodResolutionPhase errPhase =
                      firstErroneousResolutionPhase();
-@@ -1374,6 +1404,10 @@
+@@ -1374,6 +1403,10 @@
                      pos, site, name, true, argtypes, typeargtypes);
              env.info.varArgs = errPhase.isVarargsRequired;
          }
@@ -280,6 +295,29 @@
          return sym;
      }
  
+diff --git a/src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java b/src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java
+--- a/src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java
++++ b/src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java
+@@ -652,11 +652,14 @@
+             acount++;
+         }
+         if ((flags & POLYMORPHIC_SIGNATURE) != 0) {
+-            if (target.majorVersion < 51)
+-                throw new AssertionError("PolymorphicSignature attributes in java/dyn must be written with -target 7 (required major version is 51, current is"+target.majorVersion+")");
+-            int alenIdx = writeAttr(names.PolymorphicSignature);
+-            endAttr(alenIdx);
+-            acount++;
++            if (target.majorVersion < Target.JDK1_7.majorVersion) {
++                // PolymorphicSignature attributes in java/dyn must be written with -target {1} (required major version is {2})
++                log.warning("wrong.target.for.polymorphic.signature.definition", Target.JDK1_7.majorVersion, target.majorVersion);
++            } else {
++                int alenIdx = writeAttr(names.PolymorphicSignature);
++                endAttr(alenIdx);
++                acount++;
++            }
+         }
+         return acount;
+     }
 diff --git a/src/share/classes/com/sun/tools/javac/jvm/Target.java b/src/share/classes/com/sun/tools/javac/jvm/Target.java
 --- a/src/share/classes/com/sun/tools/javac/jvm/Target.java
 +++ b/src/share/classes/com/sun/tools/javac/jvm/Target.java
@@ -318,14 +356,16 @@
 diff --git a/src/share/classes/com/sun/tools/javac/resources/compiler.properties b/src/share/classes/com/sun/tools/javac/resources/compiler.properties
 --- a/src/share/classes/com/sun/tools/javac/resources/compiler.properties
 +++ b/src/share/classes/com/sun/tools/javac/resources/compiler.properties
-@@ -124,6 +124,11 @@
+@@ -124,6 +124,13 @@
  compiler.err.no.superclass=\
      {0} has no superclass
  
 +compiler.warn.type.parameter.on.polymorphic.signature=\
 +    change obsolete notation for MethodHandle invocations from x.<T>invoke(y) to (T)x.invoke(y)
 +compiler.warn.wrong.target.for.polymorphic.signature=\
-+    MethodHandle invocations work correctly only on -target 7 runtimes and better
++    MethodHandle invocations require -target 7 runtimes or better
++compiler.warn.wrong.target.for.polymorphic.signature.definition=\
++    MethodHandle API building requires -target 7 runtimes or better
 +
  compiler.err.concrete.inheritance.conflict=\
      methods {0} from {1} and {2} from {3} are inherited with the same signature