Skip to content

Commit

Permalink
Add logging of yield indy binding.
Browse files Browse the repository at this point in the history
  • Loading branch information
headius committed Jul 11, 2018
1 parent 051548f commit 6c4b3fe
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
4 changes: 4 additions & 0 deletions core/src/main/java/org/jruby/ir/targets/Bootstrap.java
Expand Up @@ -1108,6 +1108,10 @@ static String logMethod(DynamicMethod method) {
return "[#" + method.getSerialNumber() + " " + method.getImplementationClass() + "]";
}

static String logBlock(Block block) {
return "[" + block.getBody() + " " + block.getFrame() + "]";
}

private static final Binder BINDING_MAKER_BINDER = Binder.from(Binding.class, ThreadContext.class, IRubyObject.class, DynamicScope.class);

private static final MethodHandle FRAME_SCOPE_BINDING = BINDING_MAKER_BINDER.invokeStaticQuiet(LOOKUP, Bootstrap.class, "frameScopeBinding");
Expand Down
27 changes: 26 additions & 1 deletion core/src/main/java/org/jruby/ir/targets/YieldSite.java
Expand Up @@ -5,10 +5,11 @@
import org.jruby.runtime.Block;
import org.jruby.runtime.BlockBody;
import org.jruby.runtime.CompiledIRBlockBody;
import org.jruby.runtime.Helpers;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.util.cli.Options;
import org.jruby.util.log.Logger;
import org.jruby.util.log.LoggerFactory;
import org.objectweb.asm.Handle;
import org.objectweb.asm.Opcodes;

Expand All @@ -27,6 +28,8 @@
public class YieldSite extends MutableCallSite {
private final boolean unwrap;

private static final Logger LOG = LoggerFactory.getLogger(YieldSite.class);

public YieldSite(MethodType type, boolean unwrap) {
super(type);

Expand Down Expand Up @@ -74,8 +77,16 @@ public IRubyObject yield(ThreadContext context, Block block, IRubyObject arg) th
if (block.getBody() instanceof CompiledIRBlockBody) {
CompiledIRBlockBody compiledBody = (CompiledIRBlockBody) block.getBody();

if (Options.INVOKEDYNAMIC_LOG_BINDING.load()) {
LOG.info("yield \tbound directly as yield:" + Bootstrap.logBlock(block));
}

target = unwrap ? compiledBody.getNormalYieldUnwrapHandle() : compiledBody.getNormalYieldHandle();
} else {
if (Options.INVOKEDYNAMIC_LOG_BINDING.load()) {
LOG.info("yield \tbound indirectly as yield:" + Bootstrap.logBlock(block));
}

target = Binder.from(type())
.append(unwrap)
.invokeStaticQuiet(MethodHandles.lookup(), IRRuntimeHelpers.class, "yield");
Expand All @@ -102,8 +113,16 @@ public IRubyObject yieldSpecific(ThreadContext context, Block block) throws Thro
if (block.getBody() instanceof CompiledIRBlockBody) {
CompiledIRBlockBody compiledBody = (CompiledIRBlockBody) block.getBody();

if (Options.INVOKEDYNAMIC_LOG_BINDING.load()) {
LOG.info("yield \tbound directly as yieldSpecific:" + Bootstrap.logBlock(block));
}

target = compiledBody.getNormalYieldSpecificHandle();
} else {
if (Options.INVOKEDYNAMIC_LOG_BINDING.load()) {
LOG.info("yield \tbound indirectly as yieldSpecific:" + Bootstrap.logBlock(block));
}

target = Binder.from(type())
.permute(0, 1)
.invokeVirtualQuiet(MethodHandles.lookup(), "yieldSpecific");
Expand All @@ -123,6 +142,12 @@ public IRubyObject yieldSpecific(ThreadContext context, Block block) throws Thro
}

public IRubyObject yieldValues(ThreadContext context, Block block, IRubyObject[] args) {
if (Options.INVOKEDYNAMIC_YIELD.load()) {
if (Options.INVOKEDYNAMIC_LOG_BINDING.load()) {
LOG.info("yield \tbound indirectly as yieldValues:" + Bootstrap.logBlock(block));
}
}

return block.yieldValues(context, args);
}
}

0 comments on commit 6c4b3fe

Please sign in to comment.