-
-
Notifications
You must be signed in to change notification settings - Fork 925
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restructure JIT to happen in one place each for methods and blocks
This introduces a third method and block top, the "OptInterpreter" version. All methods and blocks in a normal run are MixedMode now, aggregating both an Interpreted and a slot for an optimized or jitted version. This commit also simplifies some call paths in the IR block bodies and lowers several methods into CompiledIRBlockBody to be more direct.
Showing
19 changed files
with
491 additions
and
636 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 6 additions & 7 deletions
13
...ava/org/jruby/compiler/FullBuildTask.java → ...rg/jruby/compiler/BlockFullBuildTask.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
core/src/main/java/org/jruby/compiler/MethodFullBuildTask.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package org.jruby.compiler; | ||
|
||
import org.jruby.internal.runtime.methods.MixedModeIRMethod; | ||
import org.jruby.internal.runtime.methods.OptInterpretedIRMethod; | ||
import org.jruby.runtime.MixedModeIRBlockBody; | ||
import org.jruby.runtime.OptInterpretedIRBlockBody; | ||
|
||
class MethodFullBuildTask implements Runnable { | ||
private JITCompiler jitCompiler; | ||
private final MixedModeIRMethod method; | ||
|
||
MethodFullBuildTask(JITCompiler jitCompiler, MixedModeIRMethod method) { | ||
this.jitCompiler = jitCompiler; | ||
this.method = method; | ||
} | ||
|
||
public void run() { | ||
try { | ||
method.completeBuild(new OptInterpretedIRMethod(method.getIRScope(), method.getVisibility(), method.getImplementationClass())); | ||
|
||
if (jitCompiler.config.isJitLogging()) { | ||
JITCompiler.log(method.getImplementationClass(), method.getFile(), method.getLine(), method.getName(), "done building"); | ||
} | ||
} catch (Throwable t) { | ||
if (jitCompiler.config.isJitLogging()) { | ||
JITCompiler.log(method.getImplementationClass(), method.getFile(), method.getLine(), method.getName(), | ||
"Could not build; passes run: " + method.getIRScope().getExecutedPasses(), t.getMessage()); | ||
if (jitCompiler.config.isJitLoggingVerbose()) { | ||
t.printStackTrace(); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
139 changes: 139 additions & 0 deletions
139
core/src/main/java/org/jruby/internal/runtime/methods/OptInterpretedIRMethod.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
package org.jruby.internal.runtime.methods; | ||
|
||
import org.jruby.RubyModule; | ||
import org.jruby.internal.runtime.AbstractIRMethod; | ||
import org.jruby.ir.IRMethod; | ||
import org.jruby.ir.IRScope; | ||
import org.jruby.ir.interpreter.FullInterpreterContext; | ||
import org.jruby.ir.interpreter.InterpreterContext; | ||
import org.jruby.ir.persistence.IRDumper; | ||
import org.jruby.ir.runtime.IRRuntimeHelpers; | ||
import org.jruby.runtime.Block; | ||
import org.jruby.runtime.DynamicScope; | ||
import org.jruby.runtime.ThreadContext; | ||
import org.jruby.runtime.Visibility; | ||
import org.jruby.runtime.builtin.IRubyObject; | ||
import org.jruby.util.log.Logger; | ||
import org.jruby.util.log.LoggerFactory; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
|
||
/** | ||
* Method for -X-C (interpreted only execution). See MixedModeIRMethod for inter/JIT method impl. | ||
*/ | ||
public class OptInterpretedIRMethod extends AbstractIRMethod { | ||
private static final Logger LOG = LoggerFactory.getLogger(OptInterpretedIRMethod.class); | ||
|
||
protected FullInterpreterContext interpreterContext; | ||
|
||
public OptInterpretedIRMethod(IRScope method, Visibility visibility, RubyModule implementationClass) { | ||
super(method, visibility, implementationClass); | ||
|
||
interpreterContext = method.prepareFullBuild(); | ||
} | ||
|
||
@Override | ||
public InterpreterContext ensureInstrsReady() { | ||
return interpreterContext; | ||
} | ||
|
||
@Override | ||
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject[] args, Block block) { | ||
return INTERPRET_METHOD(context, ensureInstrsReady(), getImplementationClass(), self, name, args, block); | ||
} | ||
|
||
@Override | ||
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject[] args) { | ||
return INTERPRET_METHOD(context, ensureInstrsReady(), getImplementationClass(), self, name, args, Block.NULL_BLOCK); | ||
} | ||
|
||
private IRubyObject INTERPRET_METHOD(ThreadContext context, InterpreterContext ic, RubyModule implClass, | ||
IRubyObject self, String name, IRubyObject[] args, Block block) { | ||
try { | ||
ThreadContext.pushBacktrace(context, name, ic.getFileName(), context.getLine()); | ||
return ic.getEngine().interpret(context, null, self, ic, implClass, name, args, block); | ||
} finally { | ||
ThreadContext.popBacktrace(context); | ||
} | ||
} | ||
|
||
@Override | ||
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, Block block) { | ||
return INTERPRET_METHOD(context, ensureInstrsReady(), getImplementationClass(), self, name, block); | ||
} | ||
|
||
@Override | ||
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name) { | ||
return INTERPRET_METHOD(context, ensureInstrsReady(), getImplementationClass(), self, name, Block.NULL_BLOCK); | ||
} | ||
|
||
private IRubyObject INTERPRET_METHOD(ThreadContext context, InterpreterContext ic, RubyModule implClass, | ||
IRubyObject self, String name, Block block) { | ||
try { | ||
ThreadContext.pushBacktrace(context, name, ic.getFileName(), context.getLine()); | ||
return ic.getEngine().interpret(context, null, self, ic, implClass, name, block); | ||
} finally { | ||
ThreadContext.popBacktrace(context); | ||
} | ||
} | ||
|
||
@Override | ||
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0, Block block) { | ||
return INTERPRET_METHOD(context, ensureInstrsReady(), getImplementationClass(), self, name, arg0, block); | ||
} | ||
|
||
@Override | ||
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0) { | ||
return INTERPRET_METHOD(context, ensureInstrsReady(), getImplementationClass(), self, name, arg0, Block.NULL_BLOCK); | ||
} | ||
|
||
private IRubyObject INTERPRET_METHOD(ThreadContext context, InterpreterContext ic, RubyModule implClass, | ||
IRubyObject self, String name, IRubyObject arg1, Block block) { | ||
try { | ||
ThreadContext.pushBacktrace(context, name, ic.getFileName(), context.getLine()); | ||
return ic.getEngine().interpret(context, null, self, ic, implClass, name, arg1, block); | ||
} finally { | ||
ThreadContext.popBacktrace(context); | ||
} | ||
} | ||
|
||
@Override | ||
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0, IRubyObject arg1, Block block) { | ||
return INTERPRET_METHOD(context, ensureInstrsReady(), getImplementationClass(), self, name, arg0, arg1, block); | ||
} | ||
|
||
@Override | ||
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0, IRubyObject arg1) { | ||
return INTERPRET_METHOD(context, ensureInstrsReady(), getImplementationClass(), self, name, arg0, arg1, Block.NULL_BLOCK); | ||
} | ||
|
||
private IRubyObject INTERPRET_METHOD(ThreadContext context, InterpreterContext ic, RubyModule implClass, | ||
IRubyObject self, String name, IRubyObject arg1, IRubyObject arg2, Block block) { | ||
try { | ||
ThreadContext.pushBacktrace(context, name, ic.getFileName(), context.getLine()); | ||
return ic.getEngine().interpret(context, null, self, ic, implClass, name, arg1, arg2, block); | ||
} finally { | ||
ThreadContext.popBacktrace(context); | ||
} | ||
} | ||
|
||
@Override | ||
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, Block block) { | ||
return INTERPRET_METHOD(context, ensureInstrsReady(), getImplementationClass(), self, name, arg0, arg1, arg2, block); | ||
} | ||
|
||
@Override | ||
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2) { | ||
return INTERPRET_METHOD(context, ensureInstrsReady(), getImplementationClass(), self, name, arg0, arg1, arg2, Block.NULL_BLOCK); | ||
} | ||
|
||
private IRubyObject INTERPRET_METHOD(ThreadContext context, InterpreterContext ic, RubyModule implClass, | ||
IRubyObject self, String name, IRubyObject arg1, IRubyObject arg2, IRubyObject arg3, Block block) { | ||
try { | ||
ThreadContext.pushBacktrace(context, name, ic.getFileName(), context.getLine()); | ||
return ic.getEngine().interpret(context, null, self, ic, implClass, name, arg1, arg2, arg3, block); | ||
} finally { | ||
ThreadContext.popBacktrace(context); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
core/src/main/java/org/jruby/runtime/OptInterpretedIRBlockBody.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package org.jruby.runtime; | ||
|
||
import org.jruby.ir.IRClosure; | ||
import org.jruby.ir.interpreter.Interpreter; | ||
import org.jruby.ir.interpreter.InterpreterContext; | ||
import org.jruby.runtime.builtin.IRubyObject; | ||
import org.jruby.util.log.Logger; | ||
import org.jruby.util.log.LoggerFactory; | ||
|
||
public class OptInterpretedIRBlockBody extends AbstractIRBlockBody { | ||
private static final Logger LOG = LoggerFactory.getLogger(OptInterpretedIRBlockBody.class); | ||
protected boolean pushScope; | ||
protected boolean reuseParentScope; | ||
private InterpreterContext fullInterpreterContext; | ||
|
||
public OptInterpretedIRBlockBody(IRClosure closure, Signature signature) { | ||
super(closure, signature); | ||
this.pushScope = true; | ||
this.reuseParentScope = false; | ||
this.fullInterpreterContext = closure.prepareFullBuild(); | ||
} | ||
|
||
@Override | ||
public ArgumentDescriptor[] getArgumentDescriptors() { | ||
return closure.getArgumentDescriptors(); | ||
} | ||
|
||
@Override | ||
public boolean canInvokeDirect() { | ||
return true; | ||
} | ||
|
||
@Override | ||
protected IRubyObject invokeCallDirect(ThreadContext context, Block block, IRubyObject[] args, Block blockArg, IRubyObject self) { | ||
context.setCurrentBlockType(Block.Type.PROC); | ||
InterpreterContext ic = fullInterpreterContext; | ||
return Interpreter.INTERPRET_BLOCK(context, block, null, ic, args, block.getBinding().getMethod(), blockArg); | ||
} | ||
|
||
@Override | ||
protected IRubyObject invokeYieldDirect(ThreadContext context, Block block, IRubyObject[] args, Block blockArg, IRubyObject self) { | ||
context.setCurrentBlockType(Block.Type.NORMAL); | ||
InterpreterContext ic = fullInterpreterContext; | ||
return Interpreter.INTERPRET_BLOCK(context, block, self, ic, args, block.getBinding().getMethod(), blockArg); | ||
} | ||
|
||
@Override | ||
protected IRubyObject invoke(ThreadContext context, Block block, IRubyObject[] args, Block blockArg, IRubyObject self) { | ||
throw new UnsupportedOperationException("invoke not implemented"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters