8286451: C2: assert(nb == 1) failed: only when the head is not shared

Reviewed-by: thartmann, chagedorn
This commit is contained in:
Roland Westrelin 2022-06-08 06:41:20 +00:00
parent 0960ecc407
commit bf0e625fe0
2 changed files with 68 additions and 17 deletions

View File

@ -2299,7 +2299,7 @@ ciTypeFlow::Block* ciTypeFlow::clone_loop_head(Loop* lp, StateVector* temp_vecto
}
// Have the most frequent ones branch to the clone instead
int count = 0;
int nb = 0;
int loops_with_shared_head = 0;
Block* latest_tail = tail;
bool done = false;
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
if (lp2->tail()->post_order() < latest_tail->post_order()) {
latest_tail = lp2->tail();
}
nb++;
loops_with_shared_head++;
for (SuccIter iter(lp2->tail()); !iter.done(); iter.next()) {
if (iter.succ() == head) {
iter.set_succ(clone);
@ -2319,29 +2319,28 @@ ciTypeFlow::Block* ciTypeFlow::clone_loop_head(Loop* lp, StateVector* temp_vecto
}
}
flow_block(lp2->tail(), temp_vector, temp_set);
if (lp2->head() == lp2->tail()) {
// For self-loops, clone->head becomes clone->clone
flow_block(clone, temp_vector, temp_set);
for (SuccIter iter(clone); !iter.done(); iter.next()) {
if (iter.succ() == lp2->head()) {
iter.set_succ(clone);
// Update predecessor information
lp2->head()->predecessors()->remove(clone);
clone->predecessors()->append(clone);
break;
}
}
}
if (total_count == 0 || count > (total_count * .9)) {
done = true;
}
}
}
}
assert(nb >= 1, "at least one new");
assert(loops_with_shared_head >= 1, "at least one new");
clone->set_rpo_next(latest_tail->rpo_next());
latest_tail->set_rpo_next(clone);
if (head == tail) {
assert(nb == 1, "only when the head is not shared");
// For self-loops, clone->head becomes clone->clone
flow_block(clone, temp_vector, temp_set);
for (SuccIter iter(clone); !iter.done(); iter.next()) {
if (iter.succ() == head) {
iter.set_succ(clone);
// Update predecessor information
head->predecessors()->remove(clone);
clone->predecessors()->append(clone);
break;
}
}
}
flow_block(clone, temp_vector, temp_set);
return clone;

View File

@ -0,0 +1,52 @@
/*
* Copyright (c) 2022, 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 8286451
* @summary C2: assert(nb == 1) failed: only when the head is not shared
* @run main/othervm -XX:-BackgroundCompilation TestSharedLoopHead
*/
public class TestSharedLoopHead {
public static void main(String[] args) {
for (int i = 0; i < 20_000; i++) {
test();
}
}
private static void test() {
int j = 0;
int i = 0;
do {
do {
i++;
} while (i < 2);
do {
i++;
} while (i < 2);
j++;
i = 0;
} while (j < 2);
}
}