Skip to content

Commit 83fd61b

Browse files
committed
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.
1 parent ec08455 commit 83fd61b

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed

src/vm/jvm/QAST/Compiler.nqp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3476,12 +3476,14 @@ class QAST::CompilerJAST {
34763476
my $handle := nqp::scgethandle($sc);
34773477
my $idx := nqp::scgetobjidx($sc, $val);
34783478
my $il := JAST::InstructionList.new();
3479-
$il.append(JAST::PushSVal.new( :value($handle) ));
3480-
$il.append(JAST::PushIVal.new( :value($idx) ));
34813479
$il.append(JAST::Instruction.new( :op('aload_1') ));
34823480
$il.append(JAST::InvokeDynamic.new(
3483-
'wval', $TYPE_SMO, [$TYPE_STR, 'J', $TYPE_TC],
3484-
'org/perl6/nqp/runtime/IndyBootstrap', 'wval'
3481+
'wval', $TYPE_SMO, [$TYPE_TC],
3482+
'org/perl6/nqp/runtime/IndyBootstrap', 'wval',
3483+
[
3484+
JAST::PushSVal.new( :value($handle) ),
3485+
JAST::PushIVal.new( :value($idx) )
3486+
]
34853487
));
34863488
result($il, $RT_OBJ);
34873489
}

src/vm/jvm/runtime/org/perl6/nqp/runtime/IndyBootstrap.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,42 @@ public static SixModelObject wvalResolve(MutableCallSite cs, String sc, long idx
4141
return res;
4242
}
4343

44+
public static CallSite wval(Lookup caller, String name, MethodType type,
45+
String sc, long idx) {
46+
try {
47+
/* Look up wval resolver method. */
48+
MethodType resType = MethodType.methodType(SixModelObject.class,
49+
String.class, long.class, MutableCallSite.class, ThreadContext.class);
50+
MethodHandle res = caller.findStatic(IndyBootstrap.class, "wvalResolve", resType);
51+
52+
/* Create a mutable callsite, and curry the resolver with it. */
53+
MutableCallSite cs = new MutableCallSite(type);
54+
cs.setTarget(MethodHandles.insertArguments(res, 0, sc, idx, cs));
55+
56+
/* Produce callsite; it'll be updated with the resolved WVal upon the
57+
* first invocation. */
58+
return cs;
59+
}
60+
catch (Exception e) {
61+
throw new RuntimeException(e);
62+
}
63+
}
64+
65+
public static SixModelObject wvalResolve(String sc, long idx, MutableCallSite cs, ThreadContext tc) {
66+
/* Look up the WVal. */
67+
SixModelObject res = tc.gc.scs.get(sc).root_objects.get((int)idx);
68+
69+
/* Update this callsite, so that we never run the lookup again and instead
70+
* just always use the resolved object. Discards incoming arguments, as
71+
* they are no longer needed. */
72+
cs.setTarget(MethodHandles.dropArguments(
73+
MethodHandles.constant(SixModelObject.class, res),
74+
0, ThreadContext.class));
75+
76+
/* Hand back the resulting object, for this first call. */
77+
return res;
78+
}
79+
4480
public static CallSite subcall(Lookup caller, String _, MethodType type, String name, int csIdx) {
4581
try {
4682
/* Look up subcall resolver method. */

0 commit comments

Comments
 (0)