changeset 3283:7af97c773606

Alt generic method translation fixes: * inferred calls are not patched correctly * local variable declaration in specializable calls are not patched correctly * method calls/var access using simple names are not patched correctly * disable lambda alt metafactory static arg tunnelling for alt generic method translation
author mcimadamore
date Mon, 11 Jan 2016 14:14:35 +0000
parents 3ae1321e6516
children de66408690d1
files src/jdk.compiler/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java src/jdk.compiler/share/classes/com/sun/tools/javac/comp/SpecializeTypes.java
diffstat 2 files changed, 47 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java	Tue Jan 05 12:56:28 2016 +0000
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java	Mon Jan 11 14:14:35 2016 +0000
@@ -1096,7 +1096,7 @@
             if (hasBridges) {
                 flags |= FLAG_BRIDGES;
             }
-            if (hasIndy) {
+            if (hasIndy && !specializeTypes.desugarGenericMethods) {
                 flags |= FLAG_INDY;
             }
             staticArgs = staticArgs.append(BootstrapArgument.Int(flags));
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/SpecializeTypes.java	Tue Jan 05 12:56:28 2016 +0000
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/SpecializeTypes.java	Mon Jan 11 14:14:35 2016 +0000
@@ -127,7 +127,7 @@
     private CompileStates compileStates;
     private Log log;
 
-    private boolean desugarGenericMethods;
+    boolean desugarGenericMethods;
 
     private SpecializeTypes(Context context) {
         super(context);
@@ -263,7 +263,12 @@
 
                 Symbol unspecializedMeth = msym.baseSymbol();
 
-                staticArgs = staticArgs.prepend(BootstrapArgument.MethodHandle((MethodSymbol)unspecializedMeth));
+                if (!altTranslation) {
+                    staticArgs = staticArgs.prepend(BootstrapArgument.MethodHandle((MethodSymbol)unspecializedMeth));
+                } else {
+                    //use method type instead of method handle to avoid access woes (for now)
+                    staticArgs = staticArgs.prepend(BootstrapArgument.MethodType(unspecializedMeth.type.asMethodType()));
+                }
 
                 //structural info is not required for the generic specialized call case
                 //as there, we should leave the method handle unspecialized, as it should point
@@ -423,7 +428,9 @@
 
     @Override
     public void visitMethodDef(JCMethodDecl tree) {
-        if (desugarGenericMethods && (tree.sym.flags() & Flags.ABSTRACT) == 0 && tree.typarams != null &&
+        if (desugarGenericMethods &&
+                (tree.sym.flags() & (Flags.ABSTRACT | Flags.BRIDGE)) == 0 &&
+                tree.typarams != null &&
                 tree.typarams.stream().anyMatch(p -> types.isAnyTypeVar(p.type))) {
             //desugar specializable method to inner classes (only static for now)
             tree = makeGenericMethodClass(tree);
@@ -784,13 +791,18 @@
     JCMethodDecl makeGenericMethodClass(JCMethodDecl tree) {
         MethodSymbol msym = tree.sym;
 
+        if (msym.isConstructor()) {
+            log.warning(tree, Warnings.ValhallaNotSupported("specializable constructor with alternate translation scheme"));
+            return tree;
+        }
+
         //create generic inner class symbol
         ClassSymbol genMethodClassSym = new ClassSymbol(Flags.SYNTHETIC | msym.flags(),
                 currentClass.getSimpleName().append('$', msym.name).append('$', sigHash(msym)),
                 null,
                 currentClass);
         genMethodClassSym.flags_field &= ~Flags.AccessFlags;
-        genMethodClassSym.flags_field |= Flags.PUBLIC;
+        genMethodClassSym.flags_field |= Flags.PUBLIC; //for now
 
         //compute old vs. new type parameters
         List<Type> oldTypeParams = tree.typarams.stream()
@@ -817,7 +829,7 @@
         MethodSymbol desugaredMethod = msym.clone(genMethodClassSym);
         desugaredMethod.flags_field &= ~Flags.AccessFlags;
         desugaredMethod.flags_field &= ~Flags.STATIC;
-        desugaredMethod.flags_field |= Flags.PUBLIC;
+        desugaredMethod.flags_field |= Flags.PUBLIC; //for now
         desugaredMethod.type = types.subst(msym.type.asMethodType(), oldTypeParams, newTypeParams);
         genMethodClassSym.members_field = WriteableScope.create(genMethodClassSym);
         genMethodClassSym.members().enter(desugaredMethod);
@@ -937,6 +949,20 @@
                     sel.sym = tree.sym;
                     sel.type = tree.type;
                     result = sel;
+                } else if (!tree.sym.isStatic() &&
+                        (tree.sym.kind == MTH ||
+                        tree.sym.kind == VAR) &&
+                        !tree.sym.isConstructor() &&
+                        currentClass.isSubClass(tree.sym.owner, types)) {
+                    JCIdent typ = make.Ident(currentClass.name);
+                    typ.sym = currentClass;
+                    typ.type = currentClass.type;
+                    JCFieldAccess qualThiz = (JCFieldAccess)make.Select(typ, makeThis(currentClass.type, currentClass).sym);
+                    qualThiz.type = currentClass.type;
+                    JCFieldAccess sel = make.Select(qualThiz, tree.name);
+                    sel.sym = tree.sym;
+                    sel.type = tree.type;
+                    result = sel;
                 } else {
                     tree.sym = patchParam(tree.sym);
                     result = tree;
@@ -944,6 +970,15 @@
             }
 
             @Override
+            public void visitVarDef(JCVariableDecl tree) {
+                super.visitVarDef(tree);
+                JCVariableDecl newTree = (JCVariableDecl)result;
+                if (newTree.sym.owner == oldMeth) {
+                    newTree.sym.owner = newMeth;
+                }
+            }
+
+            @Override
             public void visitClassDef(JCClassDecl tree) {
                 super.visitClassDef(tree);
                 JCClassDecl newTree = (JCClassDecl)result;
@@ -961,7 +996,12 @@
             }
 
             Type patchTypeVars(Type t) {
-                return types.subst(t, oldTypeVars, newTypeVars);
+                Type t2 = types.subst(t, oldTypeVars, newTypeVars);
+                if (t instanceof InferredMethodType) {
+                    InferredMethodType imt = (InferredMethodType)t;
+                    t2 = new InferredMethodType(t2.asMethodType(), imt.inferenceContext);
+                }
+                return t2;
             }
 
             Symbol patchParam(Symbol s) {