views:

1662

answers:

3

Hi all,

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?

+3  A: 

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.

kgiannakakis
On windows 32-bit the limit is closer to 1.3 GB
Peter Lawrey
+1  A: 

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.

Curt Sampson
+1  A: 

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.

brianegge