Preparing for Java and Spring Boot Interview?

Join my Newsletter, its FREE

Thursday, July 29, 2021

What is -XX:+UseCompressedOops in 64 bit JVM? Example

-XX:+UseCompressedOops JVM command-line option is one of the most talked-about options of 64 bit JVM. Though 64 bit JVM allows you to specify larger Java heap sizes it comes with a performance penalty by using 64 bit OOPS. Ordinary object pointers also are known as OOPS which is used to represent Java objects in Virtual Machine have an increased width of 64 bit than smaller 32 bit from earlier 32 bit JVM. because of the increased size of OOPS, fewer OOPS can be stored in CPU cache registers which effectively reduced CPU cache efficiency. -XX:+UseCompressedOops enables the use of compressed 32 bit OOPS in 64 bit JVM which effectively compensates the performance penalty imposed by 64 bit JVM without scarifying heap size advantage offered by them.

You should use -XX:+UseCompressedOops if the maximum heap size specified by -Xmx is less than 32G. This is my 3rd article on JVM after the 10 JVM options Java programmers should know and how to find 32 bit JVM or 64 bit JVM, I suggest reading those if you want to learn more about JVM.

Why should you use -XX:+UseCompressedOops JVM option

-XX:+UseCompressedOops JVM option example-XX:+UseCompressedOops JVM option neutralizes the penalty imposed by 64 bit JVM. By using -XX:+UseCompressedOops you can avail the benefit of both 64 bit JVM in terms of larger Java heap size and 32 bit JVM in terms of the compressed size of OOPS which results in better performance by utilizing CPU cache better than larger, space inefficient 64 bit OOPS pointers. 

Since better application performance is directly proportional to better CPU cache utilization, -XX:+UseCompressedOops allows you to get most of your available CPU registers along with additional CPU registers provided by some platforms like AMD x64. 

Some people may argue that further expansion of 32 bit compressed OOPS into 64-bit pointers may slow down things but that shouldn't be the problem with modern high-end processors.

Though it's important to note that the use of the Compressed Oops option limits your heap size up to 32Gigs which are still more than handy but yes a limitation if you looking for a seriously gigantic heap.

That's all on the What is UseCompressedOops JVM option and Why should you use -XX:+UseCompressedOops in 64 bit JVM. The importance of this option can also be realized by the fact that from Java 6 update 18 Oracle by default enables -XX:+UseCompressedOops in HotSpot JVM based upon maximum Java heap size.

Other Java articles you may like from the Javarevisited blog


Pavan Devarakonda [PD] said...

Mr. Paul, It is nice posting for 64bit JVM users, Better you give more quantification and baseline functionality would be more value added.

However, thanks for your time and very useful posting.

Javin @ ejb questions answers said...

@Pavan, Thanks for your comment knowledge of JVM tuning and basic options are becoming increasing important because of development of higher performance Java application, especially in high frequency trading space. -XX:UseCompressedOoops has resulted in better performance in 64 bit JVM. by the way I see your point. keep in touch.


Anonymous said...

Compress OOPS option is by default enabled form Java 7 release. Since going from 32-bit to 64-bit machine increase heap requirement for Java application almost up-to 1.5 times, simply because of bigger ordinary object pointers, its important to use -XX:+UseCompressedOops in Java version prior to 1.7. Compressed Oops manages 32-bit pointers, which means similar heap sizes for 32/64-bit apps. Also note that copressed oops option will turn off when -Xmx > 32GB, as it is only useful up to heap sizes up-to 32 Gigs, which covers almost 90% Java applications.

Anonymous said...

I am getting following error reated to compressed oops :
"Unknown VM option UseCompressedOOP, failed to start Java Virtual Machine". Please advise.

javin paul said...

@Anonymous, You might be running your Java Program in JRE version less than 1.6, since this JVM option is only introduced from Java 6, starting your JVM in Java 5 with -XX+UseCompressedOOP will fail with error "failed to start Java Virtual Machine". Please check your JVM version.

Anonymous said...

Thanks for your explanations.
You said : ''Though it's important to note that use of Compressed Oops option limits your heap size up to 32Gigs which are still more than handy but yes a limitation if you looking for a seriously gigantic heap''. I have -Xmx and -Xms set to 114688m. Should I conclude the +UseCompressedOops is useless, or worse ?

Post a Comment