1.1 --- a/src/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java Tue Jun 18 20:56:04 2013 -0700 1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java Wed Jun 19 11:48:05 2013 +0100 1.3 @@ -100,9 +100,6 @@ 1.4 /** Flag for alternate metafactories indicating the lambda object has multiple targets */ 1.5 public static final int FLAG_MARKERS = 1 << 1; 1.6 1.7 - /** Flag for alternate metafactories indicating the lambda object requires multiple bridges */ 1.8 - public static final int FLAG_BRIDGES = 1 << 2; 1.9 - 1.10 private class KlassInfo { 1.11 1.12 /** 1.13 @@ -324,7 +321,7 @@ 1.14 int refKind = referenceKind(sym); 1.15 1.16 //convert to an invokedynamic call 1.17 - result = makeMetaFactoryIndyCall(context, refKind, sym, indy_args); 1.18 + result = makeMetaFactoryIndyCall(tree, context.needsAltMetafactory(), context.isSerializable(), refKind, sym, indy_args); 1.19 } 1.20 1.21 private JCIdent makeThis(Type type, Symbol owner) { 1.22 @@ -385,7 +382,7 @@ 1.23 1.24 1.25 //build a sam instance using an indy call to the meta-factory 1.26 - result = makeMetaFactoryIndyCall(localContext, localContext.referenceKind(), refSym, indy_args); 1.27 + result = makeMetaFactoryIndyCall(tree, localContext.needsAltMetafactory(), localContext.isSerializable(), localContext.referenceKind(), refSym, indy_args); 1.28 } 1.29 1.30 /** 1.31 @@ -911,11 +908,10 @@ 1.32 /** 1.33 * Generate an indy method call to the meta factory 1.34 */ 1.35 - private JCExpression makeMetaFactoryIndyCall(TranslationContext<?> context, 1.36 - int refKind, Symbol refSym, List<JCExpression> indy_args) { 1.37 - JCFunctionalExpression tree = context.tree; 1.38 + private JCExpression makeMetaFactoryIndyCall(JCFunctionalExpression tree, boolean needsAltMetafactory, 1.39 + boolean isSerializable, int refKind, Symbol refSym, List<JCExpression> indy_args) { 1.40 //determine the static bsm args 1.41 - Type mtype = types.erasure(tree.getDescriptorType(types)); 1.42 + Type mtype = types.erasure(tree.descriptorType); 1.43 MethodSymbol samSym = (MethodSymbol) types.findDescriptorSymbol(tree.type.tsym); 1.44 List<Object> staticArgs = List.<Object>of( 1.45 new Pool.MethodHandle(ClassFile.REF_invokeInterface, 1.46 @@ -938,40 +934,25 @@ 1.47 List.<Type>nil(), 1.48 syms.methodClass); 1.49 1.50 - Name metafactoryName = context.needsAltMetafactory() ? 1.51 + Name metafactoryName = needsAltMetafactory ? 1.52 names.altMetaFactory : names.metaFactory; 1.53 1.54 - if (context.needsAltMetafactory()) { 1.55 + if (needsAltMetafactory) { 1.56 ListBuffer<Object> markers = ListBuffer.lb(); 1.57 - for (Type t : tree.targets.tail) { 1.58 - if (t.tsym != syms.serializableType.tsym) { 1.59 - markers.append(t.tsym); 1.60 + for (Symbol t : tree.targets.tail) { 1.61 + if (t != syms.serializableType.tsym) { 1.62 + markers.append(t); 1.63 } 1.64 } 1.65 - int flags = context.isSerializable() ? FLAG_SERIALIZABLE : 0; 1.66 + int flags = isSerializable? FLAG_SERIALIZABLE : 0; 1.67 boolean hasMarkers = markers.nonEmpty(); 1.68 - boolean hasBridges = context.bridges.nonEmpty(); 1.69 - if (hasMarkers) { 1.70 - flags |= FLAG_MARKERS; 1.71 - } 1.72 - if (hasBridges) { 1.73 - flags |= FLAG_BRIDGES; 1.74 - } 1.75 + flags |= hasMarkers ? FLAG_MARKERS : 0; 1.76 staticArgs = staticArgs.append(flags); 1.77 if (hasMarkers) { 1.78 staticArgs = staticArgs.append(markers.length()); 1.79 staticArgs = staticArgs.appendList(markers.toList()); 1.80 } 1.81 - if (hasBridges) { 1.82 - staticArgs = staticArgs.append(context.bridges.length() - 1); 1.83 - for (Symbol s : context.bridges) { 1.84 - Type s_erasure = s.erasure(types); 1.85 - if (!types.isSameType(s_erasure, samSym.erasure(types))) { 1.86 - staticArgs = staticArgs.append(s.erasure(types)); 1.87 - } 1.88 - } 1.89 - } 1.90 - if (context.isSerializable()) { 1.91 + if (isSerializable) { 1.92 addDeserializationCase(refKind, refSym, tree.type, samSym, 1.93 tree, staticArgs, indyType); 1.94 } 1.95 @@ -1318,6 +1299,7 @@ 1.96 1.97 // Make lambda holding the new-class call 1.98 JCLambda slam = make.Lambda(params, nc); 1.99 + slam.descriptorType = tree.descriptorType; 1.100 slam.targets = tree.targets; 1.101 slam.type = tree.type; 1.102 slam.pos = tree.pos; 1.103 @@ -1652,30 +1634,23 @@ 1.104 /** the enclosing translation context (set for nested lambdas/mref) */ 1.105 TranslationContext<?> prev; 1.106 1.107 - /** list of methods to be bridged by the meta-factory */ 1.108 - List<Symbol> bridges; 1.109 - 1.110 TranslationContext(T tree) { 1.111 this.tree = tree; 1.112 this.owner = owner(); 1.113 this.depth = frameStack.size() - 1; 1.114 this.prev = context(); 1.115 - ClassSymbol csym = 1.116 - types.makeFunctionalInterfaceClass(attrEnv, names.empty, tree.targets, ABSTRACT | INTERFACE); 1.117 - this.bridges = types.functionalInterfaceBridges(csym); 1.118 } 1.119 1.120 /** does this functional expression need to be created using alternate metafactory? */ 1.121 boolean needsAltMetafactory() { 1.122 - return tree.targets.length() > 1 || 1.123 - isSerializable() || 1.124 - bridges.length() > 1; 1.125 + return (tree.targets.length() > 1 || 1.126 + isSerializable()); 1.127 } 1.128 1.129 /** does this functional expression require serialization support? */ 1.130 boolean isSerializable() { 1.131 - for (Type target : tree.targets) { 1.132 - if (types.asSuper(target, syms.serializableType.tsym) != null) { 1.133 + for (Symbol target : tree.targets) { 1.134 + if (types.asSuper(target.type, syms.serializableType.tsym) != null) { 1.135 return true; 1.136 } 1.137 } 1.138 @@ -1858,7 +1833,7 @@ 1.139 } 1.140 1.141 Type generatedLambdaSig() { 1.142 - return types.erasure(tree.getDescriptorType(types)); 1.143 + return types.erasure(tree.descriptorType); 1.144 } 1.145 } 1.146 1.147 @@ -1934,7 +1909,7 @@ 1.148 } 1.149 1.150 Type bridgedRefSig() { 1.151 - return types.erasure(types.findDescriptorSymbol(tree.targets.head.tsym).type); 1.152 + return types.erasure(types.findDescriptorSymbol(tree.targets.head).type); 1.153 } 1.154 } 1.155 }