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

- What is maximum heap size for 32 bit JVM? 2GB or 4GB?
- Why my JVM not able to start on windows when maximum heap space around 1600M?
- Why Linux or Solaris allow more maximum heap size than windows for same, 32 bit JVM?
- Can we set more than 4GB as maximum heap size for 32 bit JVM running on 64 bit or x64 operating system?
- What is maximum heap size for 64 bit or x64 JVM, Is it 8GB or 16GB?
- 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 didn’t 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.
That’s 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 what’s 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 Learn About Linux Blog
No comments:
Post a Comment