changeset 2243:718064a04b56

8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle Summary: langtools/javac component of the fix. Reviewed-by: briangoetz, forax Contributed-by: maurizio.cimadamore@oracle.com
author rfield
date Wed, 24 Jul 2013 16:54:37 -0700
parents a81cf02dfe46
children d34073d069c8
files src/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java src/share/classes/com/sun/tools/javac/util/Names.java
diffstat 2 files changed, 24 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java	Fri Jul 19 15:12:24 2013 +0100
+++ b/src/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java	Wed Jul 24 16:54:37 2013 -0700
@@ -25,11 +25,9 @@
 package com.sun.tools.javac.comp;
 
 import com.sun.tools.javac.tree.*;
-import com.sun.tools.javac.tree.JCTree;
 import com.sun.tools.javac.tree.JCTree.*;
 import com.sun.tools.javac.tree.JCTree.JCMemberReference.ReferenceKind;
 import com.sun.tools.javac.tree.TreeMaker;
-import com.sun.tools.javac.tree.TreeScanner;
 import com.sun.tools.javac.tree.TreeTranslator;
 import com.sun.tools.javac.code.Attribute;
 import com.sun.tools.javac.code.Kinds;
@@ -47,7 +45,6 @@
 import com.sun.tools.javac.comp.Lower.BasicFreeVarCollector;
 import com.sun.tools.javac.jvm.*;
 import com.sun.tools.javac.util.*;
-import com.sun.tools.javac.util.List;
 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
 import com.sun.source.tree.MemberReferenceTree.ReferenceMode;
 
@@ -331,7 +328,7 @@
         int refKind = referenceKind(sym);
 
         //convert to an invokedynamic call
-        result = makeMetaFactoryIndyCall(context, refKind, sym, indy_args);
+        result = makeMetafactoryIndyCall(context, refKind, sym, indy_args);
     }
 
     private JCIdent makeThis(Type type, Symbol owner) {
@@ -392,7 +389,7 @@
 
 
         //build a sam instance using an indy call to the meta-factory
-        result = makeMetaFactoryIndyCall(localContext, localContext.referenceKind(), refSym, indy_args);
+        result = makeMetafactoryIndyCall(localContext, localContext.referenceKind(), refSym, indy_args);
     }
 
     /**
@@ -616,8 +613,8 @@
                 make.Return(makeIndyCall(
                     pos,
                     syms.lambdaMetafactory,
-                    names.altMetaFactory,
-                    staticArgs, indyType, serArgs.toList())),
+                    names.altMetafactory,
+                    staticArgs, indyType, serArgs.toList(), samSym.name)),
                 null);
         ListBuffer<JCStatement> stmts = kInfo.deserializeCases.get(implMethodName);
         if (stmts == null) {
@@ -914,24 +911,27 @@
     private void bridgeMemberReference(JCMemberReference tree, ReferenceTranslationContext localContext) {
         kInfo.addMethod(new MemberReferenceBridger(tree, localContext).bridge());
     }
+    
+    private MethodType typeToMethodType(Type mt) {
+        Type type = types.erasure(mt);
+        return new MethodType(type.getParameterTypes(),
+                        type.getReturnType(),
+                        type.getThrownTypes(),
+                        syms.methodClass);
+    }
 
     /**
      * Generate an indy method call to the meta factory
      */
-    private JCExpression makeMetaFactoryIndyCall(TranslationContext<?> context,
+    private JCExpression makeMetafactoryIndyCall(TranslationContext<?> context,
             int refKind, Symbol refSym, List<JCExpression> indy_args) {
         JCFunctionalExpression tree = context.tree;
         //determine the static bsm args
-        Type mtype = types.erasure(tree.getDescriptorType(types));
         MethodSymbol samSym = (MethodSymbol) types.findDescriptorSymbol(tree.type.tsym);
         List<Object> staticArgs = List.<Object>of(
-                new Pool.MethodHandle(ClassFile.REF_invokeInterface,
-                    types.findDescriptorSymbol(tree.type.tsym), types),
+                typeToMethodType(samSym.type),
                 new Pool.MethodHandle(refKind, refSym, types),
-                new MethodType(mtype.getParameterTypes(),
-                        mtype.getReturnType(),
-                        mtype.getThrownTypes(),
-                        syms.methodClass));
+                typeToMethodType(tree.getDescriptorType(types)));
 
         //computed indy arg types
         ListBuffer<Type> indy_args_types = ListBuffer.lb();
@@ -946,7 +946,7 @@
                 syms.methodClass);
 
         Name metafactoryName = context.needsAltMetafactory() ?
-                names.altMetaFactory : names.metaFactory;
+                names.altMetafactory : names.metafactory;
 
         if (context.needsAltMetafactory()) {
             ListBuffer<Object> markers = ListBuffer.lb();
@@ -984,7 +984,7 @@
             }
         }
 
-        return makeIndyCall(tree, syms.lambdaMetafactory, metafactoryName, staticArgs, indyType, indy_args);
+        return makeIndyCall(tree, syms.lambdaMetafactory, metafactoryName, staticArgs, indyType, indy_args, samSym.name);
     }
 
     /**
@@ -992,7 +992,8 @@
      * arguments types
      */
     private JCExpression makeIndyCall(DiagnosticPosition pos, Type site, Name bsmName,
-            List<Object> staticArgs, MethodType indyType, List<JCExpression> indyArgs) {
+            List<Object> staticArgs, MethodType indyType, List<JCExpression> indyArgs,
+            Name methName) {
         int prevPos = make.pos;
         try {
             make.at(pos);
@@ -1004,7 +1005,7 @@
                     bsmName, bsm_staticArgs, List.<Type>nil());
 
             DynamicMethodSymbol dynSym =
-                    new DynamicMethodSymbol(names.lambda,
+                    new DynamicMethodSymbol(methName,
                                             syms.noSymbol,
                                             bsm.isStatic() ?
                                                 ClassFile.REF_invokeStatic :
--- a/src/share/classes/com/sun/tools/javac/util/Names.java	Fri Jul 19 15:12:24 2013 +0100
+++ b/src/share/classes/com/sun/tools/javac/util/Names.java	Wed Jul 24 16:54:37 2013 -0700
@@ -174,8 +174,8 @@
 
     //lambda-related
     public final Name lambda;
-    public final Name metaFactory;
-    public final Name altMetaFactory;
+    public final Name metafactory;
+    public final Name altMetafactory;
 
     public final Name.Table table;
 
@@ -310,8 +310,8 @@
 
         //lambda-related
         lambda = fromString("lambda$");
-        metaFactory = fromString("metaFactory");
-        altMetaFactory = fromString("altMetaFactory");
+        metafactory = fromString("metafactory");
+        altMetafactory = fromString("altMetafactory");
     }
 
     protected Name.Table createTable(Options options) {