--- old/test/compiler/c2/8007294/Test8007294.java 2016-01-18 21:38:35.155918943 +0100 +++ new/test/compiler/c2/8007294/Test8007294.java 2016-01-18 21:38:34.885076942 +0100 @@ -24,6 +24,7 @@ /* * @test * @bug 8007294 + * @bug 8146999 * @summary ReduceFieldZeroing doesn't check for dependent load and can lead to incorrect execution * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+AlwaysIncrementalInline -XX:-UseOnStackReplacement -XX:-BackgroundCompilation Test8007294 * @@ -82,6 +83,7 @@ } } for (int i = 0; i < 20000; i++) { + test2(0); // pollute profile int res = test2(1); if (res != 2) { System.out.println("FAILED test2 = " + res); --- old/src/share/vm/opto/cfgnode.cpp 2016-01-18 21:38:35.158043574 +0100 +++ new/src/share/vm/opto/cfgnode.cpp 2016-01-18 21:38:34.854852161 +0100 @@ -1171,9 +1171,7 @@ Node* PhiNode::unique_input(PhaseTransform* phase, bool uncast) { // 1) One unique direct input, // or if uncast is true: - // 2) some of the inputs have an intervening ConstraintCast and - // the type of input is the same or sharper (more specific) - // than the phi's type. + // 2) some of the inputs have an intervening ConstraintCast // 3) an input is a self loop // // 1) input or 2) input or 3) input __ @@ -1193,7 +1191,21 @@ Node* n = in(i); if (n == NULL) continue; - Node* un = uncast ? n->uncast() : n; + Node* un = n; + if (uncast) { +#ifdef ASSERT + Node* m = un->uncast(); +#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 + 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 } --- old/src/share/vm/opto/node.hpp 2016-01-18 21:38:35.183278359 +0100 +++ new/src/share/vm/opto/node.hpp 2016-01-18 21:38:34.895145744 +0100 @@ -653,7 +653,7 @@ DEFINE_CLASS_ID(Type, Node, 2) DEFINE_CLASS_ID(Phi, Type, 0) DEFINE_CLASS_ID(ConstraintCast, Type, 1) - DEFINE_CLASS_ID(CheckCastPP, Type, 2) + DEFINE_CLASS_ID(CheckCastPP, ConstraintCast, 0) DEFINE_CLASS_ID(CMove, Type, 3) DEFINE_CLASS_ID(SafePointScalarObject, Type, 4) DEFINE_CLASS_ID(DecodeNarrowPtr, Type, 5)