Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In the Eclipse debugger, what kind of changes can be "hot code replaced" into the running JVM?

In Eclipse, if you run a program under "Debug" you can make changes to the code, and most of the time it will take effect immediately.

Sometimes, though, it will not -- in which case it pops up a message, or says "(may be out of sync)" next to the threads in the Debug pane.

What determines the kind of changes that can be hot-swapped? I've noticed these changes usually fail:

  • introducing new anonymous inner classes
  • changing classes (renaming/adding/removing fields and methods) when the class is instantiated
  • adding a try-catch block

but sometimes it seems to be almost random. What is the logic behind determining whether code can be replaced or not?

like image 507
PBJ Avatar asked Aug 04 '11 21:08

PBJ


People also ask

What can the Eclipse debugger do?

Eclipse allows running an application in Debug mode which helps with stepping through each line of code in a program. Eclipse also provides a Debug Perspective which is a set of views grouped together that help inspect code and make the debugging process very effective.

How do I run a debug code in Eclipse?

A Java program can be debugged simply by right clicking on the Java editor class file from Package explorer. Select Debug As → Java Application or use the shortcut Alt + Shift + D, J instead.

Which perspective is used for debugging in Eclipse?

The shortcut key to launch the previously launched Java application in the debug mode is F11. When a java program is started in the debug mode, users are prompted to switch to the debug perspective. The debug perspective offers additional views that can be used to troubleshoot an application.

How do I debug a breakpoint in Eclipse?

To put breakpoints in your code, double click in the left margin on the line you want execution to stop on. You may alternatively put your cursor in this line and then press Shift + Ctrl + B . To control execution use the Step Into, Step Over and Step Return buttons. They have the shortcuts F5 , F6 and F7 respectively.


1 Answers

Method statements (procedural code) work. Everything related to adding, removing or changing class schemas does not work. So no modifying inheritances, fields, extracting methods, changing signatures etc.

Usually hot-swapping method statements does not work if you are doing anything forbidden at the same time. Then the hot-swapping connection is "broken", so to say.

One thing I do not know for sure is anonymous classes. Have never tried that in connection with hot-swapping.

Edit: The guys over there at zeroturnaround have compiled a list in their features section what the jvm debugger can not do out of the box to promote their product: http://www.zeroturnaround.com/jrebel/features/ . Whether you like the tool or not, the list reflects my experience.

like image 122
Stefan Schubert-Peters Avatar answered Sep 27 '22 20:09

Stefan Schubert-Peters