From f2ef809719cbb14f90a0a5f673e10e7c74fa0f45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20H=C3=A4ssig?= Date: Wed, 25 Jun 2025 13:00:08 +0000 Subject: [PATCH] 8354727: CompilationPolicy creates too many compiler threads when code cache space is scarce Co-authored-by: Aleksey Shipilev Reviewed-by: kvn, shade --- src/hotspot/share/compiler/compilationPolicy.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/hotspot/share/compiler/compilationPolicy.cpp b/src/hotspot/share/compiler/compilationPolicy.cpp index 02dec8d957b..fd1357398f5 100644 --- a/src/hotspot/share/compiler/compilationPolicy.cpp +++ b/src/hotspot/share/compiler/compilationPolicy.cpp @@ -571,8 +571,15 @@ 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 max_count = (ReservedCodeCacheSize - (CodeCacheMinimumUseSpace DEBUG_ONLY(* 3))) / buffer_size; + 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; + } + size_t max_count = (NonNMethodCodeHeapSize - (CodeCacheMinimumUseSpace DEBUG_ONLY(* 3))) / buffer_size; if ((size_t)count > max_count) { // Lower the compiler count such that all buffers fit into the code cache count = MAX2((int)max_count, min_count); @@ -591,7 +598,7 @@ void CompilationPolicy::initialize() { count = 3; FLAG_SET_ERGO(CICompilerCount, count); } -#endif +#endif // _LP64 if (c1_only) { // No C2 compiler threads are needed