Skip to content

Commit e07ae66

Browse files
author
Satyen Subramaniam
committed
8336702: C2 compilation fails with "all memory state should have been processed" assert
Backport-of: ecc77a5b4a84c84ffa1580174872af6df3a4f6ca
1 parent d2dfbd8 commit e07ae66

File tree

2 files changed

+75
-2
lines changed

2 files changed

+75
-2
lines changed

src/hotspot/share/opto/loopnode.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -701,14 +701,24 @@ SafePointNode* PhaseIdealLoop::find_safepoint(Node* back_control, Node* x, Ideal
701701

702702
// We can only use that safepoint if there's no side effect between the backedge and the safepoint.
703703

704-
// mm is used for book keeping
704+
// mm is the memory state at the safepoint (when it's a MergeMem)
705+
// no_side_effect_since_safepoint() goes over the memory state at the backedge. It resets the mm input for each
706+
// component of the memory state it encounters so it points to the base memory. Once no_side_effect_since_safepoint()
707+
// is done, if no side effect after the safepoint was found, mm should transform to the base memory: the states at
708+
// the backedge and safepoint are the same so all components of the memory state at the safepoint should have been
709+
// reset.
705710
MergeMemNode* mm = nullptr;
706711
#ifdef ASSERT
707712
if (mem->is_MergeMem()) {
708713
mm = mem->clone()->as_MergeMem();
709714
_igvn._worklist.push(mm);
710715
for (MergeMemStream mms(mem->as_MergeMem()); mms.next_non_empty(); ) {
711-
if (mms.alias_idx() != Compile::AliasIdxBot && loop != get_loop(ctrl_or_self(mms.memory()))) {
716+
// Loop invariant memory state won't be reset by no_side_effect_since_safepoint(). Do it here.
717+
// Escape Analysis can add state to mm that it doesn't add to the backedge memory Phis, breaking verification
718+
// code that relies on mm. Clear that extra state here.
719+
if (mms.alias_idx() != Compile::AliasIdxBot &&
720+
(loop != get_loop(ctrl_or_self(mms.memory())) ||
721+
(mms.adr_type()->isa_oop_ptr() && mms.adr_type()->is_known_instance()))) {
712722
mm->set_memory_at(mms.alias_idx(), mem->as_MergeMem()->base_memory());
713723
}
714724
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright (c) 2024, Red Hat, Inc. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
/**
25+
* @test
26+
* @bug 8336702
27+
* @summary C2 compilation fails with "all memory state should have been processed" assert
28+
*
29+
* @run main/othervm TestSafePointWithEAState
30+
*
31+
*/
32+
33+
public class TestSafePointWithEAState {
34+
int[] b = new int[400];
35+
36+
void c() {
37+
int e;
38+
float f;
39+
for (long d = 0; d < 5000; d++) {
40+
e = 1;
41+
while ((e += 3) < 200) {
42+
if (d < b.length) {
43+
for (int g = 0; g < 10000; ++g) ;
44+
}
45+
}
46+
synchronized (TestSafePointWithEAState.class) {
47+
f = new h(e).n;
48+
}
49+
}
50+
}
51+
52+
public static void main(String[] m) {
53+
TestSafePointWithEAState o = new TestSafePointWithEAState();
54+
o.c();
55+
}
56+
}
57+
58+
class h {
59+
float n;
60+
h(float n) {
61+
this.n = n;
62+
}
63+
}

0 commit comments

Comments
 (0)