changeset 3521:ef0142d1ab9a

Fix: do not generate 'typed' opcodes if -XDenableMinimalValueTypes is set Fix translation of value capable class by omitting any extraneous opcode (such as 'typed') as well as by setting minor/major version accordingly.
author mcimadamore
date Mon, 07 Nov 2016 18:38:36 +0000
parents 54649cba25f1
children a82751a8e69b
files src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassWriter.java src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Gen.java src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Items.java test/tools/javac/valhalla/minimalvalues/TypedBytecodeTest.java
diffstat 4 files changed, 56 insertions(+), 78 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassWriter.java	Thu Oct 06 11:34:59 2016 +0530
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassWriter.java	Mon Nov 07 18:38:36 2016 +0000
@@ -1766,7 +1766,13 @@
 
         poolwriter.writePool(poolbuf);
 
-        poolbuf.elems[5] = poolwriter.minorVersion();
+        if ((c.flags() & VALUE_CAPABLE) != 0) {
+            //fixup classfile version for value capable classes
+            poolbuf.elems[5] = 1;
+            poolbuf.elems[7] = 53;
+        } else {
+            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/Gen.java	Thu Oct 06 11:34:59 2016 +0530
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Gen.java	Mon Nov 07 18:38:36 2016 +0000
@@ -1907,9 +1907,6 @@
             r.load();
             emitAndMarkIfNeeded1(returnType, types::isSpecializableTypeVar,
                     () -> {
-                        if (types.isValueCapable(returnType)) {
-                            code.emitop2(typed, pool.putValueCapableClass(returnType));
-                        }
                         code.emitop0(types.isValue(returnType) ? vreturn :
                                 (ireturn + Code.truncate(Code.typecode(erasedReturnType))));
                     });
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Items.java	Thu Oct 06 11:34:59 2016 +0530
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Items.java	Mon Nov 07 18:38:36 2016 +0000
@@ -741,9 +741,6 @@
             if (types.isValue(type)) {
                 code.emitop1w(vload, 0);
             } else {
-                if (types.isValueCapable(type)) {
-                    code.emitop2(typed, pool.putValueCapableClass(type));
-                }
                 code.emitop0(aload_0);
             }
             return stackItem[typecode];
@@ -783,9 +780,6 @@
             if (types.isValue(type)) {
                 code.emitop1w(vload, reg);
             } else {
-                if (types.isValueCapable(type)) {
-                    code.emitop2(typed, pool.putValueCapableClass(type));
-                }
                 if (reg <= 3)
                     code.emitop0(iload_0 + Code.truncate(targetcode) * 4 + reg);
                 else
@@ -799,9 +793,6 @@
             if (types.isValue(type)) {
                 code.emitop1w(vstore, reg);
             } else {
-                if (types.isValueCapable(type)) {
-                    code.emitop2(typed, pool.putValueCapableClass(type));
-                }
                 if (reg <= 3)
                     code.emitop0(istore_0 + Code.truncate(targetcode) * 4 + reg);
                 else
--- a/test/tools/javac/valhalla/minimalvalues/TypedBytecodeTest.java	Thu Oct 06 11:34:59 2016 +0530
+++ b/test/tools/javac/valhalla/minimalvalues/TypedBytecodeTest.java	Mon Nov 07 18:38:36 2016 +0000
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @summary Check that javac emits typed + {aload|astore|areturn} and not vload|vstore|vreturn
+ * @summary Check that javac does not emits typed + {aload|astore|areturn} if minimal value option is enabled
  * @compile -XDenableMinimalValueTypes TypedBytecodeTest.java
  * @run main TypedBytecodeTest
  * @modules jdk.compiler
@@ -63,72 +63,56 @@
                                             Paths.get(System.getProperty("test.classes"),
                                                 "TypedBytecodeTest$Point.class").toString() };
         runCheck(params, new String [] {
+           "minor version: 1",
+           "major version: 53",
 
-           "#12 = Utf8               QTypedBytecodeTest$Point",
-           "#13 = Class              #12            // QTypedBytecodeTest$Point",
+           "4: aload_0",
+           "5: iload_1",
+           "6: putfield      #15                 // Field x:I",
+           "9: aload_0",
+          "10: iload_2",
+          "11: putfield      #18                 // Field y:I",
+          "14: return",
 
-           "4: typed         #13                 // class QTypedBytecodeTest$Point",
-           "7: aload_0",
-           "8: iload_1",
-           "9: putfield      #17                 // Field x:I",
-          "12: typed         #13                 // class QTypedBytecodeTest$Point",
-          "15: aload_0",
-          "16: iload_2",
-          "17: putfield      #20                 // Field y:I",
-          "20: return",
-
-           "0: typed         #13                 // class QTypedBytecodeTest$Point",
-           "3: aload_0",
-           "4: getfield      #17                 // Field x:I",
-           "7: typed         #13                 // class QTypedBytecodeTest$Point",
-           "10: aload_0",
-           "11: getfield      #17                 // Field x:I",
-           "14: imul",
-           "15: typed         #13                 // class QTypedBytecodeTest$Point",
-           "18: aload_0",
-           "19: getfield      #20                 // Field y:I",
-           "22: typed         #13                 // class QTypedBytecodeTest$Point",
-           "25: aload_0",
-           "26: getfield      #20                 // Field y:I",
-           "29: imul",
-           "30: iadd",
-           "31: i2d",
-           "32: invokestatic  #26                 // Method java/lang/Math.sqrt:(D)D",
-           "35: dstore_2",
-           "36: typed         #13                 // class QTypedBytecodeTest$Point",
-           "39: aload_1",
-           "40: getfield      #17                 // Field x:I",
-           "43: typed         #13                 // class QTypedBytecodeTest$Point",
-           "46: aload_1",
-           "47: getfield      #17                 // Field x:I",
-           "50: imul",
-           "51: typed         #13                 // class QTypedBytecodeTest$Point",
-           "54: aload_1",
-           "55: getfield      #20                 // Field y:I",
-           "58: typed         #13                 // class QTypedBytecodeTest$Point",
-           "61: aload_1",
-           "62: getfield      #20                 // Field y:I",
-           "65: imul",
-           "66: iadd",
-           "67: i2d",
-           "68: invokestatic  #26                 // Method java/lang/Math.sqrt:(D)D",
-           "71: dstore        4",
-           "73: dload_2",
-           "74: dload         4",
-           "76: dcmpl",
-           "77: ifle          87",
-           "80: typed         #13                 // class QTypedBytecodeTest$Point",
-           "83: aload_1",
-           "84: goto          91",
-           "87: typed         #13                 // class QTypedBytecodeTest$Point",
-           "90: aload_0",
-           "91: typed         #13                 // class QTypedBytecodeTest$Point",
-           "94: astore        6",
-           "96: typed         #13                 // class QTypedBytecodeTest$Point",
-           "99: aload         6",
-          "101: typed         #13                 // class QTypedBytecodeTest$Point",
-          "104: areturn"
-                         });
+           "0: aload_0",
+           "1: getfield      #15                 // Field x:I",
+           "4: aload_0",
+           "5: getfield      #15                 // Field x:I",
+           "8: imul",
+           "9: aload_0",
+           "10: getfield      #18                 // Field y:I",
+           "13: aload_0",
+           "14: getfield      #18                 // Field y:I",
+           "17: imul",
+           "18: iadd",
+           "19: i2d",
+           "20: invokestatic  #24                 // Method java/lang/Math.sqrt:(D)D",
+           "23: dstore_2",
+           "24: aload_1",
+           "25: getfield      #15                 // Field x:I",
+           "28: aload_1",
+           "29: getfield      #15                 // Field x:I",
+           "32: imul",
+           "33: aload_1",
+           "34: getfield      #18                 // Field y:I",
+           "37: aload_1",
+           "38: getfield      #18                 // Field y:I",
+           "41: imul",
+           "42: iadd",
+           "43: i2d",
+           "44: invokestatic  #24                 // Method java/lang/Math.sqrt:(D)D",
+           "47: dstore        4",
+           "49: dload_2",
+           "50: dload         4",
+           "52: dcmpl",
+           "53: ifle          60",
+           "56: aload_1",
+           "57: goto          61",
+           "60: aload_0",
+           "61: astore        6",
+           "63: aload         6",
+           "65: areturn"
+         });
 
      }