2

I am using 32 bit win.7 and using Eclipse. Also having 4GB RAM.

I want to allocate my java application a maximum heapsize of around 3 GB, but I am able to allocate maximum 1.5GB through VM arguments -Xmx1056m.

What should I do? If I Install a 64 bit win.7. it would be able then to allocate 3GB heapsize to my app?

skaffman
  • 398,947
  • 96
  • 818
  • 769
Aijaaz
  • 21
  • 1
  • 2

4 Answers4

3

A regular 32-bit Windows process can only address 2GB of memory, even if you have more memory available. You can find the memory limits for different Windows versions here.

Since the VM need memory for more things than just the heap, the max heap size will be slightly less than the maxmimum memory available to the process. Usually, you can tweak the heap up to around 1.6GB for a 32-bit Windows VM.

jarnbjo
  • 33,923
  • 7
  • 70
  • 94
  • 1
    NOTE: Windows server 2003 has a switch to enable up to 3GB (/3GB). See http://www.microsoft.com/whdc/system/platform/server/pae/paemem.mspx – Berin Loritsch Nov 02 '10 at 17:18
2

You need a 64bit OS and 64bit VM to allocate this much RAM.

Faisal Feroz
  • 12,458
  • 4
  • 40
  • 51
-1

I don't have the link right now that describes the JVM memory management process. The limitation you have stumbled upon is a limitation of how Java performs garbage collection. The Java memory heap must be a contigious block. The garbage collection algorithms were optimized for this design limitation so they can perform efficiently. In a 32bit operating system, you are not in control of what memory addresses device drivers are loaded into. On Windows, the OS will only reallocate the device driver base address stored in the DLL if it conflicts with an already loaded code. Other operating systems may reallocate all device drivers on load so they live in a contiguous block near the kernel.

Basically, the limitation is the same for 64bit and 32bit operating systems. It's just on a 64bit OS there are several more address ranges to choose from. Make sure you use a 64bit JVM to match the OS. That's why the 64bit OS is able to find a larger contigious block of memory addresses than the 32bit OS.

EDIT: Additionally the 32bit JVM has a max heap size limit of 2GB.

REFERENCE:

http://publib.boulder.ibm.com/infocenter/javasdk/tools/index.jsp?topic=/com.ibm.java.doc.igaa/_1vg00014884d287-11c3fb28dae-7ff6_1001.html

Java maximum memory on Windows XP

http://forums.sun.com/thread.jspa?messageID=2715152#2715152

Community
  • 1
  • 1
Berin Loritsch
  • 11,400
  • 4
  • 30
  • 57
  • No, it's a limitation of trying to squeeze the JVM, the Java heap, the JVM heap, thread stacks, memory-mapped JARfiles, shared libraries, and miscellaneous data segments into that portion of a 32-bit address space that's left over by the OS. – Anon Nov 02 '10 at 17:05
  • It's not a VM limit, but an OS limit. Oracle's VM for Solaris is e.g. able to handle heaps up to ~3.5GB, since 32-bit Solaris allows each process to address 4GB (and not just 2GB as Windows and Linux). – jarnbjo Nov 02 '10 at 17:12
  • I've looked into this before for hosting web applications. It is both a limit of the JVM and the operating system. The facts are that the JVM requires contigious blocks of RAM, and YMMV for how big the biggest contigious block of RAM is on your machine. – Berin Loritsch Nov 02 '10 at 17:15
  • Reference this: http://stackoverflow.com/questions/171205/java-maximum-memory-on-windows-xp – Berin Loritsch Nov 02 '10 at 17:20
  • I'm running Eclipse on a 32 bit Sun Java 1.6 JVM (on 32 bit Linux) right now with a 2.2Gb main heap. The 2Gb (total) limit is a 32bit Windows imposed limit. – Stephen C Jun 11 '11 at 10:58
-2

What you will need is not only a 64bit OS and a 64bit VM, but also more memory.

On a 32bits Windows system the virtual address space is split with 2 GB for kernel operations and 2 GB for user applications. So you're screwed.

There's one possible but very unlikely workaround: you can enable the /3GB switch to raise this limitation and have the system allocate 1GB of virtual address space for for kernel operations and 3GB for user applications (if they are /LARGEADDRESSPACEAWARE).

Unfortunately, the 32bits Sun/Oracle HotSpot JVM isn't LARGEADDRESSAWARE (that I know of), and other 32bits JVM likely aren't either.

But think about it: even if you were able to do that, you would use all the memory available for you system. Nothing would be left for other programs after you've allocated your 3GB of heap for your JVM. Your system would be swapping to disk all the time. It would be unusable.

Just get a 64bis OS with more RAM. That's all there is for you, short of finding ways to have your program use less memory.

haylem
  • 22,460
  • 3
  • 67
  • 96
  • Thanks for ur answers, I will install 64 bit win7 and 64 bit JVM on my pc and will then set VM arguments. not merely ~3GB ram but larger than 2GB, i am working on graph visualization on large scale. so i think on 4GB Ram i will give ~2.5GB ram as -Xmx argument. furrther will let you know. can anyone else provide me optimization arguments in eclipse.ini file? – Aijaaz Nov 02 '10 at 18:26
  • Moreover, I have visited forums, where they discussed different optimization parameters that need to be added in eclipse.ini file.I would prefer if some one provide me consolidated optimized list pf thise vm arguments. – Aijaaz Nov 02 '10 at 18:30
  • @Aijazz: You can find this list here on stackoverflow, there's a lot of questions about this already. Do you want to run eclipse AND your app, or was eclipse the app you talked in your original question? – haylem Nov 03 '10 at 09:52
  • @Aijazz: see here for eclipse ini settings: http://stackoverflow.com/questions/142357/what-are-the-best-jvm-settings-for-eclipse/3275659#3275659 – haylem Nov 03 '10 at 09:54
  • @haylem - yes there is. On 32-bit Windows by default only 2Gb of virtual address space is available for user applications; see http://en.wikipedia.org/wiki/Virtual_address_space – Stephen C Jun 11 '11 at 10:52
  • @Stephen C.: True, not quite right. "On a 32-bit Microsoft Windows installation, by **default**, only 2GB are made available to processes for their own use". This is a restriction imposed by Windows itself, not a theoretical limitation, and it's alleviated by the /3GB switch. I will delete or edit this answer in a few days though, as it's obviously not good enough. – haylem Jun 13 '11 at 14:23