views:

204

answers:

3

I have a rather memory hungry java application. On my 32 bit systems with Windows XP Professional the application will just run fine if I give it -Xmx1280m. Everything below will end up in an java.lang.OutOfMemoryError: Java heap space exception.

If I run the same application on a 64 bit Windows XP Professional (everything else exactly the same) it requires -Xms1400m to prevent the OutOfMemory condition.

To my understanding, if I have a C program and I compile it for 32 bit and for 64 bit the 64 bit version will need more memory because pointers are wider and so on. In my java example however the virtual machine (Sun) is the same and the bytecode is the same.

Why does it need more memory on the 64 bit machine?

+3  A: 

Even though your bytecode is the same, the JVM converts that to machine code, so it has all the same reasons as C to require a larger memory footprint.

Yishai
+4  A: 

Probably because the virtual machine implementation differs between 32/64 bit architecture in such a way that it consumes more memory (wider types, different GC).

The bytecode is irrelevant when it passes on the tasks to the underlying system. Im not sure that Java and memory-efficient are two terms I would put together anyway :P

Aiden Bell
This is more obvious on .NET, because it has an IntPtr class that represents a pointer... which is 4 bytes when running in 32-bit mode and 8 bytes in 64-bit mode.
R. Bemrose
Hmm, if it did differ on 64 bit I'd expect that it could address more than 2 GB, but it can't. -Xmx1400m is the maximum that java accepts on the 64 bit machine. Seems that I only get the disadvantages (memory bloat) but not the advantages (larger process address space).
Ludwig Weinzierl
Java for you I suppose, but I am not that knowledgeable on the specifics of the JVM implementation.
Aiden Bell
+3  A: 

It's the same reason you already listed for the C program. The 64 bit system uses large memory addresses, causing it to be "leakier" (I believe that's the term I've heard used to describe it).

Gandalf
"leakier" is a very inaccurate term to describe this. There are no memory leaks involved. The pointers are just bigger.
Laurence Gonsalves