Java 21 Memory Calculator

Optimized for Java 21 with support for G1 and ZGC garbage collectors.

Memory Distribution

Heap Memory: 384MB

Young Generation: 154MB
Old Generation: 230MB

Non-Heap Memory: 344MB

Metaspace: 150MB
Code Cache: 64MB
Thread Stacks: 85MB
Compressed Class: 45MB

Other Memory: 44MB

Direct Buffers: 10MB
Native Memory: 22MB
JVM Overhead: 12MB
Recommended Total Memory: 776MB
Includes a safety margin of 4MB (0.52%)

Recommended JVM Parameters for Java 21

  • -Xms268m -Xmx384m
  • -XX:+UseG1GC
  • -XX:MaxGCPauseMillis=200
  • -Xss1M
  • -XX:ReservedCodeCacheSize=64m
  • -XX:MaxDirectMemorySize=10m
  • -XX:+ExitOnOutOfMemoryError
  • -XX:+UnlockDiagnosticVMOptions
  • -XX:NativeMemoryTracking=summary
  • -XX:+PrintNMTStatistics