Usage:
This flag allows the JVM to set the maximum size of the reserved code cache.
-XX:ReservedCodeCacheSize=value, where value is the size in bytes
Since:
Starting from JDK 6.
Examples:
This will instruct JVM to set the maximum of the reserved code cache to 512 Megabytes:
-XX:ReservedCodeCacheSize=512M
Description:
JVM compiles the bytecodes (which are converted by the Java compiler “javac” from the source code) to native code and load it to the code cache. A native code can be called a nmethod if this code is executable (a nmethod can represent a java or inlined method). Considerably, the Just-In-Time (JIT) compiler is the major consumer of code cache
When running the JVM, it has a default value for code cache size. The following table display the default value for each code cache option:
As we can see in the table above, the JVM has a fixed size for code cache. Once the code cache is full, the JIT compiler stop which makes the JVM to stop compiling code and you will see on the terminal output a warning stating that the “Code Cache is Full”. This will result in a reduced performance. To fix this issue, you should only increase the initial, reserved Code Cache or the expansion size in the table above.
For increasing the code cache, JVM introduced the flag “ReservedCodeCacheSize” since JDK 6 which can adjust (expand or resize) directly the size of code cache.
You can also specify a data unit such as “k” or “K” for kilobytes, “m” or “M” for Megabytes and “g” or “G” for Gigabytes.
- For using 512 Kilobytes: -XX:ReservedCodeCacheSize=512k
- For using 128 Megabytes: -XX:ReservedCodeCacheSize=128m
- For using 12 Gigabytes: -XX:ReservedCodeCacheSize=12g
Default Value:
The default value depends on the version of the JDK running, for JDK 8 & 11 is 240M.
Note:
You can print the usage of the code cache with this argument “-XX:+PrintCodeCache”.
You can run this following command without having a MainClass:
java -XX:+PrintCodeCache -version
It will display to you a similar output like the following:
- size: represents the maximum value of this memory area (Size set by the flag “ReservedCodeCacheSize”).
- used: the actual memory size currently used by this region.
- max_used: the historical maximum usage since the program was started
- free: unused free space in this area
The flag “PrintCodeCache” is very useful for the following cases:
- See when flushing occurs
- Determine if memory usage has reached a critical point
Arguments related:
InitialCodeCacheSize, UseCodeCacheFlushing
Related Posts:
Edit your Comment