Ashu Pachauri
Ashu Pachauri

Reputation: 1403

UseCompressedOops kick-in threshold different for G1 and CMS

I am running a 64 bit Java 1.8 Hotspot JVM by Oracle. I have been trying to wrap my head around a difference in behavior of JVM to kick in compressed object pointers when different GC mechanisms are used. For example:

$ java -XX:+UseConcMarkSweepGC -XX:+PrintFlagsFinal -Xms32766m -Xmx32766m

bool UseCompressedClassPointers        := true        {lp64_product}
bool UseCompressedOops                 := true        {lp64_product}

$ java -XX:+UseConcMarkSweepGC -XX:+PrintFlagsFinal -Xms32767m -Xmx32767m

bool UseCompressedClassPointers        = false        {lp64_product}
bool UseCompressedOops                 = false        {lp64_product}

$ java -XX:+UseG1GC -XX:+PrintFlagsFinal -Xms32736m -Xmx32736m

bool UseCompressedClassPointers        := true        {lp64_product}
bool UseCompressedOops                 := true        {lp64_product}

$ java -XX:+UseG1GC -XX:+PrintFlagsFinal -Xms32737m -Xmx32737m

bool UseCompressedClassPointers        = false        {lp64_product}
bool UseCompressedOops                 = false        {lp64_product}

I have tried changing a few other G1GC knobs but cannot get compressed pointer optimization to kick in for heap sizes above 32736 MB for G1. But, as you can see clearly that CMS can use compressed pointers for heap sizes up to 32766 MB. I am trying to understand what controls this threshold for different GC algorithms.

Upvotes: 3

Views: 1818

Answers (1)

the8472
the8472

Reputation: 43125

but cannot get it compressed pointer optimization to kick in for heap sizes above 32736 MB

That's normal because objects are aligned to 8byte boundaries by default, which means the lowest 3 bits are always zero and can be eliminated by a shift, which in turn means 32bit object pointers can at most address 4GB * 8 worth of objects with that alignment.

You need to bump the object alignment to 16 bytes via -XX:ObjectAlignmentInBytes=16 if you want to use more than 32GB with compressed oops. Note that this makes small objects larger, i.e. wastes some memory, so you will have to measure whether it actually gains you anything.

This answer has some additional diagnostic options that might be of interest.

Upvotes: 5

Related Questions