Sie sind auf Seite 1von 4

http://javarevisited.blogspot.com/2013/04/what-is-maximum-heap-size-for-32bit-64-JVM-Java-memory.

html#ixzz3eJkOf9QN

Maximum Heap Size of 32 bit or 64-bit JVM in Windows and Linux


Maximum heap size for 32 bit or 64 bit JVM looks easy to determine by looking at addressable memory space
like 2^32 (4GB) for 32 bit JVM and 2^64 for 64 bit JVM. Confusion starts here because you can not really set
4GB as maximum heap size for 32 bit JVM using -Xmx JVM heap options. You will get could not create the Java
virtual machine Invalid maximum heap size: -Xmx error. There could be many different reason why maximum
heap space for JVM is less than there theoretical limit and vary from one operating system to other e.g. different
in Windows, Linux and Solaris. I have seen couple of comments on my post 10 points on Java Heap Space
regarding what is maximum heap space for Java or 32 bit JVM or 64 bit JVM and why Windows allows only upto
1.6G memory as maximum heap space etc. In this Java article, I have collected some of the frequently asked
questions around maximum heap space on both 32 and 64 bit JVM and tried to explain them.

FAQ Maximum Java Heap Space on 32 and 64 bit JVM


Here is list of some confusions I have seen on Java programmers regarding maximum heap space of 32
and 64 bit Java Virtual Machines :

1.

What is maximum heap size for 32 bit JVM? 2GB or 4GB?

2.

Why my JVM not able to start on windows when maximum heap space around 1600M?

3.

Why Linux or Solaris allow more maximum heap size than windows for same, 32 bit JVM?

4.

Can we set more than 4GB as maximum heap size for 32 bit JVM running on 64 bit or x64 operating
system?

5.

What is maximum heap size for 64 bit or x64 JVM, Is it 8GB or 16GB?

6.

Can I specify more than 1GB as heap space if physical memory is less than 1GB?

If you also have similar confusion on JVM maximum heap space no matter whether its for your own Java
application or any Java web or application server like Tomcat, JBoss or WebLogic, This discussion applies to all
of them.
What is maximum heap size for 32 bit JVM? 2GB or 4GB?
This confusion comes because of sign bit, many programmer think in terms of signed integer and they think
maximum addressable memory (size of address bus) for 32 bit architecture is 2^32-1 or 2GB and this confusion
is supported by fact that you can not provide maximum heap space as 2GB on windows machine. But this is
wrong. Memory is nothing to do with signed or unsigned bit as there is no negative memory address. So
theoretical limit for maximum heap size on 32 bit JVM is 4GB and for 64 bit JVM its 2^64.
Why JVM not able to start on Windows XP when maximum heap space around 1600M?
This problem is most obvious on Windows platform like Windows XP, which tries to allocate a
contiguous chunk of memory as requested by -Xmx JVM parameters. Windows reserves some space for his own
and seems also allocate memory around half of memory address bar, which consequently reduces contiguous
memory space somewhere less than 2GB, around 1500 to 1600M and when you give more than this size, JVM
throws error as.
Could not create the Java virtual machine.
Invalid initial heap size: -Xms1.5G

Remember, this limit on heap space is due to windows operating system's own behavior. You can set maximum
heap space, more than this size in Linux or Solaris. Though maximum heap size for 32 bit or 64 bit JVM will
always be less than theoretical limit of addressable memory. By the way you can get this error due to many
reasons, see How to fix Invalid Initial and Maximum heap size in JVM for more details.
Why Linux or Solaris allow more maximum heap size than windows for same, 32 bit JVM?
This point is also related to second. Though there could be multiple reasons for that but I think It could be
because of Windows trying to allocate contiguous chunk of memory as Java heap space. Happy to hear your
opinion on this.

Can we set more than 4GB as maximum heap size for 32 bit JVM running on 64 bit or x64 operating
system?
This is a tricky question as you are running 32 bit JVM on x64 server. In my opinion you can set upto 4GB for 32
bit JVM but not more than that. Though x64 Servers has more memory for his needs and since every process
can have upto 2^64 bit it may look perfectly OK for 32 bit JVM to accept 4GB as maximum heap size. In
practice, I have tried both Linux and Solaris servers setting maximum heap size as 4G but it didnt accept. Solaris
goes more close to 4GB by allowing upto 3.6G (approx).

What is maximum heap size for 64 bit or x64 JVM, Is it 8GB or 16GB?
This question mostly arise because of available physical memory on machine. As no system currently
have 2^64 bit of physical memory or RAM and often high end servers has memory around 8G, 16GB or 32GB.
Theoretical maximum memory for x64 machines is 2^64 bit but again its depend on how much your operating
systems allows.I read some where that Windows allowed maximum of 32GB for 64 bit JVM.
Can I specify more than 1GB as heap space if physical memory is less than 1GB ?
Theoretically yes, because operating system can use virtual memory and swap pages between physical memory
and virtual memory, when there is no room in physical memory. Practically, if you are running on windows than it
depends how far you can go, I have run Java program with -Xmx1124M even though my machine has less
than 1GB RAM.

Thats all on what is maximum Java heap space for 32 bit and 64 bit JVM. As you see maximum heap size
depends upon host operating system. Solaris and Linux provides more heap space than windows and that could
be one of the many reason that Java Server application mostly run on UNIX based systems. Let me know whats
your thought and experience on maximum Java heap space for x86 and x64 JVM running on both x86 and x64
machines.
Other Java JVM Tutorials from Javarevisited Blog
Difference between JRE, JDK and JVM
How to find if JVM is 32 or 64 bit in Java
2 ways to solve java.lang.OutOfMemoryError in Java
How ThreadLocal variable creates memory leak in Java web application
10 JVM options Java programmer should know

You might like:

10 JDK 7 Features to Revisit, Before You Welcome Java 8

Invalid initial and maximum heap size in JVM - How to fix

Tomcat java.lang.OutOfMemoryError: PermGen space Cause and Solution

10 points about Java Heap Space or Java Heap Memory


Recommended by

Posted by Javin Paul at 8:08 AM

Email This BlogThis! Share to Twitter Share to Facebook


Labels: core java , core java interview question , J2EE
Location: United States

7 comments :

sarang anajwala said...


A very important point about why you cannot allocate 4GB an only
allocate a lot less than 4GB to a java process on a 32-bit machine. The
threads created by your java process have their own stackspace and
that also has to fit into this 4GB limit (normally due to OS overhead
this limit is 3.2GB and not 4GB). Now this default thread-stackspace
(Xss) is different on different operating systems and hence the
difference between total memory youcan allocate to heap.
As I mentioned above,
Max Heap = 3.2GB - total thread-stackspace.
One quick way to use more heap on a multi-threaded java app is to
reduce your Xss.
You can refer my blog for exact numbers.
http://oakgreen.blogspot.sg/2011/08/thread-count-supported-byjvm-on.html
April 2, 2013 at 11:29 PM
Anonymous said...
How much heap size can be allocated if the physical memory/RAM is 3
GB? I got this question in written test. Can somebody say how much
and why ?
May 13, 2013 at 6:23 AM
Anonymous said...
What is the maximum memory limit for a 64 bit JVM? Also I heard that
Java Garbage Collectors are not optimized for large heap sizes?
Considering that in mind, How much maximum heap size should be
without compromising performance?
July 13, 2013 at 12:04 AM
Reena said...
Can any one please provide following details to me, I need this to
submit to my project manager
Default Heap Size for 32 bit JVM in 32-bit Windows
Maximum Heap Size for 32 bit JVM in 32-bit Windows
Default Heap Size for 32 bit JVM in 32-bit Redhat Linux
Maximum HHeap Size for 32 bit JVM in 32-bit Redhat Linux

Default Heap Size of 32 bit JVM in 32-bit Solaris x86


Maximum Heap Size of 32 bit JVM in 32-bit Solaris x86
Default Heap space for 64 bit JVM in 64 bit Windows 2003 Server
Maximum Heap space for 64 bit JVM in 64-bit Windows 2003 Server
Default Heap space for 64 bit JVM in 64 bit Linux
Maximum Heap space for 64 bit JVM in 64-bit Linux
Default Heap space for 64 bit JVM in 64 bit Solaris x86
Maximum Heap space for 64 bit JVM in 64-bit Solaris x86
Thank you
August 14, 2013 at 9:17 PM
Unknown said...
How to reduce java heap space (out of memory) exception... Java
heap space is already set to max.. do the unhandled java runtime
exception will consume the memory in java heap?
March 14, 2014 at 11:26 AM
Anonymous said...
If you want to get rid of OutOfMemoryException, one immediate thing
you can do is to switch to a 64-bit JVM, that will allow you to allocate
more memory than your 32-bit JVM and can handle capacity better.
Ofcourse, this is only work if you don't have a memory leak, otherwise
no mater how much memory you allocate, you will eventually run out
with it after some time.
September 3, 2014 at 9:13 PM
Anonymous said...
worth remembering that most 64-bit JVMS run with 32-bit references
for heaps up to 32 GiB. In Java 8 up to 64 GiB.

Read more: http://javarevisited.blogspot.com/2013/04/what-is-maximum-heapsize-for-32-bit-64-JVM-Java-memory.html#ixzz3eJkOf9QN

Das könnte Ihnen auch gefallen