Skip to content

Commit 6c4b3fe

Browse files
committedJul 11, 2018
Add logging of yield indy binding.
1 parent 051548f commit 6c4b3fe

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed
 

Diff for: ‎core/src/main/java/org/jruby/ir/targets/Bootstrap.java

+4
Original file line numberDiff line numberDiff line change
@@ -1108,6 +1108,10 @@ static String logMethod(DynamicMethod method) {
11081108
return "[#" + method.getSerialNumber() + " " + method.getImplementationClass() + "]";
11091109
}
11101110

1111+
static String logBlock(Block block) {
1112+
return "[" + block.getBody() + " " + block.getFrame() + "]";
1113+
}
1114+
11111115
private static final Binder BINDING_MAKER_BINDER = Binder.from(Binding.class, ThreadContext.class, IRubyObject.class, DynamicScope.class);
11121116

11131117
private static final MethodHandle FRAME_SCOPE_BINDING = BINDING_MAKER_BINDER.invokeStaticQuiet(LOOKUP, Bootstrap.class, "frameScopeBinding");

Diff for: ‎core/src/main/java/org/jruby/ir/targets/YieldSite.java

+26-1
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
import org.jruby.runtime.Block;
66
import org.jruby.runtime.BlockBody;
77
import org.jruby.runtime.CompiledIRBlockBody;
8-
import org.jruby.runtime.Helpers;
98
import org.jruby.runtime.ThreadContext;
109
import org.jruby.runtime.builtin.IRubyObject;
1110
import org.jruby.util.cli.Options;
11+
import org.jruby.util.log.Logger;
12+
import org.jruby.util.log.LoggerFactory;
1213
import org.objectweb.asm.Handle;
1314
import org.objectweb.asm.Opcodes;
1415

@@ -27,6 +28,8 @@
2728
public class YieldSite extends MutableCallSite {
2829
private final boolean unwrap;
2930

31+
private static final Logger LOG = LoggerFactory.getLogger(YieldSite.class);
32+
3033
public YieldSite(MethodType type, boolean unwrap) {
3134
super(type);
3235

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

80+
if (Options.INVOKEDYNAMIC_LOG_BINDING.load()) {
81+
LOG.info("yield \tbound directly as yield:" + Bootstrap.logBlock(block));
82+
}
83+
7784
target = unwrap ? compiledBody.getNormalYieldUnwrapHandle() : compiledBody.getNormalYieldHandle();
7885
} else {
86+
if (Options.INVOKEDYNAMIC_LOG_BINDING.load()) {
87+
LOG.info("yield \tbound indirectly as yield:" + Bootstrap.logBlock(block));
88+
}
89+
7990
target = Binder.from(type())
8091
.append(unwrap)
8192
.invokeStaticQuiet(MethodHandles.lookup(), IRRuntimeHelpers.class, "yield");
@@ -102,8 +113,16 @@ public IRubyObject yieldSpecific(ThreadContext context, Block block) throws Thro
102113
if (block.getBody() instanceof CompiledIRBlockBody) {
103114
CompiledIRBlockBody compiledBody = (CompiledIRBlockBody) block.getBody();
104115

116+
if (Options.INVOKEDYNAMIC_LOG_BINDING.load()) {
117+
LOG.info("yield \tbound directly as yieldSpecific:" + Bootstrap.logBlock(block));
118+
}
119+
105120
target = compiledBody.getNormalYieldSpecificHandle();
106121
} else {
122+
if (Options.INVOKEDYNAMIC_LOG_BINDING.load()) {
123+
LOG.info("yield \tbound indirectly as yieldSpecific:" + Bootstrap.logBlock(block));
124+
}
125+
107126
target = Binder.from(type())
108127
.permute(0, 1)
109128
.invokeVirtualQuiet(MethodHandles.lookup(), "yieldSpecific");
@@ -123,6 +142,12 @@ public IRubyObject yieldSpecific(ThreadContext context, Block block) throws Thro
123142
}
124143

125144
public IRubyObject yieldValues(ThreadContext context, Block block, IRubyObject[] args) {
145+
if (Options.INVOKEDYNAMIC_YIELD.load()) {
146+
if (Options.INVOKEDYNAMIC_LOG_BINDING.load()) {
147+
LOG.info("yield \tbound indirectly as yieldValues:" + Bootstrap.logBlock(block));
148+
}
149+
}
150+
126151
return block.yieldValues(context, args);
127152
}
128153
}

0 commit comments

Comments
 (0)
Please sign in to comment.