Wednesday, July 22, 2015

32-Bit vs 64-Bit JVM (Client-Server JVM)

When we download Java we must choose a version. The choice depends upon the platform that we are using. The JVM/Java is available in 32-bit/64-bit versions. However the 32-bit/64-bit JVM is also distinguished as client/server JVM based on the JIT compiler it uses. These names come from the command-line argument used to select the compiler (e.g., either -client or -server). When downloading Java for a given operating system, there are only two options: a 32-bit or a 64-bit binary. A 32-bit binary can be expected to have  two compilers (client and server), while the 64-bit binary will have only a single (server) compiler. (In fact, the 64-bit binary will have two compilers, since the client compiler is needed to support tiered compilation. But a 64-bit JVM cannot be run with only the client compiler.)

A 32-bit client version (-client)
A 32-bit server version (-server)
A 64-bit server version (-d64)

If we have a 32-bit operating system, then we must use a 32-bit version of the JVM. If we have a 64-bit operating system, then we can choose to use either the 32- or 64-bit version of Java. Don't assume that just because we have a 64-bit operating system, we must also use a 64-bit version of Java.

If the size of our heap will be less than about 3 GB, the 32-bit version of Java will be faster and have a smaller footprint. This is because the memory references within the JVM will be only 32 bits, and manipulating those memory references is less expensive than manipulating 64-bit references (even if we have a 64-bit CPU). The 32-bit references also use less memory. JVM can use 32-bit addresses even within the 64-bit JVM. However, even with that optimization, the 64-bit JVM will have a larger footprint because the native code it uses will still have 64-bit addresses.

The downside to the 32-bit JVM is that the total heap size must be less than 4 GB (3 GB on some versions of Windows, and 3.5 GB on some old versions of Linux). That includes the heap, permgen, and the native code and native memory the JVM uses. Programs that make extensive use of long or double variables will be slower on a 32-bit JVM because they cannot use the CPUs 64-bit registers, though that is a very exceptional case.Programs that fit within a 32-bit address space will run anywhere between 5% and 20% faster in a 32-bit JVM than a similarly configured 64-bit JVM. With 64-bit JVM there is no such limit of heap size. We can select as big a hip as we want to. Howerver the downside of 64-bit JVM with larger heap size is the pause it causes during the full garbage collection. The larger the size oh the heap the bigger the pause will be. If the application doesn’t need a heap size bigger than 4GB then its always better to go for 32-bit JVM.

To determine the default compiler for a particular installation of Java, run this command:
% java -version
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b15)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)

The last line indicates which of the three possible compilers will be used: client (32-bit), server (32-bit), or 64-bit server.


No comments:

Post a Comment