This was very cool, adding a profiler using MH
Charles Oliver Nutter
headius at headius.com
Fri Feb 17 01:45:11 PST 2012
I've been meaning to do this for JRuby's Ruby-level profiler.
Currently, the profiler decorates all method objects (JRuby's
"handles") with an additional wrapper, similar to an Indy + MH option.
However, since JRuby's indy linker knows nothing about this wrapper,
it binds differently...and doesn't inline the same way as a result.
Glad to hear the overhead from decorating the call paths with handles
isn't that high!
- Charlie
On Thu, Feb 16, 2012 at 10:43 PM, Mark Roos <mroos at roos.com> wrote:
> So my code runs slow ( faster now with 23b15 by 2x but still 2x too slow)
> and I was wondering how to look for the issue.
> I was going to look for a java profiler but then I remembered a blog by Rémi
> on a code coverage monitor
> using method handles. So I decided to write my own profiler.
>
> The key code is below and it shows the power of methodHandles is ways one
> may not expect. And it
> added almost nothing to the run time ( maybe a few %). It inserts itself
> into each callsite target and
> collect entry and exit data.
>
> pretty cool
> thanks for the toolset
>
> mark
> by the was 'this' is the callSite, and this handles all airities
> // now add the profile stuff collect number of calls and the entry and
> exit times
> if( RtDebugger._profileEnable){
> mt=MethodType.methodType(RtObject[].class, RtCallSite.class,
> RtObject[].class);
> try {
> profileEntry = lookup.findStatic(RtDebugger.class, "profileEntry",
> mt);
> }
> catch (Throwable e) {
> e.printStackTrace();
> }
> profileEntry = MethodHandles.insertArguments(profileEntry, 0,
> this);
> // I have to collect the invoker, bind the call site to the entry
> filter
> // filter the invoker and then spread the invoker
> invoker = invoker.asSpreader(RtObject[].class, _airity);
> invoker = MethodHandles.filterArguments(invoker , 0, profileEntry);
> invoker = invoker.asCollector(RtObject[].class, _airity);
> // now the profile exit which collects exit time
> mt=MethodType.methodType(RtObject.class, RtCallSite.class,
> RtObject.class);
> try {
> profileExit = lookup.findStatic(RtDebugger.class, "profileExit",
> mt);
> }
> catch (Throwable e) {
> e.printStackTrace();
> }
> profileExit = MethodHandles.insertArguments(profileExit, 0, this);
> invoker = MethodHandles.filterReturnValue(invoker , profileExit);
> }
>
>
> _______________________________________________
> mlvm-dev mailing list
> mlvm-dev at openjdk.java.net
> http://mail.openjdk.java.net/mailman/listinfo/mlvm-dev
>
More information about the mlvm-dev
mailing list