changeset 55897:a76c5aa9b09a condy-lambda

adapting condy-lambda to new pool api
author vromero
date Wed, 24 Apr 2019 18:04:45 -0400
parents 99d1a7cb0dcd
children c59758565565
files make/CompileJavaModules.gmk make/common/SetupJavaCompilers.gmk make/langtools/build.xml make/test/JtregGraalUnit.gmk src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symbol.java src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java src/jdk.compiler/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassWriter.java src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Code.java src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Items.java src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/PoolWriter.java
diffstat 11 files changed, 61 insertions(+), 39 deletions(-) [+]
line wrap: on
line diff
--- a/make/CompileJavaModules.gmk	Thu Apr 18 11:24:06 2019 -0400
+++ b/make/CompileJavaModules.gmk	Wed Apr 24 18:04:45 2019 -0400
@@ -297,7 +297,8 @@
 
 jdk.compiler_ADD_JAVAC_FLAGS += -Xdoclint:all/protected \
     '-Xdoclint/package:-com.sun.tools.*,-jdk.internal.*,sun.tools.serialver.resources.*' \
-    -XDstringConcat=inline
+    -XDstringConcat=inline \
+    -XDforNonCapturingLambda=generateIndy
 jdk.compiler_CLEAN_FILES += $(wildcard \
     $(patsubst %, $(TOPDIR)/src/jdk.compiler/share/classes/%/*.properties, \
         sun/tools/serialver/resources))
@@ -337,7 +338,7 @@
 
 ################################################################################
 
-jdk.jartool_ADD_JAVAC_FLAGS += -XDstringConcat=inline
+jdk.jartool_ADD_JAVAC_FLAGS += -XDstringConcat=inline -XDforNonCapturingLambda=generateIndy
 
 ################################################################################
 
@@ -424,11 +425,11 @@
 # The exports are needed since JVMCI is dynamically exported (see
 # jdk.vm.ci.services.internal.ReflectionAccessJDK::openJVMCITo).
 
-jdk.internal.vm.ci_ADD_JAVAC_FLAGS += -parameters -Xlint:-exports -XDstringConcat=inline
+jdk.internal.vm.ci_ADD_JAVAC_FLAGS += -parameters -Xlint:-exports -XDstringConcat=inline -XDforNonCapturingLambda=generateIndy
 
 ################################################################################
 
-jdk.internal.vm.compiler_ADD_JAVAC_FLAGS += -parameters -XDstringConcat=inline \
+jdk.internal.vm.compiler_ADD_JAVAC_FLAGS += -parameters -XDstringConcat=inline -XDforNonCapturingLambda=generateIndy \
     --add-exports jdk.internal.vm.ci/jdk.vm.ci.aarch64=jdk.internal.vm.compiler \
     --add-exports jdk.internal.vm.ci/jdk.vm.ci.amd64=jdk.internal.vm.compiler \
     --add-exports jdk.internal.vm.ci/jdk.vm.ci.code=jdk.internal.vm.compiler \
@@ -495,7 +496,7 @@
 # The exports are needed since JVMCI is dynamically exported (see
 # jdk.vm.ci.services.internal.ReflectionAccessJDK::openJVMCITo).
 
-jdk.aot_ADD_JAVAC_FLAGS += -parameters -XDstringConcat=inline \
+jdk.aot_ADD_JAVAC_FLAGS += -parameters -XDstringConcat=inline -XDforNonCapturingLambda=generateIndy \
     --add-exports jdk.internal.vm.ci/jdk.vm.ci.aarch64=jdk.internal.vm.compiler,jdk.aot \
     --add-exports jdk.internal.vm.ci/jdk.vm.ci.amd64=jdk.internal.vm.compiler,jdk.aot \
     --add-exports jdk.internal.vm.ci/jdk.vm.ci.code=jdk.internal.vm.compiler,jdk.aot \
@@ -534,7 +535,7 @@
   jdk.jfr_SETUP := GENERATE_JDKBYTECODE_NOWARNINGS
 endif
 jdk.jfr_COPY := .xsd .xml .dtd
-jdk.jfr_ADD_JAVAC_FLAGS := -XDstringConcat=inline -Xlint:-exports
+jdk.jfr_ADD_JAVAC_FLAGS := -XDstringConcat=inline -XDforNonCapturingLambda=generateIndy -Xlint:-exports
 
 ################################################################################
 # If this is an imported module that has prebuilt classes, only compile
--- a/make/common/SetupJavaCompilers.gmk	Thu Apr 18 11:24:06 2019 -0400
+++ b/make/common/SetupJavaCompilers.gmk	Wed Apr 24 18:04:45 2019 -0400
@@ -65,7 +65,7 @@
 $(eval $(call SetupJavaCompiler,GENERATE_OLDBYTECODE, \
     JVM := $(JAVA_SMALL), \
     JAVAC := $(NEW_JAVAC), \
-    FLAGS := $(BOOT_JDK_SOURCETARGET) -XDignore.symbol.file=true -XDstringConcat=inline \
+    FLAGS := $(BOOT_JDK_SOURCETARGET) -XDignore.symbol.file=true -XDstringConcat=inline -XDforNonCapturingLambda=generateIndy \
         $(DISABLE_WARNINGS) -Xlint:-options, \
     SERVER_DIR := $(SJAVAC_SERVER_DIR), \
     SERVER_JVM := $(SJAVAC_SERVER_JAVA)))
--- a/make/langtools/build.xml	Thu Apr 18 11:24:06 2019 -0400
+++ b/make/langtools/build.xml	Wed Apr 24 18:04:45 2019 -0400
@@ -309,7 +309,7 @@
                classpath="${ant.core.lib}"
                bootclasspath="${langtools.jdk.home}/jre/lib/rt.jar"
                includeantruntime="false">
-            <compilerarg line="${javac.build.opts} -XDstringConcat=inline"/>
+            <compilerarg line="${javac.build.opts} -XDstringConcat=inline -XDforNonCapturingLambda=generateIndy"/>
         </javac>
         <taskdef name="pparse"
                  classname="anttasks.PropertiesParserTask"
@@ -325,7 +325,7 @@
                destdir="${build.dir}/toolclasses/"
                classpath="${ant.core.lib}"
                includeantruntime="false">
-            <compilerarg line="${javac.build.opts} -XDstringConcat=inline"/>
+            <compilerarg line="${javac.build.opts} -XDstringConcat=inline -XDforNonCapturingLambda=generateIndy"/>
         </javac>
         <taskdef name="pcompile"
                  classname="anttasks.CompilePropertiesTask"
--- a/make/test/JtregGraalUnit.gmk	Thu Apr 18 11:24:06 2019 -0400
+++ b/make/test/JtregGraalUnit.gmk	Wed Apr 24 18:04:45 2019 -0400
@@ -131,6 +131,7 @@
           ADD_JAVAC_FLAGS := \
               $(TEST_JAVAC_FLAGS) \
               -XDstringConcat=inline \
+              -XDforNonCapturingLambda=generateIndy \
               , \
       ))
 
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symbol.java	Thu Apr 18 11:24:06 2019 -0400
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symbol.java	Wed Apr 24 18:04:45 2019 -0400
@@ -2168,15 +2168,13 @@
 
     /** A class for condy.
      */
-    public static class DynamicVarSymbol extends VarSymbol {
-        public Object[] staticArgs;
-        public MethodSymbol bsm;
-        public int bsmKind;
+    public static class DynamicVarSymbol extends VarSymbol implements Dynamic, LoadableConstant {
+        public LoadableConstant[] staticArgs;
+        public MethodHandleSymbol bsm;
 
-        public DynamicVarSymbol(Name name, Symbol owner, int bsmKind, MethodSymbol bsm, Type type, Object[] staticArgs) {
+        public DynamicVarSymbol(Name name, Symbol owner, MethodHandleSymbol bsm, Type type, LoadableConstant[] staticArgs) {
             super(0, name, type, owner);
             this.bsm = bsm;
-            this.bsmKind = bsmKind;
             this.staticArgs = staticArgs;
         }
 
@@ -2184,6 +2182,26 @@
         public boolean isDynamic() {
             return true;
         }
+
+        @Override
+        public PoolConstant dynamicType() {
+            return type;
+        }
+
+        @Override
+        public LoadableConstant[] staticArgs() {
+            return staticArgs;
+        }
+
+        @Override
+        public LoadableConstant bootstrapMethod() {
+            return bsm;
+        }
+
+        @Override
+        public int poolTag() {
+            return ClassFile.CONSTANT_Dynamic;
+        }
     }
 
     /** A class for predefined operators.
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java	Thu Apr 18 11:24:06 2019 -0400
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java	Wed Apr 24 18:04:45 2019 -0400
@@ -5202,6 +5202,8 @@
                 return syms.methodHandleType;
             case ClassFile.CONSTANT_MethodType:
                 return syms.methodTypeType;
+            case ClassFile.CONSTANT_Dynamic:
+                return ((DynamicVarSymbol)c).type;
             default:
                 throw new AssertionError("Not a loadable constant: " + c.poolTag());
         }
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java	Thu Apr 18 11:24:06 2019 -0400
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java	Wed Apr 24 18:04:45 2019 -0400
@@ -176,9 +176,7 @@
         Source source = Source.instance(context);
         // format: -XDforNonCapturingLambda=generateCondy, which is the default, or -XDforNonCapturingLambda=generateIndy
         String condyOp = options.get("forNonCapturingLambda");
-        condyForLambda = (condyOp != null ?
-                condyOp.equals("generateCondy") :
-                Feature.CONDY_FOR_LAMBDA.allowedInSource(source));
+        condyForLambda = condyOp != null && condyOp.equals("generateCondy");
     }
     // </editor-fold>
 
@@ -1223,9 +1221,9 @@
             make.at(prevPos);
         }
     }
-    
+
     private JCExpression makeDynamicCall(DiagnosticPosition pos, Type site, Name bsmName,
-                                         List<Object> staticArgs, Type interfaceType, MethodType indyType, List<JCExpression> indyArgs,
+                                         List<LoadableConstant> staticArgs, Type interfaceType, MethodType indyType, List<JCExpression> indyArgs,
                                          Name methName) {
         return condyForLambda &&
                 !context.needsAltMetafactory() &&
@@ -1240,29 +1238,24 @@
     private final boolean condyForLambda;
 
     private JCExpression makeCondy(DiagnosticPosition pos, Type site, Name bsmName,
-                                   List<Object> staticArgs, Type interfaceType, Name methName) {
+                                   List<LoadableConstant> staticArgs, Type interfaceType, Name methName) {
         int prevPos = make.pos;
         try {
             make.at(pos);
             List<Type> bsm_staticArgs = List.of(syms.methodHandleLookupType,
                     syms.stringType,
-                    syms.classType).appendList(bsmStaticArgToTypes(staticArgs));
+                    syms.methodTypeType).appendList(staticArgs.map(types::constantType));
 
             Symbol bsm = rs.resolveInternalMethod(pos, attrEnv, site,
                     bsmName, bsm_staticArgs, List.nil());
 
             Symbol.DynamicVarSymbol dynSym = new Symbol.DynamicVarSymbol(methName,
                     syms.noSymbol,
-                    bsm.isStatic() ?
-                            ClassFile.REF_invokeStatic :
-                            ClassFile.REF_invokeVirtual,
-                    (MethodSymbol)bsm,
+                    ((MethodSymbol)bsm).asHandle(),
                     interfaceType,
-                    staticArgs.toArray());
-
+                    staticArgs.toArray(new LoadableConstant[staticArgs.length()]));
             JCIdent ident = make.Ident(dynSym);
             ident.type = interfaceType;
-
             return ident;
         } finally {
             make.at(prevPos);
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassWriter.java	Thu Apr 18 11:24:06 2019 -0400
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassWriter.java	Wed Apr 24 18:04:45 2019 -0400
@@ -797,9 +797,9 @@
         }
         databuf.appendChar(mergedProvides.size());
         mergedProvides.forEach((srvc, impls) -> {
-            databuf.appendChar(pool.put(srvc));
+            databuf.appendChar(poolWriter.putClass(srvc));
             databuf.appendChar(impls.size());
-            impls.forEach(impl -> databuf.appendChar(pool.put(impl)));
+            impls.forEach(impl -> databuf.appendChar(poolWriter.putClass(impl)));
         });
 
         endAttr(alenIdx);
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Code.java	Thu Apr 18 11:24:06 2019 -0400
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Code.java	Wed Apr 24 18:04:45 2019 -0400
@@ -1773,7 +1773,7 @@
                 int width = width(t);
                 Type old = stack[stacksize-width];
                 Assert.check(types.isSubtype(types.erasure(old),
-                                       types.erasure(t)));
+                                       types.erasure(t)), String.format("%s is not subtype of %s", old, t));
                 stack[stacksize-width] = t;
                 break;
             default:
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Items.java	Thu Apr 18 11:24:06 2019 -0400
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Items.java	Wed Apr 24 18:04:45 2019 -0400
@@ -168,7 +168,7 @@
     /** Make an item representing a condy.
      *  @param value    The condy value.
      */
-    Item makeCondyItem(DynamicVariable value) {
+    Item makeCondyItem(DynamicVarSymbol value) {
         return new CondyItem(value);
     }
 
@@ -484,7 +484,7 @@
             Assert.check(member.kind == Kinds.Kind.VAR);
             Type type = member.erasure(types);
             int rescode = Code.typecode(type);
-            code.emitLdc(pool.put(member));
+            code.emitLdc((DynamicVarSymbol)member);
             return stackItem[rescode];
         }
 
@@ -508,9 +508,9 @@
     /** An item representing a condy
      */
     class CondyItem extends Item {
-        DynamicVariable value;
+        DynamicVarSymbol value;
 
-        CondyItem(DynamicVariable value) {
+        CondyItem(DynamicVarSymbol value) {
             super(Code.typecode(value.type));
             this.value = value;
         }
@@ -522,11 +522,11 @@
 
         @Override
         Item load() {
-            int idx = pool.put(value);
+            int idx = poolWriter.putConstant(value);
             if (typecode == LONGcode || typecode == DOUBLEcode) {
                 code.emitop2(ldc2w, idx);
             } else {
-                code.emitLdc(idx);
+                code.emitLdc(LoadableConstant.Int(idx));
             }
             return stackItem[typecode];
         }
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/PoolWriter.java	Thu Apr 18 11:24:06 2019 -0400
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/PoolWriter.java	Wed Apr 24 18:04:45 2019 -0400
@@ -128,7 +128,7 @@
     /**
      * Puts a dynamic reference into the constant pool and return its index.
      */
-    int putDynamic(DynamicMethodSymbol d) {
+    int putDynamic(Dynamic d) {
         return pool.writeIfNeeded(d);
     }
 
@@ -459,6 +459,13 @@
                     poolbuf.appendChar(putNameAndType(d));
                     break;
                 }
+                case ClassFile.CONSTANT_Dynamic: {
+                    Symbol.DynamicVarSymbol d = (Symbol.DynamicVarSymbol)c;
+                    poolbuf.appendByte(tag);
+                    poolbuf.appendChar(makeBoostrapEntry(d));
+                    poolbuf.appendChar(putNameAndType(d));
+                    break;
+                }
                 default:
                     throw new AssertionError("Unexpected constant tag: " + tag);
             }