Using VisualVM, BTrace & Good Old Web Search
You can think of btrace as a scriptable debugger: you set breakpoints and when your breakpoints are hit some little script gets executed.
First, I wanted to see the animator calls. Those were on the actionPerformed method, resulting in this annotation for a btrace method:
@OnMethod(clazz="apple.laf.CUIAquaProgressBar$Animator",
method="actionPerformed")
I also needed the object itself, so I used the @Self annotation to get it from btrace:
public static void lnfaction(@Self Object animator)
Now, from the heap dump analysis above I knew that I had a reference to the progress bar here, so I used a bit of reflection to get to it:
println( strcat(strcat(str(timeNanos()), " : animator called "),str(animator)));
Field f = field("apple.laf.CUIAquaProgressBar$Animator", "this$0");
/*apple.laf.CUIAquaProgressBar*/ Object pbar = get(f,animator);
println(pbar);
Field f2 = field("apple.laf.CUIAquaProgressBar", "progressBar");
/*org.netbeans.modules.progress.ui.NbProgressBar*/ Object swingbar = get(f2, pbar);
println(swingbar);Note how limited you are while writing the script... no method calls are actually allowed except those from com.sun.btrace.BTraceUtils (which are statically imported). Even string concatenation has to be explicit, using BTraceUtils.strcat! Yet, it gives you enough options to progress quite nicely.
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)





Comments
Philippe Lhoste replied on Fri, 2009/08/21 - 4:25am
Beyond the particular context not interesting everyone (I don't use OSX nor NetBeans...), I appreciated the report of the detective work you did, showing good usage of tools. I knew VisualVM but it is the first time I see how to use BTrace, which is indeed an interesting tool if you can't (or don't want to) alter source code to add println's...
Thanks for sharing!
Mateo Gomez replied on Tue, 2012/04/17 - 12:20am
mexican dessert recipes
Matt Coleman replied on Tue, 2012/04/17 - 12:46am
debugging is such an important thing to do to fix the program and make it work
graphic design buffalo