0

How can I start a Java program with large max heap?

I use a memory hog program (CrashPlan) written in Java, which sometimes, at peak use, needs some 1.5 GB of memory (this is controlled by the parameter -Xmx1500M).

Usually (and at least when starting) it needs very little memory, but with anything lower than -Xmx1500M it crashes at peak use. After start (with -Xmx1000M), Task Manager shows its memory usage about 100 MB in Working Set, Private Set, and Assigned Memory.

However, Java VM cannot start with -Xmx1500M, I guess because it fails to allocate this memory. (With -Xmx1000M it does start, but crashes later on.)

I use Windows 7 pro 32-bit (not 64-bit), with 32 GB memory installed (3 GB accessible, and pagefile on a large RAM disk in inaccessible memory).

I would expect that Windows would swap out other processes in order to allocate memory for Java, and since Java does not use it anyway, would swap Java's unused memory to pagefile. Say, right now I see mydefrag process using 1700 MB allocated set with no problem.

(It seems until last week it worked this way. Then something changed.)

How can I force Java to start with -Xmx1500M?

5
  • The syntax your using should set the heap to the given size? You need to determine the reason it is failing to allocate the memory. You have 32 GB of memory installed, yet you are using a 32-bit operating system, that makes no sense at all. 32-bit applications on a 32-bit operating system are limited to the amount of memory hat they can allocated, 1.5GB is very close to that limit actually.
    – Ramhound
    Jul 3, 2016 at 19:49
  • Be sure you set both -Xmx and -Xms. Of course I suspect the reason our program is crashing is because your system is unable to allocated 1.5GB to an application, when your PC is starting, due to the system's need for the memory thus the program crashes.
    – Ramhound
    Jul 3, 2016 at 19:54
  • @Ramhound Thank you! I prefer 32-bit system for now because of compatibility; I use the rest of RAM for the pagefile, temp, and readyboost. Though 1.5 GB is "near" (is it?) to 2 GB, why cannot I get even that? As I said, right now I see MyDefrag using 1.7 GB with no problem. Yes, I do set -Xms30M, but how can it affect the ability of the VM to start? Jul 3, 2016 at 20:52
  • By "VM" you mean the Java Virtual Machine? Please use precise statements.
    – Ramhound
    Jul 3, 2016 at 21:01
  • @Ramhound To be precise, I don't know. I have a CrashPlan service, which I believe is written in Java. When I set -Xmx1500M in its .ini file and press the button "Run service" in Services.msc, the service starts and immediately stops, with no error message logged (I guess it does not have a chance to even open a log file). When I set -Xmx1000M, the service runs, but in some hours stops with OutOfMemory error message in its log file. I guess it's a problem with the Java Virtual Machine not getting enough memory from Windows to start, but I cannot say for sure. Jul 3, 2016 at 21:33

1 Answer 1

1

As you already realized the addressable memory of your user-process is limited to 2GB on 32-bit windows (half of the 4GB address-space is reserved for the OS). But you must also take into account that heap-memory is not the only kind of memory the Java-VM uses: there's also requirements for native memory-allocations, stack-space, perm-gen, code-cache etc. All of these have to come from the same 2GB that are available. So the exact maximum heap-size may vary between java-versions (maybe even between different computers), but according to Oracle

On most modern 32-bit Windows systems the maximum heap size will range from 1.4G to 1.6G.

So for anything that needs 1.5 GB up of heap you might be out of luck on a 32bit-JVM (and so on a 32-bit OS).

You might be able to gain some additional MB by reducing other memory-pools, e.g. by setting -XX:ReservedCodeCacheSize (default 32m) or -XX:MaxPermSize (default 64m), but that might lead to other problems while running your application.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .