Skip to content

Commit

Permalink
Additional cleanup of reduced block dispatch state.
Browse files Browse the repository at this point in the history
* Push self block in JIT, not passed block.
* Push self block only if present, null otherwise.
* Remove more unnecessary block type args.
* Remove thread-local block type from context.
  • Loading branch information
headius committed Jul 10, 2018
1 parent 5ff5a0e commit 901ee62
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 21 deletions.
19 changes: 6 additions & 13 deletions core/src/main/java/org/jruby/ir/targets/IRBytecodeAdapter.java
Expand Up @@ -133,7 +133,12 @@ public void loadContext() {
}

public void loadSelfBlock() {
adapter.aload(signature.argOffset(JVMVisitor.SELF_BLOCK_NAME));
int selfBlockOffset = signature.argOffset(JVMVisitor.SELF_BLOCK_NAME);
if (selfBlockOffset == -1) {
adapter.aconst_null();
} else {
adapter.aload(selfBlockOffset);
}
}

public void loadStaticScope() {
Expand Down Expand Up @@ -162,18 +167,6 @@ public void loadFrameName() {
adapter.aload(signature.argCount() - 1);
}

public void loadSuperName() {
adapter.aload(5);
}

public void loadBlockType() {
if (signature.argOffset("type") == -1) {
adapter.aconst_null();
} else {
adapter.aload(signature.argOffset("type"));
}
}

public void storeSelf() {
adapter.astore(signature.argOffset("self"));
}
Expand Down
8 changes: 4 additions & 4 deletions core/src/main/java/org/jruby/ir/targets/JVMVisitor.java
Expand Up @@ -70,7 +70,7 @@ public class JVMVisitor extends IRVisitor {

public static final Signature CLOSURE_SIGNATURE = Signature
.returning(IRubyObject.class)
.appendArgs(new String[]{"context", SELF_BLOCK_NAME, "scope", "self", "args", BLOCK_ARG_NAME, "superName", "type"}, ThreadContext.class, Block.class, StaticScope.class, IRubyObject.class, IRubyObject[].class, Block.class, String.class, Block.Type.class);
.appendArgs(new String[]{"context", SELF_BLOCK_NAME, "scope", "self", "args", BLOCK_ARG_NAME, "superName"}, ThreadContext.class, Block.class, StaticScope.class, IRubyObject.class, IRubyObject[].class, Block.class, String.class);

public JVMVisitor(Ruby runtime) {
this.jvm = Options.COMPILE_INVOKEDYNAMIC.load() ? new JVM7() : new JVM6();
Expand Down Expand Up @@ -1158,7 +1158,7 @@ private void checkArity(int required, int opt, boolean rest, boolean receivesKey
jvmAdapter().ldc(rest);
jvmAdapter().ldc(receivesKeywords);
jvmAdapter().ldc(restKey);
jvmMethod().loadBlock();
jvmMethod().loadSelfBlock();
jvmAdapter().invokestatic(p(IRRuntimeHelpers.class), "checkArity", sig(void.class, ThreadContext.class, StaticScope.class, Object[].class, int.class, int.class, boolean.class, boolean.class, int.class, Block.class));
}

Expand All @@ -1167,7 +1167,7 @@ public void CheckForLJEInstr(CheckForLJEInstr checkForljeinstr) {
jvmMethod().loadContext();
jvmLoadLocal(DYNAMIC_SCOPE);
jvmAdapter().ldc(checkForljeinstr.isDefinedWithinMethod());
jvmMethod().loadBlock();
jvmMethod().loadSelfBlock();
jvmAdapter().invokestatic(p(IRRuntimeHelpers.class), "checkForLJE", sig(void.class, ThreadContext.class, DynamicScope.class, boolean.class, Block.class));
}

Expand Down Expand Up @@ -1990,7 +1990,7 @@ public void RuntimeHelperCall(RuntimeHelperCall runtimehelpercall) {
jvmMethod().loadContext();
jvmLoadLocal(DYNAMIC_SCOPE);
visit(runtimehelpercall.getArgs()[0]);
jvmMethod().loadBlock();
jvmMethod().loadSelfBlock();
jvmAdapter().invokestatic(p(IRRuntimeHelpers.class), "handleBreakAndReturnsInLambdas", sig(IRubyObject.class, ThreadContext.class, DynamicScope.class, Object.class, Block.class));
jvmStoreLocal(runtimehelpercall.getResult());
break;
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/runtime/CompiledIRBlockBody.java
Expand Up @@ -147,7 +147,7 @@ public MethodHandle getHandle() {
@Override
protected IRubyObject callDirect(ThreadContext context, Block block, IRubyObject[] args, Block blockArg) {
try {
return (IRubyObject)handle.invokeExact(context, block, getStaticScope(), (IRubyObject)null, args, blockArg, block.getBinding().getMethod(), block.type);
return (IRubyObject)handle.invokeExact(context, block, getStaticScope(), (IRubyObject)null, args, blockArg, block.getBinding().getMethod());
} catch (Throwable t) {
Helpers.throwException(t);
return null; // not reached
Expand All @@ -157,7 +157,7 @@ protected IRubyObject callDirect(ThreadContext context, Block block, IRubyObject
@Override
protected IRubyObject yieldDirect(ThreadContext context, Block block, IRubyObject[] args, IRubyObject self) {
try {
return (IRubyObject)handle.invokeExact(context, block, getStaticScope(), self, args, Block.NULL_BLOCK, block.getBinding().getMethod(), block.type);
return (IRubyObject)handle.invokeExact(context, block, getStaticScope(), self, args, Block.NULL_BLOCK, block.getBinding().getMethod());
} catch (Throwable t) {
Helpers.throwException(t);
return null; // not reached
Expand Down
2 changes: 0 additions & 2 deletions core/src/main/java/org/jruby/runtime/ThreadContext.java
Expand Up @@ -140,7 +140,6 @@ public static ThreadContext newContext(Ruby runtime) {

// These two fields are required to support explicit call protocol
// (via IR instructions) for blocks.
private Block.Type currentBlockType; // See prepareBlockArgs code in IRRuntimeHelpers
private Throwable savedExcInLambda; // See handleBreakAndReturnsInLambda in IRRuntimeHelpers

/**
Expand Down Expand Up @@ -198,7 +197,6 @@ private ThreadContext(Ruby runtime) {
this.nil = runtime.getNil();
this.tru = runtime.getTrue();
this.fals = runtime.getFalse();
this.currentBlockType = Block.Type.NORMAL;
this.savedExcInLambda = null;

if (runtime.getInstanceConfig().isProfilingEntireRun()) {
Expand Down

0 comments on commit 901ee62

Please sign in to comment.