Skip to content

Commit

Permalink
Make ir.print only print after boot, and ir.print.all print all.
Browse files Browse the repository at this point in the history
  • Loading branch information
headius committed Mar 1, 2018
1 parent 80b9665 commit 6acf377
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.ArrayList;
import java.util.List;

import org.jruby.RubyModule;
import org.jruby.internal.runtime.methods.DynamicMethod;
import org.jruby.internal.runtime.methods.IRMethodArgs;
Expand All @@ -11,6 +12,7 @@
import org.jruby.ir.instructions.Instr;
import org.jruby.ir.instructions.PutFieldInstr;
import org.jruby.ir.interpreter.InterpreterContext;
import org.jruby.ir.runtime.IRRuntimeHelpers;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.ArgumentDescriptor;
import org.jruby.runtime.Arity;
Expand Down Expand Up @@ -41,7 +43,7 @@ public AbstractIRMethod(IRScope method, Visibility visibility, RubyModule implem
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()) {
if (IRRuntimeHelpers.shouldPrintIR(implementationClass.getRuntime())) {
ensureInstrsReady();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public InterpretedIRMethod(IRScope method, Visibility visibility, RubyModule imp
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()) {
if (IRRuntimeHelpers.shouldPrintIR(implementationClass.getRuntime())) {
ensureInstrsReady();
}
}
Expand Down Expand Up @@ -73,7 +73,7 @@ public InterpreterContext ensureInstrsReady() {
}
interpreterContext = method.getInterpreterContext();

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

LOG.info("Printing simple IR for " + method.getName() + ":\n" + new String(baos.toByteArray()));
Expand Down Expand Up @@ -295,7 +295,7 @@ private void promoteToFullBuild(ThreadContext context) {

if (callCount++ >= Options.JIT_THRESHOLD.load()) runtime.getJITCompiler().buildThresholdReached(context, this);

if (Options.IR_PRINT.load()) {
if (IRRuntimeHelpers.shouldPrintIR(implementationClass.getRuntime())) {
ByteArrayOutputStream baos = IRDumper.printIR(method, true, true);

LOG.info("Printing full IR for " + method.getName() + ":\n" + new String(baos.toByteArray()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public InterpreterContext ensureInstrsReady() {

InterpreterContext ic = method.getInterpreterContext();

if (Options.IR_PRINT.load()) {
if (IRRuntimeHelpers.shouldPrintIR(implementationClass.getRuntime())) {
ByteArrayOutputStream baos = IRDumper.printIR(method, false);

LOG.info("Printing simple IR for " + method.getName() + ":\n" + new String(baos.toByteArray()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static void runBeginBlocks(List<IRClosure> beBlocks, ThreadContext contex
protected IRubyObject execute(Ruby runtime, IRScriptBody irScope, IRubyObject self) {
BeginEndInterpreterContext ic = (BeginEndInterpreterContext) irScope.getInterpreterContext();

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

LOG.info("Printing simple IR for " + irScope.getName() + ":\n" + new String(baos.toByteArray()));
Expand Down
16 changes: 16 additions & 0 deletions core/src/main/java/org/jruby/ir/runtime/IRRuntimeHelpers.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
import org.jruby.util.ByteList;
import org.jruby.util.RegexpOptions;
import org.jruby.util.TypeConverter;
import org.jruby.util.cli.Options;
import org.jruby.util.log.Logger;
import org.jruby.util.log.LoggerFactory;
import org.objectweb.asm.Type;
Expand Down Expand Up @@ -564,6 +565,21 @@ private static IRubyObject[] frobnicateKwargsArgument(final ThreadContext contex
return args;
}

/**
* If the ir.print property is enabled and we are not booting, or the ir.print.all property is enabled and we are
* booting, return true to indicate IR should be printed.
*
* @param runtime the current runtime
* @return whether to print IR
*/
public static boolean shouldPrintIR(Ruby runtime) {
boolean booting = runtime.isBooting();
boolean print = Options.IR_PRINT.load();
boolean printAll = Options.IR_PRINT_ALL.load();

return (print && !booting) || (booting && printAll);
}

private static class DivvyKeywordsVisitor extends RubyHash.VisitorWithState {
RubyHash syms;
RubyHash others;
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/ir/targets/JVMVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ protected void codegenScriptBody(IRScriptBody script) {
protected void emitScope(IRScope scope, String name, Signature signature, boolean specificArity, boolean print) {
BasicBlock[] bbs = scope.prepareForCompilation();

if (print && Options.IR_PRINT.load()) {
if (print && IRRuntimeHelpers.shouldPrintIR(runtime)) {
ByteArrayOutputStream baos = IRDumper.printIR(scope, true);

LOG.info("Printing JIT IR for " + scope.getName() + ":\n" + new String(baos.toByteArray()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public InterpreterContext ensureInstrsReady() {
}

if (interpreterContext == null) {
if (Options.IR_PRINT.load()) {
if (IRRuntimeHelpers.shouldPrintIR(closure.getStaticScope().getModule().getRuntime())) {
ByteArrayOutputStream baos = IRDumper.printIR(closure, false);

LOG.info("Printing simple IR for " + closure.getName() + ":\n" + new String(baos.toByteArray()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public InterpreterContext ensureInstrsReady() {
}

if (interpreterContext == null) {
if (Options.IR_PRINT.load()) {
if (IRRuntimeHelpers.shouldPrintIR(closure.getStaticScope().getModule().getRuntime())) {
ByteArrayOutputStream baos = IRDumper.printIR(closure, false);

LOG.info("Printing simple IR for " + closure.getName() + ":\n" + new String(baos.toByteArray()));
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/org/jruby/util/cli/Options.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ public class Options {
public static final Option<Boolean> IR_WRITING = bool(IR, "ir.writing", false, "Write JRuby IR file.");
public static final Option<Boolean> IR_WRITING_DEBUG = bool(IR, "ir.writing.debug", false, "Debug writing JRuby IR file.");
public static final Option<String> IR_INLINE_COMPILER_PASSES = string(IR, "ir.inline_passes", "Specify comma delimeted list of passes to run after inlining a method.");
public static final Option<Boolean> IR_PRINT = bool(IR, "ir.print", false, "Print the final IR to be run before starting to execute each body of code.");
public static final Option<Boolean> IR_PRINT_ALL = bool(IR, "ir.print.all", false, "Enable ir.print and include IR executed during JRuby's boot phase.");
public static final Option<Boolean> IR_PRINT = bool(IR, "ir.print", IR_PRINT_ALL.load(), "Print the final IR to be run before starting to execute each body of code.");
public static final Option<Boolean> IR_PRINT_COLOR = bool(IR, "ir.print.color", false, "Print the final IR with color highlighting.");

public static final Option<Boolean> NATIVE_ENABLED = bool(NATIVE, "native.enabled", true, "Enable/disable native code, including POSIX features and C exts.");
Expand Down

0 comments on commit 6acf377

Please sign in to comment.