Java / JVM Architecture (Java21) Interview questions
What is the JVM Code Cache, and why can it become a problem?
The Code Cache is the native-memory region where the JIT compiler stores the compiled native machine code it generates for hot methods, separate from both the heap and Metaspace.
It has a fixed maximum size controlled by -XX:ReservedCodeCacheSize, with tiered compilation enabled the default is typically 240MB, split internally into segments for non-method code, profiled code, and non-profiled code.
If the Code Cache fills up, the JVM cannot compile any further methods - it prints a "CodeCache is full" warning and falls back to running everything through the interpreter or already-compiled code, which can cause a sudden, hard-to-diagnose throughput regression in applications with a very large number of distinct hot methods, such as ones generated heavily by proxies or dynamic bytecode frameworks.
The fix is usually to raise -XX:ReservedCodeCacheSize and monitor cache usage, since simply adding more heap memory does nothing for this particular limit.
More Related questions...