Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Eliminate two instructions per QAST::WVal.
This passes the values directly to the indy bootstrap method, which we
didn't have the infrastructure to do when QAST::WVal stuff was first
switched over.
  • Loading branch information
jnthn committed Apr 27, 2013
1 parent ec08455 commit 83fd61b
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/vm/jvm/QAST/Compiler.nqp
Expand Up @@ -3476,12 +3476,14 @@ class QAST::CompilerJAST {
my $handle := nqp::scgethandle($sc);
my $idx := nqp::scgetobjidx($sc, $val);
my $il := JAST::InstructionList.new();
$il.append(JAST::PushSVal.new( :value($handle) ));
$il.append(JAST::PushIVal.new( :value($idx) ));
$il.append(JAST::Instruction.new( :op('aload_1') ));
$il.append(JAST::InvokeDynamic.new(
'wval', $TYPE_SMO, [$TYPE_STR, 'J', $TYPE_TC],
'org/perl6/nqp/runtime/IndyBootstrap', 'wval'
'wval', $TYPE_SMO, [$TYPE_TC],
'org/perl6/nqp/runtime/IndyBootstrap', 'wval',
[
JAST::PushSVal.new( :value($handle) ),
JAST::PushIVal.new( :value($idx) )
]
));
result($il, $RT_OBJ);
}
Expand Down
36 changes: 36 additions & 0 deletions src/vm/jvm/runtime/org/perl6/nqp/runtime/IndyBootstrap.java
Expand Up @@ -41,6 +41,42 @@ public static SixModelObject wvalResolve(MutableCallSite cs, String sc, long idx
return res;
}

public static CallSite wval(Lookup caller, String name, MethodType type,
String sc, long idx) {
try {
/* Look up wval resolver method. */
MethodType resType = MethodType.methodType(SixModelObject.class,
String.class, long.class, MutableCallSite.class, ThreadContext.class);
MethodHandle res = caller.findStatic(IndyBootstrap.class, "wvalResolve", resType);

/* Create a mutable callsite, and curry the resolver with it. */
MutableCallSite cs = new MutableCallSite(type);
cs.setTarget(MethodHandles.insertArguments(res, 0, sc, idx, cs));

/* Produce callsite; it'll be updated with the resolved WVal upon the
* first invocation. */
return cs;
}
catch (Exception e) {
throw new RuntimeException(e);
}
}

public static SixModelObject wvalResolve(String sc, long idx, MutableCallSite cs, ThreadContext tc) {
/* Look up the WVal. */
SixModelObject res = tc.gc.scs.get(sc).root_objects.get((int)idx);

/* Update this callsite, so that we never run the lookup again and instead
* just always use the resolved object. Discards incoming arguments, as
* they are no longer needed. */
cs.setTarget(MethodHandles.dropArguments(
MethodHandles.constant(SixModelObject.class, res),
0, ThreadContext.class));

/* Hand back the resulting object, for this first call. */
return res;
}

public static CallSite subcall(Lookup caller, String _, MethodType type, String name, int csIdx) {
try {
/* Look up subcall resolver method. */
Expand Down

0 comments on commit 83fd61b

Please sign in to comment.