8336702: C2 compilation fails with "all memory state should have been processed" assert

Reviewed-by: thartmann, chagedorn
This commit is contained in:
Roland Westrelin 2024-10-09 14:57:37 +00:00
parent d936556799
commit ecc77a5b4a
2 changed files with 75 additions and 2 deletions

View File

@ -692,14 +692,24 @@ SafePointNode* PhaseIdealLoop::find_safepoint(Node* back_control, Node* x, Ideal
// We can only use that safepoint if there's no side effect between the backedge and the safepoint.
// mm is used for book keeping
// mm is the memory state at the safepoint (when it's a MergeMem)
// no_side_effect_since_safepoint() goes over the memory state at the backedge. It resets the mm input for each
// component of the memory state it encounters so it points to the base memory. Once no_side_effect_since_safepoint()
// is done, if no side effect after the safepoint was found, mm should transform to the base memory: the states at
// the backedge and safepoint are the same so all components of the memory state at the safepoint should have been
// reset.
MergeMemNode* mm = nullptr;
#ifdef ASSERT
if (mem->is_MergeMem()) {
mm = mem->clone()->as_MergeMem();
_igvn._worklist.push(mm);
for (MergeMemStream mms(mem->as_MergeMem()); mms.next_non_empty(); ) {
if (mms.alias_idx() != Compile::AliasIdxBot && loop != get_loop(ctrl_or_self(mms.memory()))) {
// Loop invariant memory state won't be reset by no_side_effect_since_safepoint(). Do it here.
// Escape Analysis can add state to mm that it doesn't add to the backedge memory Phis, breaking verification
// code that relies on mm. Clear that extra state here.
if (mms.alias_idx() != Compile::AliasIdxBot &&
(loop != get_loop(ctrl_or_self(mms.memory())) ||
(mms.adr_type()->isa_oop_ptr() && mms.adr_type()->is_known_instance()))) {
mm->set_memory_at(mms.alias_idx(), mem->as_MergeMem()->base_memory());
}
}

View File

@ -0,0 +1,63 @@
/*
* Copyright (c) 2024, Red Hat, Inc. 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 8336702
* @summary C2 compilation fails with "all memory state should have been processed" assert
*
* @run main/othervm TestSafePointWithEAState
*
*/
public class TestSafePointWithEAState {
int[] b = new int[400];
void c() {
int e;
float f;
for (long d = 0; d < 5000; d++) {
e = 1;
while ((e += 3) < 200) {
if (d < b.length) {
for (int g = 0; g < 10000; ++g) ;
}
}
synchronized (TestSafePointWithEAState.class) {
f = new h(e).n;
}
}
}
public static void main(String[] m) {
TestSafePointWithEAState o = new TestSafePointWithEAState();
o.c();
}
}
class h {
float n;
h(float n) {
this.n = n;
}
}