From 53530bda0031e11f0d5c298c7e7f22c2b6e08e33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20H=C3=A4ssig?= Date: Fri, 27 Jun 2025 17:28:00 +0200 Subject: [PATCH 1/5] Fix test --- .../arguments/TestCompilerCounts.java | 52 ++++++++++++++----- 1 file changed, 39 insertions(+), 13 deletions(-) diff --git a/test/hotspot/jtreg/compiler/arguments/TestCompilerCounts.java b/test/hotspot/jtreg/compiler/arguments/TestCompilerCounts.java index 420dc2b3414f3..a5e9b27a284b6 100644 --- a/test/hotspot/jtreg/compiler/arguments/TestCompilerCounts.java +++ b/test/hotspot/jtreg/compiler/arguments/TestCompilerCounts.java @@ -27,6 +27,7 @@ * @bug 8356000 * @requires vm.flagless * @requires vm.bits == "64" + * @requires vm.debug * @run driver compiler.arguments.TestCompilerCounts */ @@ -133,31 +134,56 @@ public static void main(String[] args) throws Throwable { pass(0, opt, "-XX:TieredStopAtLevel=0"); // Non-tiered modes - int nonTieredCount = heuristicCount(cpus, false); - pass(nonTieredCount, opt, "-XX:TieredStopAtLevel=1"); - pass(nonTieredCount, opt, "-XX:TieredStopAtLevel=2"); - pass(nonTieredCount, opt, "-XX:TieredStopAtLevel=3"); - pass(nonTieredCount, opt, "-XX:-TieredCompilation"); + int c1OnlyCount = heuristicCount(cpus, Compilation.C1Only); + pass(c1OnlyCount, opt, "-XX:TieredStopAtLevel=1", "-XX:NonNMethodCodeHeapSize="+NonNMethodCodeHeapSize, "-XX:CodeCacheMinimumUseSpace="+CodeCacheMinimumUseSpace); + pass(c1OnlyCount, opt, "-XX:TieredStopAtLevel=2", "-XX:NonNMethodCodeHeapSize="+NonNMethodCodeHeapSize, "-XX:CodeCacheMinimumUseSpace="+CodeCacheMinimumUseSpace); + pass(c1OnlyCount, opt, "-XX:TieredStopAtLevel=3", "-XX:NonNMethodCodeHeapSize="+NonNMethodCodeHeapSize, "-XX:CodeCacheMinimumUseSpace="+CodeCacheMinimumUseSpace); + int c2OnlyCount = heuristicCount(cpus, Compilation.C2Only); + pass(c2OnlyCount, opt, "-XX:-TieredCompilation", "-XX:NonNMethodCodeHeapSize="+NonNMethodCodeHeapSize, "-XX:CodeCacheMinimumUseSpace="+CodeCacheMinimumUseSpace); // Tiered modes - int tieredCount = heuristicCount(cpus, true); - pass(tieredCount, opt); - pass(tieredCount, opt, "-XX:TieredStopAtLevel=4"); + int tieredCount = heuristicCount(cpus, Compilation.Tiered); + pass(tieredCount, opt, "-XX:NonNMethodCodeHeapSize="+NonNMethodCodeHeapSize, "-XX:CodeCacheMinimumUseSpace="+CodeCacheMinimumUseSpace); + pass(tieredCount, opt, "-XX:TieredStopAtLevel=4", "-XX:NonNMethodCodeHeapSize="+NonNMethodCodeHeapSize, "-XX:CodeCacheMinimumUseSpace="+CodeCacheMinimumUseSpace); // Also check that heuristics did not set up more threads than CPUs available - Asserts.assertTrue(nonTieredCount <= cpus, - "Non-tiered count is larger than number of CPUs: " + nonTieredCount + " > " + cpus); + Asserts.assertTrue(c1OnlyCount <= cpus, + "Non-tiered count is larger than number of CPUs: " + c1OnlyCount + " > " + cpus); Asserts.assertTrue(tieredCount <= cpus, "Tiered count is larger than number of CPUs: " + tieredCount + " > " + cpus); } } + enum Compilation { + C1Only, + C2Only, + Tiered, + } + + // Buffer sizes for caclulating the maximum number of compiler threads. + static final int NonNMethodCodeHeapSize = 5 * 1024 * 1024; + static final int CodeCacheMinimumUseSpace = 400 * 1024; + static final int C1BufSize = 64 * 1024 * 8 + (64 * 1024 * 8 / 10); + static final int C1MaxCount = (NonNMethodCodeHeapSize - 3 * CodeCacheMinimumUseSpace) / C1BufSize; + static final int C2BufSize = 6544; + static final int C2MaxCount = (NonNMethodCodeHeapSize - 3 * CodeCacheMinimumUseSpace) / C2BufSize; + static final int TieredBufSize = C1BufSize / 3 + 2 * C2BufSize / 3; + static final int TieredMaxCount = (NonNMethodCodeHeapSize - 3 * CodeCacheMinimumUseSpace) / TieredBufSize; + + // Direct translation from CompilationPolicy::initialize: - public static int heuristicCount(int cpus, boolean tiered) { + public static int heuristicCount(int cpus, Compilation comp) { int log_cpu = log2(cpus); int loglog_cpu = log2(Math.max(log_cpu, 1)); - int min_count = tiered ? 2 : 1; - return Math.max(log_cpu * loglog_cpu * 3 / 2, min_count); + int min_count = comp == Compilation.C1Only || comp == Compilation.C2Only ? 1 : 2; + int count = Math.max(log_cpu * loglog_cpu * 3 / 2, min_count); + int max_count = switch (comp) { + case C1Only -> C1MaxCount; + case C2Only -> C2MaxCount; + case Tiered -> TieredMaxCount; + }; + return Math.max(Math.min(count, max_count), min_count); + } public static int log2(int v) { From ab1c7d9a679f7f7ccbcd67945b627ddcdf164834 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20H=C3=A4ssig?= Date: Mon, 30 Jun 2025 10:33:08 +0200 Subject: [PATCH 2/5] Make it work for product and address review comments --- .../arguments/TestCompilerCounts.java | 49 +++++++++++-------- 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/test/hotspot/jtreg/compiler/arguments/TestCompilerCounts.java b/test/hotspot/jtreg/compiler/arguments/TestCompilerCounts.java index a5e9b27a284b6..0aaa0d37dbaf9 100644 --- a/test/hotspot/jtreg/compiler/arguments/TestCompilerCounts.java +++ b/test/hotspot/jtreg/compiler/arguments/TestCompilerCounts.java @@ -28,7 +28,17 @@ * @requires vm.flagless * @requires vm.bits == "64" * @requires vm.debug - * @run driver compiler.arguments.TestCompilerCounts + * @run driver compiler.arguments.TestCompilerCounts debug + */ + +/* + * @test + * @library /test/lib / + * @bug 8356000 + * @requires vm.flagless + * @requires vm.bits == "64" + * @requires !vm.debug + * @run driver compiler.arguments.TestCompilerCounts product */ package compiler.arguments; @@ -56,6 +66,8 @@ public class TestCompilerCounts { static final int MAX_LINEAR_CPUS = Math.min(16, MAX_CPUS); public static void main(String[] args) throws Throwable { + final boolean debug = args[0].startsWith("debug"); + // CICompilerCount=0 is incorrect in default modes. fail("-XX:CICompilerCount=0"); @@ -134,17 +146,17 @@ public static void main(String[] args) throws Throwable { pass(0, opt, "-XX:TieredStopAtLevel=0"); // Non-tiered modes - int c1OnlyCount = heuristicCount(cpus, Compilation.C1Only); - pass(c1OnlyCount, opt, "-XX:TieredStopAtLevel=1", "-XX:NonNMethodCodeHeapSize="+NonNMethodCodeHeapSize, "-XX:CodeCacheMinimumUseSpace="+CodeCacheMinimumUseSpace); - pass(c1OnlyCount, opt, "-XX:TieredStopAtLevel=2", "-XX:NonNMethodCodeHeapSize="+NonNMethodCodeHeapSize, "-XX:CodeCacheMinimumUseSpace="+CodeCacheMinimumUseSpace); - pass(c1OnlyCount, opt, "-XX:TieredStopAtLevel=3", "-XX:NonNMethodCodeHeapSize="+NonNMethodCodeHeapSize, "-XX:CodeCacheMinimumUseSpace="+CodeCacheMinimumUseSpace); - int c2OnlyCount = heuristicCount(cpus, Compilation.C2Only); - pass(c2OnlyCount, opt, "-XX:-TieredCompilation", "-XX:NonNMethodCodeHeapSize="+NonNMethodCodeHeapSize, "-XX:CodeCacheMinimumUseSpace="+CodeCacheMinimumUseSpace); + int c1OnlyCount = heuristicCount(cpus, Compilation.C1Only, debug); + pass(c1OnlyCount, opt, "-XX:TieredStopAtLevel=1", "-XX:NonNMethodCodeHeapSize=" + NonNMethodCodeHeapSize); + pass(c1OnlyCount, opt, "-XX:TieredStopAtLevel=2", "-XX:NonNMethodCodeHeapSize=" + NonNMethodCodeHeapSize); + pass(c1OnlyCount, opt, "-XX:TieredStopAtLevel=3", "-XX:NonNMethodCodeHeapSize=" + NonNMethodCodeHeapSize); + int c2OnlyCount = heuristicCount(cpus, Compilation.C2Only, debug); + pass(c2OnlyCount, opt, "-XX:-TieredCompilation", "-XX:NonNMethodCodeHeapSize=" + NonNMethodCodeHeapSize); // Tiered modes - int tieredCount = heuristicCount(cpus, Compilation.Tiered); - pass(tieredCount, opt, "-XX:NonNMethodCodeHeapSize="+NonNMethodCodeHeapSize, "-XX:CodeCacheMinimumUseSpace="+CodeCacheMinimumUseSpace); - pass(tieredCount, opt, "-XX:TieredStopAtLevel=4", "-XX:NonNMethodCodeHeapSize="+NonNMethodCodeHeapSize, "-XX:CodeCacheMinimumUseSpace="+CodeCacheMinimumUseSpace); + int tieredCount = heuristicCount(cpus, Compilation.Tiered, debug); + pass(tieredCount, opt, "-XX:NonNMethodCodeHeapSize=" + NonNMethodCodeHeapSize); + pass(tieredCount, opt, "-XX:TieredStopAtLevel=4", "-XX:NonNMethodCodeHeapSize=" + NonNMethodCodeHeapSize); // Also check that heuristics did not set up more threads than CPUs available Asserts.assertTrue(c1OnlyCount <= cpus, @@ -160,27 +172,23 @@ enum Compilation { Tiered, } - // Buffer sizes for caclulating the maximum number of compiler threads. + // Buffer sizes for calculating the maximum number of compiler threads. static final int NonNMethodCodeHeapSize = 5 * 1024 * 1024; static final int CodeCacheMinimumUseSpace = 400 * 1024; static final int C1BufSize = 64 * 1024 * 8 + (64 * 1024 * 8 / 10); - static final int C1MaxCount = (NonNMethodCodeHeapSize - 3 * CodeCacheMinimumUseSpace) / C1BufSize; static final int C2BufSize = 6544; - static final int C2MaxCount = (NonNMethodCodeHeapSize - 3 * CodeCacheMinimumUseSpace) / C2BufSize; static final int TieredBufSize = C1BufSize / 3 + 2 * C2BufSize / 3; - static final int TieredMaxCount = (NonNMethodCodeHeapSize - 3 * CodeCacheMinimumUseSpace) / TieredBufSize; - // Direct translation from CompilationPolicy::initialize: - public static int heuristicCount(int cpus, Compilation comp) { + public static int heuristicCount(int cpus, Compilation comp, boolean debug) { int log_cpu = log2(cpus); int loglog_cpu = log2(Math.max(log_cpu, 1)); int min_count = comp == Compilation.C1Only || comp == Compilation.C2Only ? 1 : 2; int count = Math.max(log_cpu * loglog_cpu * 3 / 2, min_count); - int max_count = switch (comp) { - case C1Only -> C1MaxCount; - case C2Only -> C2MaxCount; - case Tiered -> TieredMaxCount; + int max_count = (NonNMethodCodeHeapSize - (debug ? 3 : 1) * CodeCacheMinimumUseSpace) / switch (comp) { + case C1Only -> C1BufSize; + case C2Only -> C2BufSize; + case Tiered -> TieredBufSize; }; return Math.max(Math.min(count, max_count), min_count); @@ -199,5 +207,4 @@ public static void fail(String... args) throws Throwable { OutputAnalyzer output = new OutputAnalyzer(pb.start()); output.shouldNotHaveExitValue(0); } - } From 3cfb1f33c1ed5a984a27ea68b602bfb4f64e28cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20H=C3=A4ssig?= Date: Mon, 30 Jun 2025 10:46:25 +0200 Subject: [PATCH 3/5] Add copyright --- test/hotspot/jtreg/compiler/arguments/TestCompilerCounts.java | 1 + 1 file changed, 1 insertion(+) diff --git a/test/hotspot/jtreg/compiler/arguments/TestCompilerCounts.java b/test/hotspot/jtreg/compiler/arguments/TestCompilerCounts.java index 0aaa0d37dbaf9..4299428ee08f1 100644 --- a/test/hotspot/jtreg/compiler/arguments/TestCompilerCounts.java +++ b/test/hotspot/jtreg/compiler/arguments/TestCompilerCounts.java @@ -1,5 +1,6 @@ /* * Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. + * Copyright (c) 2025, 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 From 8beb5898f9ce882366ccbf537f3f9e42be8fec18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20H=C3=A4ssig?= Date: Mon, 30 Jun 2025 10:53:32 +0200 Subject: [PATCH 4/5] Remove superfluous newline --- 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 4299428ee08f1..e507a2ace63e1 100644 --- a/test/hotspot/jtreg/compiler/arguments/TestCompilerCounts.java +++ b/test/hotspot/jtreg/compiler/arguments/TestCompilerCounts.java @@ -192,7 +192,6 @@ public static int heuristicCount(int cpus, Compilation comp, boolean debug) { case Tiered -> TieredBufSize; }; return Math.max(Math.min(count, max_count), min_count); - } public static int log2(int v) { From 71767802dbde05fbf744b7ba0337c6b69bf6805e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20H=C3=A4ssig?= Date: Tue, 1 Jul 2025 08:47:57 +0200 Subject: [PATCH 5/5] Fix whitespace Co-authored-by: Andrey Turbanov --- 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 e507a2ace63e1..870daa7f0a56b 100644 --- a/test/hotspot/jtreg/compiler/arguments/TestCompilerCounts.java +++ b/test/hotspot/jtreg/compiler/arguments/TestCompilerCounts.java @@ -156,7 +156,7 @@ public static void main(String[] args) throws Throwable { // Tiered modes int tieredCount = heuristicCount(cpus, Compilation.Tiered, debug); - pass(tieredCount, opt, "-XX:NonNMethodCodeHeapSize=" + NonNMethodCodeHeapSize); + pass(tieredCount, opt, "-XX:NonNMethodCodeHeapSize=" + NonNMethodCodeHeapSize); pass(tieredCount, opt, "-XX:TieredStopAtLevel=4", "-XX:NonNMethodCodeHeapSize=" + NonNMethodCodeHeapSize); // Also check that heuristics did not set up more threads than CPUs available