tune memory-related jvm flags for better memory reclamation after build end (relates to MRI-2736)

-- obsolete flags removed
   explicitly specify G1GC as the most optimal for memory reclamation

GitOrigin-RevId: cb7dba8446b9b4003181c9824358bb973bf4b32b
This commit is contained in:
Eugene Zhuravlev
2026-03-27 09:22:40 +00:00
committed by intellij-monorepo-bot
parent 720fc560cf
commit 142141f4b2
+26 -19
View File
@@ -1,16 +1,29 @@
def get_jvm_flags(flags):
return [
# Memory
# "-XX:+UseZGC",
# "-XX:+ZGenerational",
"-Xms4g",
# G1GC works best for builds with small to medium amount of changes; returns unused committed heap pages to the OS when idle (JEP 346)
"-XX:+UseG1GC",
# Grow heap when less than 40% free memory is available; after GC allow max 40% of unused memory and reclaim the rest of committed memory to OS
# setting values too low might lead to more frequent GCs during work
"-XX:MinHeapFreeRatio=40",
"-XX:MaxHeapFreeRatio=40",
# Generational ZGC works good for bigger builds, but is less optimal for small and medium builds; returns unused committed heap pages to the OS when idle
#"-XX:+UseZGC",
#"-XX:+ZGenerational",
#"-XX:ZUncommitDelay=10", # reclaim unused memory in 10 secs
#"-XX:SoftMaxHeapSize=2g", # try to keep heap compact under 2 Gbytes
"-Xmx20g",
"-Xms256m",
# IJ PSI cache
"-XX:SoftRefLRUPolicyMSPerMB=50",
# Code Cache
"-XX:NonProfiledCodeHeapSize=512m",
"-XX:ProfiledCodeHeapSize=512m",
"-XX:ReservedCodeCacheSize=2048m",
# Code Cache (JDK defaults are sufficient — 240m total, auto-segmented)
#"-XX:NonProfiledCodeHeapSize=512m",
#"-XX:ProfiledCodeHeapSize=512m",
#"-XX:ReservedCodeCacheSize=2048m",
# Prevent JVM logging warnings and errors to stdout because it breaks the protocol between Bazel and the worker process
"-XX:+DisplayVMOutputToStderr",
"-Xlog:disable",
@@ -18,23 +31,17 @@ def get_jvm_flags(flags):
# Headless
"-Djava.awt.headless=true",
"-Dapple.awt.UIElement=true",
# IJ PHM
"--add-opens=java.base/java.util.concurrent=ALL-UNNAMED",
"--add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED",
"--add-opens=java.base/java.util.concurrent.locks=ALL-UNNAMED",
"--add-opens=java.base/java.nio=ALL-UNNAMED",
# Allow querying OS-specific error message for hardlinks-related error detection on Windows
"--add-opens=java.base/java.nio=ALL-UNNAMED",
"--add-opens=java.base/sun.nio.fs=ALL-UNNAMED",
# Apache Arrow, but we already opened java.nio for PHM
# "--add-opens=java.base/java.nio=org.apache.arrow.memory.core,ALL-UNNAMED",
# kotlin compiler
"-Dkotlin.environment.keepalive=true",
# temporarily disabled to fix build on Windows, JBR-9260
"-Djbr.java.io.use.nio=false",
# https://github.com/netty/netty/issues/11532
"-Dio.netty.tryReflectionSetAccessible=true",
# see TargetConfigurationDigestProperty.KOTLIN_VERSION - we invalidate cache if kotlinc version changed
"-Dkotlin.jps.skip.cache.version.check=true",
# Set UTF-8 by default as per https://openjdk.org/jeps/400
"-Dfile.encoding=UTF-8",
] + flags