Skip to content

Commit

Permalink
Mix in arity-checking for jitted block call path.
Browse files Browse the repository at this point in the history
  • Loading branch information
headius committed Aug 15, 2018
1 parent 1093f02 commit c20a0eb
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion core/src/main/java/org/jruby/runtime/CompiledIRBlockBody.java
Expand Up @@ -21,7 +21,8 @@ public CompiledIRBlockBody(MethodHandle handle, IRScope closure, long encodedSig
super(closure, Signature.decode(encodedSignature));
// evalType copied (shared) on MixedModeIRBlockBody#completeBuild
this.handle = handle;
this.callHandle = MethodHandles.insertArguments(handle, 2, closure.getStaticScope(), null);
MethodHandle callHandle = MethodHandles.insertArguments(handle, 2, closure.getStaticScope(), null);;
this.callHandle = MethodHandles.foldArguments(callHandle, CHECK_ARITY);
this.yieldDirectHandle = MethodHandles.insertArguments(
MethodHandles.insertArguments(handle, 2, closure.getStaticScope()),
4,
Expand All @@ -35,6 +36,16 @@ public CompiledIRBlockBody(MethodHandle handle, IRScope closure, long encodedSig

private static final MethodHandle WRAP_VALUE = Binder.from(IRubyObject[].class, IRubyObject.class).invokeStaticQuiet(MethodHandles.lookup(), CompiledIRBlockBody.class, "wrapValue");

private static final MethodHandle CHECK_ARITY = Binder
.from(void.class, ThreadContext.class, Block.class, IRubyObject[].class, Block.class)
.invokeStaticQuiet(MethodHandles.lookup(), CompiledIRBlockBody.class, "checkArity");

private static void checkArity(ThreadContext context, Block selfBlock, IRubyObject[] args, Block block) {
if (selfBlock.type == Block.Type.LAMBDA) {
selfBlock.getSignature().checkArity(context.runtime, args);
}
}

private static IRubyObject[] wrapValue(IRubyObject value) { return new IRubyObject[] {value}; }

@Override
Expand Down

0 comments on commit c20a0eb

Please sign in to comment.