15
votes

I recently had a task where I had to use hot code replace functionality. So I did it using the Java Instrumentation API available in tools.jar.

Does eclipse use some different logic for hot replace of new class files or uses same Java API ? I tried to read from some places but was not clear:

Eclipse Java debugger transmits new class files over the debugging channel to another JVM

This line in Eclipse Hot Code Replace was not clear.

2
Your link is broken, try this one - wiki.eclipse.org/FAQ_What_is_hot_code_replace%3F. - Perception
@Perception I changed it nw it works - Narendra Pathai
Eclipse is open source - why don't you look? You can get a head start on how to look at it here: vogella.com/articles/EclipseCodeAccess/article.html. ALSO: if your solution "worked", then what do you care how Eclipse does it? - paulsm4
@paulsm4 if something works that does not mean that it is the best way to do it. And that is what I want to find out. - Narendra Pathai
@paulsm4 please suggest me some way to improve the question. - Narendra Pathai

2 Answers

7
votes

I believe eclipse use the same logic, they are both relying on a native interface called JVMTI. The JVMTI provide tools to inspect the state, and to control the execution of applications running in the Java virtual machine.

There is a agent of JVMTI in the Java Instrumentation Implementation. The agent to talks to vm and perform certain tasks. it also has redefineClasses method.

Eclipse Java debugger or other tools use the JPDA (Java Platform Debugger Architecture), and the JPDA mainly have three parts (JVMTI,JDWP,JDI). JVMTI act as debuggee,JDI act as debugger,and the JDWP act as communication channel between them.

In the end, they all talk to JVMTI,and it use the same logic.

4
votes

No, debuggers usually use JDI.

com.sun.jdi.VirtualMachine#redefineClasses

See the following link for details. http://docs.oracle.com/javase/7/docs/technotes/guides/jpda/index.html