Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Avoiding Initial Memory Heap Size Error

I run a Java code with the following command:

$ java -Xms4G -Xmx4G myjavacode

My cpu's RAM capacity is 6GB.

However it always fail to execute giving me this error message:

Invalid initial heap size: -Xms5G
The specified size exceeds the maximum representable size.
Could not create the Java virtual machine

Is there any way to set up Java option so that we can execute the code?

like image 238
neversaint Avatar asked May 26 '09 05:05

neversaint


People also ask

How do I fix invalid initial heap size?

64 bit JVM installed on Solaris machines runs with a 32-bit model if you don't specify either -d32 or -d64, which won't accept a Maximum heap size of 4GB, hence "invalid heap size". You can resolve this issue by running Solaris JVM with option -d64.

How do you fix initial heap size set to a larger value than the maximum heap size?

To get rid of this error, the value of Xmx(maximum heap size) should always be greater than or equal to Xms(minimum heap size). Run the HelloWorld program with the value of Xms(minimum heap size) set to 1 gigabyte and Xmx(maximum heap size) set to 2 gigabytes.

How do I stop Java heap space error?

OutOfMemoryError: Java heap space. 1) An easy way to solve OutOfMemoryError in java is to increase the maximum heap size by using JVM options "-Xmx512M", this will immediately solve your OutOfMemoryError.


3 Answers

You've exceeded the maximum heap size of your JVM. This is both JVM and OS dependent. In most 32-bit systems the maximum value will be 2Gb, regardless of the physical memory available.

like image 197
kgiannakakis Avatar answered Oct 05 '22 15:10

kgiannakakis


By default Java will run in 32 bit mode. Be sure to give it the -d64 option to put it into 64 bit mode. Once in 64-bit mode, you shouldn't have any trouble allocating a 6GB JVM.

like image 27
brianegge Avatar answered Oct 05 '22 15:10

brianegge


Actually, the maximum memory size on 32-bit systems can vary, being anything up to 4 GB, but 2 GB is a common value. It's often possible to re-link your kernel to increase this to 3 or 3.5 GB. The issue, of course, is that you just don't have the address space to map more memory. Have you tried a 64-bit machine?

Also, remember to set your ulimit higher before you do this.

like image 29
cjs Avatar answered Oct 05 '22 14:10

cjs