Skip to content

Commit

Permalink
Merge branch 'master' into truffle-head
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisseaton committed Oct 31, 2014
2 parents d023658 + f2c36e6 commit 6e38260
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 22 deletions.
Expand Up @@ -27,7 +27,18 @@ public class CachedYieldDispatchNode extends YieldDispatchNode {

public CachedYieldDispatchNode(RubyContext context, RubyProc block, YieldDispatchNode next) {
super(context);

callNode = Truffle.getRuntime().createDirectCallNode(block.getCallTarget());
insert(callNode);

if (callNode.isCallTargetCloningAllowed()) {
callNode.cloneCallTarget();
}

if (callNode.isInlinable()) {
callNode.forceInlining();
}

this.next = next;
}

Expand Down
Expand Up @@ -10,21 +10,19 @@
package org.jruby.truffle.nodes.yield;

import com.oracle.truffle.api.*;
import com.oracle.truffle.api.source.*;
import com.oracle.truffle.api.frame.*;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.nodes.NodeCost;
import com.oracle.truffle.api.nodes.NodeInfo;
import com.oracle.truffle.api.nodes.NodeUtil;
import org.jruby.common.IRubyWarnings;
import org.jruby.truffle.runtime.*;
import org.jruby.truffle.runtime.core.*;
import org.jruby.util.cli.Options;

@NodeInfo(cost = NodeCost.UNINITIALIZED)
public class UninitializedYieldDispatchNode extends YieldDispatchNode {

private static final int MAX_DISPATCHES = 4;
private static final int MAX_DEPTH = MAX_DISPATCHES + 1; // MAX_DISPATCHES + UninitializedDispatchNode
private int depth = 0;

public UninitializedYieldDispatchNode(RubyContext context) {
super(context);
Expand All @@ -34,10 +32,10 @@ public UninitializedYieldDispatchNode(RubyContext context) {
public Object dispatch(VirtualFrame frame, RubyProc block, Object[] argumentsObjects) {
CompilerDirectives.transferToInterpreterAndInvalidate();

int depth = getDepth();
final YieldDispatchHeadNode dispatchHead = (YieldDispatchHeadNode) NodeUtil.getNthParent(this, depth);
depth++;

if (depth > MAX_DEPTH) {
if (depth == Options.TRUFFLE_DISPATCH_POLYMORPHIC_MAX.load()) {
final YieldDispatchHeadNode dispatchHead = (YieldDispatchHeadNode) NodeUtil.getNthParent(this, depth);
final GeneralYieldDispatchNode newGeneralYield = new GeneralYieldDispatchNode(getContext());
dispatchHead.getDispatch().replace(newGeneralYield);
return newGeneralYield.dispatch(frame, block, argumentsObjects);
Expand All @@ -52,10 +50,10 @@ public Object dispatch(VirtualFrame frame, RubyProc block, Object[] argumentsObj
public Object dispatchWithModifiedSelf(VirtualFrame frame, RubyProc block, Object self, Object[] argumentsObjects) {
CompilerDirectives.transferToInterpreterAndInvalidate();

int depth = getDepth();
final YieldDispatchHeadNode dispatchHead = (YieldDispatchHeadNode) NodeUtil.getNthParent(this, depth);
depth++;

if (depth > MAX_DEPTH) {
if (depth == Options.TRUFFLE_DISPATCH_POLYMORPHIC_MAX.load()) {
final YieldDispatchHeadNode dispatchHead = (YieldDispatchHeadNode) NodeUtil.getNthParent(this, depth);
final GeneralYieldDispatchNode newGeneralYield = new GeneralYieldDispatchNode(getContext());
dispatchHead.getDispatch().replace(newGeneralYield);
return newGeneralYield.dispatchWithModifiedSelf(frame, block, self, argumentsObjects);
Expand All @@ -66,16 +64,4 @@ public Object dispatchWithModifiedSelf(VirtualFrame frame, RubyProc block, Objec
return dispatch.dispatchWithModifiedSelf(frame, block, self, argumentsObjects);
}

public int getDepth() {
int depth = 1;
Node parent = this.getParent();

while (!(parent instanceof YieldDispatchHeadNode)) {
parent = parent.getParent();
depth++;
}

return depth;
}

}

0 comments on commit 6e38260

Please sign in to comment.