Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into non-indy-jit
Browse files Browse the repository at this point in the history
Conflicts:
	core/src/main/java/org/jruby/ir/IRScope.java
  • Loading branch information
headius committed Oct 15, 2014
2 parents b7f248b + 4dea67a commit 8e8f161
Show file tree
Hide file tree
Showing 69 changed files with 738 additions and 1,615 deletions.
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/Ruby.java
Expand Up @@ -2831,7 +2831,7 @@ public void loadFile(String scriptName, InputStream in, boolean wrap) {

try {
ThreadContext.pushBacktrace(context, "(root)", file, 0);
context.preNodeEval(objectClass, self, scriptName);
context.preNodeEval(self);
ParseResult parseResult = parseFile(scriptName, in, null);

if (wrap) {
Expand Down
Expand Up @@ -48,15 +48,15 @@ void post(ThreadContext context) {
},
FrameBacktraceScopeFull (Framing.Backtrace, Scoping.Full) {
void pre(ThreadContext context, IRubyObject self, RubyModule implementer, String name, Block block, StaticScope scope) {
context.preMethodBacktraceAndScope(name, implementer, scope);
context.preMethodBacktraceAndScope(name, scope);
}
void post(ThreadContext context) {
context.postMethodBacktraceAndScope();
}
},
FrameBacktraceScopeDummy (Framing.Backtrace, Scoping.Dummy) {
void pre(ThreadContext context, IRubyObject self, RubyModule implementer, String name, Block block, StaticScope scope) {
context.preMethodBacktraceDummyScope(implementer, name, scope);
context.preMethodBacktraceDummyScope(name, scope);
}
void post(ThreadContext context) {
context.postMethodBacktraceDummyScope();
Expand All @@ -72,15 +72,15 @@ void post(ThreadContext context) {
},
FrameNoneScopeFull(Framing.None, Scoping.Full) {
void pre(ThreadContext context, IRubyObject self, RubyModule implementer, String name, Block block, StaticScope scope) {
context.preMethodScopeOnly(implementer, scope);
context.preMethodScopeOnly(scope);
}
void post(ThreadContext context) {
context.postMethodScopeOnly();
}
},
FrameNoneScopeDummy(Framing.None, Scoping.Dummy) {
void pre(ThreadContext context, IRubyObject self, RubyModule implementer, String name, Block block, StaticScope scope) {
context.preMethodNoFrameAndDummyScope(implementer, scope);
context.preMethodNoFrameAndDummyScope(scope);
}
void post(ThreadContext context) {
context.postMethodScopeOnly();
Expand Down
Expand Up @@ -5,6 +5,7 @@

import org.jruby.RubyModule;
import org.jruby.ir.*;
import org.jruby.ir.operands.InterpreterContext;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.Block;
import org.jruby.runtime.DynamicScope;
Expand All @@ -22,22 +23,24 @@ public List<String[]> getParameterList() {
}

@Override
protected void post(ThreadContext context) {
protected void post(InterpreterContext ic, ThreadContext context) {
// update call stacks (pop: ..)
context.popFrame();
context.popScope();
if (ic.popDynScope()) {
context.popScope();
}
}

@Override
protected void pre(ThreadContext context, IRubyObject self, String name, Block block) {
protected void pre(InterpreterContext ic, ThreadContext context, IRubyObject self, String name, Block block) {
// update call stacks (push: frame, class, scope, etc.)

StaticScope ss = method.getStaticScope();
context.preMethodFrameAndClass(getImplementationClass(), name, self, block, ss);
// Add a parent-link to current dynscope to support non-local returns cheaply
// This doesn't affect variable scoping since local variables will all have
// the right scope depth.
context.pushScope(DynamicScope.newDynamicScope(ss, context.getCurrentScope()));
context.preMethodFrameOnly(getImplementationClass(), name, self, block);
if (ic.pushNewDynScope()) {
// Add a parent-link to current dynscope to support non-local returns cheaply
// This doesn't affect variable scoping since local variables will all have
// the right scope depth.
context.pushScope(DynamicScope.newDynamicScope(method.getStaticScope(), context.getCurrentScope()));
}
context.setCurrentVisibility(getVisibility());
}

Expand Down
Expand Up @@ -29,7 +29,6 @@ public class InterpretedIRMethod extends DynamicMethod implements IRMethodArgs,

private Arity arity;
private boolean displayedCFG = false; // FIXME: Remove when we find nicer way of logging CFG
private boolean pushScope;

protected final IRScope method;

Expand All @@ -45,7 +44,6 @@ public InterpretedIRMethod(IRScope method, Visibility visibility, RubyModule imp
this.method = method;
this.method.getStaticScope().determineModule();
this.arity = calculateArity();
this.pushScope = true;
if (!implementationClass.getRuntime().getInstanceConfig().getCompileMode().shouldJIT()) {
this.box.callCount = -1;
}
Expand Down Expand Up @@ -90,18 +88,18 @@ public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule claz
DynamicMethod actualMethod = box.actualMethod;
if (actualMethod != null) return actualMethod.call(context, self, clazz, name, args, block);

ensureInstrsReady();
InterpreterContext ic = ensureInstrsReady();

if (IRRuntimeHelpers.isDebug()) doDebug();

if (method.hasExplicitCallProtocol()) return Interpreter.INTERPRET_METHOD(context, this, self, name, args, block);

pre(context, self, name, block);
pre(ic, context, self, name, block);

try {
return Interpreter.INTERPRET_METHOD(context, this, self, name, args, block);
} finally {
post(context);
post(ic, context);
}
}

Expand All @@ -110,39 +108,37 @@ protected void doDebug() {
String realName = name == null || "".equals(name) ? method.getName() : name;
LOG.info("Executing '" + realName + "'");
if (displayedCFG == false) {
// The base IR may not have been processed yet
CFG cfg = method.getCFG();
LOG.info("Graph:\n" + cfg.toStringGraph());
LOG.info("CFG:\n" + cfg.toStringInstrs());
displayedCFG = true;
}
}

protected void post(ThreadContext context) {
protected void post(InterpreterContext ic, ThreadContext context) {
// update call stacks (pop: ..)
context.popFrame();
if (this.pushScope) {
if (ic.popDynScope()) {
context.popScope();
}
}

protected void pre(ThreadContext context, IRubyObject self, String name, Block block) {
protected void pre(InterpreterContext ic, ThreadContext context, IRubyObject self, String name, Block block) {
// update call stacks (push: frame, class, scope, etc.)
StaticScope ss = method.getStaticScope();
context.preMethodFrameAndClass(getImplementationClass(), name, self, block, ss);
if (this.pushScope) {
context.pushScope(DynamicScope.newDynamicScope(ss));
context.preMethodFrameOnly(getImplementationClass(), name, self, block);
if (ic.pushNewDynScope()) {
context.pushScope(DynamicScope.newDynamicScope(method.getStaticScope()));
}
context.setCurrentVisibility(getVisibility());
}

public void ensureInstrsReady() {
// SSS FIXME: Move this out of here to some other place?
// Prepare method if not yet done so we know if the method has an explicit/implicit call protocol
if (method.getInstrsForInterpretation() == null) {
InterpreterContext context = method.prepareForInterpretation();
this.pushScope = !context.getFlags().contains(IRFlags.DYNSCOPE_ELIMINATED);
public InterpreterContext ensureInstrsReady() {
InterpreterContext context = method.getInterpreterContext();
if (context == null) {
context = method.prepareForInterpretation();
}
return context;
}

public DynamicMethod getMethodForCaching() {
Expand Down
Expand Up @@ -25,9 +25,7 @@
***** END LICENSE BLOCK *****/
package org.jruby.internal.runtime.methods;

import org.jruby.Ruby;
import org.jruby.RubyModule;
import org.jruby.anno.JRubyMethod;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.Arity;
import org.jruby.runtime.Block;
Expand Down Expand Up @@ -120,23 +118,23 @@ protected final void preFrameOnly(ThreadContext context, IRubyObject self, Strin
}

protected final void preScopeOnly(ThreadContext context) {
context.preMethodScopeOnly(implementationClass, staticScope);
context.preMethodScopeOnly(staticScope);
}

protected final void preNoFrameDummyScope(ThreadContext context) {
context.preMethodNoFrameAndDummyScope(implementationClass, staticScope);
context.preMethodNoFrameAndDummyScope(staticScope);
}

protected final void preBacktraceOnly(ThreadContext context, String name) {
context.preMethodBacktraceOnly(name);
}

protected final void preBacktraceDummyScope(ThreadContext context, String name) {
context.preMethodBacktraceDummyScope(implementationClass, name, staticScope);
context.preMethodBacktraceDummyScope(name, staticScope);
}

protected final void preBacktraceAndScope(ThreadContext context, String name) {
context.preMethodBacktraceAndScope(name, implementationClass, staticScope);
context.preMethodBacktraceAndScope(name, staticScope);
}

protected final void preNoop() {}
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/ir/IRBuilder.java
Expand Up @@ -1986,7 +1986,7 @@ public void buildMultipleAsgn19Assignment(final MultipleAsgn19Node multipleAsgnN
private void handleBreakAndReturnsInLambdas(IRClosure s) {
Label rBeginLabel = s.getNewLabel();
Label rEndLabel = s.getNewLabel();
Label rescueLabel = Label.GLOBAL_ENSURE_BLOCK_LABEL;
Label rescueLabel = Label.getGlobalEnsureBlockLabel();

// protect the entire body as it exists now with the global ensure block
addInstrAtBeginning(s, new ExceptionRegionStartMarkerInstr(rescueLabel));
Expand Down
21 changes: 21 additions & 0 deletions core/src/main/java/org/jruby/ir/IRClosure.java
Expand Up @@ -109,6 +109,27 @@ public IRClosure(IRManager manager, IRScope lexicalParent, int lineNumber, Stati
this.nestingDepth++;
}

public InterpreterContext prepareInterpreterContext(Operand self) {
if (interpreterContext != null) return interpreterContext; // Already prepared

initScope(false);

Instr[] linearizedInstrArray = prepareInstructions();

interpreterContext = new ClosureInterpreterContext(getTemporaryVariablesCount(), getBooleanVariablesCount(),
getFixnumVariablesCount(), getFloatVariablesCount(),getFlags().clone(), linearizedInstrArray,
self, getStaticScope(), getBlockBody());

return interpreterContext;
}

@Override
public synchronized InterpreterContext prepareForInterpretation() {
// This should have already been prepared during preparation of parent scopes.
// If this is null, it would be a bug and let users throw a NPE.
return interpreterContext;
}

public void setBeginEndBlock() {
this.isBeginEndBlock = true;
}
Expand Down

0 comments on commit 8e8f161

Please sign in to comment.