Debugging classes generated at run time
Debug, inspect and understand Java bytecode from classes that are completely generated at runtime. Dr. Garbage does visualization of classes retrieved from Java Virtual Machine via Java™ Debug Interface.
Synthetic classes which are completely generated at runtime can now be visualized thanks to this new feature of Dr. Garbage Tool Suite.
To learn more about the debugging feature download this java project and go through the tutorial steps.
- Importing the project into eclipse work space
- Setting break points
- Running the test application
- Reading loaded classes from the JVM
Open your Eclipse (with the newest Dr. Garbage Tool Suite installed), right
click in the Package Explorer and then choose
The import window opens up, choose Existing Projects into Workspace and then
Browse for the unzipped folder you downloaded in Step 1
In the Project Explorer, you should see the structure of the imported Project like this:
Now you can switch to the Debug View from the top right corner of Eclipse:
Open the main class
TestCaseForByteCodeVisualizer.java, set two breakpoints at
line 18 and 66:
Click on the triangle on the right of the Debug symbol and choose the class
At first you may only see one frame for
TestCaseForByteCodeVisualizer.callback() line: 66. After pressing F8 or
click on the resume button (marked on the picture), you will be able to see
The GeneratedRunnableImpl.run() is the method of the class which is generated
at runtime and also the class we want to debug or visualize. But when you click
on the frame for this class, in the source window you can only see "Source not
found" and a button
Edit Source Lookup Path.... Because it does not have any
counter part in the build path of our Eclipse Project.
Now we will copy this generated class from the JVM and export into our Project
build path. Click on the button
Read classes from JVM ...
A search dialog opens up, and as you can search for the
class. We need to specify a path to copy to
browse..., you will be able to create a new folder inside the
And give it a name
After that, the path to this class will be displayed in the textbox in the dialog (You cannot modify that path inside this textbox). On the left, you can see the test folder is added to the project folder and also to build path. At this step, you may also choose more than one class in the JVM to export, sometimes it will take a little bit longer, a progress dialog will also be displayed.
Click on the
Copy to Build Path button, the class inside JVM will be exported
and copied into the test folder we created before, the class can now be
visualized and debugged. With two marked buttons you can step over single
instruction or step into byte code of this generated class.
To retrieve the GeneratedRunnableImpl class from the JVM via JDI we need to go to the Dr. Garbage Preferences and choose the option "JVM via JDI (Java Debug Interface)" when visualizing a class:
It is easy to recognize the differences between 2 Visualizations. The
constructor from the exported class (inside the test folder) contains no
nop) and the exported class (at this time) does not contain all
attributes, because the complete content will only be available at runtime.