Search
Close this search box.

Month: June 2005

Thanks to everyone who attended Jarod’s and my talk this afternoon at JavaOne and especially to those who had to go to the overflow room. The rest of the DTrace team and I were thrilled by the turnout — we would never have thought that 900+ Java developers would be so interested in DTrace. We spent the next few hours hashing out some ways to get better support for Java in DTrace; we look forward to giving an update at next year’s conference.

As promised, here are the slides from the talk:

To get started with the dvm provider on your Solaris 10 system, download the agent here. You may need to set your LD_LIBRARY_PATH to point to wherever you install it. Then invoke java with the -Xrundvmti:all option.

I wasn’t able to capture the command history as was requested, but Bryan wrote up a nice post which can be used for the first part of the talk, and here are some of the java-specific commands from today.

# dtrace -n dvm`pgrep java`:::method-entry'{ @[copyinstr(arg0), copyinstr(arg1)] = count() }'
# dtrace -n dvm`pgrep java`:::object-alloc'{ @[jstack(20, 8000)] = count() }'
# dtrace -n dvm`pgrep java`:::object-alloc'/copyinstr(arg0) == "java/awt/Rectangle"/{}'

Try mixing and matching. Check out the Solaris Dynamic Tracing Guide for the exhaustive reference guide. If you have questions or want to figure out some more scripts, feel free to post a question here or — even better — on the DTrace forum on opensolaris.org.


Technorati Tags:

In case you missed the DTrace demo during the JavaOne keynote, you can view it in RealPlayer format here. To skip to the DTrace stuff, jump 1:12:30 in. I haven’t actually been able to bring myself to watch it — I’m too self-conscious — so feel free to comment on it. Things to keep in mind when watching: I can type better when I’m not in front of 7,000 people and I’m well aware that I need a hair cut.

That guy next to me is John Loiacono (not to be confused with Laocoon, the tragic figure of Roman epic).


Technorati Tags:

This morning I gave a demo of DTrace with the Java agents during the keynote at JavaOne. In the past few hours I’ve had a lot of great feedback from Java developers — we’ve found a bunch of big performance wins already, and I expect we’ll find more this week (remember the DTrace challenge). For the demo, I ran /usr/java/demo/jfc/Java2D/Java2Demo.jar with the Java DTrace agents enabled and ran a couple of scripts on it.

The first script just gathered a frequency count for each method invoked — nothing too subtle:

jmethod.d

#!/usr/sbin/dtrace -s
dvm$1:::method-entry
{
@[copyinstr(arg0), copyinstr(arg1)] = count();
}
END
{
printa("%-10@u %s.%s()\n", @);
}

bash-3.00# dtrace -s jmethods.d `pgrep java`
...
574        sun/java2d/SunGraphics2D.getCompClip()
608        sun/java2d/pipe/Region.dimAdd()
648        java/lang/ref/Reference.get()
671        java/awt/geom/AffineTransform.transform()
685        java/awt/Component.getParent_NoClientCode()
685        java/awt/Component.getParent()
702        sun/misc/VM.addFinalRefCount()
798        java/lang/ref/ReferenceQueue.remove()
809        java/lang/ref/Reference.access$200()
923        java/awt/geom/RectIterator.isDone()
1228       sun/dc/pr/Rasterizer.nextTile()
1657       sun/dc/pr/Rasterizer.getTileState()
1692       sun/java2d/pipe/AlphaColorPipe.renderPathTile()
1692       sun/java2d/pipe/AlphaColorPipe.needTile()
1702       sun/java2d/SunGraphics2D.getSurfaceData()
3457       java/lang/Math.min()
^C

The second demo was a little more exciting: this guy followed a thread of control all the way from Java code through the native library code, the system calls, and all the kernel function calls to the lowest levels of the system. Each different layer of the stack is annotated with color — the first use of color in a DTrace script as far as I know.

follow.d

#!/usr/sbin/dtrace -s
/*
* This script was used for the DTrace demo during the JavaOne keynote.
*
* VT100 escape sequences are used to produce multi-colored output from
* dtrace(1M). Pink is Java code, red is library code, blue is system calls,
* and green is kernel function calls.
*/
#pragma D option quiet
dvm$1:::method-entry
/copyinstr(arg0) == "sun/java2d/pipe/AlphaColorPipe" &&
copyinstr(arg1) == "renderPathTile"/
{
self->interested = 1;
self->depth = 8;
}
dvm$1:::method-entry
/self->interested/
{
printf("33[01;35m%*.*s -> %s.%s33[0m\n",
self->depth, self->depth, "",
copyinstr(arg0), copyinstr(arg1));
self->depth += 2;
}
dvm$1:::method-return
/self->interested/
{
self->depth -= 2;
printf("33[01;35m%*.*s depth, self->depth, "",
copyinstr(arg0), copyinstr(arg1));
}
dvm$1:::method-return
/self->interested &&
copyinstr(arg0) == "sun/java2d/pipe/AlphaColorPipe" &&
copyinstr(arg1) == "renderPathTile"/
{
self->interested = 0;
self->depth = 0;
exit(0);
}
pid$1:::entry
/self->interested && probemod != "libdvmti.so"/
{
printf("33[01;31m%*.*s -> %s`%s33[0m\n",
self->depth, self->depth, "",
probemod, probefunc);
self->depth += 2;
}
pid$1:::return
/self->interested && probemod != "libdvmti.so"/
{
self->depth -= 2;
printf("33[01;31m%*.*s depth, self->depth, "",
probemod, probefunc);
}
syscall:::entry
/self->interested/
{
printf("33[01;34m%*.*s => %s33[0m\n",
self->depth, self->depth, "",
probefunc);
self->depth += 2;
}
syscall:::return
/self->interested/
{
self->depth -= 2;
printf("33[01;34m%*.*s depth, self->depth, "",
probefunc);
}
fbt:::entry
/self->interested/
{
printf("33[32m%*.*s -> %s33[0m\n",
self->depth, self->depth, "",
probefunc);
self->depth += 2;
}
fbt:::return
/self->interested/
{
self->depth -= 2;
printf("33[32m%*.*s depth, self->depth, "",
probefunc);
}

bash-3.00# dtrace -s follow.d `pgrep java`
     -> sun/java2d/pipe/AlphaColorPipe.renderPathTile
       -> copyout
       <- kcopy
       -> sun/java2d/SunGraphics2D.getSurfaceData
...
           <- libc.so.1`_lwp_cond_signal
         <- libjvm.so`__1cNObjectMonitorEexit6MpnGThread__v_
       <- libjvm.so`__1cSObjectSynchronizerIjni_exit6FpnHoopDesc_pnGThread__v_
     <- libjvm.so`jni_MonitorExit
   <- libawt.so`Java_sun_java2d_loops_MaskFill_MaskFill
<- sun/java2d/pipe/AlphaColorPipe.renderPathTile

Now you can give a keynote demo of your very own.


Technorati Tags:

I’ll be at JavaOne this week demonstrating the new Java/DTrace mash-up. At Monday morning’s keynote, I get a 100 second talk-within-a-talk (which itself is a talk-within-a-talk). On Monday evening, Stephen, Mike, Bryan, and I (and possibly some other Solaris folks) will be holding a BoF on OpenSolaris, DTrace and what they mean for Java. We’ll be in Golden Gate B1 at the Marriott Hotel from 7:30pm to 8:30pm. I’ll be hanging around one of the DTrace or Solaris booths whenever I can to watch Jarod Jenson getting performance wins in Java applications and giving away iPods if he can’t (I’m betting he gives away between zero and one iPods). Feel free to come by the booth or stop me in the halls for a demo or to talk about DTrace.


Technorati Tags:

Something kind of crazy is going on. I got a call from Chris; “Check out what we’re going to do at JavaOne,” he said. Here’s the deal: come to JavaOne, bring your Java application (on a usb device or CD or whatever), and we’ll[1] improve your application using DTrace. Or you get a free tchotchke — possibly one of several iPods. Usually you only see this kind of offer at furniture stores, and there’s some catch, but this is the real deal: either your application goes faster because of our clever DTrace trickery or you’re up some whizzy gadget. I was dubious until I saw the official announcement.

On the subject of JavaOne, this seems as good a time as any to plug the session I’m giving on Thursday at 1:15pm in Room 121/122 (TS-5211). I’ll be talking about the same technology we’re (apparently) going to be using on your application.

See you at JavaOne; bring your app.


[1] For some value of the term we — I’m guessing I am going to be party to this insanity…


Technorati Tags:

The OpenSolaris launch has been pretty fun — I’ve already had some discussions with customers over the source code. Of course, the first thing people seemed to do with the source code is look for references to “shit” and “fuck”. This was titillating to be sure. Unsatisfied with the cheap laugh, ZDNet wanted to draw some conclusions from the profanity:

The much-vaunted dynamic tracing (dtrace) feature of Sun’s system may not be as safe to use as most people think.

“This bit me in the ass a couple of times, so lets toss this in as a cursory sanity check,” wrote one careful developer in the dtrace section.

I wrote that code in October of 2002. For those of you keeping score at home, that’s almost a year before DTrace integrated into Solaris 10 and more than two years before Solaris 10 hit the streets. Here’s the larger context of that comment:

923 	/*
924 	 * This bit me in the ass a couple of times, so lets toss this
925 	 * in as a cursory sanity check.
926 	 */
927 	ASSERT(pc != rp->r_g7 + 4);
928 	ASSERT(pc != rp->r_g7 + 8);

This gets pretty deep into the bowels of the pid provider, but the code preceeding these ASSERTs does the work of modifying the registers appropriately to emulate the effects of the traced instruction. For most instructions, we relocate the instruction bits to some per-thread scratch space and execute it there. We keep this scratch space in the user-land per-thread structure which, on SPARC, is always pointed to by the %g7 register (rp->r_g7 in the code above). The tricky thing is that while we change the program counter (%pc) to point to the scratch space, we leave the next program counter (%npc) where it was.

A bug I ran into very early in development was winding up executing the wrong code because I had incorrectly emulated an instruction. One way this manifested itself was that the program counter was set to %g7 + 4 or %g7 + 8. I added these ASSERTs after tracking down the problem — not because it was a condition that I thought should be handled, but because I wanted everything to stop immediately if it did.

In the nearly three years this code has existed, those ASSERTs have never been tripped. Of course, I didn’t expect them to be — they were a cursory sanity check so I could be sure this aberrant condition wasn’t occuring. Of course, if I had omitted the curse this might not have inspired such a puerile thrill.


Technorati Tags:

Recent Posts

April 17, 2024
January 13, 2024
December 29, 2023
February 12, 2017
December 18, 2016

Archives

Archives