Insufficient memory for the Java Runtime Environment

For the past couple of days, the jenkins application is running into memory errors. Here are the logs. We’re running Jenkins 2.249.2 on a Windows 2019 VM. The VM has 12 GB of RAM. I’ve adjusted the heap size in the jenkins.xml with the following values, still no luck. The issue is causing jenkins to go down and I have to restart Jenkins. Can you anyone please advise?

Heap Setting

“D:\java\bin\java”
-Xrs -Xms2048m -Xmx2048m -XX:MaxPermSize=512m -Dhudson.lifecycle=hudson.lifecycle.WindowsServiceLifecycle -jar “%BASE%\jenkins.war” --httpListenAddress=127.0.0.1 --httpPort=8080 --webroot=“%BASE%\war”

Error

There is insufficient memory for the Java Runtime Environment to continue.
Native memory allocation (malloc) failed to allocate 1048576 bytes for AllocateHeap
An error report file with more information is saved as:
D:\jenkins\hs_err_pid4848.log
Running from: D:\jenkins\jenkins.war

What JRE/JDK are you using? If you are using Java 8, I would recommend trying Java 11 or Java 17 (and make sure it is a 64-bit JRE/JDK). Can you also check the Task Manager and see where all your memory is going?

There is not enough information in the snippet to tell exactly what the problem might be.

In case you are running OpenJDK 11.0.16 or 17.0.4, please note the following from the LTS upgrade guide and upgrade OpenJDK:

OpenJDK 11.0.16/17.0.4 and the C2 JIT compiler

OpenJDK 11.0.16 and 17.0.4 are susceptible to JDK-8292260, a regression in the C2 JIT compiler which may cause the JVM to crash unpredictably. The OpenJDK project has released fixes in 11.0.16.1 and 17.0.4.1. As of August 26, 2022, the official Jenkins Docker images have been updated with OpenJDK 11.0.16.1 and 17.0.4.1 in version 2.346.3-2.

1 Like

You are granting (only) 2GB of heap to jenkins. If you are keeping lots of builds this may not be enough.
→ increase the heap memory
→ use the build discarder plugin to discard old builds

1 Like

And one other thing:
if you run agents in the same vm, then each agent by default uses the same heap size ( + memory for all the things that are running during a build or for the os ). So profile your total memory usage as well.

I’m using Java 11. Thanks for the reply.

Increased the heap size to 4 gb, still no luck. I’ll look into the build discarder plugin.

I’m using 11.0.3 JDK. Thanks for the reply.

@renyk Can you update to the newest 11.0.x release? There were known issues with the early JDK 11 releases…

1 Like