1

I DO know that the maximum Heap space of a 32bit JVM is said to be 2G, but I experimentally found that I can only allocate a varying space of around 1290M, sometimes more, sometimes less. (Sometimes I can safely allocate more, sometimes I get an error even at that number.)

I also have a 64bit JRE and my OS is Win7 64bit, so that can barely restrict the RAM usage.

I have no problems with that since I can simply use the 64bit JVM instead, but the more precise the things you know are, the better you can help others.

So I wonder: Why do I get this weird maximum heap area?

I used cmd commands like

"%java32%" -xmx****M Program

With varying numbers for xmx and java32 as a variable that points to a 32bit JRE.

I DID look for this topic at other places, but either it is nowhere else or I am not very skilled at searching.

EDIT:

allocate is inaccurate, since I did not use that memory, I just asked the System for it.

The 64bit JRE of course allows Heap spaces even above 4G.

user3657016
  • 11
  • 1
  • 2

1 Answers1

1

You can ask the Java Runtime for the maximum:

public class MaxMemory {
    public static void main(String[] args) {
        Runtime rt = Runtime.getRuntime();
        long totalMem = rt.totalMemory();
        long maxMem = rt.maxMemory();
        long freeMem = rt.freeMemory();
        double megs = 1048576.0;

        System.out.println ("Total Memory: " + totalMem + " (" + (totalMem/megs) + " MiB)");
        System.out.println ("Max Memory:   " + maxMem + " (" + (maxMem/megs) + " MiB)");
        System.out.println ("Free Memory:  " + freeMem + " (" + (freeMem/megs) + " MiB)");
    }
}

Source: https://stackoverflow.com/a/7019624/12860

The reasons (from the FAQ of Oracle):

The maximum theoretical heap limit for the 32-bit JVM is 4G. Due to various additional constraints such as available swap, kernel address space usage, memory fragmentation, and VM overhead, in practice the limit can be much lower. On most modern 32-bit Windows systems the maximum heap size will range from 1.4G to 1.6G. On 32-bit Solaris kernels the address space is limited to 2G. On 64-bit operating systems running the 32-bit VM, the max heap size can be higher, approaching 4G on many Solaris systems.

Community
  • 1
  • 1
Burkhard
  • 14,596
  • 22
  • 87
  • 108
  • Sorry if that wasn't clear enough in the Question, but the problem is not How close I am to the reserved limit, but what exactly the limit of the limit is. – user3657016 May 20 '14 at 14:49
  • Enter was not supposed to post the comment, I'm new here. I mean if you do -xmx10G you pobviously get an error. But with 32bit JVM I get it at AROUND 1290M and I wonder, why. – user3657016 May 20 '14 at 14:51