Apache Tomcat JVM Sizing & Configuration Compiler
Mathematical memory budgeting, platform-isolated compilation (POSIX Shell & Windows Batch), and diagnostic hardening.
1. Target Architecture & Runtime Environment
Deployment Environment Profile
What it does: Governs OS memory reserve (Mreserve) and target heap allocation ratios.
Formulas: Dedicated: 20% (min 2GB) | Container: 15% (min 512MB) | Shared: 35% (min 4GB) | Constrained (≤ 4 GB): 25%.
Discovery: Check your hosting SLA or hypervisor allocation.
Java Runtime Version
What it does: Validates Garbage Collector syntax and removes deprecated JVM parameters.
Discovery: Run java -version or echo $JAVA_HOME on target host.
Compatibility: Generational ZGC requires JDK 21+. CMS is blocked on JDK 17+.
Tomcat Launch Mode
Critical Notice: Windows Services (Procrun / tomcat.exe) BYPASS setenv.bat!
Resolution: Service options must be registered via tomcat10w.exe //ES//Tomcat10 or service installation script.
JVM Garbage Collector
G1GC: Standard default for web heaps 2GB-32GB+.
ZGC / GenZGC: Ultra-low pause times (<1ms). Auto-activates Generational mode on Java 21.
ParallelGC: Highest throughput for offline batch processing.
2. Resource Budgeting & Sizing Engine
Effective Memory Pool (Meffective)
What it does: Total physical RAM or Container Cgroup limit (R).
Discovery (Linux): free -g or cat /sys/fs/cgroup/memory.max
Discovery (Windows): (Get-CimInstance Win32_ComputerSystem).TotalPhysicalMemory / 1GB
Initial vs Maximum Heap
Fixed (-Xms == -Xmx): Pre-allocates heap at startup to eliminate runtime OS paging and GC expansion pauses.
Elastic (Xms = 50% Xmx): Yields unused physical memory back to host until load spikes.
Max Metaspace (-XX:MaxMetaspaceSize)
Minimal (256MB): Microservices / static servlets.
Standard (512MB): Spring Boot, Jakarta EE applications.
Complex (1024MB): Heavy reflection, Hibernate, dynamic proxies.
Unbounded: Omitted from CLI, allowing JVM dynamic growth.
Thread Call Stacks & Direct Memory
Stack Memory: Nthreads × 1 MB (200 threads = ~0.2 GB).
Direct Memory: 0.5 GB default buffer for NIO socket byte buffers.
3. Java Runtime Paths & Diagnostic Telemetry
JAVA_HOME Path
POSIX: /usr/lib/jvm/java-17-openjdk-amd64 or /opt/java/jdk-17
Windows: C:\Program Files\Java\jdk-17
Safety: Quotes and escape sequences are safely transpiled.
OutOfMemoryError Diagnostic Dump
Capacity Rule: Storage mount must have free space ≥ Xmx × 1.25.
Security: Contains raw decrypted memory state. Restrict permissions strictly (chmod 750).
-XX:HeapDumpPath.
Application Timezone
Standardizes JVM timestamps across servers regardless of local host OS timezone.
Custom JVM Arguments
Add Spring profiles, APM agents, or JMX flags:
-Dspring.profiles.active=prod -javaagent:/opt/opentelemetry-javaagent.jar
CATALINA_OPTS with safe space tokenization.