From e340aeeee010baf2773fd0d50ce59aa55a823de3 Mon Sep 17 00:00:00 2001 From: Guanqiang Han Date: Wed, 1 Apr 2026 09:12:51 +0000 Subject: [PATCH] 8379174: G1: Too high G1RemSetArrayOfCardsEntriesBase causes invalid ergonomic G1RemSetArrayOfCardsEntries Reviewed-by: tschatzl, iwalulya --- src/hotspot/share/gc/g1/g1Arguments.cpp | 3 +- ...tG1RemSetArrayOfCardsEntriesErgoLimit.java | 43 +++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 test/hotspot/jtreg/gc/g1/TestG1RemSetArrayOfCardsEntriesErgoLimit.java diff --git a/src/hotspot/share/gc/g1/g1Arguments.cpp b/src/hotspot/share/gc/g1/g1Arguments.cpp index 8bec6e7e86f..c3bbd5a3b52 100644 --- a/src/hotspot/share/gc/g1/g1Arguments.cpp +++ b/src/hotspot/share/gc/g1/g1Arguments.cpp @@ -148,8 +148,9 @@ void G1Arguments::initialize_card_set_configuration() { if (FLAG_IS_DEFAULT(G1RemSetArrayOfCardsEntries)) { uint max_cards_in_inline_ptr = G1CardSetConfiguration::max_cards_in_inline_ptr(G1HeapRegion::LogCardsPerRegion); + const JVMTypedFlagLimit* limit = JVMFlagLimit::get_range_at(FLAG_MEMBER_ENUM(G1RemSetArrayOfCardsEntries))->cast(); FLAG_SET_ERGO(G1RemSetArrayOfCardsEntries, MAX2(max_cards_in_inline_ptr * 2, - G1RemSetArrayOfCardsEntriesBase << region_size_log_mb)); + MIN2(G1RemSetArrayOfCardsEntriesBase << region_size_log_mb, limit->max()))); } // Howl card set container globals. diff --git a/test/hotspot/jtreg/gc/g1/TestG1RemSetArrayOfCardsEntriesErgoLimit.java b/test/hotspot/jtreg/gc/g1/TestG1RemSetArrayOfCardsEntriesErgoLimit.java new file mode 100644 index 00000000000..4af09066def --- /dev/null +++ b/test/hotspot/jtreg/gc/g1/TestG1RemSetArrayOfCardsEntriesErgoLimit.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2026, 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 + * @bug 8379174 + * @summary Test for G1 ergonomics deriving an out-of-range + * G1RemSetArrayOfCardsEntries value from G1RemSetArrayOfCardsEntriesBase + * @requires vm.gc.G1 + * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions + * -XX:+UseG1GC + * -XX:G1RemSetArrayOfCardsEntriesBase=62117 + * -XX:G1HeapRegionSize=4m + * ${test.main.class} + */ + +package gc.g1; + +public class TestG1RemSetArrayOfCardsEntriesErgoLimit { + public static void main(String[] args) { + System.out.println("passed"); + } +}