Quick revision
The short answer
The log line means the code cache, where JIT-compiled machine code lives, has no room left, so the JIT has stopped: new hot methods stay interpreted or at a low tier, and methods whose compiled code is thrown away after deoptimisation cannot be compiled again, which is why latency gets worse hour by hour. We confirm it with jcmd Compiler.codecache, the CodeHeap memory pools and the compilation log, then raise ReservedCodeCacheSize and find out why so much code is being compiled, for example classes generated per request.
What to remember
In this answer, we saw that CodeCache is full. Compiler has been disabled. means the JIT has nowhere to put new machine code, so new hot methods and deoptimised methods stay slow, and latency degrades hour by hour. Large applications, generated classes and deoptimise and recompile churn fill the cache. We confirm with jcmd Compiler.codecache, the CodeHeap pools and compilation logs, raise ReservedCodeCacheSize, fix runaway code generation, and make sure the bigger Code category fits in the container budget.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
The log line means the code cache, where JIT-compiled machine code lives, has no room left, so the JIT has stopped: new hot methods stay interpreted or at a low tier, and methods whose compiled code is thrown away after deoptimisation cannot be compiled again, which is why latency gets worse hour by hour. We confirm it with jcmd Compiler.codecache, the CodeHeap memory pools and the compilation log, then raise ReservedCodeCacheSize and find out why so much code is being compiled, for example classes generated per request.
Why this question is asked
This is a slow failure that confuses people. The service does not crash and the heap looks normal, but every hour it is a bit slower, and a restart makes the problem go away for a while. Interviewers ask it because diagnosing it needs an understanding of how the JIT behaves over a service's lifetime, not just a flag. In this answer, we will recap the role of the code cache, explain why a full cache degrades latency gradually, look at the usual causes, confirm the diagnosis with tools, and then fix it, including how it fits into the container's memory budget.
1A Quick Recap: Where the JIT Puts Its Work
HotSpot starts every method in the interpreter. Methods that are called often are compiled by C1, with profiling, and the hottest are later compiled by C2 into highly optimised machine code. All of that machine code goes into the code cache, a native memory area whose maximum size is set by ReservedCodeCacheSize, 240 MB by default with tiered compilation on most 64-bit platforms.
Compiled code is not permanent. C2 makes assumptions, for example that a call site only ever sees one type. When an assumption breaks, the JVM deoptimises the method, throws away its compiled code, goes back to the interpreter, and later compiles it again with the new information. A healthy service compiles, deoptimises and recompiles all the time, and that needs free space.
2Why Latency Degrades Gradually
When the cache is full, HotSpot prints the warning and disables the compiler. Nothing that is already compiled is lost, so the service keeps working at first. But from that moment, every method that becomes hot stays in the interpreter or in C1 code, which can be ten times slower than C2 code. Every time an existing compiled method is deoptimised, for example because a new code path starts receiving traffic, it falls back to the interpreter and cannot be compiled again.
So the share of slow code grows with every deoptimisation and every newly hot path. That is exactly the gradual degradation over hours that we see, and it explains why a restart helps: a fresh JVM has an empty code cache.
- Code cache reaches its limitNo room for new compiled methods
- Compiler disabled
CodeCacheis full. Compiler has been disabled. - New hot methods stay interpretedOr stay at a low C1 tier
- Deoptimised methods lose their codeThey cannot be recompiled
- Share of slow code grows each hourLatency creeps up until a restart
5 steps in order. Play them, or step through them one at a time.
3What Fills the Code Cache
The first cause is sheer size: a large monolith with many frameworks can have tens of thousands of hot methods, and the default cache simply is not big enough. The second is generated code. Libraries that generate classes at runtime, such as dynamic proxies, bytecode-generated serializers, scripting engines or expression languages compiled per request, create new methods that the JIT then compiles. If a class is generated per request instead of once, the amount of code grows without end. The third is churn: frequent deoptimise and recompile cycles, often caused by highly polymorphic call sites, keep producing new versions of the same methods.
4Confirming the Diagnosis
We check the cache directly and look at what is being compiled. The compilation log shows which methods are compiled and whether they are being made not entrant, which is HotSpot's word for code that was thrown away.
In monitoring, the memory pools named CodeHeap show the same story: used climbing to the size of the segment over days, then flat. Java Flight Recorder also records code cache events, which helps when we cannot attach jcmd at the right time.
5Fixing It, and Budgeting the Memory
The immediate fix is a larger cache. For a large application, ReservedCodeCacheSize of 512 MB is common; we then watch the CodeHeap pools to confirm that usage levels off with room to spare.
The lasting fix is to understand why so much code is compiled. If a template engine compiles a template on every request, or a library builds a new proxy class per call, the fix is to cache the generated class or template, so the code is created once. If deoptimisation churn is high, the compilation log shows which methods keep being recompiled, and the cause is usually a call site that sees many types.
Finally, the code cache is native memory and counts against the container's limit. Native memory tracking shows it as the Code category. If we raise the cache from 240 to 512 MB, the container limit or the heap percentage must leave room for the extra committed code, or we will trade a slow service for a killed one.
6Follow-up questions
Why can this appear only after days of uptime?
Because compiled code accumulates slowly. Some code paths only become hot at certain times, such as nightly batch jobs, month-end reports or rare customer features. Generated classes pile up as traffic arrives, and every deoptimisation leaves room only if the old code is freed in time. On top of that, the cache fragments, so even with some free space there may be no block large enough for a big method. After days, all of these together reach the limit, and a restart resets them, which is why the problem seems to come back on a schedule.
Can the JVM free code on its own?
Yes. Unused and not-entrant compiled code is reclaimed, and in recent JDKs this happens as part of GC class unloading and code cache cleanup. But if the live amount of compiled code is genuinely larger than the cache, freeing cannot keep up, and the compiler stays disabled.
Would turning off tiered compilation help?
It reduces code cache use because there is no profiled C1 code, but it also slows warmup and gives up profiling data for C2. It is rarely the right answer for a server; a bigger cache and less generated code are better fixes.
7Conclusion
In this answer, we saw that CodeCache is full. Compiler has been disabled. means the JIT has nowhere to put new machine code, so new hot methods and deoptimised methods stay slow, and latency degrades hour by hour. Large applications, generated classes and deoptimise and recompile churn fill the cache. We confirm with jcmd Compiler.codecache, the CodeHeap pools and compilation logs, raise ReservedCodeCacheSize, fix runaway code generation, and make sure the bigger Code category fits in the container budget.
Open with
That message means the code cache, where the JIT stores machine code, has no free space, so HotSpot has disabled compilation. The service keeps running with the code it has, but any method that becomes hot afterwards stays in the interpreter or in C1 code, and whenever a compiled method is deoptimised, because an assumption like a single receiver type breaks, it falls back to the interpreter and cannot be recompiled.
Then, if they want more
So the share of slow code grows over time, which is the gradual latency increase we see, and a restart hides it because the cache starts empty. The usual causes are a very large application with many hot methods, classes generated at runtime, especially per request, and constant deoptimise and recompile cycles.
I would confirm it with jcmd Compiler.codecache, which shows each segment full and compilation disabled, check the CodeHeap memory pools in monitoring to see the climb over days, and look at the compilation log and class counts for generated code.
The fix has two parts: raise ReservedCodeCacheSize, for example to 512 MB, and find why so much code is compiled, such as caching generated templates or proxies instead of creating them per request. Since the code cache is native memory, I would check the Code category in native memory tracking and make sure it fits in the container's budget.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "A large service logs "CodeCache is full. Compiler has been disabled." and latency...": https://scrivio-interview-library.netlify.app/java/memory-layout/11cb49c7c5/