Skip to content

Instantly share code, notes, and snippets.

@schneefisch
Last active September 26, 2022 09:37
Show Gist options
  • Save schneefisch/e156d74585737a633d20d71ee577349f to your computer and use it in GitHub Desktop.
Save schneefisch/e156d74585737a633d20d71ee577349f to your computer and use it in GitHub Desktop.

Docker: JVM Memory Debugging

Prerequisites

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
...

Show detailed options:

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment