When a JDK 25 HotSpot service slows after days of uptime and its stderr shows "CodeHeap 'non-profiled nmethods' is full. Compiler has been disabled.", what happened, and how do you confirm and fix it?
answer
- where JIT output lives
- three code heaps
- stopped_count and max_used
- 240 MB under tiered
basics
~20 sThe JIT's code cache segment for optimised code filled, so HotSpot stopped compiling and new or recompiled hot methods run slower code. Confirm with jcmd Compiler.codecache and the CodeCacheFull event, then size the cache from max_used with headroom.
solid answer
~50 sCompiled methods live in the **code cache**, a native region of fixed maximum size. On JDK 25 with tiered compilation it defaults to `ReservedCodeCacheSize` of 240 MB on x86-64 and AArch64 and is segmented into three code heaps: `non-nmethods`, `profiled nmethods` and `non-profiled nmethods`. The warning means the heap for non-profiled code, where C2's fully optimised methods live, filled, so the compile broker stopped compiling. With `UseCodeCacheFlushing` on by default it restarts once unloading frees space, but meanwhile newly hot or deoptimised methods stay at a slower tier, which is the slowdown. I confirm with `jcmd <pid> Compiler.codecache`: per-heap `size`, `used`, `max_used`, `free`, and a `Compilation:` line with `stopped_count` and `restarted_count`; JFR's `jdk.CodeCacheFull` dates it. Then I look for churn or code generation, and size the cache, or the heap the second warning line names, above observed `max_used`.
code
console · 2 linesOpenJDK 64-Bit Server VM warning: CodeHeap 'non-profiled nmethods' is full. Compiler has been disabled.
OpenJDK 64-Bit Server VM warning: Try increasing the code heap size using -XX:NonProfiledCodeHeapSize=go deeper
Recall that the JIT stores compiled methods in a native area called the code cache, separate from the Java heap.
Explain the three segmented code heaps, the 240 MB tiered default, and that a full heap stops new compilations rather than crashing the JVM.
Prove it from evidence, using the warning, Compiler.codecache's max_used and stopped_count, and the CodeCacheFull event, then separate a cache that is too small from compilation churn before sizing it.
Decide whether services with heavy generated code get an explicit code cache size and an alert on CodeCacheFull, accepting the extra native memory in their container budget.
## What the code cache is When HotSpot's just-in-time compilers turn a hot method into machine code, the result (an **nmethod**) is stored in the **code cache**, a region of native memory outside the Java heap with a fixed maximum size. Interpreter stubs, adapters and other generated code (the **non-nmethods**) live there too. NMT reports the region under its **Code** category. On JDK 25 the sizing works like this: - The platform default for `ReservedCodeCacheSize` is 48 MB on both x86-64 and AArch64. - With **tiered compilation** (the default), the JVM multiplies it by five at startup, capped at 2 GB, giving **240 MB**, because tiered compiles far more code. - Because the cache is then at least 240 MB, the JVM turns on `SegmentedCodeCache` ergonomically, splitting it into three **code heaps**: | Code heap | Holds | Sizing flag | |---|---|---| | `non-nmethods` | interpreter, stubs, adapters | `NonNMethodCodeHeapSize` | | `profiled nmethods` | tier 2 and tier 3 code: C1-compiled methods that still collect profiles | `ProfiledCodeHeapSize` | | `non-profiled nmethods` | tier 1 and tier 4 code: C2-optimised methods and C1 code compiled without profiling, plus native method wrappers | `NonProfiledCodeHeapSize` | ## What the warning means When one code heap has no room for a new nmethod, HotSpot prints two warnings on stderr (also logged under the `codecache` tag): ```console OpenJDK 64-Bit Server VM warning: CodeHeap 'non-profiled nmethods' is full. Compiler has been disabled. OpenJDK 64-Bit Server VM warning: Try increasing the code heap size using -XX:NonProfiledCodeHeapSize= ``` With segmentation off, the text is `CodeCache is full. Compiler has been disabled.` and it points at `ReservedCodeCacheSize`. What happens next depends on `UseCodeCacheFlushing`, which is **on by default**. The compile broker **stops** new compilations, and when code unloading later frees memory it **restarts** them, logging `Restarting compiler` and emitting a `jdk.JITRestart` JFR event. With flushing off, compilation is disabled for good. Either way the JVM keeps running: code already compiled still executes, but methods that become hot, or that are deoptimised and need recompiling, stay interpreted or at a lower tier. That is why the symptom is a gradual slowdown and higher CPU, not a crash. (Running out of room for stubs or adapters can end the VM with a `CodeCache: no room for …` error, but that is a different and much rarer failure.) ## Confirming it 1. **Find the warning** in stderr or the `codecache` log, and note when it first appeared. 2. **Read the layout** with `jcmd <pid> Compiler.codecache`. Each heap prints `size`, `used`, `max_used` and `free`, then the totals with `full_count`, and a line such as `Compilation: disabled (not enough contiguous free space left), stopped_count=1, restarted_count=0`. 3. **Date it from JFR**: the `jdk.CodeCacheFull` event is enabled in the default recording settings and records which heap filled. 4. **Correlate with the slowdown**: a latency or CPU step that begins at the first full event, rather than at a deploy or a traffic change, ties the two together. ## Too small, or churning? Two different causes produce the same warning: - **A working set larger than the cache.** Large applications, heavy use of generated classes and frameworks that create many small methods can need more than the default. `max_used` sits at `size` and stays there. - **Churn.** Repeated deoptimisation and recompilation, or code generated and discarded, keeps refilling the cache. `stopped_count` and `restarted_count` both climb, and compilation logs show the same methods compiled again and again. Churn is fixed at its source; a larger cache only delays the next fill. ## Where else it shows - **NMT**, if enabled: the Code category's committed figure sits close to its reserved size, and a `summary.diff` shows it rising until the fill. - **The `codecache` log tag**: `-Xlog:codecache` records the full warning and, at info level, `Code cache is full - disabling compilation` and `Restarting compiler`, which gives the stop and restart times without a recording. - **JFR**: `jdk.JITRestart` events after `jdk.CodeCacheFull` show whether the compiler came back on its own. ## Fixing it - Size the cache from evidence: the observed `max_used` per heap plus headroom, set with `ReservedCodeCacheSize` or the specific heap flag the second warning names. - Remember that the code cache is native memory: what fills it is committed and counts toward the container's limit, so include it in the memory budget. - Do not switch tiered compilation off to save space; that slows warm-up for a smaller cache and hides the real cause. - Keep the `jdk.CodeCacheFull` event in continuous recordings so the next occurrence is dated without a reproduction.
- Why does the message name a CodeHeap rather than say CodeCache is full?Under tiered compilation the JVM turns on `SegmentedCodeCache` ergonomically when the reserved cache is at least 240 MB, which it is by default. Each code heap fills independently, so the warning names the heap and suggests its own flag, here `NonProfiledCodeHeapSize`. With segmentation off there is one cache and the message reads `CodeCache is full. Compiler has been disabled.` with a pointer to `ReservedCodeCacheSize`.
- Is raising ReservedCodeCacheSize free?Reserving more address space is cheap, but every byte of compiled code that fills it is committed native memory, reported in NMT's Code category and charged against the container. So size it from evidence: the observed `max_used` per heap plus headroom, and first rule out churn, such as repeated deoptimisation and recompilation or generated classes being compiled and discarded.
- How can you tell whether compilation recovered by itself?With flushing on, HotSpot logs `Restarting compiler` under the `codecache` log tag and emits a `jdk.JITRestart` JFR event when freed space lets it compile again, and `restarted_count` in `Compiler.codecache` rises. A `stopped_count` that keeps climbing while `max_used` sits near `size` means the cache is simply too small for the working set of compiled code.
- A full code heap for compiled methods makes the JVM crash or throw OutOfMemoryError.
- Once the compiler is disabled it can never restart without a JVM restart.
- The default code cache is 48 MB, so it should always be raised.
- A code cache problem would show up in the Java heap's usage graph.
- The fix is to switch tiered compilation off to save code space.
Assumes JDK 25 HotSpot with tiered compilation, where the code cache defaults to 240 MB and is segmented; with segmentation off the message reads CodeCache is full instead.