Why doesn't it work?
As already mentioned, this particular user computer most likely does not have a sufficiently large contiguous block of free memory for the JVM in the 32-bit address space. The maximum 32-bit heap space depends on the system (note that both the OS and the exact version of the JVM matter), but usually it is around 1100-1600 MB on Windows. For example, on my 64-bit Windows 7 system, these are the maximum -Xmx sizes for the specific 32-bit versions of the JVM that I installed:
- Java 7: between 1100 and 1200 m
- Java 6: between 1400 and 1500 m
- Java 5: between 1500 and 1600 m
The remaining memory allocated for the process is used by the OS (or the emulator, in the case of a 32-bit process on a 64-bit host), the JVM itself, and other structures used by the JVM.
Recommended Solution: Combine the 64-bit JVM with your application
If you cannot force the client to install the 64-bit JVM, link it to your application. A 64-bit address space will have a contiguous block of memory larger than 1300 MB, even if not necessarily a large enough contiguous block of physical memory.
If your software is a standalone application, this is a piece of cake to integrate the JVM. If the launcher is an applet, you may need to check the applet for the 64-bit JVM in a known place (and, if necessary, download it) before starting the application.
Do not forget about dependencies
If your application uses 32-bit native libraries, make sure that you can also get 64-bit versions of these native libraries.
What if you cannot bind the JVM or have 32-bit native dependencies?
There really is no reason why you should not associate the JVM with your application, but you might have 32-bit native dependencies that were not ported to 64-bit, in which case it won. It doesn't matter if you build the JVM, because you are still stuck with 32 bit. In this case, you can do your launcher to perform a binary search to determine the maximum heap size by repeatedly executing java -Xmx####m -version and java -Xmx####m -version output (where #### is the java -Xmx####m -version value, of course). Once you find the maximum Xmx, you can run your program with this value. (Note: a slightly safer option is to simply try to run your program and check for a heap space error by decreasing Xmx after every failed attempt to start your program.)
You will need to use a lower Xmx if you get an error message similar to one of the following:
Java 7:
Error occurred during initialization of VM Could not reserve enough space for object heap Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred. Program will exit.
Java 6:
Error occurred during initialization of VM Could not reserve enough space for object heap Could not create the Java virtual machine.
Java 5:
Error occurred during initialization of VM Could not reserve enough space for object heap Could not create the Java virtual machine.
But if you get something like the following, you know that you either found the maximum, or you can try a larger Xmx value:
Java(TM) SE Runtime Environment (build 1.7.0_21-b11) Java HotSpot(TM) Client VM (build 23.21-b01, mixed mode)