views:

630

answers:

3

I need to run a Java memory intensive application that uses more than 2GB, but I am having problems to increase the heap maximum size. So far, I have tried the following approaches:

  • Setting the -Xmx parameter, e.g. -Xmx3000m. This approaches fails at the creation of the JVM. From what I've googled, it looks like that -Xmx must be less than 2GB.

  • Using the -XX:+AggressiveHeap option. When I try this approach I get an 'Not enough memory' error that tells that the heap size is 1273.4 MB, even though my computer has 8GB of memory.

Is there another approach that I can try to increase the maximum heap size of the JVM? Here's a summary of the computer specs:

  • OS: Windows 7 (64 bit)
  • Processor: Intel Core i7 (2.66 GHz)
  • Memory: 8 GB
  • java -version:
java version "1.6.0_18"
Java(TM) SE Runtime Environment (build 1.6.0_18-b07)
Java HotSpot(TM) Client VM (build 16.0-b13, mixed mode, sharing)
+3  A: 

Get yourself a 64-bit JVM from java.sun.com.

GregS
Worked for me :-) Running the application using -Xmx4g and no problems so far.
Alceu Costa
+1  A: 

I believe the 2GB limit is for 32-bit Java. I thought v1.6 was always 64 bit, but try forcing 64 bit mode just to see: add the -d64 option.

Greg Harman
The -D64 option didn't work, I will try using the 64-bit JVM as GregS suggested and report the results.
Alceu Costa
The -d64 and -d32 switches works correctly only on Solaris (at least according these documentation): http://java.sun.com/docs/hotspot/HotSpotFAQ.html#64bit_layering.
Lukasz Stelmach
@Alceu did you use -D64 or -d64? They are different...
Greg Harman
I've tried with both options. With -d64 the JVM fails to launch even if I don't specify the Xmx option. The -D64 only works when I don't specify the Xmx.
Alceu Costa
Greg Harman
+1  A: 

When you are using JVM in 32-bit mode, the maximum heap size that can be allocated is 1280 MB. So, if you want to go beyond that, you need to invoke JVM in 64-mode.

You can use following:

$ java -d64 -Xms512m -Xmx4g HelloWorld

where,

  • -d64: Will enable 64-bit JVM
  • -Xms512m: Will set initial heap size as 512 MB
  • -Xmx4g: Will set maximum heap size as 4 GB

You can tune in -Xms and -Xmx as per you requirements (YMMV)

A very good resource on JVM performance tuning, which might want to look into: http://java.sun.com/javase/technologies/hotspot/gc/gc_tuning_6.html

mohitsoni