Xiaofeng
Xiaofeng

Reputation: 33

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:\Users\optitest>I:\j2sdk\bin\java -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:\Users\optitest>I:\j2sdk\bin\java -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:\Users\optitest>I:\j2sdk\bin\java -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:\Users\optitest>I:\j2sdk\bin\java -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:\Users\optitest>I:\j2sdk\bin\java -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:\Users\optitest>I:\j2sdk\bin\java -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?

Upvotes: 3

Views: 2685

Answers (3)

cmcginty
cmcginty

Reputation: 117106

I have this same issue. I'm still debugging it right now, but it appears that it might have something to do with the default MaxHeapSize being set to TOTALRAM/4 or (16GB/4 = 4GB = 2^32):

(uint32) 2^32 = 0

I get the following output from -XX:PrintFlagsFinal:

uintx MaxHeapSize                              := 0               {product}

And also the output of -XX:+PrintCommandLineFlags confirms the 4G value:

-XX:InitialHeapSize=268428160 -XX:MaxHeapSize=4294850560 -XX:+PrintCommandLineFlags -XX:+UseCompressedOops -XX:-UseLargePagesIndividualAllocation -XX:+UseParallelGC

Upvotes: 0

Dileep
Dileep

Reputation: 5440

The heap size of your machine depends on lot more than how much RAM you got!

Maximum heap size for 32 bit or 64 bit JVM looks easy to determine by looking at addressable memory space like 2^32 (4GB) for 32 bit JVM and 2^64 for 64 bit JVM.

You can not really set 4GB as maximum heap size for 32 bit JVM using -Xmx JVM heap options. You will get could not create the Java virtual machine Invalid maximum heap size: -Xmx error.

You can look here for a well explained document about the heap size.

Another important thing is that, You can only postpone the OutofMemory Exception by in creasing the Heap size. Unless your clean up your memory you will get the exception one time or another Use the applications like Visual VM to understand what's going on in the background. I suggest you try to Optimise code, for increasing performance.

Upvotes: 0

Stephen C
Stephen C

Reputation: 719386

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 

Upvotes: 1

Related Questions