Skip to content
Permalink
Browse files
[Truffle] Move dispatch guards from the DSL into the body of the spec…
…ialisation.
  • Loading branch information
chrisseaton committed Jan 11, 2015
1 parent 0c11cad commit ad066eb3916cbd9894fe04699ef8d5c0326a98e3
Showing 7 changed files with 41 additions and 122 deletions.
@@ -104,14 +104,23 @@ public CachedBooleanDispatchNode(CachedBooleanDispatchNode prev) {
indirectCallNode = prev.indirectCallNode;
}

@Specialization(guards = "guardName")
@Specialization
public Object dispatch(
VirtualFrame frame,
boolean receiverObject,
Object receiverObject,
Object methodName,
Object blockObject,
Object argumentsObjects) {
if (receiverObject) {
if (!guardName(methodName) || !(receiverObject instanceof Boolean)) {
return next.executeDispatch(
frame,
receiverObject,
methodName,
blockObject,
argumentsObjects);
}

if ((boolean) receiverObject) {
trueProfile.enter();

try {
@@ -211,19 +220,4 @@ public Object dispatch(
}
}

@Fallback
public Object dispatch(
VirtualFrame frame,
Object receiverObject,
Object methodName,
Object blockObject,
Object argumentsObjects) {
return next.executeDispatch(
frame,
receiverObject,
methodName,
blockObject,
argumentsObjects);
}

}
@@ -103,21 +103,19 @@ public CachedBoxedDispatchNode(CachedBoxedDispatchNode prev) {
indirectCallNode = prev.indirectCallNode;
}

@Specialization(guards = "guardName")
@Specialization
public Object dispatch(
VirtualFrame frame,
RubyBasicObject receiverObject,
Object receiverObject,
Object methodName,
Object blockObject,
Object argumentsObjects) {
// Check the lookup node is what we expect

if (receiverObject.getMetaClass() != expectedClass) {
if (!guardName(methodName) || !(receiverObject instanceof RubyBasicObject) || ((RubyBasicObject) receiverObject).getMetaClass() != expectedClass) {
return next.executeDispatch(
frame,
receiverObject,
methodName,
CompilerDirectives.unsafeCast(blockObject, RubyProc.class, true, false),
blockObject,
argumentsObjects);
}

@@ -170,21 +168,6 @@ public Object dispatch(
}
}

@Fallback
public Object dispatch(
VirtualFrame frame,
Object receiverObject,
Object methodName,
Object blockObject,
Object argumentsObjects) {
return next.executeDispatch(
frame,
receiverObject,
methodName,
blockObject,
argumentsObjects);
}

@Override
public String toString() {
return String.format("CachedBoxedDispatchNode(:%s, %s@%x, %s, %s)",
@@ -83,21 +83,19 @@ public CachedBoxedMethodMissingDispatchNode(CachedBoxedMethodMissingDispatchNode
indirectCallNode = prev.indirectCallNode;
}

@Specialization(guards = "guardName")
@Specialization
public Object dispatch(
VirtualFrame frame,
RubyBasicObject receiverObject,
Object receiverObject,
Object methodName,
Object blockObject,
Object argumentsObjects) {
// Check the lookup node is what we expect

if (receiverObject.getMetaClass() != expectedClass) {
if (!guardName(methodName) || !(receiverObject instanceof RubyBasicObject) || ((RubyBasicObject) receiverObject).getMetaClass() != expectedClass) {
return next.executeDispatch(
frame,
receiverObject,
methodName,
CompilerDirectives.unsafeCast(blockObject, RubyProc.class, true, false),
blockObject,
argumentsObjects);
}

@@ -177,19 +175,4 @@ public Object dispatch(
}
}

@Fallback
public Object dispatch(
VirtualFrame frame,
Object receiverObject,
Object methodName,
Object blockObject,
Object argumentsObjects) {
return next.executeDispatch(
frame,
receiverObject,
methodName,
blockObject,
argumentsObjects);
}

}
@@ -45,21 +45,19 @@ public CachedBoxedReturnMissingDispatchNode(CachedBoxedReturnMissingDispatchNode
unmodifiedAssumption = prev.unmodifiedAssumption;
}

@Specialization(guards = "guardName")
@Specialization
public Object dispatch(
VirtualFrame frame,
RubyBasicObject receiverObject,
Object receiverObject,
Object methodName,
Object blockObject,
Object argumentsObjects) {
// Check the lookup node is what we expect

if (receiverObject.getMetaClass() != expectedClass) {
if (!guardName(methodName) || !(receiverObject instanceof RubyBasicObject) || ((RubyBasicObject) receiverObject).getMetaClass() != expectedClass) {
return next.executeDispatch(
frame,
receiverObject,
methodName,
CompilerDirectives.unsafeCast(blockObject, RubyProc.class, true, false),
blockObject,
argumentsObjects);
}

@@ -89,19 +87,4 @@ public Object dispatch(
}
}

@Fallback
public Object dispatch(
VirtualFrame frame,
Object receiverObject,
Object methodName,
Object blockObject,
Object argumentsObjects) {
return next.executeDispatch(
frame,
receiverObject,
methodName,
blockObject,
argumentsObjects);
}

}
@@ -20,6 +20,7 @@
import com.oracle.truffle.api.nodes.InvalidAssumptionException;
import org.jruby.truffle.runtime.RubyArguments;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.RubyBasicObject;
import org.jruby.truffle.runtime.core.RubyProc;
import org.jruby.truffle.runtime.core.RubySymbol;
import org.jruby.truffle.runtime.methods.RubyMethod;
@@ -71,13 +72,22 @@ public CachedBoxedSymbolDispatchNode(CachedBoxedSymbolDispatchNode prev) {
indirectCallNode = prev.indirectCallNode;
}

@Specialization(guards = "guardName")
@Specialization
public Object dispatch(
VirtualFrame frame,
RubySymbol receiverObject,
Object receiverObject,
Object methodName,
Object blockObject,
Object argumentsObjects) {
if (!guardName(methodName) || !(receiverObject instanceof RubySymbol)) {
return next.executeDispatch(
frame,
receiverObject,
methodName,
blockObject,
argumentsObjects);
}

// Check the class has not been modified

try {
@@ -127,19 +137,4 @@ public Object dispatch(
}
}

@Fallback
public Object dispatch(
VirtualFrame frame,
Object receiverObject,
Object methodName,
Object blockObject,
Object argumentsObjects) {
return next.executeDispatch(
frame,
receiverObject,
methodName,
blockObject,
argumentsObjects);
}

}
@@ -58,11 +58,7 @@ public CachedDispatchNode(CachedDispatchNode prev) {
indirect = prev.indirect;
}

protected final boolean guardName(
Object receiverObject,
Object methodName,
Object blockObject,
Object argumentsObjects) {
protected final boolean guardName(Object methodName) {
if (cachedName == methodName) {
return true;
}
@@ -72,6 +68,7 @@ protected final boolean guardName(
if (cachedName instanceof String) {
return cachedName.equals(methodName);
} else if (cachedName instanceof RubySymbol) {
// TODO(CS, 11-Jan-15) this just repeats the above guard...
return cachedName == methodName;
} else if (cachedName instanceof RubyString) {
return (methodName instanceof RubyString) && ((RubyString) cachedName).getBytes().equals(((RubyString) methodName).getBytes());
@@ -20,6 +20,7 @@
import com.oracle.truffle.api.nodes.InvalidAssumptionException;
import org.jruby.truffle.runtime.RubyArguments;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.RubyBasicObject;
import org.jruby.truffle.runtime.core.RubyProc;
import org.jruby.truffle.runtime.methods.RubyMethod;

@@ -69,16 +70,14 @@ public CachedUnboxedDispatchNode(CachedUnboxedDispatchNode prev) {
indirectCallNode = prev.indirectCallNode;
}

@Specialization(guards = {"!isRubyBasicObject", "guardName"})
@Specialization
public Object dispatch(
VirtualFrame frame,
Object receiverObject,
Object methodName,
Object blockObject,
Object argumentsObjects) {
// Check the class is what we expect

if (receiverObject.getClass() != expectedClass) {
if (!guardName(methodName) || receiverObject instanceof RubyBasicObject || receiverObject.getClass() != expectedClass) {
return next.executeDispatch(
frame,
receiverObject,
@@ -134,19 +133,4 @@ public Object dispatch(
}
}

@Fallback
public Object fallback(
VirtualFrame frame,
Object receiverObject,
Object methodName,
Object blockObject,
Object argumentsObjects) {
return next.executeDispatch(
frame,
receiverObject,
methodName,
blockObject,
argumentsObjects);
}

}

0 comments on commit ad066eb

Please sign in to comment.