Backend Development 16 min read

Analyzing and Mitigating CPU Spikes During Java Application Deployment via JIT Optimization

The article explains that CPU spikes during Java deployments are caused mainly by HotSpot C2 JIT compiler threads, and demonstrates that tiered compilation, CodeCache sizing, JWarmUp pre‑warming, gradual traffic ramp‑up, and higher JIT compile thresholds together effectively smooth startup CPU usage.

Xianyu Technology
Xianyu Technology
Xianyu Technology
Analyzing and Mitigating CPU Spikes During Java Application Deployment via JIT Optimization

In typical application deployments or restarts, CPU usage can spike dramatically due to JVM class loading and object initialization, leading to performance instability. This article investigates the root causes of such CPU jitter in a messaging system and proposes mitigation strategies.

Java compilation consists of two phases: the javac compiler produces bytecode (compile‑time) and the interpreter/JIT executes it (run‑time). HotSpot combines an interpreter with a Just‑In‑Time (JIT) compiler (C1 and C2) to balance startup speed and execution efficiency.

Using Arthas for online diagnostics, the team observed that during deployment the C2 compiler threads consume a large portion of CPU, causing the spike. Two main thread types were identified: “VM Thread” (related to JVM shutdown, not the main cause) and C1/C2 CompilerThreads (the primary source of the spike).

Five mitigation methods were evaluated:

Layered compilation (mixed, full, tiered) – leveraging C1 for quick startup and C2 for deep optimization.

CodeCache tuning – monitoring and adjusting the size of the native code cache.

DragonWell (JWarmUp) – pre‑recording compilation data to warm up the JVM before traffic arrives.

Gradual traffic ramp‑up – limiting load during deployment to reduce concurrent JIT activity.

Adjusting JIT thresholds – increasing compile thresholds to spread compilation work over time.

Key findings include that raising the JIT compilation threshold significantly reduces the instantaneous CPU usage of C2 compiler threads, while still preserving overall performance. CodeCache monitoring via Arthas dashboards and JVM flags (e.g., -XX:+PrintCodeCache , -XX:ReservedCodeCacheSize=256M ) helps prevent cache‑related flushes that could also cause spikes.

Typical Arthas commands used:

curl -O https://arthas.aliyun.com/arthas-boot.jar

java -jar arthas-boot.jar

dashboard

Relevant JVM options:

-XX:+PrintCodeCache , -XX:ReservedCodeCacheSize=256M , -XX:+CompilationWarmUp , -XX:CompileThreshold=5000

In conclusion, a combination of tiered compilation, appropriate CodeCache sizing, JWarmUp, controlled traffic release, and tuned JIT thresholds provides an effective strategy to smooth CPU usage during Java application startup and redeployment.

JavaJVMJITCPU optimizationperformance tuningArthas
Xianyu Technology
Written by

Xianyu Technology

Official account of the Xianyu technology team

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.