Scrivio Interview library
DebuggingIntermediate6 min read · updated 12 November 2026

A large service logs "CodeCache is full. Compiler has been disabled." and latency degrades gradually over the following hours. Explain what is happening and how you fix it.

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.

Step throughHow a full code cache turns into slow latency
  1. Code cache reaches its limitNo room for new compiled methods
  2. Compiler disabledCodeCache is full. Compiler has been disabled.
  3. New hot methods stay interpretedOr stay at a low C1 tier
  4. Deoptimised methods lose their codeThey cannot be recompiled
  5. 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.

Shell
jcmd 4711 Compiler.codecache
# CodeHeap 'non-profiled nmethods': size=119168Kb used=119100Kb max_used=119168Kb free=68Kb
# CodeHeap 'profiled nmethods': size=119164Kb used=118990Kb max_used=119164Kb free=174Kb
# compilation: disabled (not enough contiguous free space left)
# Which classes keep appearing? A rising count of generated classes is a clue
jcmd 4711 VM.classloader_stats
jcmd 4711 GC.class_histogram | grep -i -E 'proxy|generated|lambda' | head
# Compilation activity (diagnostic output, use in a test environment)
java -XX:+PrintCompilation -jar app.jar | grep 'made not entrant' | wc -l

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.

Text
# Before: default 240 MB, cache full after about three days
# After:
-XX:ReservedCodeCacheSize=512m
-XX:NativeMemoryTracking=summary
jcmd 4711 VM.native_memory summary | grep -A1 Code
# - Code (reserved=528MB, committed=310MB) <- must fit into the container budget

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.

What to say in the interviewAbout 90 seconds aloud

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/