0

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.

2
  • Have a look at this answer stackoverflow.com/questions/35146746/…. Commented Mar 3, 2017 at 9:53
  • @suboptimal thanks. i will investigate. though we are not using CGLIB. will see sun.jvm.hotspot.HSDB though right not its saying cant load, even when i run it with sudo on my local. Commented Mar 3, 2017 at 11:07

1 Answer 1

2

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.