changeset 68:49cabfbbb3da

meth-edrfix: better diagnostics for corner cases, respect -XDinvokedynamic as before
author jrose
date Thu, 12 Aug 2010 22:03:52 -0700
parents 0e98cb257be0
children 76d6efbc30a4
files meth-edrfix.patch
diffstat 1 files changed, 42 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/meth-edrfix.patch	Thu Aug 12 22:03:01 2010 -0700
+++ b/meth-edrfix.patch	Thu Aug 12 22:03:52 2010 -0700
@@ -7,6 +7,20 @@
  "new version of javac" = version which requires @PolymorphicSignature annotations in java.dyn.MethodHandle.
  "old version of JSR 292 code" = version in which java.dyn.MethodHandle lacks @PolymorphicSignature annotations or uses type parameters.
 
+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
+@@ -171,10 +171,6 @@
+     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/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
@@ -105,6 +119,25 @@
      public void visitTypeTest(JCInstanceOf tree) {
          Type exprtype = chk.checkNullOrRefType(
              tree.expr.pos(), attribExpr(tree.expr, env));
+diff --git a/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java b/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java
+--- a/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java
++++ b/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java
+@@ -772,8 +772,14 @@
+             // translates to a classfile attribute.
+             if (!c.type.isErroneous()
+                 && types.isSameType(c.type, syms.polymorphicSignatureType)) {
++                if (!target.hasMethodHandles()) {
++                    // Somebody is compiling JDK7 source code to a JDK6 target.
++                    // Make it a strict warning, since it is unlikely but important.
++                    log.strictWarning(env.tree.pos(), "wrong.target.for.polymorphic.signature.definition", target.name);
++                }
++                // Pull the flag through for better diagnostics, even on a bad target.
+                 s.flags_field |= Flags.POLYMORPHIC_SIGNATURE;
+-            }
++              }
+             if (!annotated.add(a.type.tsym))
+                 log.error(a.pos, "duplicate.annotation");
+         }
 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
@@ -127,7 +160,7 @@
 +        allowTransitionalJSR292 = options.get("allowTransitionalJSR292") != null;
 +        Target target = Target.instance(context);
 +        recognizeMethodHandles = allowTransitionalJSR292 || target.hasMethodHandles();
-+        recognizeInvokeDynamic = allowTransitionalJSR292 || target.hasInvokedynamic() && source.allowPolymorphicSignature();
++        recognizeInvokeDynamic = allowTransitionalJSR292 || target.hasInvokedynamic() && options.get("invokedynamic") != null;
      }
  
      /** error symbols, which are returned when resolution fails
@@ -283,13 +316,15 @@
          if (sym.kind >= AMBIGUOUS) {//if nothing is found return the 'first' error
              MethodResolutionPhase errPhase =
                      firstErroneousResolutionPhase();
-@@ -1374,6 +1404,10 @@
+@@ -1374,6 +1404,12 @@
                      pos, site, name, true, argtypes, typeargtypes);
              env.info.varArgs = errPhase.isVarargsRequired;
          }
 +        if (isPolymorphicSignatureGeneric(sym)) {
 +            // Should have expanded this sym already.  Oops.
-+            log.warning(pos, "wrong.target.for.polymorphic.signature");
++            // Somebody is compiling JDK7 source code to a JDK6 target.
++            // Make it a strict warning, since it is unlikely but important.
++            log.strictWarning(pos, "wrong.target.for.polymorphic.signature");
 +        }
          return sym;
      }
@@ -297,7 +332,7 @@
 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 @@
+@@ -652,11 +652,12 @@
              acount++;
          }
          if ((flags & POLYMORPHIC_SIGNATURE) != 0) {
@@ -306,10 +341,8 @@
 -            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 {
++            // Emit the attribute only if the target expects it.
++            if (target.hasMethodHandles()) {
 +                int alenIdx = writeAttr(names.PolymorphicSignature);
 +                endAttr(alenIdx);
 +                acount++;
@@ -364,7 +397,7 @@
 +compiler.warn.wrong.target.for.polymorphic.signature=\
 +    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
++    MethodHandle API building requires -target 7 runtimes or better; current is -target {0}
 +
  compiler.err.concrete.inheritance.conflict=\
      methods {0} from {1} and {2} from {3} are inherited with the same signature