From f9d81d15bfbfa80d04d05079ab212d26a7935f07 Mon Sep 17 00:00:00 2001 From: Aleksey Shipilev Date: Wed, 30 Apr 2025 20:59:22 +0200 Subject: [PATCH 1/4] Fix --- .../share/compiler/compilationPolicy.cpp | 19 +++-- .../arguments/TestCompilerCounts.java | 75 +++++++++++++++++++ 2 files changed, 89 insertions(+), 5 deletions(-) create mode 100644 test/hotspot/jtreg/compiler/arguments/TestCompilerCounts.java diff --git a/src/hotspot/share/compiler/compilationPolicy.cpp b/src/hotspot/share/compiler/compilationPolicy.cpp index fa18b3c8ab4c0..74a31ed396b3b 100644 --- a/src/hotspot/share/compiler/compilationPolicy.cpp +++ b/src/hotspot/share/compiler/compilationPolicy.cpp @@ -440,10 +440,12 @@ void CompilationPolicy::initialize() { FLAG_SET_DEFAULT(CICompilerCountPerCPU, true); } if (CICompilerCountPerCPU) { + int min_count = (c1_only || c2_only) ? 1 : 2; + int active_cpus = os::active_processor_count(); // Simple log n seems to grow too slowly for tiered, try something faster: log n * log log n - int log_cpu = log2i(os::active_processor_count()); + int log_cpu = log2i(active_cpus); int loglog_cpu = log2i(MAX2(log_cpu, 1)); - count = MAX2(log_cpu * loglog_cpu * 3 / 2, 2); + count = MAX2(log_cpu * loglog_cpu * 3 / 2, min_count); // Make sure there is enough space in the code cache to hold all the compiler buffers size_t c1_size = 0; #ifdef COMPILER1 @@ -453,12 +455,20 @@ void CompilationPolicy::initialize() { #ifdef COMPILER2 c2_size = C2Compiler::initial_code_buffer_size(); #endif - size_t buffer_size = c1_only ? c1_size : (c1_size/3 + 2*c2_size/3); + size_t buffer_size = 0; + if (c1_only) { + buffer_size = c1_size; + } else if (c2_only) { + buffer_size = c2_size; + } else { + buffer_size = c1_size/3 + 2*c2_size/3; + } int max_count = (ReservedCodeCacheSize - (CodeCacheMinimumUseSpace DEBUG_ONLY(* 3))) / (int)buffer_size; if (count > max_count) { // Lower the compiler count such that all buffers fit into the code cache - count = MAX2(max_count, c1_only ? 1 : 2); + count = MAX2(max_count, min_count); } + assert((!c1_only && !c2_only) || count <= active_cpus, "Too many threads: %d", count); FLAG_SET_ERGO(CICompilerCount, count); } #else @@ -476,7 +486,6 @@ void CompilationPolicy::initialize() { #endif if (c1_only) { - // No C2 compiler thread required set_c1_count(count); } else if (c2_only) { set_c2_count(count); diff --git a/test/hotspot/jtreg/compiler/arguments/TestCompilerCounts.java b/test/hotspot/jtreg/compiler/arguments/TestCompilerCounts.java new file mode 100644 index 0000000000000..3506b5a9066b2 --- /dev/null +++ b/test/hotspot/jtreg/compiler/arguments/TestCompilerCounts.java @@ -0,0 +1,75 @@ +/* + * Copyright Amazon.com Inc. 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 + * @library /test/lib / + * @bug 8356000 + * @requires vm.flagless + * @requires vm.debug + * @requires os.arch=="amd64" | os.arch=="x86_64" + * + * @summary Test compiler counts selection, verified by internal assertions + * @run driver compiler.arguments.TestCompilerCounts + */ + +package compiler.arguments; + +import java.io.IOException; +import java.util.List; +import java.util.Arrays; +import java.util.ArrayList; +import jdk.test.lib.process.ProcessTools; +import jdk.test.lib.process.OutputAnalyzer; + +public class TestCompilerCounts { + + public static void main(String[] args) throws IOException { + if (args.length > 0) { + System.out.println("Pass"); + return; + } + + testWith("-XX:TieredStopAtLevel=0"); + testWith("-XX:TieredStopAtLevel=1"); + testWith("-XX:TieredStopAtLevel=2"); + testWith("-XX:TieredStopAtLevel=3"); + testWith("-XX:TieredStopAtLevel=4"); + testWith("-XX:-TieredCompilation"); + } + + public static void testWith(String mode) throws IOException { + for (int cpus = 1; cpus < Runtime.getRuntime().availableProcessors(); cpus++) { + String[] args = new String[] { + mode, + "-XX:ActiveProcessorCount=" + cpus, + "compiler.arguments.TestCompilerCounts", + "run" + }; + ProcessBuilder pb = ProcessTools.createLimitedTestJavaProcessBuilder(args); + OutputAnalyzer output = new OutputAnalyzer(pb.start()); + output.shouldHaveExitValue(0); + } + } + +} From 6dfae11ff4a1f8e2dcfc9d805459a8c6c5e13069 Mon Sep 17 00:00:00 2001 From: Aleksey Shipilev Date: Wed, 30 Apr 2025 21:02:19 +0200 Subject: [PATCH 2/4] Adjust test bound --- test/hotspot/jtreg/compiler/arguments/TestCompilerCounts.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/hotspot/jtreg/compiler/arguments/TestCompilerCounts.java b/test/hotspot/jtreg/compiler/arguments/TestCompilerCounts.java index 3506b5a9066b2..920fff3358e5f 100644 --- a/test/hotspot/jtreg/compiler/arguments/TestCompilerCounts.java +++ b/test/hotspot/jtreg/compiler/arguments/TestCompilerCounts.java @@ -59,7 +59,7 @@ public static void main(String[] args) throws IOException { } public static void testWith(String mode) throws IOException { - for (int cpus = 1; cpus < Runtime.getRuntime().availableProcessors(); cpus++) { + for (int cpus = 1; cpus <= Runtime.getRuntime().availableProcessors(); cpus++) { String[] args = new String[] { mode, "-XX:ActiveProcessorCount=" + cpus, From 57d473406205335b059f4541049292735ee5afcb Mon Sep 17 00:00:00 2001 From: Aleksey Shipilev Date: Wed, 30 Apr 2025 21:04:15 +0200 Subject: [PATCH 3/4] Simplify test --- .../jtreg/compiler/arguments/TestCompilerCounts.java | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/test/hotspot/jtreg/compiler/arguments/TestCompilerCounts.java b/test/hotspot/jtreg/compiler/arguments/TestCompilerCounts.java index 920fff3358e5f..691e73aa27550 100644 --- a/test/hotspot/jtreg/compiler/arguments/TestCompilerCounts.java +++ b/test/hotspot/jtreg/compiler/arguments/TestCompilerCounts.java @@ -45,11 +45,6 @@ public class TestCompilerCounts { public static void main(String[] args) throws IOException { - if (args.length > 0) { - System.out.println("Pass"); - return; - } - testWith("-XX:TieredStopAtLevel=0"); testWith("-XX:TieredStopAtLevel=1"); testWith("-XX:TieredStopAtLevel=2"); @@ -63,8 +58,7 @@ public static void testWith(String mode) throws IOException { String[] args = new String[] { mode, "-XX:ActiveProcessorCount=" + cpus, - "compiler.arguments.TestCompilerCounts", - "run" + "-version" }; ProcessBuilder pb = ProcessTools.createLimitedTestJavaProcessBuilder(args); OutputAnalyzer output = new OutputAnalyzer(pb.start()); From 8e3366a13ed58a60eb16d8ce4c351124315f192a Mon Sep 17 00:00:00 2001 From: Aleksey Shipilev Date: Wed, 30 Apr 2025 21:05:03 +0200 Subject: [PATCH 4/4] Unnecessary arch limitation --- test/hotspot/jtreg/compiler/arguments/TestCompilerCounts.java | 1 - 1 file changed, 1 deletion(-) diff --git a/test/hotspot/jtreg/compiler/arguments/TestCompilerCounts.java b/test/hotspot/jtreg/compiler/arguments/TestCompilerCounts.java index 691e73aa27550..4770da44c5e78 100644 --- a/test/hotspot/jtreg/compiler/arguments/TestCompilerCounts.java +++ b/test/hotspot/jtreg/compiler/arguments/TestCompilerCounts.java @@ -27,7 +27,6 @@ * @bug 8356000 * @requires vm.flagless * @requires vm.debug - * @requires os.arch=="amd64" | os.arch=="x86_64" * * @summary Test compiler counts selection, verified by internal assertions * @run driver compiler.arguments.TestCompilerCounts