2

I'm looking for a tool for debugging and stepping through Java Bytecode, with visualizing of the basic JVM state, including the operand stack and the local variables array, merely for educational purposes and JVM learning (for myself, and hopefully for others as well). Is there such a tool at hand?

I came across the Bytecode Visualizer Eclipse plugin by Dr. Garbage, which allows breaking on and stepping through Bytecode, but it doesn't visualize the JVM state:

http://www.drgarbage.com/bytecode-visualizer

The following related questions (quite old) mention a few tools, some of which allow stepping through Bytecode, but none with JVM state visualization:

Is there such a tool at hand, that is capable of debugging simple Java programs? Or even a simple JVM simulator?

Thanks!

valiano
  • 16,433
  • 7
  • 64
  • 79
  • JC decompile plug-in for eclipse may be of helpful..Nut i don't think it will provide visualization of JVM state – pragadez Jun 01 '17 at 13:28
  • Thanks @pragadez - the JVM state visualization is really the piece I'm missing. Cheers – valiano Jun 01 '17 at 14:15
  • The debug interface of an ordinary JVM doesn’t support reading the operand stack. – Holger Jun 01 '17 at 17:44
  • Thanks @Holger, that's good affirmation... I guess it means that some form of simulation of the operand stack is needed, for visualizing it. – valiano Jun 01 '17 at 17:54
  • FYI, there's a new project on Github called [MiniSpot](https://github.com/GentlyGuitar/MiniSpot), that aims to be an educational JVM based on HotSpot VM, and uses JNI (it seems in very early development). Seems very interesting but not quite what I'm after, although it may be a good place to implement operand stack modeling etc. – valiano Jun 03 '17 at 08:45
  • There's also this very old page with educational JVM simulation examples, but I couldn't get them to run: http://www.artima.com/insidejvm/applets – valiano Jun 03 '17 at 08:48

1 Answers1

2

I've adapted the PyJVM to do what you are after. It shows a simple gui for each thread of the Java program (they have to be compiled for Java7).

The only issue with this tool is that it doesn't have a GC, since garbage collection is handled by Python itself. Therefore, the Thread 1 (daemon) (the reference handler) will not ever do anything. Finalize method also won't trigger.

Source is available on https://github.com/MatevzFa/pyjvm (warning: the source code isn't very nice to look at), you can also install it with pip (pip2 actually, since PyJVM is written in Python2).

Install:

pip install pyjvmgui

Upgrade:

pip install pyjvmgui --upgrade --no-deps

I stil have to write a good README for it.

  • Thanks Matevž, it sounds great, but unfortunately I wasn't able to run it. `pip2 install pyjvmgui` resulted with: `ImportError: No module named pyjvm_util.globals`, and trying to run `pava` from cloned sources failed since `java.py` is missing. – valiano Sep 08 '18 at 13:06
  • 1
    Hello, I have patched the install script. If you want to run from sources, run the pyjvmgui.py script. – Matevž Fabjančič Sep 09 '18 at 22:06
  • Thank you Matevž, it is working now. Just what I was looking for! – valiano Sep 11 '18 at 11:32