changeset 3515:7c372b827541

Enhancement: fine grained minor version * use different minor version masks for different features: 1 = CP contains type-entries 2 = CP contains ConstantDynamic entries Of course, masks can be or-ed.
author mcimadamore
date Fri, 26 Aug 2016 17:56:53 +0100
parents a1f724d412b0
children 801acf5df528
files src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassWriter.java src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/PoolWriter.java
diffstat 2 files changed, 22 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassWriter.java	Fri Aug 26 14:19:48 2016 +0100
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassWriter.java	Fri Aug 26 17:56:53 2016 +0100
@@ -26,7 +26,6 @@
 package com.sun.tools.javac.jvm;
 
 import java.io.*;
-import java.util.LinkedHashMap;
 import java.util.Map;
 import java.util.Iterator;
 
@@ -1767,10 +1766,7 @@
 
         poolwriter.writePool(poolbuf);
 
-        if (poolwriter.useNewCPForms) {
-            //bump minor version by one
-            poolbuf.elems[5] = 0b1;
-        }
+        poolbuf.elems[5] = poolwriter.minorVersion();
 
         poolbuf.appendBytes(databuf.elems, 0, databuf.length);
         out.write(poolbuf.elems, 0, poolbuf.length);
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/PoolWriter.java	Fri Aug 26 14:19:48 2016 +0100
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/PoolWriter.java	Fri Aug 26 17:56:53 2016 +0100
@@ -27,7 +27,6 @@
 
 import com.sun.tools.javac.code.Dynamic;
 import com.sun.tools.javac.code.Dynamic.DynamicConstant;
-import com.sun.tools.javac.code.Flags;
 import com.sun.tools.javac.code.Kinds.Kind;
 import com.sun.tools.javac.code.Symbol;
 import com.sun.tools.javac.code.Symbol.ClassSymbol;
@@ -81,7 +80,6 @@
 import static com.sun.tools.javac.code.Kinds.Kind.TYP;
 import static com.sun.tools.javac.code.TypeTag.ANY_BOUND;
 import static com.sun.tools.javac.code.TypeTag.CLASS;
-import static com.sun.tools.javac.code.TypeTag.TYPEVAR;
 
 /**
  * Pool interface towards {@code ClassWriter}. Exposes methods to encode and write javac entities
@@ -105,8 +103,11 @@
     /** The list of entries in the BootstrapMethods attribute. */
     Map<BootstrapMethodsKey, Tuple2<MethodHandle, Integer>> bootstrapMethods = new LinkedHashMap<>();
 
-    /** Did this class encoded any of the Valhalla-specific CP-forms? */
-    boolean useNewCPForms = false;
+    /** Did this class encoded any of the Valhalla-specific CP type entries? */
+    boolean useTypeEntries = false;
+
+    /** Did this class encoded any of the Valhalla-specific ConstantDynamic entries? */
+    boolean useConstantDynamic = false;
 
     Type[] typeVarsByOwner;
 
@@ -119,6 +120,17 @@
                 .toArray(Type[]::new);
     }
 
+    byte minorVersion() {
+        byte minorVersion = 0;
+        if (useTypeEntries) {
+            minorVersion |= 1;
+        }
+        if (useConstantDynamic) {
+            minorVersion |= 2;
+        }
+        return minorVersion;
+    }
+
     /**
      * Puts a symbol into the pool and returns the index of the resulting entry.
      * Note: if a matching entry is already in the pool, no new entry is persisted.
@@ -149,6 +161,7 @@
      */
     @SuppressWarnings("unchecked")
     int putConstant(DynamicConstant dc) {
+        useConstantDynamic = true;
         int bsmIndex = makeBoostrapEntry(dc);
         Type constType = dc.getType();
         Constant<Name> type = (Constant<Name>)makeConstant(typeToSig(constType), constType);
@@ -473,7 +486,7 @@
         @SuppressWarnings("unchecked")
         public Entry visitTypeVar(TypeVar tv, Function<Type, Name> typeNameFunc) {
             if (needsGenericEntry(tv)) {
-                useNewCPForms = true;
+                useTypeEntries = true;
                 int adr = typeVarIndex(tv);
                 if (adr == -1) {
                     return super.visit(types.getBounds(tv).head, typeNameFunc);
@@ -501,7 +514,7 @@
         @SuppressWarnings("unchecked")
         public Entry visitClassType(ClassType t, Function<Type, Name> typeNameFunc) {
             if (needsGenericEntry(t)) {
-                useNewCPForms = true;
+                useTypeEntries = true;
                 Type encl = t.getEnclosingType();
                 Entry encl_entry = null;
                 while (!encl.hasTag(TypeTag.NONE)) {
@@ -537,7 +550,7 @@
         @SuppressWarnings("unchecked")
         public Entry visitArrayType(ArrayType t, Function<Type, Name> typeNameFunc) {
             if (needsGenericEntry(t)) {
-                useNewCPForms = true;
+                useTypeEntries = true;
                 int dim = types.dimensions(t);
                 Assert.check(dim <= 16);
                 Type elemRec = elemtypeRecursive(t);
@@ -553,7 +566,7 @@
         @SuppressWarnings("unchecked")
         public Entry visitMethodType(Type.MethodType t, Function<Type, Name> typeNameFunc) {
             if (needsGenericEntry(t)) {
-                useNewCPForms = true;
+                useTypeEntries = true;
                 Entry[] args = t.getParameterTypes().stream()
                         .map(p -> visit(p, PoolWriter.this::typeToSig))
                         .toArray(Entry[]::new);