Search code examples
javajarcentos

Error occurred during initialization of VM: Could not reserve enough space for code cache when executing jar file as regular user on Centos 7


I have a Centos 7 machine with 64gb memory (49gb available) where I am experiencing an issue when trying to execute a jar file as a regular user with the following command:

java -jar jarfile.jar

It returns the error:

Error occurred during initialization of VM
Could not reserve enough space for code cache

However, when I switch to the root user and execute the same command, it runs successfully. I have checked that the user executing the jar file is the owner and the permissions of the file are set to:

-rw-rw-r--

I have also checked that there is enough space available on the machine.

Can anyone kindly suggest what could be causing this issue and how I can resolve it to enable the jar file to be executed successfully as a regular user?

Thanks


Solution

  • I updated /etc/profile with the below to resolve

         LIMITUSER=$USER
            if [ -e "/usr/bin/whoami" ]; then
                    LIMITUSER=`/usr/bin/whoami`
            fi
            if [ "$LIMITUSER" == "root" ]; then
                    ulimit -n 6144 -u 14335 -m unlimited -d unlimited -s 8192 -c 1000000 -v unlimited 2>/dev/null
            elif  [ "$LIMITUSER" == "uptime" ]; then
                     ulimit -n 1024 -u 2047 -m unlimited -d unlimited -s 8192 -c 1000000 -v unlimited 2>/dev/null
            else
                    ulimit -n 6144 -u 14335 -m unlimited -d unlimited -s 8192 -c 1000000 -v unlimited 2>/dev/null
            fi