This commit is contained in:
Jesper Wilhelmsson 2022-01-18 01:10:17 +00:00
commit 37143c09ab
6 changed files with 123 additions and 7 deletions
src
test/hotspot/jtreg/compiler/loopopts

@ -2008,13 +2008,21 @@ void G1ConcurrentMark::print_stats() {
}
void G1ConcurrentMark::concurrent_cycle_abort() {
if (!cm_thread()->in_progress() || _has_aborted) {
// We haven't started a concurrent cycle or we have already aborted it. No need to do anything.
// We haven't started a concurrent cycle no need to do anything; we might have
// aborted the marking because of shutting down though. In this case the marking
// might have already completed the abort (leading to in_progress() below to
// return false), however this still left marking state particularly in the
// shared marking bitmap that must be cleaned up.
// If there are multiple full gcs during shutdown we do this work repeatedly for
// nothing, but this situation should be extremely rare (a full gc after shutdown
// has been signalled is alredy rare), and this work should be negligible compared
// to actual full gc work.
if (!cm_thread()->in_progress() && !_g1h->concurrent_mark_is_terminating()) {
return;
}
// Clear all marks in the next bitmap for the next marking cycle. This will allow us to skip the next
// concurrent bitmap clearing.
// Clear all marks in the next bitmap for this full gc as it has been used by the
// marking that is interrupted by this full gc.
{
GCTraceTime(Debug, gc) debug("Clear Next Bitmap");
clear_next_bitmap(_g1h->workers());
@ -2028,9 +2036,8 @@ void G1ConcurrentMark::concurrent_cycle_abort() {
for (uint i = 0; i < _max_num_tasks; ++i) {
_tasks[i]->clear_region_fields();
}
_first_overflow_barrier_sync.abort();
_second_overflow_barrier_sync.abort();
_has_aborted = true;
abort_marking_threads();
SATBMarkQueueSet& satb_mq_set = G1BarrierSet::satb_mark_queue_set();
satb_mq_set.abandon_partial_marking();
@ -2041,6 +2048,13 @@ void G1ConcurrentMark::concurrent_cycle_abort() {
satb_mq_set.is_active() /* expected_active */);
}
void G1ConcurrentMark::abort_marking_threads() {
assert(!_root_regions.scan_in_progress(), "still doing root region scan");
_has_aborted = true;
_first_overflow_barrier_sync.abort();
_second_overflow_barrier_sync.abort();
}
static void print_ms_time_info(const char* prefix, const char* name,
NumberSeq& ns) {
log_trace(gc, marking)("%s%5d %12s: total time = %8.2f s (avg = %8.2f ms).",

@ -496,6 +496,11 @@ public:
void concurrent_cycle_abort();
void concurrent_cycle_end();
// Notifies marking threads to abort. This is a best-effort notification. Does not
// guarantee or update any state after the call. Root region scan must not be
// running.
void abort_marking_threads();
void update_accum_task_vtime(int i, double vtime) {
_accum_task_vtime[i] += vtime;
}

@ -139,6 +139,15 @@ void G1ConcurrentMarkThread::run_service() {
}
void G1ConcurrentMarkThread::stop_service() {
if (in_progress()) {
// We are not allowed to abort the marking threads during root region scan.
// Needs to be done separately.
_cm->root_regions()->abort();
_cm->root_regions()->wait_until_scan_finished();
_cm->abort_marking_threads();
}
MutexLocker ml(CGC_lock, Mutex::_no_safepoint_check_flag);
CGC_lock->notify_all();
}

@ -3437,6 +3437,11 @@ bool IdealLoopTree::do_one_iteration_loop(PhaseIdealLoop *phase) {
//=============================================================================
//------------------------------iteration_split_impl---------------------------
bool IdealLoopTree::iteration_split_impl(PhaseIdealLoop *phase, Node_List &old_new) {
if (!_head->is_Loop()) {
// Head could be a region with a NeverBranch that was added in beautify loops but the region was not
// yet transformed into a LoopNode. Bail out and wait until beautify loops turns it into a Loop node.
return false;
}
// Compute loop trip count if possible.
compute_trip_count(phase);

@ -23,6 +23,7 @@
* questions.
*/
#include <cstddef>
#include <cstring>
#include "tstrings.h"
#include "JvmLauncher.h"

@ -0,0 +1,82 @@
/*
* Copyright (c) 2022, 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
* @requires vm.compiler2.enabled
* @bug 8279837
* @summary Tests infinite loop with region head in iteration split.
* @run main/othervm -Xcomp -XX:-TieredCompilation
* -XX:CompileCommand=compileonly,compiler.loopopts.TestIterationSplitWithRegionHead::test
* -XX:CompileCommand=dontinline,compiler.loopopts.TestIterationSplitWithRegionHead::*
* compiler.loopopts.TestIterationSplitWithRegionHead
*/
package compiler.loopopts;
public class TestIterationSplitWithRegionHead {
static boolean flagFalse = false;
public static void main(String[] args) {
test();
}
public static void test() {
// 1) The loop tree is built. We find that nested loop N2 is an infinite loop and add a NeverBranch
// to the inner loop to make it reachable. But the current loop tree does not have N2, yet. The
// resulting loop tree is:
//
// Loop: N0/N0 has_call has_sfpt
// Loop: N77/N121 has_call // N1 outer
// Loop: N77/N111 has_call sfpts={ 111 97 } // N1 inner
//
// 2) beautify_loops() finds that the outer loop head of N1 is shared and thus adds a new region
// in merge_many_backedges(). As a result, the loop tree is built again. This time, the NeverBranch
// in the inner loop of N2 allows that a loop tree can be built for it:
//
// Loop: N0/N0 has_call has_sfpt
// Loop: N216/N213 limit_check profile_predicated predicated has_call sfpts={ 111 97 } // N1 shared loop head
// Loop: N196/N201 sfpts={ 201 } // N2 inner loop now discovered with the new NeverBranch
//
// However, a LoopNode is only added by beautify_loops() which won't be called until the next iteration of loop opts.
// This means that we have a Region node (N196) as head in the loop tree which cannot be handled by iteration_split_impl()
// resulting in an assertion failure.
// Nested loop N1
while (flagFalse) {
while (dontInlineFalse()) {
}
}
dontInlineFalse();
// Nested loop N2
while (flagFalse) {
while (true) ; // Detected as infinite inner loop by C2 -> NeverBranch added
}
}
public static boolean dontInlineFalse() {
return false;
}
}