changeset 3266:358b7a32d810

Enhancement: add support for multivnewarray Contributed-by: michael.haupt@oracle.com, srikanth.adayapalam@oracle.com
author mcimadamore
date Thu, 03 Dec 2015 12:15:04 +0000
parents 5de3c2615ab6
children 2568113d414c
files src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ByteCodes.java src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Code.java src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Gen.java src/jdk.jdeps/share/classes/com/sun/tools/classfile/Opcode.java
diffstat 4 files changed, 35 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ByteCodes.java	Wed Dec 02 16:00:08 2015 +0000
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ByteCodes.java	Thu Dec 03 12:15:04 2015 +0000
@@ -250,11 +250,13 @@
         vastore         = 206,
         vnew            = 207,
         vnewarray       = 208,
-        vreturn         = 209,
-        vgetfield       = 210,
-        typed           = 211,
+        multivnewarray  = 209,
+        vreturn         = 210,
+        vgetfield       = 211,
 
-        ByteCodeCount   = 212;
+        typed           = 212,
+
+        ByteCodeCount   = 213;
 
     /** Virtual instruction codes; used for constant folding.
      */
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Code.java	Wed Dec 02 16:00:08 2015 +0000
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Code.java	Thu Dec 03 12:15:04 2015 +0000
@@ -429,8 +429,8 @@
         postop();
     }
 
-    public void emitVnewarray(int ndims, int type, Type arrayType) {
-        emitop(vnewarray);
+    public void emitMultivnewarray(int ndims, int type, Type arrayType) {
+        emitop(multivnewarray);
         if (!alive) return;
         emit2(type);
         emit1(ndims);
@@ -461,6 +461,15 @@
         postop();
     }
 
+    public void emitVnewarray(int od, Type arrayType) {
+        emitop(vnewarray);
+        if (!alive) return;
+        emit2(od);
+        state.pop(1);
+        state.push(arrayType);
+        postop();
+    }
+
     /** Emit an invokeinterface instruction.
      */
     public void emitInvokeinterface(int meth, Type mtype) {
@@ -2527,8 +2536,10 @@
             mnem[vastore] = "vastore";
             mnem[vnew] = "vnew";
             mnem[vnewarray] = "vnewarray";
+            mnem[multivnewarray] = "multivnewarray";
             mnem[vreturn] = "vreturn";
             mnem[vgetfield] = "vgetfield";
+            mnem[typed] = "typed";
         }
     }
 }
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Gen.java	Wed Dec 02 16:00:08 2015 +0000
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Gen.java	Thu Dec 03 12:15:04 2015 +0000
@@ -2061,11 +2061,20 @@
             }
             int elemcode = Code.arraycode(erasedElementType);
             if (erasedElementType.isValue()) {
-                code.emitVnewarray(ndims, makeRef(tree, erasedType), erasedType);
+                code.emitVnewarray(makeRef(tree, erasedElementType), erasedType);
             } else if (elemcode == 0 || (elemcode == 1 && ndims == 1)) {
                 emitAndMarkIfNeeded2(tree, sigType, erasedElementType, (ref) -> code.emitAnewarray(ref, erasedType));
             } else if (elemcode == 1) {
-                emitAndMarkIfNeeded2(tree, sigType, erasedType, (ref) -> code.emitMultianewarray(ndims, ref, erasedType));
+                // if the ultimate elements are values, use multivnewarray
+                Type u = erasedElementType;
+                while (types.isArray(u)) {
+                    u = types.elemtype(u);
+                }
+                if (u.isValue()) {
+                    emitAndMarkIfNeeded2(tree, sigType, erasedType, (ref) -> code.emitMultivnewarray(ndims, ref, erasedType));
+                } else {
+                    emitAndMarkIfNeeded2(tree, sigType, erasedType, (ref) -> code.emitMultianewarray(ndims, ref, erasedType));
+                }
             } else {
                 code.emitNewarray(elemcode, erasedType);
             }
--- a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/Opcode.java	Wed Dec 02 16:00:08 2015 +0000
+++ b/src/jdk.jdeps/share/classes/com/sun/tools/classfile/Opcode.java	Thu Dec 03 12:15:04 2015 +0000
@@ -248,11 +248,12 @@
     VALOAD(205),
     VASTORE(206),
     VNEW(207, CPREF_W),
-    VNEWARRAY(208, CPREF_W_UBYTE),
-    VRETURN(209),
-    VGETFIELD(210, CPREF_W),
+    VNEWARRAY(208, CPREF_W),
+    MULTIVNEWARRAY(209, CPREF_W_UBYTE),
+    VRETURN(210),
+    VGETFIELD(211, CPREF_W),
 
-    TYPED(211, CPREF_W),
+    TYPED(212, CPREF_W),
 
     // impdep 0xfe: PicoJava nonpriv
     // impdep 0xff: Picojava priv