Skip to content

Commit

Permalink
Showing 4 changed files with 26 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -47,6 +47,11 @@ public InterpretedIRMethod(IRScope method, Visibility visibility, RubyModule imp

// -1 jit.threshold is way of having interpreter not promote full builds.
if (Options.JIT_THRESHOLD.load() == -1) callCount = -1;

// If we are printing, do the build right at creation time so we can see it
if (Options.IR_PRINT.load()) {
ensureInstrsReady();
}
}

public IRScope getIRScope() {
@@ -101,7 +106,7 @@ public InterpreterContext ensureInstrsReady() {
interpreterContext = method.getInterpreterContext();

if (Options.IR_PRINT.load()) {
ByteArrayOutputStream baos = IRDumper.printIR(method, false);
ByteArrayOutputStream baos = IRDumper.printIR(method, false, true);

LOG.info("Printing simple IR for " + method.getName(), "\n" + new String(baos.toByteArray()));
}
10 changes: 10 additions & 0 deletions core/src/main/java/org/jruby/ir/interpreter/Interpreter.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.jruby.ir.interpreter;

import java.io.ByteArrayOutputStream;
import java.util.List;
import org.jruby.EvalType;
import org.jruby.Ruby;
@@ -15,6 +16,7 @@
import org.jruby.ir.IRTranslator;
import org.jruby.ir.operands.IRException;
import org.jruby.ir.operands.WrappedIRClosure;
import org.jruby.ir.persistence.IRDumper;
import org.jruby.ir.runtime.IRBreakJump;
import org.jruby.ir.runtime.IRRuntimeHelpers;
import org.jruby.parser.StaticScope;
@@ -26,6 +28,7 @@
import org.jruby.runtime.Visibility;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.runtime.scope.ManyVarsDynamicScope;
import org.jruby.util.cli.Options;
import org.jruby.util.log.Logger;
import org.jruby.util.log.LoggerFactory;

@@ -58,6 +61,13 @@ public static void runBeginBlocks(List<IRClosure> beBlocks, ThreadContext contex
@Override
protected IRubyObject execute(Ruby runtime, IRScriptBody irScope, IRubyObject self) {
BeginEndInterpreterContext ic = (BeginEndInterpreterContext) irScope.getInterpreterContext();

if (Options.IR_PRINT.load()) {
ByteArrayOutputStream baos = IRDumper.printIR(irScope, false);

LOG.info("Printing simple IR for " + irScope.getName(), "\n" + new String(baos.toByteArray()));
}

ThreadContext context = runtime.getCurrentContext();
String name = ROOT;

6 changes: 5 additions & 1 deletion core/src/main/java/org/jruby/ir/persistence/IRDumper.java
Original file line number Diff line number Diff line change
@@ -77,10 +77,14 @@ public IRDumper(PrintStream ps, boolean color) {
}

public static ByteArrayOutputStream printIR(IRScope scope, boolean full) {
return printIR(scope, full, false);
}

public static ByteArrayOutputStream printIR(IRScope scope, boolean full, boolean recurse) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
IRDumper dumper = new IRDumper(ps, Options.IR_PRINT_COLOR.load());
dumper.visit(scope, full, false);
dumper.visit(scope, full, recurse);
return baos;
}

10 changes: 5 additions & 5 deletions core/src/main/java/org/jruby/ir/targets/JVMVisitor.java
Original file line number Diff line number Diff line change
@@ -143,7 +143,7 @@ public void emitScope(IRScope scope, String name, Signature signature, boolean s

Map <BasicBlock, Label> exceptionTable = scope.buildJVMExceptionTable();

emitClosures(scope);
emitClosures(scope, print);

jvm.pushmethod(name, scope, signature, specificArity);

@@ -312,18 +312,18 @@ public Handle emitModuleBodyJIT(IRModuleBody method) {
return handle;
}

private void emitClosures(IRScope s) {
private void emitClosures(IRScope s, boolean print) {
// Emit code for all nested closures
for (IRClosure c: s.getClosures()) {
c.setHandle(emitClosure(c));
c.setHandle(emitClosure(c, print));
}
}

public Handle emitClosure(IRClosure closure) {
public Handle emitClosure(IRClosure closure, boolean print) {
/* Compile the closure like a method */
String name = JavaNameMangler.encodeScopeForBacktrace(closure) + "$" + methodIndex++;

emitScope(closure, name, CLOSURE_SIGNATURE, false, true);
emitScope(closure, name, CLOSURE_SIGNATURE, false, print);

return new Handle(Opcodes.H_INVOKESTATIC, jvm.clsData().clsName, name, sig(CLOSURE_SIGNATURE.type().returnType(), CLOSURE_SIGNATURE.type().parameterArray()));
}

0 comments on commit e606af3

Please sign in to comment.