A simple PIC api
Mark Roos
mroos at roos.com
Wed Mar 11 23:13:04 UTC 2015
Hi Jochen
I have to think about yours some more but I thought I would share mine. I
condensed it to
make it easier to explain.
regards
mark
I extended callsite to hold a bunch of values one of which is the depth.
And my model for the cache is up to 10 chained GWTs after that I drop the
chain and start over.
When I get a miss in the cache off to the fallback ( look below to see how
this MH is made)
static RtObject fallbackSelf(RtCallSite site, Object... args)
For each guard I create a test MH which takes all of the args and returns
a bool.
Since I only look at the TOS it drops the rest, yours is more
complicated. This can be
different for each guard in my case.
RtObject rcvr=(RtObject)args[args.length - 1]; // top of stack
test=MethodHandles.insertArguments(test, 0, rcvr.classField()); //
the behavior field
test=MethodHandles.dropArguments(test, 0, site.dropArray()); //
match test signature
then finds the code based on the site and the receiver in this case
MethodHandle newTarget=rcvr.lookupSelf(site.getSelector());
makes a new GWT with the existing chain as its slow path
if the cache is full will make the bootstrap MH (see below) the target
dropping the existing cache
if(site._depth < 10)
MethodHandle gwt=MethodHandles.guardWithTest(test, newTarget, site
.getRealTarget());
site._depth = site._depth + 1; // bump the depth
inserts it at the start of the chain by making it the new target
site.setRealTarget(gwt);
and invokes it ( has to spread the args here as they were compressed on
the way to the fallback)
MethodHandle invoke=newTarget.asSpreader(Object[].class, site
.getAirity());
result=(RtObject) invoke.invokeExact((Object[])args);
You probably need to see the bootstrap to understand the invoke. To limit
myself to only one fallback signature
I bind the callsite and collect the args
MethodHandle mh=lookup.findStatic(RtCallSite.class,
"fallbackSelf", mt);
MethodHandle mh2=MethodHandles.insertArguments(mh, 0, site); //
insert the call site
MethodHandle mh3=mh2.asCollector(RtObject[].class, site
.getAirity()); // combine the args into an array
site.setBootstrapTarget(mh3);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/mlvm-dev/attachments/20150311/9028e307/attachment-0001.html>
More information about the mlvm-dev
mailing list