3

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?

3 Answers 3

1

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 
Sign up to request clarification or add additional context in comments.

6 Comments

Thanks, Stephen. The problem is on the "trouble" machine, it is a 64bit OS, with 16GB physical memory. I personally do not think setting Xms128m should have any issue, as obviously default Xmx should not be < 128M.
Just to clarify: Both "trouble" machine and "trouble-free" machine are running 64bit Windows Server 2008 R2 Enterprise 64bit, with 16GB physical memory.
Well, clearly it "has an issue" ... whether you think it should be or not. If you are unhappy with my explanation, I suggest that you ask Oracle via your Java support contract ... or download the OpenJDK 6 source code and try to figure out what is actually happening for yourself. Telling us that you think it "should not happen" is ... well ... moot, since it clearly does happen.
Hmm, please do not get me wrong. Your comment is really helpful, I was just curious why 2 machine work differently. The good thing is: I use a newer version of JDK (1.6_u17 does not support this option) to run the command with -XX:+PrintFlagsFinal, the result surprise me. The "trouble" machine showes "uintx MaxHeapSize := 0 {product}" while the "good" machine showes "uintx MaxHeapSize := 4160749568 {product}". Now it seems to be tricky... Why MaxHeapSize is ZERO on the trouble one?
I'm guessing, but maybe there is some OS setting (access control? security?) that prevents the JVM from finding out how much physical memory there is on the "trouble" machine.
|
0

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.

1 Comment

Thanks, Dileep. As my comment made to Stephen, Both "trouble" and "trouble-free" machines are Windows Server 2008 R2 Enterprise 64bit, with 16GB physical memory. Just be curious why setting Xms128m does not work, as default allocated Xmx should be definitly > 128m on the 16GB physical memory.
0

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 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.