I am trying to follow up on some tips in this blog https://www.elastic.co/blog/a-heap-of-trouble#ref5 which discusses the benefits of sizing one's Java heap so that (a) compressed pointers can be used (for heaps under 32GB) and (b) so that the heap resides at address 0 in memory. The article details how compressed pointers allow more efficient use of heap space, and explains that when the heap lives at address zero this reduces the amount of arithmetic necessary to resolve pointer addresses. Finally, the article says that if I use JVM options -XX:+UnlockDiagnosticVMOptions
-XX:+PrintCompressedOopsMode
I will see log output either like this:
heap address: 0x000000011be00000, size: 27648 MB, zero based Compressed Oops
which indicates zero-based compressed oops are enabled, or output like this
heap address: 0x0000000118400000, size: 28672 MB, Compressed Oops with base: 0x00000001183ff000
Which indicates that the heap begins at an address other than zero, therefore requiring the aforementioned increase amount of arithmetic processing.
However, when I tried those options and grep'd through my application's (Elastic Search's) log directory I could find no such messages. If anyone could advise me on how I can force details of zero-based (or not zero based) compressed pointers to be logged I'd be very grateful.
RESOLUTION:
great answers !.. I accepted @apangin's and I wrapped the java program he provided in a shell script that can run as long as you have java.. which you should if you are looking at Java heap! here is the script: https://github.com/buildlackey/scripts/blob/master/verify_compressed_pointers_from_zero_offset.sh
HotSpot Serviceability Agent can show this on a running JVM process even with no extra command-line flags required.
Run the following program with the target Java process ID as an argument.
import sun.jvm.hotspot.runtime.VM;
import sun.jvm.hotspot.tools.Tool;
public class CompressedOopsInfo extends Tool {
@Override
public void run() {
VM vm = VM.getVM();
System.out.println("CompressedOops = " + vm.isCompressedOopsEnabled());
System.out.println("CompressedClassPointers = " + vm.isCompressedKlassPointersEnabled());
System.out.println("OOP base = 0x" + Long.toHexString(vm.getDebugger().getNarrowOopBase()));
System.out.println("OOP shift = " + vm.getDebugger().getNarrowOopShift());
}
public static void main(String[] args) {
new CompressedOopsInfo().execute(args);
}
}
Prior to JDK 9 this requires including ${JDK_HOME}/lib/sa-jdi.jar
in the classpath. The program needs to run under the same JVM version as used to run the target process.