Difference between 32 bit and 64 bit JVM – Choose Wisely

This post will focus on the Difference between 32 bit and 64 bit JVM and which one to choose in a situation.
Today while deploying my application I was getting a very familiar exception that is related to the heap size.

After looking at the exception I was very happy that I will fix it in few minutes, so for doing that I increased my heap size to 1024M and restarted my servers. The result was totally unexpected and it failed again with the same error , after this I slowly increased it by 1280 , 1372 and then 1536M but the result was same. Now at this point I was sure that there is something wrong happening that is beyond of my control and I have to look at the specs. At this point I was sure that there is something wrong at JVM level , so I started looking into details over the internet and after that I was able to successfully resolve my problem.

Here I am going to put my findings whatever I gathered on 32 Vs 64 bit JVM over the internet.

What 32 and 64 bit means ? :
If we look at the basic definition of 32 vs 64 bit , then it simply means how much data can be operated at an instance , in case of 32 bit system it utilizes the data in 32 pieces and in case of 64 bit system in 64 pieces. This difference exists at both hardware and software level as in 64 bit system you will have bigger data paths that will process the data much faster in comparison to 32 bit system. On the software side in 64 bit systems you will have new instructions , opcodes that can simulate with above components.

Difference between 32 bit and 64 bit JVM ?
In my case as I was using the 32 bit JVM , so that maximum memory that it can allocate to heap size is 1536M reason behind that in a 32 bit system the maximum memory that can be allocated for a process is 4GB and now again this 4GB (depends on OS)is divided into two parts one that is used by kernel process and the other that is used by user process.So, at the end the maximum memory available for the disposal of Heap size is 2GB , but here is one more restriction when we talk about the contiguous memory allocation ,address space needs to be in contiguous pattern , so at end we left with 1.4 to 1.7 GB at our disposal.

On the contrary in the 64 bit version as per the oracle specs there is no such limitation on address space and what I found that a max of 200GB of heap size has been already benchmarked. So, in my case it was quite obvious that I have to switch the JVM version from 32bit to 64 bit and after switching my problem was resolved. But in this lovely world nothing comes for free same was the case with 64 bit JVM.

When to use 32 bit and 64 bit JVM ?
Next thing that will come in our minds so which JVM to use when. Answer to this is very simple and can be resembled in terms of Space Vs Performance , let’s see how. As by switching over to 64 bit version , I have more memory at my disposal for defining my heap size but here is a twist if we look at from Garbage collection aspect that means bigger the heap size more time it will take to collect the unwanted or unused objects that means bigger the halt for your application that you never want to have in your application.Difference between 32 bit and 64 bit JVM

One more thing that changed in the 64 bit JVM architecture is object headers size , it is now of 12 bytes in comparison to 8 bytes headers in 32 bit JVM . Other thing that changed is size of internal references that means it can go maximum upto 8bytes where in 32 bit JVM upto 4bytes. So, from these two points you can conclude that an application running on 64 bit JVM will consume more space in comparison when same application will run on 32 bit version. If we take IBM research as a reference for performance comparison then applications running on 64 bits are 20% slower in comparison to its counterpart.

Conclusion :
After seeing all the pros and cons of 32 and 64 bit JVM , it can be easily concluded that if your application required more memory (>1.5G) then 64 bit JVM would be an ideal option , but if you think memory provided by 32 bit JVM is sufficient then better to continue with the same ,why to take extra overhead on performance.

It all depends on you what you love to choose “Performance Vs Memory”.

PS :Intention of this post is not discouraging the users from using 64 bit JVM.

Please share your thoughts and experience on the same.

Image Source : access.redhat.com

Share and Enjoy

  • Facebook
  • Twitter
  • Delicious
  • LinkedIn
  • StumbleUpon
  • Add to favorites
  • Email
  • RSS