--- old/src/share/vm/opto/callnode.cpp 2016-03-11 15:59:07.591145538 +0100 +++ new/src/share/vm/opto/callnode.cpp 2016-03-11 15:59:07.451145533 +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); } --- old/src/share/vm/opto/cfgnode.cpp 2016-03-11 15:59:08.243145558 +0100 +++ new/src/share/vm/opto/cfgnode.cpp 2016-03-11 15:59:08.147145555 +0100 @@ -1207,13 +1207,12 @@ #endif while (un != NULL && un->req() == 2 && un->is_ConstraintCast()) { Node* next = un->in(1); - if (phase->type(next)->isa_rawptr() && phase->type(un)->isa_oopptr()) { - // risk exposing raw ptr at safepoint + // Make sure we don't lose type information + if (!phase->type(next)->higher_equal(phase->type(un))) { break; } un = next; } - assert(m == un || un->in(1) == m, "Only expected at CheckCastPP from allocation"); } if (un == NULL || un == this || phase->type(un) == Type::TOP) { continue; // ignore if top, or in(i) and "this" are in a data cycle --- /dev/null 2016-03-11 08:02:51.305839015 +0100 +++ new/test/compiler/types/TestPhiElimination.java 2016-03-11 15:59:08.803145576 +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 { + +}