Fundamentals 15 min read

JVM JIT and CodeCache Parameter Configuration Guide

This article explains the JVM's Just‑In‑Time compilation mechanism and CodeCache memory area, detailing the purpose and default values of key JIT parameters such as TieredCompilation, CompileThreshold, OnStackReplacePercentage, CICompilerCount, as well as CodeCache settings like InitialCodeCacheSize, ReservedCodeCacheSize, Xmaxjitcodesize, CodeCacheMinimumFreeSpace and UseCodeCacheFlushing, and provides practical tuning advice for high‑traffic Java services.

Sohu Tech Products
Sohu Tech Products
Sohu Tech Products
JVM JIT and CodeCache Parameter Configuration Guide

Preface

The article continues a series on JVM configuration, focusing on the JIT compiler and the CodeCache memory region after covering heap and metaspace settings.

JIT (Just‑In‑Time)

Java source is first compiled by a front‑end compiler (e.g., javac ) into bytecode; at runtime a back‑end compiler (the JIT) translates hot bytecode into native machine code to improve performance.

JIT Parameter Configuration

Four main flags control JIT behavior: TieredCompilation, CompileThreshold, OnStackReplacePercentage, and CICompilerCount.

TieredCompilation

Enables or disables tiered (multi‑level) compilation.

-XX:+TieredCompilation  // enable
-XX:-TieredCompilation // disable

Enabled by default on JDK 8+; it allows the JVM to use a fast C1 compiler first and later switch to the optimizing C2 compiler.

CompileThreshold

Specifies how many interpreter executions of a method must occur before it is JIT‑compiled.

-XX:CompileThreshold=10000

Default is 10 000 in Server mode and 1 500 in Client mode (JDK 8).

OnStackReplacePercentage

Controls when OSR (On‑Stack Replacement) compilation of hot loops is triggered.

-XX:OnStackReplacePercentage=140

Typical defaults: 140 for Server, 933 for Client. OSR thresholds are calculated from CompileThreshold and this percentage.

CICompilerCount

Sets the number of concurrent JIT compilation threads.

-XX:CICompilerCount=2

The default adapts to the number of CPU cores.

CodeCache

CodeCache stores the native code generated by the JIT and other dynamically generated code (e.g., JNI). If it fills up, JIT compilation stops and performance degrades.

CodeCache Parameter Configuration

Five flags control the size and behavior of CodeCache.

InitialCodeCacheSize

Initial size of the CodeCache region.

-XX:InitialCodeCacheSize=10M

On Linux the default is about 2.44 MiB.

ReservedCodeCacheSize

Maximum size of CodeCache.

-XX:ReservedCodeCacheSize=240M

Defaults to 48 MiB without tiered compilation and 240 MiB when tiered compilation is enabled.

Xmaxjitcodesize

Alternative flag for the maximum CodeCache size.

-Xmaxjitcodesize20M

CodeCacheMinimumFreeSpace

When free space falls below this value, JIT compilation is halted.

-XX:CodeCacheMinimumFreeSpace=1M

Default on Linux is 500 KiB.

UseCodeCacheFlushing

Enables automatic eviction of old compiled code when the cache is full, preventing the JVM from staying in interpreted‑only mode.

Issues with this flag existed in JDK 7 but were fixed in JDK 8.

JIT Tuning Recommendations

For low‑traffic services the default JIT settings are usually sufficient. In high‑traffic, concurrent environments, avoid sudden traffic spikes that can trigger massive JIT compilation, which may temporarily raise CPU load and latency. Gradually ramp up traffic to allow JIT warm‑up.

CodeCache Tuning Recommendations

Monitor CodeCache usage; if it becomes full, the compiler is disabled and performance drops dramatically. Adjust the size parameters based on observed workload to keep the cache from filling.

Conclusion

The article summarized the importance of JIT and CodeCache for JVM performance, highlighted which parameters matter for large‑scale services, and provided practical guidance for configuring them.

JavaJVMJITPerformance TuningHotSpotCodeCache
Sohu Tech Products
Written by

Sohu Tech Products

A knowledge-sharing platform for Sohu's technology products. As a leading Chinese internet brand with media, video, search, and gaming services and over 700 million users, Sohu continuously drives tech innovation and practice. We’ll share practical insights and tech news here.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.