Hot Code Replacement

Questions about YourKit Java Profiler
Post Reply
phancox
Posts: 7
Joined: Thu Jun 19, 2008 12:04 pm

Hot Code Replacement

Post by phancox »

When profiling an application from within Eclipse, does the profiler support hot code replacement? i.e., If I save changes to the source code of the application being profiled will the changed classes be automatically loaded into the running code similar to what happens when debugging an application?

If this doesn't normally happen, can I achieve the same affect by launching the debugger and attaching the profiler to the running JVM?
Anton Katilin
Posts: 6172
Joined: Wed Aug 11, 2004 8:37 am

Re: Hot Code Replacement

Post by Anton Katilin »

Profiling features relying on bytecode instrumentation (CPU tracing, probes, object allocation recording) may not work after hot swap due to JVM limitations.

Profiling modes not relying on bytecode instrumentation (e.g. CPU sampling, telemetry etc.) should work just fine.
If this doesn't normally happen, can I achieve the same affect by launching the debugger and attaching the profiler to the running JVM?
If you attach after making changes, and do not plan further changes, then yes. Otherwise, the situation is the same as above: you can't fully rely on bytecode instrumentation after changing already loaded classes.

Please also note that the attach mode has limitations by itself, no matter you use it with or without debugger and hot swap:
http://www.yourkit.com/docs/java/help/attach_agent.jsp

So, I can recommend the following:
1) If you need bytecode instrumentation related profiling modes, don't use NEITHER hot swap NOR the attach mode.
2) For other profiling modes, BOTH hot swap and the attach mode should be fine.
phancox
Posts: 7
Joined: Thu Jun 19, 2008 12:04 pm

Re: Hot Code Replacement

Post by phancox »

Hi Anton,

It was CPU sampling I was working with. Commented out a high CPU call, saved and reran the test without restarting the application. Seemed to be still going into the commented out method. My first assumption was that hot swap wasn't available and the application was still running the initial method.

My interpretation of your response was that this shouldn't have been the case. It is reasonably possible I made a mistake so I will retry in the knowlwdge that it should be running the updated method?
Anton Katilin
Posts: 6172
Joined: Wed Aug 11, 2004 8:37 am

Re: Hot Code Replacement

Post by Anton Katilin »

Are you sure Eclipse (debugger) has actually loaded the new class version?
Please note that JVM is not always able to perform hot swap, e.g. it can't add or remove methods.

Anyway, since you use CPU sampling, this must be a JVM hot swap issue, not the profiler's one.
Post Reply