From a09083ba96f5b6a8e4b4aaa0ca292d809d8a83e7 Mon Sep 17 00:00:00 2001 From: Saranya Natarajan Date: Wed, 29 Apr 2026 08:54:08 +0000 Subject: [PATCH] 8350971: C2: assert(idx == alias_idx) failed: Following Phi nodes should be on the same memory slice Reviewed-by: qamai, kvn, aseoane --- src/hotspot/share/opto/escape.cpp | 10 ++- .../escapeAnalysis/TestMemoryPhiAlias.java | 72 +++++++++++++++++++ 2 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 test/hotspot/jtreg/compiler/escapeAnalysis/TestMemoryPhiAlias.java diff --git a/src/hotspot/share/opto/escape.cpp b/src/hotspot/share/opto/escape.cpp index d9dd38590e6..366a9b3fb4b 100644 --- a/src/hotspot/share/opto/escape.cpp +++ b/src/hotspot/share/opto/escape.cpp @@ -4813,8 +4813,14 @@ void ConnectionGraph::split_unique_types(GrowableArray &alloc_worklist, if (visited.test_set(n->_idx)) { continue; } - if (n->is_Phi() || n->is_ClearArray()) { - // we don't need to do anything, but the users must be pushed + if (n->is_Phi()) { + if ((uint) _compile->get_alias_index(n->as_Phi()->adr_type()) < new_index_start) { + // Push memory phis on the orig_phis worklist to update + // during Phase 4 if needed. + orig_phis.append_if_missing(n->as_Phi()); + } + } else if (n->is_ClearArray()) { + // we don't need to do anything, but the users must be pushed } else if (n->is_MemBar()) { // MemBar nodes if (!n->is_Initialize()) { // memory projections for Initialize pushed below (so we get to all their uses) // we don't need to do anything, but the users must be pushed diff --git a/test/hotspot/jtreg/compiler/escapeAnalysis/TestMemoryPhiAlias.java b/test/hotspot/jtreg/compiler/escapeAnalysis/TestMemoryPhiAlias.java new file mode 100644 index 00000000000..efe9146fa49 --- /dev/null +++ b/test/hotspot/jtreg/compiler/escapeAnalysis/TestMemoryPhiAlias.java @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2026, 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 8350971 + * @summary C2 compilation fails with assert(idx == alias_idx) failed: Following Phi nodes should be on the same memory slice + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:-TieredCompilation -Xbatch -XX:CompileCommand=compileonly,compiler.escapeAnalysis.TestMemoryPhiAlias::main + * compiler.escapeAnalysis.TestMemoryPhiAlias + */ + +package compiler.escapeAnalysis; + +import java.util.function.*; + +public class TestMemoryPhiAlias { + static int[] iArrFld = new int[400]; + static int counter = 0; + static int doWork() { + int[] more = {94}; + java.util.function.Predicate check = m -> m == 0; + java.util.function.IntConsumer decrement = x -> more[0]--; + java.util.function.BooleanSupplier innerLoop = () -> { + while (!check.test(more[0])) { + decrement.accept(0); + } + return true; + }; + counter++; + if (counter == 10000000) { + throw new RuntimeException("excepted"); + } + innerLoop.getAsBoolean(); + java.util.function.BooleanSupplier process = () -> check.test(more[0]); + while (!process.getAsBoolean()) { + } + return 0; + } + + public static void main(String[] strArr) { + int i14 = 1; + do { + iArrFld[i14] = 211; + for (int i15 = 1; i15 < 4; ++i15) + try { + TestMemoryPhiAlias.doWork(); + } catch (RuntimeException e) { + return; + } + } while (i14 < 5); + } +} \ No newline at end of file