changeset 10485:6daf6d082fd0

8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer Summary: Wait with removing casts from inputs in PhiNode::ideal() until after parsing for the type information to propagate. Reviewed-by: kvn
author thartmann
date Tue, 15 Mar 2016 17:42:28 +0100
parents 97c1a4ad293c
children a67e578d4015
files src/share/vm/opto/callnode.cpp src/share/vm/opto/cfgnode.cpp test/compiler/types/TestPhiElimination.java
diffstat 3 files changed, 119 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/vm/opto/callnode.cpp	Tue Mar 15 16:23:31 2016 +0300
+++ b/src/share/vm/opto/callnode.cpp	Tue Mar 15 17:42:28 2016 +0100
@@ -1243,13 +1243,13 @@
 
 Node *SafePointNode::peek_monitor_box() const {
   int mon = jvms()->nof_monitors() - 1;
-  assert(mon >= 0, "most have a monitor");
+  assert(mon >= 0, "must have a monitor");
   return monitor_box(jvms(), mon);
 }
 
 Node *SafePointNode::peek_monitor_obj() const {
   int mon = jvms()->nof_monitors() - 1;
-  assert(mon >= 0, "most have a monitor");
+  assert(mon >= 0, "must have a monitor");
   return monitor_obj(jvms(), mon);
 }
 
--- a/src/share/vm/opto/cfgnode.cpp	Tue Mar 15 16:23:31 2016 +0300
+++ b/src/share/vm/opto/cfgnode.cpp	Tue Mar 15 17:42:28 2016 +0100
@@ -1665,7 +1665,7 @@
 
   bool uncasted = false;
   Node* uin = unique_input(phase, false);
-  if (uin == NULL) {
+  if (uin == NULL && can_reshape) {
     uncasted = true;
     uin = unique_input(phase, true);
   }
@@ -1702,6 +1702,8 @@
     }
 
     if (uncasted) {
+      // Wait until after parsing for the type information to propagate from the casts
+      assert(can_reshape, "Invalid during parsing");
       const Type* phi_type = bottom_type();
       assert(phi_type->isa_int() || phi_type->isa_ptr(), "bad phi type");
       int opcode;
@@ -1720,8 +1722,9 @@
       Node* cast = ConstraintCastNode::make_cast(opcode, r, uin, phi_type, true);
       cast = phase->transform(cast);
       // set all inputs to the new cast so the Phi is removed by Identity
+      PhaseIterGVN* igvn = phase->is_IterGVN();
       for (uint i = 1; i < req(); i++) {
-        set_req(i, cast);
+        set_req_X(i, cast, igvn);
       }
       uin = cast;
     }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/compiler/types/TestPhiElimination.java	Tue Mar 15 17:42:28 2016 +0100
@@ -0,0 +1,112 @@
+/*
+ * Copyright (c) 2016, 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 8150804
+ * @summary Tests elimination of Phi nodes without losing type information.
+ * @run main/othervm -XX:-BackgroundCompilation -XX:-UseOnStackReplacement TestPhiElimination
+ */
+public class TestPhiElimination {
+    /*
+       A::get() is inlined into test(obj) producing the following graph:
+
+               Parm (obj)
+            TestPhiElimination
+                   |
+                 CastPP
+        TestPhiElimination:NotNull
+                   |
+              CheckCastPP
+               A:NotNull
+               /       \
+       CheckCastPP     |
+        A:NotNull      |
+                \     /
+                  Phi
+                   A
+                   |
+               Safepoint
+
+       PhiNode::ideal() then replaces the Phi by a CheckCastPP:
+
+               Parm (obj)
+            TestPhiElimination
+                   |
+              CheckCastPP
+                   A
+                   |
+               Safepoint
+
+       losing the :NotNull information. Therefore, we cannot prove that obj != null
+       when accessing a field and add an uncommon trap. Since obj is used as monitor, we
+       set it to TOP in the uncommon trap branch and later fail in Process_OopMap_Node
+       because the monitor object is TOP.
+    */
+    public Object test(TestPhiElimination obj) {
+        if (obj instanceof A) {
+            return ((A) obj).get();
+        }
+        return null;
+    }
+
+    static public void main(String[] args) {
+        TestPhiElimination t = new TestPhiElimination();
+
+        // Warmup
+        B b = new B();
+        for (int i = 0; i < 1_000; ++i) {
+            t.test(b);
+        }
+
+        // Compile
+        A a = new A();
+        for (int i = 0; i < 20_000; ++i) {
+            if (i % 2 == 0) {
+                a.f = null;
+            }
+            t.test(a);
+        }
+    }
+
+}
+
+class A extends TestPhiElimination {
+    public Object f;
+
+    public A create() {
+        return new A();
+    }
+
+    public synchronized Object get() {
+        if (f == null) {
+            f = create();
+        }
+        return f;
+    }
+}
+
+class B extends A {
+
+}