Thursday, 14 February 2019

java.lang.VirtualMachineError: out of space in CodeCache for adapters

Code Cache issue:

We are getting below exception “java.lang.VirtualMachineError: out of space in CodeCache” error on JBoss instance

Error log:
 11:19:08,460 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/WebApplication].[default]] (ajp-/ Servlet.service() for servlet default threw exception: java.lang.VirtualMachineError: out of space in CodeCache for adapters
at java.lang.Class.getDeclaredConstructors0(Native Method) [rt.jar:1.6.0_35]
at java.lang.Class.privateGetDeclaredConstructors( [rt.jar:1.6.0_35]
at java.lang.Class.getDeclaredConstructors( [rt.jar:1.6.0_35]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors( [spring-beans.jar:3.1.1.RELEASE]
at [spring-beans.jar:3.1.1.RELEASE]
at [spring-beans.jar:3.1.1.RELEASE]
at [spring-beans.jar:3.1.1.RELEASE]
at [spring-beans.jar:3.1.1.RELEASE]
at [spring-beans.jar:3.1.1.RELEASE]
at [spring-beans.jar:3.1.1.RELEASE]

What is CodeCache ??
The Java Virtual Machine (JVM) generates native (compiled) code and stores it in a memory area called the codecache. The code cache is where jar definitions are stored.
The default maximum size of the CodeCache on most of the platforms is 48M. If any application needs to compile a large number of methods resulting in a huge amount of compiled code then this CodeCache may become full. 
You can set the code cache size by setting the property -XX:ReservedCodeCacheSize and monitor it by tools like JConsole. When the code cache becomes full, the Java VM flushes and sweeps it. In Java 7 and higher, code cache flushing is enabled by default.

Codecache Size Options:-

160K (varies)
Initial code cache size (in bytes)
Reserved code cache size (in bytes) - maximum code cache size
Code cache expansion size (in bytes)

Steps to check CodeCache Size in JBOSS:

Step 1: Locate to $JBOSS_Home/bin

Step 2: Command to connect JBoss instance :

            Command jboss-cli.bat -c --controller=localhost:9999

Step 3: Command to check CodeCache size in JVM.

            Command:    /core-service=platform-mbean/type=memory-pool/name=Code_Cache/:read-resource(recursive=true,proxies=true,include-runtime=true,include-defaults=true)

Step 4: Output as follows:

    "outcome" => "success",
    "result" => {
        "name" => "Code_Cache",
        "type" => "NON_HEAP",
        "valid" => true,
        "memory-manager-names" => ["CodeCacheManager"],
        "usage-threshold-supported" => true,
        "collection-usage-threshold-supported" => false,
        "usage-threshold" => 0L,
        "collection-usage-threshold" => undefined,
        "usage" => {
            "init" => 2555904L,
            "used" => 99788096L,
            "committed" => 100663296L,
            "max" => 100663296L
        "peak-usage" => {
            "init" => 2555904L,
            "used" => 99797824L,
            "committed" => 100663296L,
            "max" => 100663296L
        "usage-threshold-exceeded" => true,
        "usage-threshold-count" => 0L,
        "collection-usage-threshold-exceeded" => undefined,
        "collection-usage-threshold-count" => undefined,
        "collection-usage" => undefined

Step 5: Increase a CodeCache size by “-XX:ReservedCodeCacheSize=128M” in  JBOSS JVM  argument.

Reference URL :


No comments:

Post a Comment