changeset 12:c52c3f68bfba 7.0

Update to support constant dynamic constant pool entry.
author psandoz
date Tue, 10 Oct 2017 16:53:12 -0700
parents f2cacbad3e0c
children 23bab4083830
files src/org/openjdk/asmtools/jasm/ClassData.java src/org/openjdk/asmtools/jasm/ConstantPool.java src/org/openjdk/asmtools/jasm/ParserCP.java src/org/openjdk/asmtools/jasm/Tables.java src/org/openjdk/asmtools/jcoder/JcodTokens.java src/org/openjdk/asmtools/jdec/ClassData.java src/org/openjdk/asmtools/jdis/ConstantPool.java
diffstat 7 files changed, 127 insertions(+), 39 deletions(-) [+]
line wrap: on
line diff
--- a/src/org/openjdk/asmtools/jasm/ClassData.java	Mon Oct 09 16:50:26 2017 -0700
+++ b/src/org/openjdk/asmtools/jasm/ClassData.java	Tue Oct 10 16:53:12 2017 -0700
@@ -146,8 +146,8 @@
 
     /*
      * After a constant pool has been explicitly declared,
-     * this method links the Constant_InvokeDynamic constants
-     * with any bootstrap methods that they index in the
+     * this method links the Constant_InvokeDynamic Constant_ConstantDynamic
+     * constants with any bootstrap methods that they index in the
      * Bootstrap Methods Attribute
      */
     protected void relinkBootstrapMethods() {
@@ -163,27 +163,25 @@
                 ref = cell.ref;
             }
             if (ref != null
-                    && ref.tag == ConstType.CONSTANT_INVOKEDYNAMIC) {
+                    && (ref.tag == ConstType.CONSTANT_INVOKEDYNAMIC || ref.tag == ConstType.CONSTANT_CONSTANTDYNAMIC)) {
                 // Find only the Constant
-                ConstantPool.ConstValue_IndyPair refval = (ConstantPool.ConstValue_IndyPair) ref;
-                if (refval != null) {
-                    BootstrapMethodData bsmdata = refval.bsmData;
-                    // only care about BSM Data that were placeholders
-                    if (bsmdata != null && bsmdata.isPlaceholder()) {
-                        // find the real BSM Data at the index
-                        int bsmindex = bsmdata.placeholder_index;
-                        if (bsmindex < 0 || bsmindex > bootstrapMethodsAttr.size()) {
-                            // bad BSM index --
-                            // give a warning, but place the index in the arg anyway
-                            env.traceln("Warning: (ClassData.relinkBootstrapMethods()): Bad bootstrapMethods index: " + bsmindex);
-                            // env.error("const.bsmindex", bsmindex);
-                            bsmdata.arg = bsmindex;
-                        } else {
+                ConstantPool.ConstValue_IndyOrCondyPair refval = (ConstantPool.ConstValue_IndyOrCondyPair) ref;
+                BootstrapMethodData bsmdata = refval.bsmData;
+                // only care about BSM Data that were placeholders
+                if (bsmdata != null && bsmdata.isPlaceholder()) {
+                    // find the real BSM Data at the index
+                    int bsmindex = bsmdata.placeholder_index;
+                    if (bsmindex < 0 || bsmindex > bootstrapMethodsAttr.size()) {
+                        // bad BSM index --
+                        // give a warning, but place the index in the arg anyway
+                        env.traceln("Warning: (ClassData.relinkBootstrapMethods()): Bad bootstrapMethods index: " + bsmindex);
+                        // env.error("const.bsmindex", bsmindex);
+                        bsmdata.arg = bsmindex;
+                    } else {
 
-                            BootstrapMethodData realbsmdata = bootstrapMethodsAttr.get(bsmindex);
-                            // make the IndyPairs BSM Data point to the one from the attribute
-                            refval.bsmData = realbsmdata;
-                        }
+                        BootstrapMethodData realbsmdata = bootstrapMethodsAttr.get(bsmindex);
+                        // make the IndyPairs BSM Data point to the one from the attribute
+                        refval.bsmData = realbsmdata;
                     }
                 }
             }
--- a/src/org/openjdk/asmtools/jasm/ConstantPool.java	Mon Oct 09 16:50:26 2017 -0700
+++ b/src/org/openjdk/asmtools/jasm/ConstantPool.java	Tue Oct 10 16:53:12 2017 -0700
@@ -370,18 +370,15 @@
         }
     }
 
-    /**
-     * ConstValue
-     *
-     * A (typed) tagged value in the constant pool.
-     */
-    static public class ConstValue_IndyPair extends ConstValue {
-
+    static public class ConstValue_IndyOrCondyPair extends ConstValue {
         BootstrapMethodData bsmData;
         ConstantPool.ConstCell napeCell;
 
-        public ConstValue_IndyPair(BootstrapMethodData bsmdata, ConstCell napeCell) {
-            super(ConstType.CONSTANT_INVOKEDYNAMIC);
+        protected ConstValue_IndyOrCondyPair(ConstType tag, BootstrapMethodData bsmdata, ConstCell napeCell) {
+            super(tag);
+            assert (tag == ConstType.CONSTANT_CONSTANTDYNAMIC && ConstValue_CondyPair.class.isAssignableFrom(getClass())) ||
+                   tag == ConstType.CONSTANT_INVOKEDYNAMIC && ConstValue_IndyPair.class.isAssignableFrom(getClass());
+
             this.bsmData = bsmdata;
             this.napeCell = napeCell;
             isSet = (bsmdata != null && napeCell != null);
@@ -389,11 +386,11 @@
 
         @Override
         public boolean equals(Object obj) {
-            if ((obj == null) || !(obj instanceof ConstValue_IndyPair)) {
+            if ((obj == null) || !(getClass().isInstance(obj))) {
                 return false;
             }
 
-            ConstValue_IndyPair iobj = (ConstValue_IndyPair) obj;
+            ConstValue_IndyOrCondyPair iobj = (ConstValue_IndyOrCondyPair) obj;
             return (iobj.bsmData == bsmData) && (iobj.napeCell == napeCell);
         }
 
@@ -417,6 +414,29 @@
             out.writeShort(napeCell.arg);
         }
     }
+    /**
+     * ConstValue
+     *
+     * A (typed) tagged value in the constant pool.
+     */
+    static public class ConstValue_CondyPair extends ConstValue_IndyOrCondyPair {
+
+        public ConstValue_CondyPair(BootstrapMethodData bsmdata, ConstCell napeCell) {
+            super(ConstType.CONSTANT_CONSTANTDYNAMIC, bsmdata, napeCell);
+        }
+    }
+
+    /**
+     * ConstValue
+     *
+     * A (typed) tagged value in the constant pool.
+     */
+    static public class ConstValue_IndyPair extends ConstValue_IndyOrCondyPair {
+
+        public ConstValue_IndyPair(BootstrapMethodData bsmdata, ConstCell napeCell) {
+            super(ConstType.CONSTANT_INVOKEDYNAMIC, bsmdata, napeCell);
+        }
+    }
 
     /*-------------------------------------------------------- */
     /* ConstantPool Inner Classes */
@@ -539,12 +559,12 @@
                 case CONSTANT_METHODHANDLE:
                     retVal = visitMethodhandle(tag);
                     break;
+                case CONSTANT_CONSTANTDYNAMIC:
+                    retVal = visitConstantdynamic(tag);
+                    break;
                 case CONSTANT_INVOKEDYNAMIC:
                     retVal = visitInvokedynamic(tag);
                     break;
-//                case CONSTANT_INVOKEDYNAMIC_TRANS:
-//                    retVal = visitInvokedynamicTrans(tag);
-//                    break;
                 default:
                     visitDefault(tag);
             }
@@ -616,6 +636,10 @@
         }
 
         ;
+        public R visitConstantdynamic(ConstType tag) {
+            return null;
+        }
+
         public R visitInvokedynamic(ConstType tag) {
             return null;
         }
@@ -689,6 +713,9 @@
                 case CONSTANT_METHODHANDLE:
                     retVal = visitMethodhandle((ConstValue_Pair) val);
                     break;
+                case CONSTANT_CONSTANTDYNAMIC:
+                    retVal = visitConstantdynamic((ConstValue_CondyPair) val);
+                    break;
                 case CONSTANT_INVOKEDYNAMIC:
                     retVal = visitInvokedynamic((ConstValue_IndyPair) val);
                     break;
@@ -769,6 +796,9 @@
         }
 
         ;
+        public R visitConstantdynamic(ConstValue_CondyPair p) { return null;}
+
+        ;
         public R visitInvokedynamic(ConstValue_IndyPair p) { return null;}
 
         ;
@@ -980,6 +1010,12 @@
 
         ;
         @Override
+        public Void visitConstantdynamic(ConstValue_CondyPair p) {
+            return null;
+        }
+
+        ;
+        @Override
         public Void visitInvokedynamic(ConstValue_IndyPair p) {
             return null;
         }
--- a/src/org/openjdk/asmtools/jasm/ParserCP.java	Mon Oct 09 16:50:26 2017 -0700
+++ b/src/org/openjdk/asmtools/jasm/ParserCP.java	Tue Oct 10 16:53:12 2017 -0700
@@ -469,6 +469,50 @@
             return obj;
         }
 
+        @Override
+        public ConstantPool.ConstValue_CondyPair visitConstantdynamic(ConstType tag) {
+            debugStr("------- [ParserCPVisitor.visitConstantDynamic]: ");
+            ConstantPool.ConstValue_CondyPair obj = null;
+            try {
+                if (scanner.token == Token.INTVAL) {
+                    // Handle explicit constant pool form
+                    int bsmIndex = scanner.intValue;
+                    scanner.scan();
+                    scanner.expect(Token.COLON);
+                    if (scanner.token != Token.CPINDEX) {
+                        env.traceln("token=" + scanner.token);
+                        env.error(scanner.pos, "token.expected", "<CPINDEX>");
+                        throw new Scanner.SyntaxError();
+                    }
+                    int cpx = scanner.intValue;
+                    scanner.scan();
+                    // Put a placeholder in place of BSM.
+                    // resolve placeholder after the attributes are scanned.
+                    BootstrapMethodData bsmData = new BootstrapMethodData(bsmIndex);
+                    obj = new ConstantPool.ConstValue_CondyPair(bsmData, parser.pool.getCell(cpx));
+
+                } else {
+                    // Handle full form
+                    ConstantPool.ConstCell MHCell = parser.pool.FindCell(parseConstValue(ConstType.CONSTANT_METHODHANDLE));
+                    scanner.expect(Token.COLON);
+                    ConstantPool.ConstCell NapeCell = parser.pool.FindCell(parseConstValue(ConstType.CONSTANT_NAMEANDTYPE));
+
+                    ArrayList<ConstantPool.ConstCell> bsm_args = new ArrayList<>(256);
+                    while (scanner.token != Token.SEMICOLON) {
+                        if (scanner.token == Token.COMMA) {
+                            scanner.scan();
+                        }
+                        bsm_args.add(parseConstRef(null));
+                    }
+                    BootstrapMethodData bsmData = new BootstrapMethodData(MHCell, bsm_args);
+                    parser.cd.addBootstrapMethod(bsmData);
+                    obj = new ConstantPool.ConstValue_CondyPair(bsmData, NapeCell);
+                }
+            } catch (IOException e) {
+                IOProb = e;
+            }
+            return obj;
+        }
     } // End Visitor
 
     /**
--- a/src/org/openjdk/asmtools/jasm/Tables.java	Mon Oct 09 16:50:26 2017 -0700
+++ b/src/org/openjdk/asmtools/jasm/Tables.java	Tue Oct 10 16:53:12 2017 -0700
@@ -127,7 +127,7 @@
         // Constant 14 reserved
         CONSTANT_METHODHANDLE               (15, "CONSTANT_METHODHANDLE", "MethodHandle"),
         CONSTANT_METHODTYPE                 (16, "CONSTANT_METHODTYPE", "MethodType"),
-        // Constant 17 reserved
+        CONSTANT_CONSTANTDYNAMIC            (17, "CONSTANT_CONSTANTDYNAMIC", "ConstantDynamic"),
         CONSTANT_INVOKEDYNAMIC              (18, "CONSTANT_INVOKEDYNAMIC", "InvokeDynamic"),
         CONSTANT_MODULE                     (19, "CONSTANT_MODULE",        "Module"),
         CONSTANT_PACKAGE                    (20, "CONSTANT_PACKAGE",       "Package");
--- a/src/org/openjdk/asmtools/jcoder/JcodTokens.java	Mon Oct 09 16:50:26 2017 -0700
+++ b/src/org/openjdk/asmtools/jcoder/JcodTokens.java	Tue Oct 10 16:53:12 2017 -0700
@@ -304,7 +304,7 @@
         // Constant 14 reserved
         CONSTANT_METHODHANDLE               (15, "CONSTANT_METHODHANDLE", "MethodHandle"),
         CONSTANT_METHODTYPE                 (16, "CONSTANT_METHODTYPE", "MethodType"),
-      // Constant 17 reserved
+        CONSTANT_CONSTANTDYNAMIC            (17, "CONSTANT_CONSTANTDYNAMIC", "ConstantDynamic"),
         CONSTANT_INVOKEDYNAMIC              (18, "CONSTANT_INVOKEDYNAMIC", "InvokeDynamic"),
         CONSTANT_MODULE                     (19, "CONSTANT_MODULE",  "Module"),
         CONSTANT_MODULE_PACKAGE             (20, "CONSTANT_PACKAGE", "Package");
--- a/src/org/openjdk/asmtools/jdec/ClassData.java	Mon Oct 09 16:50:26 2017 -0700
+++ b/src/org/openjdk/asmtools/jdec/ClassData.java	Tue Oct 10 16:53:12 2017 -0700
@@ -231,6 +231,7 @@
                 case CONSTANT_NAMEANDTYPE:
                     cpool[i] = "#" + in.readUnsignedShort() + " #" + in.readUnsignedShort();
                     break;
+                case CONSTANT_CONSTANTDYNAMIC:
                 case CONSTANT_INVOKEDYNAMIC:
                     cpool[i] = in.readUnsignedShort() + "s #" + in.readUnsignedShort();
                     break;
@@ -342,6 +343,9 @@
                     case CONSTANT_METHODTYPE:
                         valstr = (String) cpool[i];
                         break;
+                    case CONSTANT_CONSTANTDYNAMIC:
+                        valstr = (String) cpool[i];
+                        break;
                     case CONSTANT_INVOKEDYNAMIC:
                         valstr = (String) cpool[i];
                         break;
--- a/src/org/openjdk/asmtools/jdis/ConstantPool.java	Mon Oct 09 16:50:26 2017 -0700
+++ b/src/org/openjdk/asmtools/jdis/ConstantPool.java	Tue Oct 10 16:53:12 2017 -0700
@@ -65,6 +65,7 @@
         CONSTANT_NAMEANDTYPE        ((byte) 12, "NameAndType", "CONSTANT_NAMEANDTYPE"),
         CONSTANT_METHODHANDLE       ((byte) 15, "MethodHandle", "CONSTANT_METHODHANDLE"),
         CONSTANT_METHODTYPE         ((byte) 16, "MethodType", "CONSTANT_METHODTYPE"),
+        CONSTANT_CONSTANTDYNAMIC    ((byte) 17, "ConstantDynamic", "CONSTANT_CONSTANTDYNAMIC"),
         CONSTANT_INVOKEDYNAMIC      ((byte) 18, "InvokeDynamic", "CONSTANT_INVOKEDYNAMIC"),
         CONSTANT_MODULE             ((byte) 19, "Module", "CONSTANT_MODULE"),
         CONSTANT_PACKAGE            ((byte) 20, "Package", "CONSTANT_PACKAGE");
@@ -164,6 +165,7 @@
         taghash.put(new Byte(TAG.CONSTANT_NAMEANDTYPE.value()), TAG.CONSTANT_NAMEANDTYPE);
         taghash.put(new Byte(TAG.CONSTANT_METHODHANDLE.value()), TAG.CONSTANT_METHODHANDLE);
         taghash.put(new Byte(TAG.CONSTANT_METHODTYPE.value()), TAG.CONSTANT_METHODTYPE);
+        taghash.put(new Byte(TAG.CONSTANT_CONSTANTDYNAMIC.value()), TAG.CONSTANT_CONSTANTDYNAMIC);
         taghash.put(new Byte(TAG.CONSTANT_INVOKEDYNAMIC.value()), TAG.CONSTANT_INVOKEDYNAMIC);
         taghash.put(new Byte(TAG.CONSTANT_MODULE.value()), TAG.CONSTANT_MODULE);
         taghash.put(new Byte(TAG.CONSTANT_PACKAGE.value()), TAG.CONSTANT_PACKAGE);
@@ -486,7 +488,7 @@
      *
      * Constant entries that contain two constant-pool indices. Usually, this includes:
      * CONSTANT_FIELD CONSTANT_METHOD CONSTANT_INTERFACEMETHOD CONSTANT_NAMEANDTYPE
-     * CONSTANT_METHODHANDLE CONSTANT_INVOKEDYNAMIC
+     * CONSTANT_METHODHANDLE CONSTANT_CONSTANTDYNAMIC CONSTANT_INVOKEDYNAMIC
      *
      */
     class CPX2 extends Constant {
@@ -515,6 +517,7 @@
                 case CONSTANT_METHODHANDLE:
                     str = subtagToString(value1) + ":" + StringValue(value2);
                     break;
+                case CONSTANT_CONSTANTDYNAMIC:
                 case CONSTANT_INVOKEDYNAMIC:
                     int bsm_attr_idx = value1;
                     int nape_idx = value2;
@@ -542,7 +545,7 @@
                     }
 
                     str = StringValue(bsm_ref) + ":" + StringValue(nape_idx)
-                            + bsm_args_str.toString();
+                          + bsm_args_str.toString();
                     break;
                 default:
                     break;
@@ -566,6 +569,7 @@
                 case CONSTANT_NAMEANDTYPE:
                     out.println("#" + value1 + ":#" + value2 + ";\t//  " + stringVal());
                     break;
+                case CONSTANT_CONSTANTDYNAMIC:
                 case CONSTANT_INVOKEDYNAMIC:
                     out.println(value1 + ":#" + value2 + ";\t//  " + stringVal());
                     break;
@@ -650,6 +654,7 @@
                 case CONSTANT_METHOD:
                 case CONSTANT_INTERFACEMETHOD:
                 case CONSTANT_NAMEANDTYPE:
+                case CONSTANT_CONSTANTDYNAMIC:
                 case CONSTANT_INVOKEDYNAMIC:
                     pool.add(i, new CPX2(tagobj, in.readUnsignedShort(), in.readUnsignedShort()));
                     break;
@@ -974,6 +979,7 @@
         }
         switch (cns.tag) {
             case CONSTANT_METHODHANDLE:
+            case CONSTANT_CONSTANTDYNAMIC:
             case CONSTANT_INVOKEDYNAMIC:
             case CONSTANT_METHOD:
             case CONSTANT_INTERFACEMETHOD: