Skip to content

Commit 6acf377

Browse files
committedMar 1, 2018
Make ir.print only print after boot, and ir.print.all print all.
1 parent 80b9665 commit 6acf377

File tree

9 files changed

+29
-10
lines changed

9 files changed

+29
-10
lines changed
 

Diff for: ‎core/src/main/java/org/jruby/internal/runtime/AbstractIRMethod.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.util.ArrayList;
44
import java.util.List;
5+
56
import org.jruby.RubyModule;
67
import org.jruby.internal.runtime.methods.DynamicMethod;
78
import org.jruby.internal.runtime.methods.IRMethodArgs;
@@ -11,6 +12,7 @@
1112
import org.jruby.ir.instructions.Instr;
1213
import org.jruby.ir.instructions.PutFieldInstr;
1314
import org.jruby.ir.interpreter.InterpreterContext;
15+
import org.jruby.ir.runtime.IRRuntimeHelpers;
1416
import org.jruby.parser.StaticScope;
1517
import org.jruby.runtime.ArgumentDescriptor;
1618
import org.jruby.runtime.Arity;
@@ -41,7 +43,7 @@ public AbstractIRMethod(IRScope method, Visibility visibility, RubyModule implem
4143
if (Options.JIT_THRESHOLD.load() == -1) callCount = -1;
4244

4345
// If we are printing, do the build right at creation time so we can see it
44-
if (Options.IR_PRINT.load()) {
46+
if (IRRuntimeHelpers.shouldPrintIR(implementationClass.getRuntime())) {
4547
ensureInstrsReady();
4648
}
4749
}

Diff for: ‎core/src/main/java/org/jruby/internal/runtime/methods/InterpretedIRMethod.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public InterpretedIRMethod(IRScope method, Visibility visibility, RubyModule imp
3838
if (Options.JIT_THRESHOLD.load() == -1) callCount = -1;
3939

4040
// If we are printing, do the build right at creation time so we can see it
41-
if (Options.IR_PRINT.load()) {
41+
if (IRRuntimeHelpers.shouldPrintIR(implementationClass.getRuntime())) {
4242
ensureInstrsReady();
4343
}
4444
}
@@ -73,7 +73,7 @@ public InterpreterContext ensureInstrsReady() {
7373
}
7474
interpreterContext = method.getInterpreterContext();
7575

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

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

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

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

301301
LOG.info("Printing full IR for " + method.getName() + ":\n" + new String(baos.toByteArray()));

Diff for: ‎core/src/main/java/org/jruby/internal/runtime/methods/MixedModeIRMethod.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public InterpreterContext ensureInstrsReady() {
6868

6969
InterpreterContext ic = method.getInterpreterContext();
7070

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

7474
LOG.info("Printing simple IR for " + method.getName() + ":\n" + new String(baos.toByteArray()));

Diff for: ‎core/src/main/java/org/jruby/ir/interpreter/Interpreter.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public static void runBeginBlocks(List<IRClosure> beBlocks, ThreadContext contex
6363
protected IRubyObject execute(Ruby runtime, IRScriptBody irScope, IRubyObject self) {
6464
BeginEndInterpreterContext ic = (BeginEndInterpreterContext) irScope.getInterpreterContext();
6565

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

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

Diff for: ‎core/src/main/java/org/jruby/ir/runtime/IRRuntimeHelpers.java

+16
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
import org.jruby.util.ByteList;
7878
import org.jruby.util.RegexpOptions;
7979
import org.jruby.util.TypeConverter;
80+
import org.jruby.util.cli.Options;
8081
import org.jruby.util.log.Logger;
8182
import org.jruby.util.log.LoggerFactory;
8283
import org.objectweb.asm.Type;
@@ -564,6 +565,21 @@ private static IRubyObject[] frobnicateKwargsArgument(final ThreadContext contex
564565
return args;
565566
}
566567

568+
/**
569+
* If the ir.print property is enabled and we are not booting, or the ir.print.all property is enabled and we are
570+
* booting, return true to indicate IR should be printed.
571+
*
572+
* @param runtime the current runtime
573+
* @return whether to print IR
574+
*/
575+
public static boolean shouldPrintIR(Ruby runtime) {
576+
boolean booting = runtime.isBooting();
577+
boolean print = Options.IR_PRINT.load();
578+
boolean printAll = Options.IR_PRINT_ALL.load();
579+
580+
return (print && !booting) || (booting && printAll);
581+
}
582+
567583
private static class DivvyKeywordsVisitor extends RubyHash.VisitorWithState {
568584
RubyHash syms;
569585
RubyHash others;

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ protected void codegenScriptBody(IRScriptBody script) {
134134
protected void emitScope(IRScope scope, String name, Signature signature, boolean specificArity, boolean print) {
135135
BasicBlock[] bbs = scope.prepareForCompilation();
136136

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

140140
LOG.info("Printing JIT IR for " + scope.getName() + ":\n" + new String(baos.toByteArray()));

Diff for: ‎core/src/main/java/org/jruby/runtime/InterpretedIRBlockBody.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public InterpreterContext ensureInstrsReady() {
6666
}
6767

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

7272
LOG.info("Printing simple IR for " + closure.getName() + ":\n" + new String(baos.toByteArray()));

Diff for: ‎core/src/main/java/org/jruby/runtime/MixedModeIRBlockBody.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public InterpreterContext ensureInstrsReady() {
8787
}
8888

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

9393
LOG.info("Printing simple IR for " + closure.getName() + ":\n" + new String(baos.toByteArray()));

Diff for: ‎core/src/main/java/org/jruby/util/cli/Options.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ public class Options {
127127
public static final Option<Boolean> IR_WRITING = bool(IR, "ir.writing", false, "Write JRuby IR file.");
128128
public static final Option<Boolean> IR_WRITING_DEBUG = bool(IR, "ir.writing.debug", false, "Debug writing JRuby IR file.");
129129
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.");
130-
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.");
130+
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.");
131+
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.");
131132
public static final Option<Boolean> IR_PRINT_COLOR = bool(IR, "ir.print.color", false, "Print the final IR with color highlighting.");
132133

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

0 commit comments

Comments
 (0)
Please sign in to comment.