MAVEN_OPTS ignored when setting java heap size - java

How is this possible? I do not understand linux correctly because I do not
know how this can happen. I believe there is something else happening here as im trying to set the max heap size to 1G and it is failing
The MAVEN_OPTS specify a heap of 1024m but the maven command fails because the heap is 4096m. The machine is 32 bit with 6G installed
Memory
$free -h
total used free shared buffers cached
Mem: 5.8G 3.8G 2.0G 186M 351M 2.1G
-/+ buffers/cache: 1.3G 4.4G
Swap: 5.8G 0B 5.8G
Maven
echo $MAVEN_OPTS
-Xms512m -Xmx1024m -XX:MaxPermSize=1024m
$ mvn -version
Invalid maximum heap size: -Xmx4096m
The specified size exceeds the maximum representable size.
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
Java
java -version
java version "1.8.0_111"
Java(TM) SE Runtime Environment (build 1.8.0_111-b14)
Java HotSpot(TM) Server VM (build 25.111-b14, mixed mode)
Linux
uname -a 102-Ubuntu SMP Tue Aug 11 14:28:35 UTC 2015 i686 i686 i686 GNU/Linux

Set again with below and try:
Linux:
export MAVEN_OPTS="-Xmx1024m -XX:MaxPermSize=1024m"
Windows
set MAVEN_OPTS="-Xmx1024m -XX:MaxPermSize=1024m"

I just ran across this same error, and the solution was provided to my via this blog post. In the post, it is stated;
Check mvn.bat: the MAVEN_OPTS is passed as JVM parameter directly:
SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" %MAVEN_JAVA_EXE%
%MAVEN_OPTS% -classpath %CLASSWORLDS_JAR%
"-Dclassworlds.conf=%M2_HOME%\bin\m2.conf" "-Dmaven.home=%M2_HOME%"
%CLASSWORLDS_LAUNCHER% %MAVEN_CMD_LINE_ARGS%
If we run set MAVEN_OPTS="-Xmx1024M -XX:MaxPermSize=256M",the previous
command would be replaced with %MAVEN_JAVA_EXE% "-Xmx1024M
-XX:MaxPermSize=256M" ...
If we run java "-Xmx1024M -XX:MaxermSize=256M" -version: we will see
same error message.
The solution is simple: We can run: set "MAVEN_OPTS=-Xmx1024M
-XX:MaxPermSize=256M" or remove the double quotes completely: set MAVEN_OPTS=-Xmx1024M -XX:MaxPermSize=256M
The value of MAVEN_OPTS would be with no surrounding double quotes.
This certainly addressed my issue.

Related

Why can java -Xms exceed available memory when in docker container?

I am running a java application within a docker container and java allows me to specify a -Xms size well in excess of the memory available to the container. Why is this the case?
When running outside of a container I get the expected result:
$ free -g; java -Xms100g -version
total used free shared buff/cache available
Mem: 31 14 17 0 0 17
Swap: 28 0 28
OpenJDK 64-Bit Server VM warning: INFO: os::commit_memory(0x00007f5f60a00000, 71583137792, 0) failed; error='Cannot allocate memory' (errno=12)
#
# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (mmap) failed to map 71583137792 bytes for committing reserved memory.
But when I run the same command from within a docker container
$ free -g; java -Xms100g -version
total used free shared buff/cache available
Mem: 4 0 3 0 0 3
Swap: 0 0 0
openjdk version "1.8.0_222"
OpenJDK Runtime Environment (build 1.8.0_222-8u222-b10-1ubuntu1~18.04.1-b10)
OpenJDK 64-Bit Server VM (build 25.222-b10, mixed mode)
The command somehow succeeds. Checking the JVM parameters, it doesn't look like the container is overriding JVM parameters. It looks like java thinks it successfully allocated a heap size 25 time larger than the available memory:
java -XX:+PrintFlagsFinal -Xms100g -version 2>&1 | grep InitialHeapSize
uintx InitialHeapSize := 107374182400 {product}
Why does this happen?
Both systems are Ubuntu 18.04.1 LTS (WSL vs FROM ubuntu:18.04) and java 1.8.0_222. Docker desktop 2.1.0.3 (38240). Win10 host OS.

Invoking jMeter from the command line with 64-bit directive loses the class

We were running 32-bit JDK and jMeter 2.6, and were running into heap memory issues when simulating 8000 users spread out over the course of an hour.
We upgraded to 64-bit Java, and jMeter 2.12.
Java(TM) SE Runtime Environment (build 1.7.0_79-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)
When we run from the command line requesting a 4Gb heap (the server has 32Gb), we receive the message that the initial heap size is too large.
set JVM_ARGS="-Xms4G -Xmx4G -XX:NewSize=512m -XX:MaxNewSize=1G" jmeter.sh
When we add the option -d64 to JVM_ARGS, we no longer receive the error about the heap size, but it no longer finds the class
set JVM_ARGS="-d64 -Xms4G -Xmx4G -XX:NewSize=512m -XX:MaxNewSize=1G" jmeter.sh
Pointing it to the directory seems to have no effect
set JVM_ARGS="-d64 -Xms4G -Xmx4G -XX:NewSize=512m -XX:MaxNewSize=1G -cp mypath" jmeter.sh
Looking into jmeter.sh it seems you're trying to run JMeter on Linux or MacOSX. I believe you need to remove set word (or replace it with export)
Given you have correct java executable in PATH providing -d64 option shouldn't be required. Something like:
JAVA_HOME=/path/to/64-bit/jdk && export JAVA_HOME
PATH=$JAVA_HOME/bin:$PATH && export PATH
You can edit jmeter script and amend the following lines:
HEAP="-Xms512m -Xmx512m"
NEW="-XX:NewSize=128m -XX:MaxNewSize=128m"
"Telling" Jmeter to use Concurrent Mark Sweep (CMS) Garbage Collector can also improve JMeter-side performance greatly. The relevant line is:
-XX:+UseConcMarkSweepGC
See 9 Easy Solutions for a JMeter Load Test “Out of Memory” Failure article for more information on getting the most from your JMeter installation.

increase size of jvm permanently in Ubuntu

I want to increase the size of my JVM permanently rather than doing it manually every time.I tried several options but none of them are working.
SET _JAVA_OPTIONS = -Xms5g -Xmx16g
error SET: command not found
After that i tried small set command.It runs perfectly but when i did java -Xshowsettings:all, JAVA_OPTIONS was set to 1g only
set _JAVA_OPTIONS = -Xms5g -Xmx16g
java -XshowSettings:all
Picked up _JAVA_OPTIONS: -Xmx1g
VM settings:
Max. Heap Size (Estimated): 910.50M
Ergonomics Machine Class: server
Using VM: Java HotSpot(TM) 64-Bit Server VM
After that i tried exporting.But again error is coming.Please help me out.
> export _JAVA_OPTIONS="-Xmx1g"
> java -jar jconsole.jar &
[1] 28931
Error: Unable to access jarfile jconsole.jar

Linux - Java - Error occurred during initialization of VM

I have gone through SO for similar questions but none of them gave a correct working answer w.r.t my setup (the answers on the other questions were applicable for Windows machine, 64-bit).
I have the following setup:
$
$ uname -a
Linux localhost.localdomain 3.8.4-102.fc17.i686 #1 SMP Sun Mar 24 13:20:55 UTC 2013 i686 i686 i386 GNU/Linux
$
$ java -version
java version "1.7.0_17"
Java(TM) SE Runtime Environment (build 1.7.0_17-b02)
Java HotSpot(TM) Server VM (build 23.7-b01, mixed mode)
$
$ javac -version
javac 1.7.0_17
$
$
$ free -m
total used free shared buffers cached
Mem: 3520 3435 85 0 472 1531
-/+ buffers/cache: 1431 2089
Swap: 5567 0 5567
$
$
$ echo $JAVA_HOME
/usr/java/jdk1.7.0_17
$
$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/usr/java/jdk1.7.0_17/bin
$
I am getting the following error when attempting to run java programs!
Error occurred during initialization of VM
Could not reserve enough space for object heap
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
Do I need to upgrade to 64-bit OS and install 64-bit JVM? or should I upgrade my hardware with more RAM?
Please visit Running java with JAVA_OPTS env variable, HEX provides that you should set up _JAVA_OPTIONS variable.
You need to check if you have any JAVA_OPTS defined: echo $JAVA_OPTS. Do you specify any heap size?
First you can try to allocate more RAM for your machine.
Second, you can try and run your java command with specified MaxHeapSize and maybe Xmx/Xms.
Check out Tuning the JVM heap sizes in the Oracle's docs.
Looking at the memory, you just have 85mb available. You might want to free some memory before launching your program. Also, try running it with the following command line options:
-Xmx512m, -XX:MaxHeapSize=256m

unable to set xmx beyond 4gb on system having 8gb RAM

I need to set
ANT_OPTS=-Xms1024m -Xmx6144m -XX:PermSize=1024m -XX:MaxPermSize=1024m
JAVA_OPTS=-Xms1024m -Xmx6144m -XX:PermSize=1024m -XX:MaxPermSize=1024m
I have a system with 8gb(recently upgraded from 4 gb)
But once i set the ant opts to above said value I am not able to run any of my ant targets and I get the following error
[ERROR] Argument error: -Xmx6144m
[ERROR] Specified maximum heap size (6144 MB) is larger than the address space on this platform (4 GB).
[WARN ] -XX:PermSize=1024m is not a valid VM option. Ignoring
[WARN ] -XX:MaxPermSize=1024m is not a valid VM option. Ignoring
Could not create the Java virtual machine.
This indicates the Java that I have on my system
java version "1.6.0_20"
Java(TM) SE Runtime Environment (build 1.6.0_20-b02)
Oracle JRockit(R) (build R28.1.0-123-138454-1.6.0_20-20101014-1351-windows-x86_64, compiled mode)
and I am running a Windows 7 on Intel Core 2 Duo 3Ghz processor and 8GB RAM.
PS: I did Google for the error and it was one of my first such occurrences where I did not get any links pointing to the specific solution.
As discussed in the comments:
It would seem that your ANT installation is using a 32-bit JVM. While a 64-bi JVM is in your PATH ANT doesn't obey the JVM in your PATH, it first looks at JAVA_HOME. You can verify this by running $JAVA_HOME/bin/java -version.
You can update your environment to set JAVA_HOME to the 64-bit version or change the ANT script to always use a specific version of Java.
The error message appears to be suggesting the platform is 32-bit. I imagine you can't actually use 4 GB.
I would try installing the 64-bit version of Java and using that.
For the HotSpot JVM I would expect to see
$ java -mx30g -version
java version "1.6.0_31"
Java(TM) SE Runtime Environment (build 1.6.0_31-b05)
Java HotSpot(TM) 64-Bit Server VM (build 20.6-b01, mixed mode)

Categories

Resources