Merge

Wed, 17 Jul 2013 10:40:53 -0700

author
lana
date
Wed, 17 Jul 2013 10:40:53 -0700
changeset 1907
e990e6bcecbe
parent 1906
10711bd8bb2d
parent 1882
39ec5d8a691b
child 1908
82f68da70e47
child 1911
80e75aa6a707

Merge

src/share/classes/com/sun/tools/javac/code/Types.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/comp/Attr.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/comp/Check.java file | annotate | diff | comparison | revisions
     1.1 --- a/.hgtags	Wed Jul 17 15:08:58 2013 +0200
     1.2 +++ b/.hgtags	Wed Jul 17 10:40:53 2013 -0700
     1.3 @@ -219,3 +219,4 @@
     1.4  4cb1136231275a1f8af53f5bfdef0b488e4b5bab jdk8-b95
     1.5  988aef3a8c3adac482363293f65e77ec4c5ce98d jdk8-b96
     1.6  6a11a81a8824c17f6cd2ec8f8492e1229b694e96 jdk8-b97
     1.7 +ce5a90df517bdceb2739d7dd3e6764b070def802 jdk8-b98
     2.1 --- a/src/share/classes/com/sun/tools/javac/code/Types.java	Wed Jul 17 15:08:58 2013 +0200
     2.2 +++ b/src/share/classes/com/sun/tools/javac/code/Types.java	Wed Jul 17 10:40:53 2013 -0700
     2.3 @@ -33,10 +33,15 @@
     2.4  import java.util.Set;
     2.5  import java.util.WeakHashMap;
     2.6  
     2.7 +import javax.tools.JavaFileObject;
     2.8 +
     2.9  import com.sun.tools.javac.code.Attribute.RetentionPolicy;
    2.10  import com.sun.tools.javac.code.Lint.LintCategory;
    2.11  import com.sun.tools.javac.code.Type.UndetVar.InferenceBound;
    2.12 +import com.sun.tools.javac.comp.AttrContext;
    2.13  import com.sun.tools.javac.comp.Check;
    2.14 +import com.sun.tools.javac.comp.Enter;
    2.15 +import com.sun.tools.javac.comp.Env;
    2.16  import com.sun.tools.javac.jvm.ClassReader;
    2.17  import com.sun.tools.javac.util.*;
    2.18  import static com.sun.tools.javac.code.BoundKind.*;
    2.19 @@ -83,6 +88,7 @@
    2.20      final boolean allowDefaultMethods;
    2.21      final ClassReader reader;
    2.22      final Check chk;
    2.23 +    final Enter enter;
    2.24      JCDiagnostic.Factory diags;
    2.25      List<Warner> warnStack = List.nil();
    2.26      final Name capturedName;
    2.27 @@ -109,6 +115,7 @@
    2.28          allowDefaultMethods = source.allowDefaultMethods();
    2.29          reader = ClassReader.instance(context);
    2.30          chk = Check.instance(context);
    2.31 +        enter = Enter.instance(context);
    2.32          capturedName = names.fromString("<captured wildcard>");
    2.33          messages = JavacMessages.instance(context);
    2.34          diags = JCDiagnostic.Factory.instance(context);
    2.35 @@ -605,6 +612,84 @@
    2.36              return site;
    2.37          }
    2.38      }
    2.39 +
    2.40 +    /**
    2.41 +     * Create a symbol for a class that implements a given functional interface
    2.42 +     * and overrides its functional descriptor. This routine is used for two
    2.43 +     * main purposes: (i) checking well-formedness of a functional interface;
    2.44 +     * (ii) perform functional interface bridge calculation.
    2.45 +     */
    2.46 +    public ClassSymbol makeFunctionalInterfaceClass(Env<AttrContext> env, Name name, List<Type> targets, long cflags) {
    2.47 +        Assert.check(targets.nonEmpty() && isFunctionalInterface(targets.head));
    2.48 +        Symbol descSym = findDescriptorSymbol(targets.head.tsym);
    2.49 +        Type descType = findDescriptorType(targets.head);
    2.50 +        ClassSymbol csym = new ClassSymbol(cflags, name, env.enclClass.sym.outermostClass());
    2.51 +        csym.completer = null;
    2.52 +        csym.members_field = new Scope(csym);
    2.53 +        MethodSymbol instDescSym = new MethodSymbol(descSym.flags(), descSym.name, descType, csym);
    2.54 +        csym.members_field.enter(instDescSym);
    2.55 +        Type.ClassType ctype = new Type.ClassType(Type.noType, List.<Type>nil(), csym);
    2.56 +        ctype.supertype_field = syms.objectType;
    2.57 +        ctype.interfaces_field = targets;
    2.58 +        csym.type = ctype;
    2.59 +        csym.sourcefile = ((ClassSymbol)csym.owner).sourcefile;
    2.60 +        return csym;
    2.61 +    }
    2.62 +
    2.63 +    /**
    2.64 +     * Find the minimal set of methods that are overridden by the functional
    2.65 +     * descriptor in 'origin'. All returned methods are assumed to have different
    2.66 +     * erased signatures.
    2.67 +     */
    2.68 +    public List<Symbol> functionalInterfaceBridges(TypeSymbol origin) {
    2.69 +        Assert.check(isFunctionalInterface(origin));
    2.70 +        Symbol descSym = findDescriptorSymbol(origin);
    2.71 +        CompoundScope members = membersClosure(origin.type, false);
    2.72 +        ListBuffer<Symbol> overridden = ListBuffer.lb();
    2.73 +        outer: for (Symbol m2 : members.getElementsByName(descSym.name, bridgeFilter)) {
    2.74 +            if (m2 == descSym) continue;
    2.75 +            else if (descSym.overrides(m2, origin, Types.this, false)) {
    2.76 +                for (Symbol m3 : overridden) {
    2.77 +                    if (isSameType(m3.erasure(Types.this), m2.erasure(Types.this)) ||
    2.78 +                            (m3.overrides(m2, origin, Types.this, false) &&
    2.79 +                            (pendingBridges((ClassSymbol)origin, m3.enclClass()) ||
    2.80 +                            (((MethodSymbol)m2).binaryImplementation((ClassSymbol)m3.owner, Types.this) != null)))) {
    2.81 +                        continue outer;
    2.82 +                    }
    2.83 +                }
    2.84 +                overridden.add(m2);
    2.85 +            }
    2.86 +        }
    2.87 +        return overridden.toList();
    2.88 +    }
    2.89 +    //where
    2.90 +        private Filter<Symbol> bridgeFilter = new Filter<Symbol>() {
    2.91 +            public boolean accepts(Symbol t) {
    2.92 +                return t.kind == Kinds.MTH &&
    2.93 +                        t.name != names.init &&
    2.94 +                        t.name != names.clinit &&
    2.95 +                        (t.flags() & SYNTHETIC) == 0;
    2.96 +            }
    2.97 +        };
    2.98 +        private boolean pendingBridges(ClassSymbol origin, TypeSymbol s) {
    2.99 +            //a symbol will be completed from a classfile if (a) symbol has
   2.100 +            //an associated file object with CLASS kind and (b) the symbol has
   2.101 +            //not been entered
   2.102 +            if (origin.classfile != null &&
   2.103 +                    origin.classfile.getKind() == JavaFileObject.Kind.CLASS &&
   2.104 +                    enter.getEnv(origin) == null) {
   2.105 +                return false;
   2.106 +            }
   2.107 +            if (origin == s) {
   2.108 +                return true;
   2.109 +            }
   2.110 +            for (Type t : interfaces(origin.type)) {
   2.111 +                if (pendingBridges((ClassSymbol)t.tsym, s)) {
   2.112 +                    return true;
   2.113 +                }
   2.114 +            }
   2.115 +            return false;
   2.116 +        }
   2.117      // </editor-fold>
   2.118  
   2.119     /**
   2.120 @@ -2672,6 +2757,7 @@
   2.121                  public boolean accepts(Symbol s) {
   2.122                      return s.kind == Kinds.MTH &&
   2.123                              s.name == msym.name &&
   2.124 +                            (s.flags() & SYNTHETIC) == 0 &&
   2.125                              s.isInheritedIn(site.tsym, Types.this) &&
   2.126                              overrideEquivalent(memberType(site, s), memberType(site, msym));
   2.127                  }
     3.1 --- a/src/share/classes/com/sun/tools/javac/comp/Attr.java	Wed Jul 17 15:08:58 2013 +0200
     3.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java	Wed Jul 17 10:40:53 2013 -0700
     3.3 @@ -2330,13 +2330,12 @@
     3.4              if (pt() != Type.recoveryType) {
     3.5                  target = targetChecker.visit(target, that);
     3.6                  lambdaType = types.findDescriptorType(target);
     3.7 -                chk.checkFunctionalInterface(that, target);
     3.8              } else {
     3.9                  target = Type.recoveryType;
    3.10                  lambdaType = fallbackDescriptorType(that);
    3.11              }
    3.12  
    3.13 -            setFunctionalInfo(that, pt(), lambdaType, target, resultInfo.checkContext.inferenceContext());
    3.14 +            setFunctionalInfo(localEnv, that, pt(), lambdaType, target, resultInfo.checkContext);
    3.15  
    3.16              if (lambdaType.hasTag(FORALL)) {
    3.17                  //lambda expression target desc cannot be a generic method
    3.18 @@ -2715,13 +2714,12 @@
    3.19              if (pt() != Type.recoveryType) {
    3.20                  target = targetChecker.visit(pt(), that);
    3.21                  desc = types.findDescriptorType(target);
    3.22 -                chk.checkFunctionalInterface(that, target);
    3.23              } else {
    3.24                  target = Type.recoveryType;
    3.25                  desc = fallbackDescriptorType(that);
    3.26              }
    3.27  
    3.28 -            setFunctionalInfo(that, pt(), desc, target, resultInfo.checkContext.inferenceContext());
    3.29 +            setFunctionalInfo(localEnv, that, pt(), desc, target, resultInfo.checkContext);
    3.30              List<Type> argtypes = desc.getParameterTypes();
    3.31              Resolve.MethodCheck referenceCheck = rs.resolveMethodCheck;
    3.32  
    3.33 @@ -2941,31 +2939,37 @@
    3.34       * might contain inference variables, we might need to register an hook in the
    3.35       * current inference context.
    3.36       */
    3.37 -    private void setFunctionalInfo(final JCFunctionalExpression fExpr, final Type pt,
    3.38 -            final Type descriptorType, final Type primaryTarget, InferenceContext inferenceContext) {
    3.39 -        if (inferenceContext.free(descriptorType)) {
    3.40 -            inferenceContext.addFreeTypeListener(List.of(pt, descriptorType), new FreeTypeListener() {
    3.41 +    private void setFunctionalInfo(final Env<AttrContext> env, final JCFunctionalExpression fExpr,
    3.42 +            final Type pt, final Type descriptorType, final Type primaryTarget, final CheckContext checkContext) {
    3.43 +        if (checkContext.inferenceContext().free(descriptorType)) {
    3.44 +            checkContext.inferenceContext().addFreeTypeListener(List.of(pt, descriptorType), new FreeTypeListener() {
    3.45                  public void typesInferred(InferenceContext inferenceContext) {
    3.46 -                    setFunctionalInfo(fExpr, pt, inferenceContext.asInstType(descriptorType),
    3.47 -                            inferenceContext.asInstType(primaryTarget), inferenceContext);
    3.48 +                    setFunctionalInfo(env, fExpr, pt, inferenceContext.asInstType(descriptorType),
    3.49 +                            inferenceContext.asInstType(primaryTarget), checkContext);
    3.50                  }
    3.51              });
    3.52          } else {
    3.53 -            ListBuffer<TypeSymbol> targets = ListBuffer.lb();
    3.54 +            ListBuffer<Type> targets = ListBuffer.lb();
    3.55              if (pt.hasTag(CLASS)) {
    3.56                  if (pt.isCompound()) {
    3.57 -                    targets.append(primaryTarget.tsym); //this goes first
    3.58 +                    targets.append(types.removeWildcards(primaryTarget)); //this goes first
    3.59                      for (Type t : ((IntersectionClassType)pt()).interfaces_field) {
    3.60                          if (t != primaryTarget) {
    3.61 -                            targets.append(t.tsym);
    3.62 +                            targets.append(types.removeWildcards(t));
    3.63                          }
    3.64                      }
    3.65                  } else {
    3.66 -                    targets.append(pt.tsym);
    3.67 +                    targets.append(types.removeWildcards(primaryTarget));
    3.68                  }
    3.69              }
    3.70              fExpr.targets = targets.toList();
    3.71 -            fExpr.descriptorType = descriptorType;
    3.72 +            if (checkContext.deferredAttrContext().mode == DeferredAttr.AttrMode.CHECK &&
    3.73 +                    pt != Type.recoveryType) {
    3.74 +                //check that functional interface class is well-formed
    3.75 +                ClassSymbol csym = types.makeFunctionalInterfaceClass(env,
    3.76 +                        names.empty, List.of(fExpr.targets.head), ABSTRACT);
    3.77 +                chk.checkImplementations(env.tree, csym, csym);
    3.78 +            }
    3.79          }
    3.80      }
    3.81  
    3.82 @@ -4644,9 +4648,6 @@
    3.83          @Override
    3.84          public void visitLambda(JCLambda that) {
    3.85              super.visitLambda(that);
    3.86 -            if (that.descriptorType == null) {
    3.87 -                that.descriptorType = syms.unknownType;
    3.88 -            }
    3.89              if (that.targets == null) {
    3.90                  that.targets = List.nil();
    3.91              }
    3.92 @@ -4658,9 +4659,6 @@
    3.93              if (that.sym == null) {
    3.94                  that.sym = new MethodSymbol(0, names.empty, syms.unknownType, syms.noSymbol);
    3.95              }
    3.96 -            if (that.descriptorType == null) {
    3.97 -                that.descriptorType = syms.unknownType;
    3.98 -            }
    3.99              if (that.targets == null) {
   3.100                  that.targets = List.nil();
   3.101              }
     4.1 --- a/src/share/classes/com/sun/tools/javac/comp/Check.java	Wed Jul 17 15:08:58 2013 +0200
     4.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Check.java	Wed Jul 17 10:40:53 2013 -0700
     4.3 @@ -2276,24 +2276,6 @@
     4.4          c.flags_field |= ACYCLIC;
     4.5      }
     4.6  
     4.7 -    /**
     4.8 -     * Check that functional interface methods would make sense when seen
     4.9 -     * from the perspective of the implementing class
    4.10 -     */
    4.11 -    void checkFunctionalInterface(JCTree tree, Type funcInterface) {
    4.12 -        ClassType c = new ClassType(Type.noType, List.<Type>nil(), null);
    4.13 -        ClassSymbol csym = new ClassSymbol(0, names.empty, c, syms.noSymbol);
    4.14 -        c.interfaces_field = List.of(types.removeWildcards(funcInterface));
    4.15 -        c.supertype_field = syms.objectType;
    4.16 -        c.tsym = csym;
    4.17 -        csym.members_field = new Scope(csym);
    4.18 -        Symbol descSym = types.findDescriptorSymbol(funcInterface.tsym);
    4.19 -        Type descType = types.findDescriptorType(funcInterface);
    4.20 -        csym.members_field.enter(new MethodSymbol(PUBLIC, descSym.name, descType, csym));
    4.21 -        csym.completer = null;
    4.22 -        checkImplementations(tree, csym, csym);
    4.23 -    }
    4.24 -
    4.25      /** Check that all methods which implement some
    4.26       *  method conform to the method they implement.
    4.27       *  @param tree         The class definition whose members are checked.
     5.1 --- a/src/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java	Wed Jul 17 15:08:58 2013 +0200
     5.2 +++ b/src/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java	Wed Jul 17 10:40:53 2013 -0700
     5.3 @@ -100,6 +100,9 @@
     5.4      /** Flag for alternate metafactories indicating the lambda object has multiple targets */
     5.5      public static final int FLAG_MARKERS = 1 << 1;
     5.6  
     5.7 +    /** Flag for alternate metafactories indicating the lambda object requires multiple bridges */
     5.8 +    public static final int FLAG_BRIDGES = 1 << 2;
     5.9 +
    5.10      private class KlassInfo {
    5.11  
    5.12          /**
    5.13 @@ -321,7 +324,7 @@
    5.14          int refKind = referenceKind(sym);
    5.15  
    5.16          //convert to an invokedynamic call
    5.17 -        result = makeMetaFactoryIndyCall(tree, context.needsAltMetafactory(), context.isSerializable(), refKind, sym, indy_args);
    5.18 +        result = makeMetafactoryIndyCall(context, refKind, sym, indy_args);
    5.19      }
    5.20  
    5.21      private JCIdent makeThis(Type type, Symbol owner) {
    5.22 @@ -382,7 +385,7 @@
    5.23  
    5.24  
    5.25          //build a sam instance using an indy call to the meta-factory
    5.26 -        result = makeMetaFactoryIndyCall(tree, localContext.needsAltMetafactory(), localContext.isSerializable(), localContext.referenceKind(), refSym, indy_args);
    5.27 +        result = makeMetafactoryIndyCall(localContext, localContext.referenceKind(), refSym, indy_args);
    5.28      }
    5.29  
    5.30      /**
    5.31 @@ -606,8 +609,8 @@
    5.32                  make.Return(makeIndyCall(
    5.33                      pos,
    5.34                      syms.lambdaMetafactory,
    5.35 -                    names.altMetaFactory,
    5.36 -                    staticArgs, indyType, serArgs.toList())),
    5.37 +                    names.altMetafactory,
    5.38 +                    staticArgs, indyType, serArgs.toList(), samSym.name)),
    5.39                  null);
    5.40          ListBuffer<JCStatement> stmts = kInfo.deserializeCases.get(implMethodName);
    5.41          if (stmts == null) {
    5.42 @@ -905,22 +908,26 @@
    5.43          kInfo.addMethod(new MemberReferenceBridger(tree, localContext).bridge());
    5.44      }
    5.45  
    5.46 +    private MethodType typeToMethodType(Type mt) {
    5.47 +        Type type = types.erasure(mt);
    5.48 +        return new MethodType(type.getParameterTypes(),
    5.49 +                        type.getReturnType(),
    5.50 +                        type.getThrownTypes(),
    5.51 +                        syms.methodClass);
    5.52 +    }
    5.53 +
    5.54      /**
    5.55       * Generate an indy method call to the meta factory
    5.56       */
    5.57 -    private JCExpression makeMetaFactoryIndyCall(JCFunctionalExpression tree, boolean needsAltMetafactory,
    5.58 -            boolean isSerializable, int refKind, Symbol refSym, List<JCExpression> indy_args) {
    5.59 +    private JCExpression makeMetafactoryIndyCall(TranslationContext<?> context,
    5.60 +            int refKind, Symbol refSym, List<JCExpression> indy_args) {
    5.61 +        JCFunctionalExpression tree = context.tree;
    5.62          //determine the static bsm args
    5.63 -        Type mtype = types.erasure(tree.descriptorType);
    5.64          MethodSymbol samSym = (MethodSymbol) types.findDescriptorSymbol(tree.type.tsym);
    5.65          List<Object> staticArgs = List.<Object>of(
    5.66 -                new Pool.MethodHandle(ClassFile.REF_invokeInterface,
    5.67 -                    types.findDescriptorSymbol(tree.type.tsym), types),
    5.68 +                typeToMethodType(samSym.type),
    5.69                  new Pool.MethodHandle(refKind, refSym, types),
    5.70 -                new MethodType(mtype.getParameterTypes(),
    5.71 -                        mtype.getReturnType(),
    5.72 -                        mtype.getThrownTypes(),
    5.73 -                        syms.methodClass));
    5.74 +                typeToMethodType(tree.getDescriptorType(types)));
    5.75  
    5.76          //computed indy arg types
    5.77          ListBuffer<Type> indy_args_types = ListBuffer.lb();
    5.78 @@ -934,31 +941,46 @@
    5.79                  List.<Type>nil(),
    5.80                  syms.methodClass);
    5.81  
    5.82 -        Name metafactoryName = needsAltMetafactory ?
    5.83 -                names.altMetaFactory : names.metaFactory;
    5.84 +        Name metafactoryName = context.needsAltMetafactory() ?
    5.85 +                names.altMetafactory : names.metafactory;
    5.86  
    5.87 -        if (needsAltMetafactory) {
    5.88 +        if (context.needsAltMetafactory()) {
    5.89              ListBuffer<Object> markers = ListBuffer.lb();
    5.90 -            for (Symbol t : tree.targets.tail) {
    5.91 -                if (t != syms.serializableType.tsym) {
    5.92 -                    markers.append(t);
    5.93 +            for (Type t : tree.targets.tail) {
    5.94 +                if (t.tsym != syms.serializableType.tsym) {
    5.95 +                    markers.append(t.tsym);
    5.96                  }
    5.97              }
    5.98 -            int flags = isSerializable? FLAG_SERIALIZABLE : 0;
    5.99 +            int flags = context.isSerializable() ? FLAG_SERIALIZABLE : 0;
   5.100              boolean hasMarkers = markers.nonEmpty();
   5.101 -            flags |= hasMarkers ? FLAG_MARKERS : 0;
   5.102 +            boolean hasBridges = context.bridges.nonEmpty();
   5.103 +            if (hasMarkers) {
   5.104 +                flags |= FLAG_MARKERS;
   5.105 +            }
   5.106 +            if (hasBridges) {
   5.107 +                flags |= FLAG_BRIDGES;
   5.108 +            }
   5.109              staticArgs = staticArgs.append(flags);
   5.110              if (hasMarkers) {
   5.111                  staticArgs = staticArgs.append(markers.length());
   5.112                  staticArgs = staticArgs.appendList(markers.toList());
   5.113              }
   5.114 -            if (isSerializable) {
   5.115 +            if (hasBridges) {
   5.116 +                staticArgs = staticArgs.append(context.bridges.length() - 1);
   5.117 +                for (Symbol s : context.bridges) {
   5.118 +                    Type s_erasure = s.erasure(types);
   5.119 +                    if (!types.isSameType(s_erasure, samSym.erasure(types))) {
   5.120 +                        staticArgs = staticArgs.append(s.erasure(types));
   5.121 +                    }
   5.122 +                }
   5.123 +            }
   5.124 +            if (context.isSerializable()) {
   5.125                  addDeserializationCase(refKind, refSym, tree.type, samSym,
   5.126                          tree, staticArgs, indyType);
   5.127              }
   5.128          }
   5.129  
   5.130 -        return makeIndyCall(tree, syms.lambdaMetafactory, metafactoryName, staticArgs, indyType, indy_args);
   5.131 +        return makeIndyCall(tree, syms.lambdaMetafactory, metafactoryName, staticArgs, indyType, indy_args, samSym.name);
   5.132      }
   5.133  
   5.134      /**
   5.135 @@ -966,7 +988,8 @@
   5.136       * arguments types
   5.137       */
   5.138      private JCExpression makeIndyCall(DiagnosticPosition pos, Type site, Name bsmName,
   5.139 -            List<Object> staticArgs, MethodType indyType, List<JCExpression> indyArgs) {
   5.140 +            List<Object> staticArgs, MethodType indyType, List<JCExpression> indyArgs,
   5.141 +            Name methName) {
   5.142          int prevPos = make.pos;
   5.143          try {
   5.144              make.at(pos);
   5.145 @@ -978,7 +1001,7 @@
   5.146                      bsmName, bsm_staticArgs, List.<Type>nil());
   5.147  
   5.148              DynamicMethodSymbol dynSym =
   5.149 -                    new DynamicMethodSymbol(names.lambda,
   5.150 +                    new DynamicMethodSymbol(methName,
   5.151                                              syms.noSymbol,
   5.152                                              bsm.isStatic() ?
   5.153                                                  ClassFile.REF_invokeStatic :
   5.154 @@ -1299,7 +1322,6 @@
   5.155  
   5.156                  // Make lambda holding the new-class call
   5.157                  JCLambda slam = make.Lambda(params, nc);
   5.158 -                slam.descriptorType = tree.descriptorType;
   5.159                  slam.targets = tree.targets;
   5.160                  slam.type = tree.type;
   5.161                  slam.pos = tree.pos;
   5.162 @@ -1634,23 +1656,30 @@
   5.163              /** the enclosing translation context (set for nested lambdas/mref) */
   5.164              TranslationContext<?> prev;
   5.165  
   5.166 +            /** list of methods to be bridged by the meta-factory */
   5.167 +            List<Symbol> bridges;
   5.168 +
   5.169              TranslationContext(T tree) {
   5.170                  this.tree = tree;
   5.171                  this.owner = owner();
   5.172                  this.depth = frameStack.size() - 1;
   5.173                  this.prev = context();
   5.174 +                ClassSymbol csym =
   5.175 +                        types.makeFunctionalInterfaceClass(attrEnv, names.empty, tree.targets, ABSTRACT | INTERFACE);
   5.176 +                this.bridges = types.functionalInterfaceBridges(csym);
   5.177              }
   5.178  
   5.179              /** does this functional expression need to be created using alternate metafactory? */
   5.180              boolean needsAltMetafactory() {
   5.181 -                return (tree.targets.length() > 1 ||
   5.182 -                        isSerializable());
   5.183 +                return tree.targets.length() > 1 ||
   5.184 +                        isSerializable() ||
   5.185 +                        bridges.length() > 1;
   5.186              }
   5.187  
   5.188              /** does this functional expression require serialization support? */
   5.189              boolean isSerializable() {
   5.190 -                for (Symbol target : tree.targets) {
   5.191 -                    if (types.asSuper(target.type, syms.serializableType.tsym) != null) {
   5.192 +                for (Type target : tree.targets) {
   5.193 +                    if (types.asSuper(target, syms.serializableType.tsym) != null) {
   5.194                          return true;
   5.195                      }
   5.196                  }
   5.197 @@ -1833,7 +1862,7 @@
   5.198              }
   5.199  
   5.200              Type generatedLambdaSig() {
   5.201 -                return types.erasure(tree.descriptorType);
   5.202 +                return types.erasure(tree.getDescriptorType(types));
   5.203              }
   5.204          }
   5.205  
   5.206 @@ -1909,7 +1938,7 @@
   5.207              }
   5.208  
   5.209              Type bridgedRefSig() {
   5.210 -                return types.erasure(types.findDescriptorSymbol(tree.targets.head).type);
   5.211 +                return types.erasure(types.findDescriptorSymbol(tree.targets.head.tsym).type);
   5.212              }
   5.213          }
   5.214      }
     6.1 --- a/src/share/classes/com/sun/tools/javac/comp/TransTypes.java	Wed Jul 17 15:08:58 2013 +0200
     6.2 +++ b/src/share/classes/com/sun/tools/javac/comp/TransTypes.java	Wed Jul 17 10:40:53 2013 -0700
     6.3 @@ -68,6 +68,7 @@
     6.4      private TreeMaker make;
     6.5      private Enter enter;
     6.6      private boolean allowEnums;
     6.7 +    private boolean allowInterfaceBridges;
     6.8      private Types types;
     6.9      private final Resolve resolve;
    6.10  
    6.11 @@ -91,6 +92,7 @@
    6.12          Source source = Source.instance(context);
    6.13          allowEnums = source.allowEnums();
    6.14          addBridges = source.addBridges();
    6.15 +        allowInterfaceBridges = source.allowDefaultMethods();
    6.16          types = Types.instance(context);
    6.17          make = TreeMaker.instance(context);
    6.18          resolve = Resolve.instance(context);
    6.19 @@ -252,7 +254,8 @@
    6.20  
    6.21          // Create a bridge method symbol and a bridge definition without a body.
    6.22          Type bridgeType = meth.erasure(types);
    6.23 -        long flags = impl.flags() & AccessFlags | SYNTHETIC | BRIDGE;
    6.24 +        long flags = impl.flags() & AccessFlags | SYNTHETIC | BRIDGE |
    6.25 +                (origin.isInterface() ? DEFAULT : 0);
    6.26          if (hypothetical) flags |= HYPOTHETICAL;
    6.27          MethodSymbol bridge = new MethodSymbol(flags,
    6.28                                                 meth.name,
    6.29 @@ -387,11 +390,12 @@
    6.30          }
    6.31      }
    6.32      // where
    6.33 -        Filter<Symbol> overrideBridgeFilter = new Filter<Symbol>() {
    6.34 +        private Filter<Symbol> overrideBridgeFilter = new Filter<Symbol>() {
    6.35              public boolean accepts(Symbol s) {
    6.36                  return (s.flags() & (SYNTHETIC | OVERRIDE_BRIDGE)) != SYNTHETIC;
    6.37              }
    6.38          };
    6.39 +
    6.40          /**
    6.41           * @param method The symbol for which a bridge might have to be added
    6.42           * @param impl The implementation of method
    6.43 @@ -999,8 +1003,9 @@
    6.44                      ListBuffer<JCTree> bridges = new ListBuffer<JCTree>();
    6.45                      if (false) //see CR: 6996415
    6.46                          bridges.appendList(addOverrideBridgesIfNeeded(tree, c));
    6.47 -                    if ((tree.sym.flags() & INTERFACE) == 0)
    6.48 -                        addBridges(tree.pos(), tree.sym, bridges);
    6.49 +                    if (allowInterfaceBridges || (tree.sym.flags() & INTERFACE) == 0) {
    6.50 +                        addBridges(tree.pos(), c, bridges);
    6.51 +                    }
    6.52                      tree.defs = bridges.toList().prependList(tree.defs);
    6.53                  }
    6.54                  tree.type = erasure(tree.type);
     7.1 --- a/src/share/classes/com/sun/tools/javac/tree/JCTree.java	Wed Jul 17 15:08:58 2013 +0200
     7.2 +++ b/src/share/classes/com/sun/tools/javac/tree/JCTree.java	Wed Jul 17 10:40:53 2013 -0700
     7.3 @@ -641,10 +641,12 @@
     7.4              polyKind = PolyKind.POLY;
     7.5          }
     7.6  
     7.7 -        /** target descriptor inferred for this functional expression. */
     7.8 -        public Type descriptorType;
     7.9          /** list of target types inferred for this functional expression. */
    7.10 -        public List<TypeSymbol> targets;
    7.11 +        public List<Type> targets;
    7.12 +
    7.13 +        public Type getDescriptorType(Types types) {
    7.14 +            return types.findDescriptorType(targets.head);
    7.15 +        }
    7.16      }
    7.17  
    7.18      /**
     8.1 --- a/src/share/classes/com/sun/tools/javac/util/Names.java	Wed Jul 17 15:08:58 2013 +0200
     8.2 +++ b/src/share/classes/com/sun/tools/javac/util/Names.java	Wed Jul 17 10:40:53 2013 -0700
     8.3 @@ -174,8 +174,8 @@
     8.4  
     8.5      //lambda-related
     8.6      public final Name lambda;
     8.7 -    public final Name metaFactory;
     8.8 -    public final Name altMetaFactory;
     8.9 +    public final Name metafactory;
    8.10 +    public final Name altMetafactory;
    8.11  
    8.12      public final Name.Table table;
    8.13  
    8.14 @@ -310,8 +310,8 @@
    8.15  
    8.16          //lambda-related
    8.17          lambda = fromString("lambda$");
    8.18 -        metaFactory = fromString("metaFactory");
    8.19 -        altMetaFactory = fromString("altMetaFactory");
    8.20 +        metafactory = fromString("metafactory");
    8.21 +        altMetafactory = fromString("altMetafactory");
    8.22      }
    8.23  
    8.24      protected Name.Table createTable(Options options) {
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/test/tools/javac/generics/bridges/Bridge.java	Wed Jul 17 10:40:53 2013 -0700
     9.3 @@ -0,0 +1,28 @@
     9.4 +/*
     9.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
     9.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     9.7 + *
     9.8 + * This code is free software; you can redistribute it and/or modify it
     9.9 + * under the terms of the GNU General Public License version 2 only, as
    9.10 + * published by the Free Software Foundation.
    9.11 + *
    9.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    9.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    9.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    9.15 + * version 2 for more details (a copy is included in the LICENSE file that
    9.16 + * accompanied this code).
    9.17 + *
    9.18 + * You should have received a copy of the GNU General Public License version
    9.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    9.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    9.21 + *
    9.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    9.23 + * or visit www.oracle.com if you need additional information or have any
    9.24 + * questions.
    9.25 + */
    9.26 +import java.lang.annotation.Repeatable;
    9.27 +
    9.28 +@Repeatable(Bridges.class)
    9.29 +@interface Bridge {
    9.30 +    String value();
    9.31 +}
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/test/tools/javac/generics/bridges/BridgeHarness.java	Wed Jul 17 10:40:53 2013 -0700
    10.3 @@ -0,0 +1,218 @@
    10.4 +/*
    10.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
    10.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    10.7 + *
    10.8 + * This code is free software; you can redistribute it and/or modify it
    10.9 + * under the terms of the GNU General Public License version 2 only, as
   10.10 + * published by the Free Software Foundation.
   10.11 + *
   10.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   10.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   10.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   10.15 + * version 2 for more details (a copy is included in the LICENSE file that
   10.16 + * accompanied this code).
   10.17 + *
   10.18 + * You should have received a copy of the GNU General Public License version
   10.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   10.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   10.21 + *
   10.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   10.23 + * or visit www.oracle.com if you need additional information or have any
   10.24 + * questions.
   10.25 + */
   10.26 +
   10.27 +/*
   10.28 + * @test
   10.29 + * @bug 8013789
   10.30 + * @summary Compiler should emit bridges in interfaces
   10.31 + * @library /tools/javac/lib
   10.32 + * @build JavacTestingAbstractProcessor BridgeHarness
   10.33 + * @run main BridgeHarness
   10.34 + */
   10.35 +
   10.36 +import com.sun.source.util.JavacTask;
   10.37 +import com.sun.tools.classfile.AccessFlags;
   10.38 +import com.sun.tools.classfile.ClassFile;
   10.39 +import com.sun.tools.classfile.ConstantPool;
   10.40 +import com.sun.tools.classfile.ConstantPoolException;
   10.41 +import com.sun.tools.classfile.Method;
   10.42 +import com.sun.tools.javac.code.Symbol.ClassSymbol;
   10.43 +import com.sun.tools.javac.util.List;
   10.44 +
   10.45 +import java.io.File;
   10.46 +import java.util.Arrays;
   10.47 +import java.util.Collections;
   10.48 +import java.util.HashMap;
   10.49 +import java.util.Map;
   10.50 +import java.util.Set;
   10.51 +
   10.52 +import javax.annotation.processing.RoundEnvironment;
   10.53 +import javax.annotation.processing.SupportedAnnotationTypes;
   10.54 +import javax.lang.model.element.Element;
   10.55 +import javax.lang.model.element.TypeElement;
   10.56 +import javax.tools.JavaCompiler;
   10.57 +import javax.tools.JavaFileObject;
   10.58 +import javax.tools.StandardJavaFileManager;
   10.59 +import javax.tools.ToolProvider;
   10.60 +
   10.61 +import static javax.tools.StandardLocation.*;
   10.62 +
   10.63 +public class BridgeHarness {
   10.64 +
   10.65 +    /** number of errors found (must be zero for the test to pass) */
   10.66 +    static int nerrors = 0;
   10.67 +
   10.68 +    /** the (shared) Java compiler used for compiling the tests */
   10.69 +    static final JavaCompiler comp = ToolProvider.getSystemJavaCompiler();
   10.70 +
   10.71 +    /** the (shared) file manager used by the compiler */
   10.72 +    static final StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null);
   10.73 +
   10.74 +    public static void main(String[] args) throws Exception {
   10.75 +        //set sourcepath
   10.76 +        fm.setLocation(SOURCE_PATH,
   10.77 +                Arrays.asList(new File(System.getProperty("test.src"), "tests")));
   10.78 +        //set output (-d)
   10.79 +        fm.setLocation(javax.tools.StandardLocation.CLASS_OUTPUT,
   10.80 +                Arrays.asList(new File(System.getProperty("user.dir"))));
   10.81 +        for (JavaFileObject jfo : fm.list(SOURCE_PATH, "", Collections.singleton(JavaFileObject.Kind.SOURCE), true)) {
   10.82 +            //for each source, compile and check against annotations
   10.83 +            new BridgeHarness(jfo).compileAndCheck();
   10.84 +        }
   10.85 +        //if there were errors, fail
   10.86 +        if (nerrors > 0) {
   10.87 +            throw new AssertionError("Errors were found");
   10.88 +        }
   10.89 +    }
   10.90 +
   10.91 +    /* utility methods */
   10.92 +
   10.93 +    /**
   10.94 +     * Remove an element from a list
   10.95 +     */
   10.96 +    static <Z> List<Z> drop(List<Z> lz, Z z) {
   10.97 +        if (lz.head == z) {
   10.98 +            return drop(lz.tail, z);
   10.99 +        } else if (lz.isEmpty()) {
  10.100 +            return lz;
  10.101 +        } else {
  10.102 +            return drop(lz.tail, z).prepend(lz.head);
  10.103 +        }
  10.104 +    }
  10.105 +
  10.106 +    /**
  10.107 +     * return a string representation of a bytecode method
  10.108 +     */
  10.109 +    static String descriptor(Method m, ConstantPool cp) throws ConstantPoolException {
  10.110 +        return m.getName(cp) + m.descriptor.getValue(cp);
  10.111 +    }
  10.112 +
  10.113 +    /* test harness */
  10.114 +
  10.115 +    /** Test file to be compiled */
  10.116 +    JavaFileObject jfo;
  10.117 +
  10.118 +    /** Mapping between class name and list of bridges in class with that name */
  10.119 +    Map<String, List<Bridge>> bridgesMap = new HashMap<String, List<Bridge>>();
  10.120 +
  10.121 +    protected BridgeHarness(JavaFileObject jfo) {
  10.122 +        this.jfo = jfo;
  10.123 +    }
  10.124 +
  10.125 +    /**
  10.126 +     * Compile a test using a custom annotation processor and check the generated
  10.127 +     * bytecode against discovered annotations.
  10.128 +     */
  10.129 +    protected void compileAndCheck() throws Exception {
  10.130 +        JavacTask ct = (JavacTask)comp.getTask(null, fm, null, null, null, Arrays.asList(jfo));
  10.131 +        ct.setProcessors(Collections.singleton(new BridgeFinder()));
  10.132 +
  10.133 +        for (JavaFileObject jfo : ct.generate()) {
  10.134 +            checkBridges(jfo);
  10.135 +        }
  10.136 +    }
  10.137 +
  10.138 +    /**
  10.139 +     * Check that every bridge in the generated classfile has a matching bridge
  10.140 +     * annotation in the bridge map
  10.141 +     */
  10.142 +    protected void checkBridges(JavaFileObject jfo) {
  10.143 +        try {
  10.144 +            ClassFile cf = ClassFile.read(jfo.openInputStream());
  10.145 +            System.err.println("checking: " + cf.getName());
  10.146 +
  10.147 +            List<Bridge> bridgeList = bridgesMap.get(cf.getName());
  10.148 +            if (bridgeList == null) {
  10.149 +                //no bridges - nothing to check;
  10.150 +                bridgeList = List.nil();
  10.151 +            }
  10.152 +
  10.153 +            for (Method m : cf.methods) {
  10.154 +                if (m.access_flags.is(AccessFlags.ACC_SYNTHETIC | AccessFlags.ACC_BRIDGE)) {
  10.155 +                    //this is a bridge - see if there's a match in the bridge list
  10.156 +                    Bridge match = null;
  10.157 +                    for (Bridge b : bridgeList) {
  10.158 +                        if (b.value().equals(descriptor(m, cf.constant_pool))) {
  10.159 +                            match = b;
  10.160 +                            break;
  10.161 +                        }
  10.162 +                    }
  10.163 +                    if (match == null) {
  10.164 +                        error("No annotation for bridge method: " + descriptor(m, cf.constant_pool));
  10.165 +                    } else {
  10.166 +                        bridgeList = drop(bridgeList, match);
  10.167 +                    }
  10.168 +                }
  10.169 +            }
  10.170 +            if (bridgeList.nonEmpty()) {
  10.171 +                error("Redundant bridge annotation found: " + bridgeList.head.value());
  10.172 +            }
  10.173 +        } catch (Exception e) {
  10.174 +            e.printStackTrace();
  10.175 +            throw new Error("error reading " + jfo.toUri() +": " + e);
  10.176 +        }
  10.177 +    }
  10.178 +
  10.179 +    /**
  10.180 +     * Log an error
  10.181 +     */
  10.182 +    protected void error(String msg) {
  10.183 +        nerrors++;
  10.184 +        System.err.printf("Error occurred while checking file: %s\nreason: %s\n", jfo.getName(), msg);
  10.185 +    }
  10.186 +
  10.187 +    /**
  10.188 +     * This annotation processor is used to populate the bridge map with the
  10.189 +     * contents of the annotations that are found on the tests being compiled
  10.190 +     */
  10.191 +    @SupportedAnnotationTypes({"Bridges","Bridge"})
  10.192 +    class BridgeFinder extends JavacTestingAbstractProcessor {
  10.193 +        @Override
  10.194 +        public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
  10.195 +            if (roundEnv.processingOver())
  10.196 +                return true;
  10.197 +
  10.198 +            TypeElement bridgeAnno = elements.getTypeElement("Bridge");
  10.199 +            TypeElement bridgesAnno = elements.getTypeElement("Bridges");
  10.200 +
  10.201 +            //see if there are repeated annos
  10.202 +            for (Element elem: roundEnv.getElementsAnnotatedWith(bridgesAnno)) {
  10.203 +                List<Bridge> bridgeList = List.nil();
  10.204 +                Bridges bridges = elem.getAnnotation(Bridges.class);
  10.205 +                for (Bridge bridge : bridges.value()) {
  10.206 +                    bridgeList = bridgeList.prepend(bridge);
  10.207 +                }
  10.208 +                bridgesMap.put(((ClassSymbol)elem).flatname.toString(), bridgeList);
  10.209 +            }
  10.210 +
  10.211 +            //see if there are non-repeated annos
  10.212 +            for (Element elem: roundEnv.getElementsAnnotatedWith(bridgeAnno)) {
  10.213 +                Bridge bridge = elem.getAnnotation(Bridge.class);
  10.214 +                bridgesMap.put(((ClassSymbol)elem).flatname.toString(),
  10.215 +                        List.of(bridge));
  10.216 +            }
  10.217 +
  10.218 +            return true;
  10.219 +        }
  10.220 +    }
  10.221 +}
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/test/tools/javac/generics/bridges/Bridges.java	Wed Jul 17 10:40:53 2013 -0700
    11.3 @@ -0,0 +1,25 @@
    11.4 +/*
    11.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
    11.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    11.7 + *
    11.8 + * This code is free software; you can redistribute it and/or modify it
    11.9 + * under the terms of the GNU General Public License version 2 only, as
   11.10 + * published by the Free Software Foundation.
   11.11 + *
   11.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   11.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   11.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   11.15 + * version 2 for more details (a copy is included in the LICENSE file that
   11.16 + * accompanied this code).
   11.17 + *
   11.18 + * You should have received a copy of the GNU General Public License version
   11.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   11.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   11.21 + *
   11.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   11.23 + * or visit www.oracle.com if you need additional information or have any
   11.24 + * questions.
   11.25 + */
   11.26 +@interface Bridges {
   11.27 +    Bridge[] value();
   11.28 +}
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/test/tools/javac/generics/bridges/tests/TestBridgeWithDefault.java	Wed Jul 17 10:40:53 2013 -0700
    12.3 @@ -0,0 +1,31 @@
    12.4 +/*
    12.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
    12.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    12.7 + *
    12.8 + * This code is free software; you can redistribute it and/or modify it
    12.9 + * under the terms of the GNU General Public License version 2 only, as
   12.10 + * published by the Free Software Foundation.
   12.11 + *
   12.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   12.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   12.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   12.15 + * version 2 for more details (a copy is included in the LICENSE file that
   12.16 + * accompanied this code).
   12.17 + *
   12.18 + * You should have received a copy of the GNU General Public License version
   12.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   12.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   12.21 + *
   12.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   12.23 + * or visit www.oracle.com if you need additional information or have any
   12.24 + * questions.
   12.25 + */
   12.26 +class TestBridgeWithDefault {
   12.27 +    interface A { Object m(int x); }
   12.28 +
   12.29 +    @Bridge("m(I)Ljava/lang/Object;")
   12.30 +    interface B extends A {
   12.31 +        String m(int x);
   12.32 +        default Integer m(long x) { return null; }
   12.33 +    }
   12.34 +}
    13.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.2 +++ b/test/tools/javac/generics/bridges/tests/TestClassAndInterfaceBridgeIdentical01.java	Wed Jul 17 10:40:53 2013 -0700
    13.3 @@ -0,0 +1,45 @@
    13.4 +/*
    13.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
    13.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    13.7 + *
    13.8 + * This code is free software; you can redistribute it and/or modify it
    13.9 + * under the terms of the GNU General Public License version 2 only, as
   13.10 + * published by the Free Software Foundation.
   13.11 + *
   13.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   13.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   13.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   13.15 + * version 2 for more details (a copy is included in the LICENSE file that
   13.16 + * accompanied this code).
   13.17 + *
   13.18 + * You should have received a copy of the GNU General Public License version
   13.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   13.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   13.21 + *
   13.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   13.23 + * or visit www.oracle.com if you need additional information or have any
   13.24 + * questions.
   13.25 + */
   13.26 +class TestClassAndInterfaceBridgeIdentical01 {
   13.27 +
   13.28 +    interface A { Object m(); }
   13.29 +    interface B { Number m(); }
   13.30 +
   13.31 +    @Bridge("m()Ljava/lang/Object;")
   13.32 +    @Bridge("m()Ljava/lang/Number;")
   13.33 +    interface C extends A, B {
   13.34 +        Integer m();
   13.35 +    }
   13.36 +
   13.37 +    @Bridge("m()Ljava/lang/Object;")
   13.38 +    @Bridge("m()Ljava/lang/Number;")
   13.39 +    static abstract class D implements A, B {
   13.40 +        public abstract Integer m();
   13.41 +    }
   13.42 +
   13.43 +    @Bridge("m()Ljava/lang/Object;")
   13.44 +    @Bridge("m()Ljava/lang/Number;")
   13.45 +    static class E implements A, B {
   13.46 +        public Integer m() { return 1; }
   13.47 +    }
   13.48 +}
    14.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.2 +++ b/test/tools/javac/generics/bridges/tests/TestClassAndInterfaceBridgeIdentical02.java	Wed Jul 17 10:40:53 2013 -0700
    14.3 @@ -0,0 +1,45 @@
    14.4 +/*
    14.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
    14.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    14.7 + *
    14.8 + * This code is free software; you can redistribute it and/or modify it
    14.9 + * under the terms of the GNU General Public License version 2 only, as
   14.10 + * published by the Free Software Foundation.
   14.11 + *
   14.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   14.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   14.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   14.15 + * version 2 for more details (a copy is included in the LICENSE file that
   14.16 + * accompanied this code).
   14.17 + *
   14.18 + * You should have received a copy of the GNU General Public License version
   14.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   14.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   14.21 + *
   14.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   14.23 + * or visit www.oracle.com if you need additional information or have any
   14.24 + * questions.
   14.25 + */
   14.26 +class TestClassAndInterfaceBridgeIdentical02 {
   14.27 +
   14.28 +    interface A<X extends Object> { void m(X x); }
   14.29 +    interface B<X extends Number> { void m(X x); }
   14.30 +
   14.31 +    @Bridge("m(Ljava/lang/Object;)V")
   14.32 +    @Bridge("m(Ljava/lang/Number;)V")
   14.33 +    interface C extends A<Integer>, B<Integer> {
   14.34 +        void m(Integer i);
   14.35 +    }
   14.36 +
   14.37 +    @Bridge("m(Ljava/lang/Object;)V")
   14.38 +    @Bridge("m(Ljava/lang/Number;)V")
   14.39 +    static abstract class D implements A<Integer>, B<Integer> {
   14.40 +        public abstract void m(Integer i);
   14.41 +    }
   14.42 +
   14.43 +    @Bridge("m(Ljava/lang/Object;)V")
   14.44 +    @Bridge("m(Ljava/lang/Number;)V")
   14.45 +    static class E implements A<Integer>, B<Integer> {
   14.46 +        public void m(Integer i) { }
   14.47 +    }
   14.48 +}
    15.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.2 +++ b/test/tools/javac/generics/bridges/tests/TestNoBridgeInSiblingsSuper.java	Wed Jul 17 10:40:53 2013 -0700
    15.3 @@ -0,0 +1,34 @@
    15.4 +/*
    15.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
    15.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    15.7 + *
    15.8 + * This code is free software; you can redistribute it and/or modify it
    15.9 + * under the terms of the GNU General Public License version 2 only, as
   15.10 + * published by the Free Software Foundation.
   15.11 + *
   15.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   15.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   15.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   15.15 + * version 2 for more details (a copy is included in the LICENSE file that
   15.16 + * accompanied this code).
   15.17 + *
   15.18 + * You should have received a copy of the GNU General Public License version
   15.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   15.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   15.21 + *
   15.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   15.23 + * or visit www.oracle.com if you need additional information or have any
   15.24 + * questions.
   15.25 + */
   15.26 +class TestNoBridgeInSiblingSuper {
   15.27 +    interface A { Object m(); }
   15.28 +    interface B { String m(); }
   15.29 +    //no bridge here!
   15.30 +    interface C extends A, B { }
   15.31 +
   15.32 +    @Bridge("m()Ljava/lang/Object;")
   15.33 +    interface D extends C {
   15.34 +        String m();
   15.35 +    }
   15.36 +}
   15.37 +
    16.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    16.2 +++ b/test/tools/javac/generics/bridges/tests/TestNoDuplicateBridges01.java	Wed Jul 17 10:40:53 2013 -0700
    16.3 @@ -0,0 +1,29 @@
    16.4 +/*
    16.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
    16.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    16.7 + *
    16.8 + * This code is free software; you can redistribute it and/or modify it
    16.9 + * under the terms of the GNU General Public License version 2 only, as
   16.10 + * published by the Free Software Foundation.
   16.11 + *
   16.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   16.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   16.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   16.15 + * version 2 for more details (a copy is included in the LICENSE file that
   16.16 + * accompanied this code).
   16.17 + *
   16.18 + * You should have received a copy of the GNU General Public License version
   16.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   16.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   16.21 + *
   16.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   16.23 + * or visit www.oracle.com if you need additional information or have any
   16.24 + * questions.
   16.25 + */
   16.26 +class TestNoDuplicateBridges01 {
   16.27 +    interface A1 { Object m(); }
   16.28 +    interface A2 { Object m(); }
   16.29 +
   16.30 +    @Bridge("m()Ljava/lang/Object;")
   16.31 +    interface B extends A1, A2 { B m(); }
   16.32 +}
    17.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    17.2 +++ b/test/tools/javac/generics/bridges/tests/TestNoDuplicateBridges02.java	Wed Jul 17 10:40:53 2013 -0700
    17.3 @@ -0,0 +1,38 @@
    17.4 +/*
    17.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
    17.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    17.7 + *
    17.8 + * This code is free software; you can redistribute it and/or modify it
    17.9 + * under the terms of the GNU General Public License version 2 only, as
   17.10 + * published by the Free Software Foundation.
   17.11 + *
   17.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   17.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   17.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   17.15 + * version 2 for more details (a copy is included in the LICENSE file that
   17.16 + * accompanied this code).
   17.17 + *
   17.18 + * You should have received a copy of the GNU General Public License version
   17.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   17.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   17.21 + *
   17.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   17.23 + * or visit www.oracle.com if you need additional information or have any
   17.24 + * questions.
   17.25 + */
   17.26 +class TestNoDuplicateBridges02 {
   17.27 +    interface A<T> {
   17.28 +        A<T> get();
   17.29 +    }
   17.30 +
   17.31 +    @Bridge("get()LTestNoDuplicateBridges02$A;")
   17.32 +    interface B<T> extends A<T> {
   17.33 +        B<T> get();
   17.34 +    }
   17.35 +
   17.36 +    @Bridge("get()LTestNoDuplicateBridges02$A;")
   17.37 +    @Bridge("get()LTestNoDuplicateBridges02$B;")
   17.38 +    interface C<T> extends A<T>, B<T> {
   17.39 +        C<T> get();
   17.40 +    }
   17.41 +}
    18.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    18.2 +++ b/test/tools/javac/lambda/bridge/TestMetafactoryBridges.java	Wed Jul 17 10:40:53 2013 -0700
    18.3 @@ -0,0 +1,359 @@
    18.4 +/*
    18.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
    18.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    18.7 + *
    18.8 + * This code is free software; you can redistribute it and/or modify it
    18.9 + * under the terms of the GNU General Public License version 2 only, as
   18.10 + * published by the Free Software Foundation.
   18.11 + *
   18.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   18.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   18.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   18.15 + * version 2 for more details (a copy is included in the LICENSE file that
   18.16 + * accompanied this code).
   18.17 + *
   18.18 + * You should have received a copy of the GNU General Public License version
   18.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   18.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   18.21 + *
   18.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   18.23 + * or visit www.oracle.com if you need additional information or have any
   18.24 + * questions.
   18.25 + */
   18.26 +
   18.27 +/*
   18.28 + * @test
   18.29 + * @bug 8013789
   18.30 + * @summary Compiler should emit bridges in interfaces
   18.31 + */
   18.32 +
   18.33 +import com.sun.source.util.JavacTask;
   18.34 +import com.sun.tools.javac.api.ClientCodeWrapper.DiagnosticSourceUnwrapper;
   18.35 +import com.sun.tools.javac.code.Symbol;
   18.36 +import com.sun.tools.javac.util.JCDiagnostic;
   18.37 +
   18.38 +import java.io.File;
   18.39 +import java.io.PrintWriter;
   18.40 +import java.net.URI;
   18.41 +import java.util.ArrayList;
   18.42 +import java.util.Arrays;
   18.43 +import java.util.EnumSet;
   18.44 +import java.util.List;
   18.45 +import java.util.Set;
   18.46 +
   18.47 +import javax.tools.Diagnostic;
   18.48 +import javax.tools.Diagnostic.Kind;
   18.49 +import javax.tools.JavaCompiler;
   18.50 +import javax.tools.JavaFileObject;
   18.51 +import javax.tools.SimpleJavaFileObject;
   18.52 +import javax.tools.ToolProvider;
   18.53 +
   18.54 +public class TestMetafactoryBridges {
   18.55 +
   18.56 +    static int checkCount = 0;
   18.57 +
   18.58 +    enum ClasspathKind {
   18.59 +        NONE(),
   18.60 +        B7(7, ClassKind.B),
   18.61 +        A7(7, ClassKind.A),
   18.62 +        B8(8, ClassKind.B),
   18.63 +        A8(8, ClassKind.A);
   18.64 +
   18.65 +        int version;
   18.66 +        ClassKind ck;
   18.67 +
   18.68 +        ClasspathKind() {
   18.69 +            this(-1, null);
   18.70 +        }
   18.71 +
   18.72 +        ClasspathKind(int version, ClassKind ck) {
   18.73 +            this.version = version;
   18.74 +            this.ck = ck;
   18.75 +        }
   18.76 +    }
   18.77 +
   18.78 +    enum PreferPolicy {
   18.79 +        SOURCE("-Xprefer:source"),
   18.80 +        NEWER("-Xprefer:newer");
   18.81 +
   18.82 +        String preferOpt;
   18.83 +
   18.84 +        PreferPolicy(String preferOpt) {
   18.85 +            this.preferOpt = preferOpt;
   18.86 +        }
   18.87 +    }
   18.88 +
   18.89 +    enum SourcepathKind {
   18.90 +        NONE,
   18.91 +        A(ClassKind.A),
   18.92 +        B(ClassKind.B),
   18.93 +        C(ClassKind.C),
   18.94 +        AB(ClassKind.A, ClassKind.B),
   18.95 +        BC(ClassKind.B, ClassKind.C),
   18.96 +        AC(ClassKind.A, ClassKind.C),
   18.97 +        ABC(ClassKind.A, ClassKind.B, ClassKind.C);
   18.98 +
   18.99 +        List<ClassKind> sources;
  18.100 +
  18.101 +        SourcepathKind(ClassKind... sources) {
  18.102 +            this.sources = Arrays.asList(sources);
  18.103 +        }
  18.104 +    }
  18.105 +
  18.106 +    enum SourceSet {
  18.107 +        ALL() {
  18.108 +            @Override
  18.109 +            List<List<ClassKind>> permutations() {
  18.110 +                return Arrays.asList(
  18.111 +                    Arrays.asList(ClassKind.A, ClassKind.B, ClassKind.C),
  18.112 +                    Arrays.asList(ClassKind.A, ClassKind.B, ClassKind.C),
  18.113 +                    Arrays.asList(ClassKind.B, ClassKind.A, ClassKind.C),
  18.114 +                    Arrays.asList(ClassKind.B, ClassKind.C, ClassKind.A),
  18.115 +                    Arrays.asList(ClassKind.C, ClassKind.A, ClassKind.B),
  18.116 +                    Arrays.asList(ClassKind.C, ClassKind.B, ClassKind.A)
  18.117 +                );
  18.118 +            }
  18.119 +        },
  18.120 +        AC() {
  18.121 +            @Override
  18.122 +            List<List<ClassKind>> permutations() {
  18.123 +                return Arrays.asList(
  18.124 +                    Arrays.asList(ClassKind.A, ClassKind.C),
  18.125 +                    Arrays.asList(ClassKind.C, ClassKind.A)
  18.126 +                );
  18.127 +            }
  18.128 +        },
  18.129 +        C() {
  18.130 +            @Override
  18.131 +            List<List<ClassKind>> permutations() {
  18.132 +                return Arrays.asList(Arrays.asList(ClassKind.C));
  18.133 +            }
  18.134 +        };
  18.135 +
  18.136 +        abstract List<List<ClassKind>> permutations();
  18.137 +    }
  18.138 +
  18.139 +    enum ClassKind {
  18.140 +        A("A", "interface A { Object m(); }"),
  18.141 +        B("B", "interface B extends A { Integer m(); }", A),
  18.142 +        C("C", "class C { B b = ()->42; }", A, B);
  18.143 +
  18.144 +        String name;
  18.145 +        String source;
  18.146 +        ClassKind[] deps;
  18.147 +
  18.148 +        ClassKind(String name, String source, ClassKind... deps) {
  18.149 +            this.name = name;
  18.150 +            this.source = source;
  18.151 +            this.deps = deps;
  18.152 +        }
  18.153 +    }
  18.154 +
  18.155 +    public static void main(String... args) throws Exception {
  18.156 +        String SCRATCH_DIR = System.getProperty("user.dir");
  18.157 +        //create default shared JavaCompiler - reused across multiple compilations
  18.158 +        JavaCompiler comp = ToolProvider.getSystemJavaCompiler();
  18.159 +
  18.160 +        int n = 0;
  18.161 +        for (SourceSet ss : SourceSet.values()) {
  18.162 +            for (List<ClassKind> sources : ss.permutations()) {
  18.163 +                for (SourcepathKind spKind : SourcepathKind.values()) {
  18.164 +                    for (ClasspathKind cpKind : ClasspathKind.values()) {
  18.165 +                        for (PreferPolicy pp : PreferPolicy.values()) {
  18.166 +                            Set<ClassKind> deps = EnumSet.noneOf(ClassKind.class);
  18.167 +                            if (cpKind.ck != null) {
  18.168 +                                deps.add(cpKind.ck);
  18.169 +                            }
  18.170 +                            deps.addAll(sources);
  18.171 +                            if (deps.size() < 3) continue;
  18.172 +                            File testDir = new File(SCRATCH_DIR, "test" + n);
  18.173 +                            testDir.mkdir();
  18.174 +                            try (PrintWriter debugWriter = new PrintWriter(new File(testDir, "debug.txt"))) {
  18.175 +                                new TestMetafactoryBridges(testDir, sources, spKind, cpKind, pp, debugWriter).run(comp);
  18.176 +                                n++;
  18.177 +                            }
  18.178 +                        }
  18.179 +                    }
  18.180 +                }
  18.181 +            }
  18.182 +        }
  18.183 +        System.out.println("Total check executed: " + checkCount);
  18.184 +    }
  18.185 +
  18.186 +    File testDir;
  18.187 +    List<ClassKind> sources;
  18.188 +    SourcepathKind spKind;
  18.189 +    ClasspathKind cpKind;
  18.190 +    PreferPolicy pp;
  18.191 +    PrintWriter debugWriter;
  18.192 +    DiagnosticChecker diagChecker;
  18.193 +
  18.194 +    TestMetafactoryBridges(File testDir, List<ClassKind>sources, SourcepathKind spKind,
  18.195 +            ClasspathKind cpKind, PreferPolicy pp, PrintWriter debugWriter) {
  18.196 +        this.testDir = testDir;
  18.197 +        this.sources = sources;
  18.198 +        this.spKind = spKind;
  18.199 +        this.cpKind = cpKind;
  18.200 +        this.pp = pp;
  18.201 +        this.debugWriter = debugWriter;
  18.202 +        this.diagChecker = new DiagnosticChecker();
  18.203 +    }
  18.204 +
  18.205 +    class JavaSource extends SimpleJavaFileObject {
  18.206 +
  18.207 +        final String source;
  18.208 +
  18.209 +        public JavaSource(ClassKind ck) {
  18.210 +            super(URI.create(String.format("myfo:/%s.java", ck.name)), JavaFileObject.Kind.SOURCE);
  18.211 +            this.source = ck.source;
  18.212 +        }
  18.213 +
  18.214 +        @Override
  18.215 +        public CharSequence getCharContent(boolean ignoreEncodingErrors) {
  18.216 +            return source;
  18.217 +        }
  18.218 +    }
  18.219 +
  18.220 +    void run(JavaCompiler tool) throws Exception {
  18.221 +        File classesDir = new File(testDir, "classes");
  18.222 +        File outDir = new File(testDir, "out");
  18.223 +        File srcDir = new File(testDir, "src");
  18.224 +        classesDir.mkdir();
  18.225 +        outDir.mkdir();
  18.226 +        srcDir.mkdir();
  18.227 +
  18.228 +        debugWriter.append(testDir.getName() + "\n");
  18.229 +        debugWriter.append("sources = " + sources + "\n");
  18.230 +        debugWriter.append("spKind = " + spKind  + "\n");
  18.231 +        debugWriter.append("cpKind = " + cpKind + "\n");
  18.232 +        debugWriter.append("preferPolicy = " + pp.preferOpt + "\n");
  18.233 +
  18.234 +        //step 1 - prepare sources (older!!)
  18.235 +        debugWriter.append("Preparing sources\n");
  18.236 +        for (ClassKind ck : spKind.sources) {
  18.237 +            //skip sources explicitly provided on command line
  18.238 +            if (!sources.contains(ck)) {
  18.239 +                debugWriter.append("Copy " + ck.name + ".java to" + srcDir.getAbsolutePath() + "\n");
  18.240 +                File dest = new File(srcDir, ck.name + ".java");
  18.241 +                PrintWriter pw = new PrintWriter(dest);
  18.242 +                pw.append(ck.source);
  18.243 +                pw.close();
  18.244 +            }
  18.245 +        }
  18.246 +
  18.247 +        //step 2 - prepare classes
  18.248 +        debugWriter.append("Preparing classes\n");
  18.249 +        if (cpKind != ClasspathKind.NONE) {
  18.250 +            List<JavaSource> sources = new ArrayList<>();
  18.251 +            ClassKind toRemove = null;
  18.252 +            sources.add(new JavaSource(cpKind.ck));
  18.253 +            if (cpKind.ck.deps.length != 0) {
  18.254 +                //at most only one dependency
  18.255 +                toRemove = cpKind.ck.deps[0];
  18.256 +                sources.add(new JavaSource(toRemove));
  18.257 +            }
  18.258 +            JavacTask ct = (JavacTask)tool.getTask(debugWriter, null, null,
  18.259 +                    Arrays.asList("-d", classesDir.getAbsolutePath(), "-source", String.valueOf(cpKind.version)), null, sources);
  18.260 +            try {
  18.261 +                ct.generate();
  18.262 +                if (toRemove != null) {
  18.263 +                    debugWriter.append("Remove " + toRemove.name + ".class from" + classesDir.getAbsolutePath() + "\n");
  18.264 +                    File fileToRemove = new File(classesDir, toRemove.name + ".class");
  18.265 +                    fileToRemove.delete();
  18.266 +                }
  18.267 +            } catch (Throwable ex) {
  18.268 +                throw new AssertionError("Error thrown when generating side-classes");
  18.269 +            }
  18.270 +        }
  18.271 +
  18.272 +        //step 3 - compile
  18.273 +        debugWriter.append("Compiling test\n");
  18.274 +        List<JavaSource> sourcefiles = new ArrayList<>();
  18.275 +        for (ClassKind ck : sources) {
  18.276 +            sourcefiles.add(new JavaSource(ck));
  18.277 +        }
  18.278 +        JavacTask ct = (JavacTask)tool.getTask(debugWriter, null, diagChecker,
  18.279 +                    Arrays.asList("-XDdumpLambdaToMethodStats", "-d", outDir.getAbsolutePath(),
  18.280 +                                  "-sourcepath", srcDir.getAbsolutePath(),
  18.281 +                                  "-classpath", classesDir.getAbsolutePath(),
  18.282 +                                  pp.preferOpt), null, sourcefiles);
  18.283 +        try {
  18.284 +            ct.generate();
  18.285 +        } catch (Throwable ex) {
  18.286 +            throw new AssertionError("Error thrown when compiling test case");
  18.287 +        }
  18.288 +        check();
  18.289 +    }
  18.290 +
  18.291 +    void check() {
  18.292 +        checkCount++;
  18.293 +        if (diagChecker.errorFound) {
  18.294 +            throw new AssertionError("Unexpected compilation failure");
  18.295 +        }
  18.296 +
  18.297 +        boolean altMetafactory =
  18.298 +                cpKind == ClasspathKind.B7 &&
  18.299 +                !sources.contains(ClassKind.B) &&
  18.300 +                (pp == PreferPolicy.NEWER || !spKind.sources.contains(ClassKind.B));
  18.301 +
  18.302 +        if (altMetafactory != diagChecker.altMetafactory) {
  18.303 +            throw new AssertionError("Bad metafactory detected - expected altMetafactory: " + altMetafactory +
  18.304 +                    "\ntest: " + testDir);
  18.305 +        }
  18.306 +    }
  18.307 +
  18.308 +    static class DiagnosticChecker implements javax.tools.DiagnosticListener<JavaFileObject> {
  18.309 +
  18.310 +        boolean altMetafactory = false;
  18.311 +        boolean errorFound = false;
  18.312 +
  18.313 +        public void report(Diagnostic<? extends JavaFileObject> diagnostic) {
  18.314 +            if (diagnostic.getKind() == Diagnostic.Kind.ERROR) {
  18.315 +                errorFound = true;
  18.316 +            } else if (statProcessor.matches(diagnostic)) {
  18.317 +                statProcessor.process(diagnostic);
  18.318 +            }
  18.319 +        }
  18.320 +
  18.321 +        abstract class DiagnosticProcessor {
  18.322 +
  18.323 +            List<String> codes;
  18.324 +            Diagnostic.Kind kind;
  18.325 +
  18.326 +            public DiagnosticProcessor(Kind kind, String... codes) {
  18.327 +                this.codes = Arrays.asList(codes);
  18.328 +                this.kind = kind;
  18.329 +            }
  18.330 +
  18.331 +            abstract void process(Diagnostic<? extends JavaFileObject> diagnostic);
  18.332 +
  18.333 +            boolean matches(Diagnostic<? extends JavaFileObject> diagnostic) {
  18.334 +                return (codes.isEmpty() || codes.contains(diagnostic.getCode())) &&
  18.335 +                        diagnostic.getKind() == kind;
  18.336 +            }
  18.337 +
  18.338 +            JCDiagnostic asJCDiagnostic(Diagnostic<? extends JavaFileObject> diagnostic) {
  18.339 +                if (diagnostic instanceof JCDiagnostic) {
  18.340 +                    return (JCDiagnostic)diagnostic;
  18.341 +                } else if (diagnostic instanceof DiagnosticSourceUnwrapper) {
  18.342 +                    return ((DiagnosticSourceUnwrapper)diagnostic).d;
  18.343 +                } else {
  18.344 +                    throw new AssertionError("Cannot convert diagnostic to JCDiagnostic: " + diagnostic.getClass().getName());
  18.345 +                }
  18.346 +            }
  18.347 +        }
  18.348 +
  18.349 +        DiagnosticProcessor statProcessor = new DiagnosticProcessor(Kind.NOTE,
  18.350 +                "compiler.note.lambda.stat",
  18.351 +                "compiler.note.mref.stat",
  18.352 +                "compiler.note.mref.stat.1") {
  18.353 +            @Override
  18.354 +            void process(Diagnostic<? extends JavaFileObject> diagnostic) {
  18.355 +                JCDiagnostic diag = asJCDiagnostic(diagnostic);
  18.356 +                if ((Boolean)diag.getArgs()[0]) {
  18.357 +                    altMetafactory = true;
  18.358 +                }
  18.359 +            }
  18.360 +        };
  18.361 +    }
  18.362 +}
    19.1 --- a/test/tools/javac/lambda/lambdaExpression/LambdaTest6.java	Wed Jul 17 15:08:58 2013 +0200
    19.2 +++ b/test/tools/javac/lambda/lambdaExpression/LambdaTest6.java	Wed Jul 17 10:40:53 2013 -0700
    19.3 @@ -105,7 +105,7 @@
    19.4              Class returnType = m.getReturnType();
    19.5              assertTrue(types.remove(returnType.getName()));
    19.6          }
    19.7 -        assertTrue(types.isEmpty());
    19.8 +        assertTrue(types.size() == 1); //there's a bridge
    19.9      }
   19.10  
   19.11  
    20.1 --- a/test/tools/javac/lambda/methodReference/BridgeMethod.java	Wed Jul 17 15:08:58 2013 +0200
    20.2 +++ b/test/tools/javac/lambda/methodReference/BridgeMethod.java	Wed Jul 17 10:40:53 2013 -0700
    20.3 @@ -112,6 +112,6 @@
    20.4              Class<?> returnType = m.getReturnType();
    20.5              assertTrue(types.remove(returnType.getName()));
    20.6          }
    20.7 -        assertTrue(types.isEmpty());
    20.8 +        assertTrue(types.size() == 1); //there's a bridge
    20.9      }
   20.10  }
    21.1 --- a/test/tools/javac/lambdaShapes/org/openjdk/tests/vm/DefaultMethodsTest.java	Wed Jul 17 15:08:58 2013 +0200
    21.2 +++ b/test/tools/javac/lambdaShapes/org/openjdk/tests/vm/DefaultMethodsTest.java	Wed Jul 17 10:40:53 2013 -0700
    21.3 @@ -395,6 +395,7 @@
    21.4       * TEST: C c = new C(); c.m() == 88;
    21.5       * TEST: I i = new C(); i.m() == 88;
    21.6       */
    21.7 +    @Test(enabled=false)
    21.8      public void testSelfFill() {
    21.9          // This test ensures that a concrete method overrides a default method
   21.10          // that matches at the language-level, but has a different method
   21.11 @@ -484,6 +485,7 @@
   21.12       * TEST: J<String,String> j = new C(); j.m("A","B","C") == 88;
   21.13       * TEST: K<String> k = new C(); k.m("A","B","C") == 88;
   21.14       */
   21.15 +    @Test(enabled=false)
   21.16      public void testBridges() {
   21.17          DefaultMethod dm = new DefaultMethod("int", stdMethodName, "return 99;",
   21.18              new MethodParameter("T", "t"), new MethodParameter("V", "v"),
   21.19 @@ -672,6 +674,7 @@
   21.20       * class S { Object foo() { return (new D()).m(); } // link sig: ()LInteger;
   21.21       * TEST: S s = new S(); s.foo() == new Integer(99)
   21.22       */
   21.23 +    @Test(enabled=false)
   21.24      public void testCovarBridge() {
   21.25          Interface I = new Interface("I", new DefaultMethod(
   21.26              "Integer", "m", "return new Integer(88);"));
   21.27 @@ -754,6 +757,7 @@
   21.28       * Test that a erased-signature-matching method does not implement
   21.29       * non-language-level matching methods
   21.30       */
   21.31 +    @Test(enabled=false)
   21.32      public void testNonConcreteFill() {
   21.33          AbstractMethod ipm = new AbstractMethod("int", "m",
   21.34              new MethodParameter("T", "t"),

mercurial