Skip to content

8356000: C1/C2-only modes use 2 compiler threads on low CPU count machines #24972

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions src/hotspot/share/compiler/compilationPolicy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be the general rule: don't create more compiler threads than available cpus?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Except when specified on command line with -XX:CICompilerCount=n.
Actually your changes does not take this flag into account.

FLAG_SET_ERGO(CICompilerCount, count);
}
#else
Expand All @@ -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);
Expand Down
68 changes: 68 additions & 0 deletions test/hotspot/jtreg/compiler/arguments/TestCompilerCounts.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* 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
*
* @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 {
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,
"-version"
};
ProcessBuilder pb = ProcessTools.createLimitedTestJavaProcessBuilder(args);
OutputAnalyzer output = new OutputAnalyzer(pb.start());
output.shouldHaveExitValue(0);
}
}

}