7169782: C2: SIGSEGV in LShiftLNode::Ideal(PhaseGVN*, bool)
authorkvn
Tue, 12 Jun 2012 09:47:23 -0700
changeset 12956 1078d92535e8
parent 12955 7cb409520a04
child 12957 f3cc386f349e
7169782: C2: SIGSEGV in LShiftLNode::Ideal(PhaseGVN*, bool) Summary: keep intermediate node alive till the end of the graph construction using dummy hook node trick Reviewed-by: kvn, twisti Contributed-by: vladimir.x.ivanov@oracle.com
hotspot/src/share/vm/opto/divnode.cpp
hotspot/test/compiler/6732154/Test6732154.java
hotspot/test/compiler/7169782/Test7169782.java
--- a/hotspot/src/share/vm/opto/divnode.cpp	Tue Jun 12 10:02:36 2012 +0200
+++ b/hotspot/src/share/vm/opto/divnode.cpp	Tue Jun 12 09:47:23 2012 -0700
@@ -284,9 +284,14 @@
 
   const int N = 64;
 
+  // Dummy node to keep intermediate nodes alive during construction
+  Node* hook = new (phase->C, 4) Node(4);
+
   // u0 = u & 0xFFFFFFFF;  u1 = u >> 32;
   Node* u0 = phase->transform(new (phase->C, 3) AndLNode(dividend, phase->longcon(0xFFFFFFFF)));
   Node* u1 = phase->transform(new (phase->C, 3) RShiftLNode(dividend, phase->intcon(N / 2)));
+  hook->init_req(0, u0);
+  hook->init_req(1, u1);
 
   // v0 = v & 0xFFFFFFFF;  v1 = v >> 32;
   Node* v0 = phase->longcon(magic_const & 0xFFFFFFFF);
@@ -299,19 +304,14 @@
   Node* u1v0 = phase->transform(new (phase->C, 3) MulLNode(u1, v0));
   Node* temp = phase->transform(new (phase->C, 3) URShiftLNode(w0, phase->intcon(N / 2)));
   Node* t    = phase->transform(new (phase->C, 3) AddLNode(u1v0, temp));
+  hook->init_req(2, t);
 
   // w1 = t & 0xFFFFFFFF;
-  Node* w1 = new (phase->C, 3) AndLNode(t, phase->longcon(0xFFFFFFFF));
+  Node* w1 = phase->transform(new (phase->C, 3) AndLNode(t, phase->longcon(0xFFFFFFFF)));
+  hook->init_req(3, w1);
 
   // w2 = t >> 32;
-  Node* w2 = new (phase->C, 3) RShiftLNode(t, phase->intcon(N / 2));
-
-  // 6732154: Construct both w1 and w2 before transforming, so t
-  // doesn't go dead prematurely.
-  // 6837011: We need to transform w2 before w1 because the
-  // transformation of w1 could return t.
-  w2 = phase->transform(w2);
-  w1 = phase->transform(w1);
+  Node* w2 = phase->transform(new (phase->C, 3) RShiftLNode(t, phase->intcon(N / 2)));
 
   // w1 = u0*v1 + w1;
   Node* u0v1 = phase->transform(new (phase->C, 3) MulLNode(u0, v1));
@@ -322,6 +322,16 @@
   Node* temp1 = phase->transform(new (phase->C, 3) AddLNode(u1v1, w2));
   Node* temp2 = phase->transform(new (phase->C, 3) RShiftLNode(w1, phase->intcon(N / 2)));
 
+  // Remove the bogus extra edges used to keep things alive
+  PhaseIterGVN* igvn = phase->is_IterGVN();
+  if (igvn != NULL) {
+    igvn->remove_dead_node(hook);
+  } else {
+    for (int i = 0; i < 4; i++) {
+      hook->set_req(i, NULL);
+    }
+  }
+
   return new (phase->C, 3) AddLNode(temp1, temp2);
 }
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/compiler/6732154/Test6732154.java	Tue Jun 12 09:47:23 2012 -0700
@@ -0,0 +1,111 @@
+/*
+ * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+/**
+ * @test
+ * @bug 6732154
+ * @summary REG: Printing an Image using image/gif doc flavor crashes the VM, Solsparc
+ *
+ * @run main/othervm -Xcomp -XX:CompileOnly="Test6732154::ascii85Encode" Test6732154
+ */
+public class Test6732154 {
+
+    // Exact copy of sun.print.PSPrinterJob.ascii85Encode([b)[b
+    private byte[] ascii85Encode(byte[] inArr) {
+        byte[]  outArr = new byte[((inArr.length+4) * 5 / 4) + 2];
+        long p1 = 85;
+        long p2 = p1*p1;
+        long p3 = p1*p2;
+        long p4 = p1*p3;
+        byte pling = '!';
+
+        int i = 0;
+        int olen = 0;
+        long val, rem;
+
+        while (i+3 < inArr.length) {
+            val = ((long)((inArr[i++]&0xff))<<24) +
+                  ((long)((inArr[i++]&0xff))<<16) +
+                  ((long)((inArr[i++]&0xff))<< 8) +
+                  ((long)(inArr[i++]&0xff));
+            if (val == 0) {
+                outArr[olen++] = 'z';
+            } else {
+                rem = val;
+                outArr[olen++] = (byte)(rem / p4 + pling); rem = rem % p4;
+                outArr[olen++] = (byte)(rem / p3 + pling); rem = rem % p3;
+                outArr[olen++] = (byte)(rem / p2 + pling); rem = rem % p2;
+                outArr[olen++] = (byte)(rem / p1 + pling); rem = rem % p1;
+                outArr[olen++] = (byte)(rem + pling);
+            }
+        }
+        // input not a multiple of 4 bytes, write partial output.
+        if (i < inArr.length) {
+            int n = inArr.length - i; // n bytes remain to be written
+
+            val = 0;
+            while (i < inArr.length) {
+                val = (val << 8) + (inArr[i++]&0xff);
+            }
+
+            int append = 4 - n;
+            while (append-- > 0) {
+                val = val << 8;
+            }
+            byte []c = new byte[5];
+            rem = val;
+            c[0] = (byte)(rem / p4 + pling); rem = rem % p4;
+            c[1] = (byte)(rem / p3 + pling); rem = rem % p3;
+            c[2] = (byte)(rem / p2 + pling); rem = rem % p2;
+            c[3] = (byte)(rem / p1 + pling); rem = rem % p1;
+            c[4] = (byte)(rem + pling);
+
+            for (int b = 0; b < n+1 ; b++) {
+                outArr[olen++] = c[b];
+            }
+        }
+
+        // write EOD marker.
+        outArr[olen++]='~'; outArr[olen++]='>';
+
+        /* The original intention was to insert a newline after every 78 bytes.
+         * This was mainly intended for legibility but I decided against this
+         * partially because of the (small) amount of extra space, and
+         * partially because for line breaks either would have to hardwire
+         * ascii 10 (newline) or calculate space in bytes to allocate for
+         * the platform's newline byte sequence. Also need to be careful
+         * about where its inserted:
+         * Ascii 85 decoder ignores white space except for one special case:
+         * you must ensure you do not split the EOD marker across lines.
+         */
+        byte[] retArr = new byte[olen];
+        System.arraycopy(outArr, 0, retArr, 0, olen);
+        return retArr;
+    }
+
+    public static void main(String[] args) {
+        new Test6732154().ascii85Encode(new byte[0]);
+        System.out.println("Test passed.");
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/compiler/7169782/Test7169782.java	Tue Jun 12 09:47:23 2012 -0700
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+/**
+ * @test
+ * @bug 7169782
+ * @summary C2: SIGSEGV in LShiftLNode::Ideal(PhaseGVN*, bool)
+ *
+ * @run main/othervm -Xcomp -XX:CompileOnly="Test7169782::<clinit>" Test7169782
+ */
+
+public class Test7169782 {
+    static long var_8;
+
+    static {
+        var_8 /= (long)(1E100 + ("".startsWith("a", 0) ? 1 : 2));
+    }
+
+    public static void main(String[] args) {
+        System.out.println("Test passed.");
+    }
+}