Skip to content

Commit bf0e625

Browse files
committed
8286451: C2: assert(nb == 1) failed: only when the head is not shared
Reviewed-by: thartmann, chagedorn
1 parent 0960ecc commit bf0e625

File tree

2 files changed

+68
-17
lines changed

2 files changed

+68
-17
lines changed

src/hotspot/share/ci/ciTypeFlow.cpp

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2299,7 +2299,7 @@ ciTypeFlow::Block* ciTypeFlow::clone_loop_head(Loop* lp, StateVector* temp_vecto
22992299
}
23002300
// Have the most frequent ones branch to the clone instead
23012301
int count = 0;
2302-
int nb = 0;
2302+
int loops_with_shared_head = 0;
23032303
Block* latest_tail = tail;
23042304
bool done = false;
23052305
for (Loop* lp1 = lp; lp1 != NULL && !done; lp1 = lp1->parent()) {
@@ -2309,7 +2309,7 @@ ciTypeFlow::Block* ciTypeFlow::clone_loop_head(Loop* lp, StateVector* temp_vecto
23092309
if (lp2->tail()->post_order() < latest_tail->post_order()) {
23102310
latest_tail = lp2->tail();
23112311
}
2312-
nb++;
2312+
loops_with_shared_head++;
23132313
for (SuccIter iter(lp2->tail()); !iter.done(); iter.next()) {
23142314
if (iter.succ() == head) {
23152315
iter.set_succ(clone);
@@ -2319,29 +2319,28 @@ ciTypeFlow::Block* ciTypeFlow::clone_loop_head(Loop* lp, StateVector* temp_vecto
23192319
}
23202320
}
23212321
flow_block(lp2->tail(), temp_vector, temp_set);
2322+
if (lp2->head() == lp2->tail()) {
2323+
// For self-loops, clone->head becomes clone->clone
2324+
flow_block(clone, temp_vector, temp_set);
2325+
for (SuccIter iter(clone); !iter.done(); iter.next()) {
2326+
if (iter.succ() == lp2->head()) {
2327+
iter.set_succ(clone);
2328+
// Update predecessor information
2329+
lp2->head()->predecessors()->remove(clone);
2330+
clone->predecessors()->append(clone);
2331+
break;
2332+
}
2333+
}
2334+
}
23222335
if (total_count == 0 || count > (total_count * .9)) {
23232336
done = true;
23242337
}
23252338
}
23262339
}
23272340
}
2328-
assert(nb >= 1, "at least one new");
2341+
assert(loops_with_shared_head >= 1, "at least one new");
23292342
clone->set_rpo_next(latest_tail->rpo_next());
23302343
latest_tail->set_rpo_next(clone);
2331-
if (head == tail) {
2332-
assert(nb == 1, "only when the head is not shared");
2333-
// For self-loops, clone->head becomes clone->clone
2334-
flow_block(clone, temp_vector, temp_set);
2335-
for (SuccIter iter(clone); !iter.done(); iter.next()) {
2336-
if (iter.succ() == head) {
2337-
iter.set_succ(clone);
2338-
// Update predecessor information
2339-
head->predecessors()->remove(clone);
2340-
clone->predecessors()->append(clone);
2341-
break;
2342-
}
2343-
}
2344-
}
23452344
flow_block(clone, temp_vector, temp_set);
23462345

23472346
return clone;
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright (c) 2022, 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 8286451
27+
* @summary C2: assert(nb == 1) failed: only when the head is not shared
28+
* @run main/othervm -XX:-BackgroundCompilation TestSharedLoopHead
29+
*/
30+
31+
public class TestSharedLoopHead {
32+
public static void main(String[] args) {
33+
for (int i = 0; i < 20_000; i++) {
34+
test();
35+
}
36+
}
37+
38+
private static void test() {
39+
int j = 0;
40+
int i = 0;
41+
do {
42+
do {
43+
i++;
44+
} while (i < 2);
45+
do {
46+
i++;
47+
} while (i < 2);
48+
j++;
49+
i = 0;
50+
} while (j < 2);
51+
}
52+
}

0 commit comments

Comments
 (0)