JVM code cache exceeds ReservedCodeCacheSize

Tags: , ,



I have a java app running in a docker with flags on OpenJDK8:

-XX:+UseContainerSupport -XX:MaxRAMPercentage=80.0 -XX:NativeMemoryTracking=summary

and I’ve noticed that Code Cache memory allocation reported by Native Memory Tracking tool exceeds 240MB (default ReservedCodeCacheSize value):

jcmd 1 VM.native_memory summary | grep -i code
-                      Code (reserved=260013KB, committed=60465KB)

which is ~ 254MB reserved memory. Here’s printed flag and java version:

java -XX:+UnlockDiagnosticVMOptions -XX:+PrintFlagsFinal -version | grep -i reserved
    uintx ReservedCodeCacheSize                     = 251658240                           {pd product}
openjdk version "1.8.0_262"
OpenJDK Runtime Environment (build 1.8.0_262-b10)
OpenJDK 64-Bit Server VM (build 25.262-b10, mixed mode)

My question is if this is expected behavior? If yes, then is it possible to calculate actual limit for the max code cache size?

thanks!

Answer

Code in the Native Memory Tracking report accounts not just Code Cache, but also a few other things. The report includes:

  1. Fixed size spaces reserved with mmap:
    • Code Cache – 240 MB;
    • the map of the Code Cache segments – 1/64 of the Code Cache size = 3.75 MB.
  2. Auxiliary VM structures malloc‘ed in the native heap:
    • code strings, OopMaps, exception handler caches, adapter handler tables, and other structures for maintaining the generated code.

      These structures are allocated dynamically; there is no a dedicated limit for them, but usually they make up only a small portion of the total generated code (see malloc= line in the Code section of the NMT report).

Note that reserved memory does not actually consume resources other than the address space. For analyzing the real memory usage, committed is more relevant.



Source: stackoverflow