In the Dockerfile use the JVM debugging container as base-container e.g.
FROM gcr.io/distroless/java:11-debug
and add -XXNativeMemoryTracking=summary
to the startup-parameters e.g.
ENTRYPOINT ["java","-XX:NativeMemoryTracking=summary","-jar", "/app/dmsvc.jar"]
Connect into the container:
kubectl exec -it <pod-name> sh
Show available jvm processes
$ /usr/lib/jvm/java-11-openjdk-amd64/bin/jcmd
1 /app/<your-app>.jar
7724 jdk.jcmd/sun.tools.jcmd.JCmd
Show options for <your-app>.jar
in this case is the process number 1
$ /usr/lib/jvm/java-11-openjdk-amd64/bin/jcmd 1
1:
The following commands are available:
Compiler.CodeHeap_Analytics
Compiler.codecache
...
VM.flags
$ /usr/lib/jvm/java-11-openjdk-amd64/bin/jcmd 1 VM.flags
1:
-XX:CICompilerCount=2 -XX:InitialHeapSize=8388608 -XX:MaxHeapSize=132120576 -XX:MaxNewSize=44040192 -XX:MinHeapDeltaBytes=196608 -XX:NativeMemoryTracking=summary -XX:NewSize=2752512 -XX:NonNMethodCodeHeapSize=5825164 -XX:NonProfiledCodeHeapSize=122916538 -XX:OldSize=5636096 -XX:ProfiledCodeHeapSize=122916538 -XX:ReservedCodeCacheSize=251658240
-XX:+SegmentedCodeCache -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseFastUnorderedTimeStamps -XX:+UseSerialGC
VM.info
$ /usr/lib/jvm/java-11-openjdk-amd64/bin/jcmd 1 VM.info