Emilian has posted 6 posts at DZone. View Full User Profile

Using VisualVM, BTrace & Good Old Web Search

  • submit to reddit
At this point I still didn't know what exactly was going on, but it had to do with the NbProgressBar class. So I downloaded a new tool, btrace, and started writing a new btrace script using their online tutorial.

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:


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);

Field f2 = field("apple.laf.CUIAquaProgressBar", "progressBar");
/*org.netbeans.modules.progress.ui.NbProgressBar*/ Object swingbar = get(f2, pbar);

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.

Published at DZone with permission of its author, Emilian Bold.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)


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

thanks for sharing this valuable information to us, i know you have put in a lot of hard work in this project


 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

Ray Naa replied on Wed, 2014/09/24 - 4:00pm


We needed help with our SQL issues...http://nosqlguide.com was really helpful, a great resource and really helped us find a solution fast too.
NoSQL vs Relational databases

Ray Naa replied on Tue, 2014/09/30 - 3:10pm


While researching housing tools, I hit upon this real estate website,<a href="http://ochousingnews.com/">OC Housing Market News</a>.The news reporting and analysis on this site is of very high quality, the cartoons are hilarious, and the many user guides are extremely valuable. I recommend using this website to experience it.
Housing News

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.