Skip to content
Advertisement

JVM error when try to allocate more than 128M Xms, without specifying Xmx

I am seeing an JVM issue when I am running my application and I simply to below java commands:

C:Usersoptitest>I:j2sdkbinjava -version
java version "1.6.0_17"
Java(TM) SE Runtime Environment (build 1.6.0_17-b04)
Java HotSpot(TM) 64-Bit Server VM (build 14.3-b01, mixed mode)

C:Usersoptitest>I:j2sdkbinjava -Xms4g -version
Error occurred during initialization of VM
Incompatible minimum and maximum heap sizes specified

Even Xms is set to 128M does not work:

C:Usersoptitest>I:j2sdkbinjava -Xms128m -version
Error occurred during initialization of VM
Incompatible minimum and maximum heap sizes specified

Works only when Xms is set to 64M or less:

C:Usersoptitest>I:j2sdkbinjava -Xms64m -version
java version "1.6.0_17"
Java(TM) SE Runtime Environment (build 1.6.0_17-b04)
Java HotSpot(TM) 64-Bit Server VM (build 14.3-b01, mixed mode)

The interesting thing is if I specify Xmx, then it works well.

C:Usersoptitest>I:j2sdkbinjava -Xms4g -Xmx4g-version
java version "1.6.0_17"
Java(TM) SE Runtime Environment (build 1.6.0_17-b04)
Java HotSpot(TM) 64-Bit Server VM (build 14.3-b01, mixed mode)

C:Usersoptitest>I:j2sdkbinjava -Xms4g -Xmx8g-version
java version "1.6.0_17"
Java(TM) SE Runtime Environment (build 1.6.0_17-b04)
Java HotSpot(TM) 64-Bit Server VM (build 14.3-b01, mixed mode)

More interesting thing is: All above commands run well on another machine with same OS (Windows Server 2008 R2 Enterprise SP1) & same jdk version. Physical Memory is 16GB.

Any idea?

Advertisement

Answer

Any idea?

Well the obvious conclusion is that if you want to use -Xms to specify the initial heap size, and you want to set the size to a value that is larger than the default maximum heap size, you need to specify a maximum heap size.

The reason that you are getting different results on different machines is that the JVM computes the default heap size in different ways, depending on the version of Java and on the execution platform. In some cases it is a constant. In others, it depends on the amount of physical memory on the system.

Just set the maximum heap size explicitly and you won’t have this problem.


If you want to find out what the default heap size is for a given machine, run this command:

java -XX:+PrintFlagsFinal -version 
Advertisement