Reputation: 4598
With the jmap command I can view variables and their state. Similarly is there an open source tool to save the byte code that is running in the JVM? Although we have the source code, there are times when its changed - with the help of AOP for example. Also there could be different versions of the code at runtime, like for example a classpath that has 2 versions of a jar ...
Aim is to be able to attach to a process on my system, and save the state of the JVM including the byte code to files, for further inspection, without changing anything in the launcher. So we connect when the process is running, take out snapshot and the detach (so we do not disturb existing production system much).
Can use Open JDK or Oracle JDK to run the app.
Upvotes: 0
Views: 627
Reputation: 22963
Following command works with Oracle JDK (could not test it with OpenJDK)
java -cp ${JDK_HOME}/lib/sa-jdi.jar \
-Dsun.jvm.hotspot.tools.jcore.filter=sun.jvm.hotspot.tools.jcore.PackageNameFilter \
-Dsun.jvm.hotspot.tools.jcore.PackageNameFilter.pkgList=sub.optimal \
sun.jvm.hotspot.tools.jcore.ClassDump \
12345
This would dump from JVM with pid 12345
all classes from package sub.optimal
. The classes are dumped into the current directory sub/optimal/...
.
note The running process and the java
executable from above command must be of the same JVM version. Otherwise it will fail with an exception like
VMVersionMismatchException: Supported versions are 25.112-b15. Target VM is 25.112-b6
Upvotes: 2