Skip to content

Commit 23a3a11

Browse files
committed
Fix mis-optimization of sub calls.
The outer is tied up with the CodeRef, so we can't just blindly curry the callsite with that. Fixes lexical issues that plagued some of the Rakudo sanity tests.
1 parent 2f67595 commit 23a3a11

File tree

1 file changed

+37
-7
lines changed

1 file changed

+37
-7
lines changed

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

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -171,17 +171,26 @@ public static void subcallResolve_noa(Lookup caller, MutableCallSite cs, String
171171
* and callsite with what they've been resolved to. Don't do it if
172172
* it's a compiler stub, though. */
173173
if (!cr.isCompilerStub && !shared) {
174-
cs.setTarget(MethodHandles
175-
.insertArguments(
176-
MethodHandles.dropArguments(cr.staticInfo.mh, 0, String.class, int.class),
177-
3, cr, csd)
178-
.asVarargsCollector(Object[].class)
179-
.asType(cs.getTarget().type()));
174+
try {
175+
MethodType invType = MethodType.methodType(void.class,
176+
MethodHandle.class, String.class, CallSiteDescriptor.class,
177+
ThreadContext.class, Object[].class);
178+
MethodHandle inv = caller.findStatic(IndyBootstrap.class, "subInvoker", invType);
179+
cs.setTarget(MethodHandles
180+
.dropArguments(
181+
MethodHandles.insertArguments(inv, 0, cr.staticInfo.mh, name, csd),
182+
0, String.class, int.class)
183+
.asVarargsCollector(Object[].class)
184+
.asType(cs.getTarget().type()));
185+
}
186+
catch (Throwable t) {
187+
throw ExceptionHandling.dieInternal(tc, t);
188+
}
180189
}
181190

182191
/* Make the sub call directly for this initial call. */
183192
try {
184-
cr.staticInfo.mh.invokeExact(tc, cr, csd, args);
193+
cr.staticInfo.mh.invokeExact(tc, (CodeRef)cr, csd, args);
185194
}
186195
catch (ControlException e) {
187196
throw e;
@@ -219,6 +228,27 @@ public static void lexotic_s_noa(long target, SixModelObject boxType, String _,
219228
throw throwee;
220229
}
221230

231+
public static void subInvoker(MethodHandle mh, String name, CallSiteDescriptor csd, ThreadContext tc, Object[] args) throws Throwable {
232+
SixModelObject invokee = Ops.getlex(name, tc);
233+
CodeRef cr;
234+
if (invokee instanceof CodeRef) {
235+
cr = (CodeRef)invokee;
236+
}
237+
else {
238+
InvocationSpec is = invokee.st.InvocationSpec;
239+
if (is == null)
240+
throw ExceptionHandling.dieInternal(tc, "Can not invoke this object");
241+
if (is.ClassHandle != null)
242+
cr = (CodeRef)invokee.get_attribute_boxed(tc, is.ClassHandle, is.AttrName, is.Hint);
243+
else {
244+
cr = (CodeRef)is.InvocationHandler;
245+
csd = csd.injectInvokee(tc, args, invokee);
246+
args = tc.flatArgs;
247+
}
248+
}
249+
mh.invokeExact(tc, cr, csd, args);
250+
}
251+
222252
public static CallSite indcall_noa(Lookup caller, String _, MethodType type) {
223253
try {
224254
/* Look up indirect call invoker method. */

0 commit comments

Comments
 (0)