Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[Truffle] Remove DSL from dispatch nodes.
  • Loading branch information
chrisseaton committed Jan 13, 2015
1 parent 6218a4d commit 99a2573
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 110 deletions.
Expand Up @@ -23,7 +23,7 @@
import org.jruby.truffle.runtime.core.RubyProc;
import org.jruby.truffle.runtime.methods.InternalMethod;

public abstract class CachedBooleanDispatchNode extends CachedDispatchNode {
public class CachedBooleanDispatchNode extends CachedDispatchNode {

private final Assumption falseUnmodifiedAssumption;
private final InternalMethod falseMethod;
Expand Down Expand Up @@ -90,21 +90,8 @@ public CachedBooleanDispatchNode(
}
}

public CachedBooleanDispatchNode(CachedBooleanDispatchNode prev) {
super(prev);
falseUnmodifiedAssumption = prev.falseUnmodifiedAssumption;
falseMethod = prev.falseMethod;
falseValue = prev.falseValue;
falseCallDirect = prev.falseCallDirect;
trueUnmodifiedAssumption = prev.trueUnmodifiedAssumption;
trueValue = prev.trueValue;
trueMethod = prev.trueMethod;
trueCallDirect = prev.trueCallDirect;
indirectCallNode = prev.indirectCallNode;
}

@Specialization
public Object dispatch(
@Override
public Object executeDispatch(
VirtualFrame frame,
Object receiverObject,
Object methodName,
Expand Down
Expand Up @@ -25,7 +25,7 @@
import org.jruby.truffle.runtime.core.RubyProc;
import org.jruby.truffle.runtime.methods.InternalMethod;

public abstract class CachedBoxedDispatchNode extends CachedDispatchNode {
public class CachedBoxedDispatchNode extends CachedDispatchNode {

private final RubyClass expectedClass;
private final Assumption unmodifiedAssumption;
Expand Down Expand Up @@ -92,18 +92,8 @@ public CachedBoxedDispatchNode(
}
}

public CachedBoxedDispatchNode(CachedBoxedDispatchNode prev) {
super(prev);
expectedClass = prev.expectedClass;
unmodifiedAssumption = prev.unmodifiedAssumption;
value = prev.value;
method = prev.method;
callNode = prev.callNode;
indirectCallNode = prev.indirectCallNode;
}

@Specialization
public Object dispatch(
@Override
public Object executeDispatch(
VirtualFrame frame,
Object receiverObject,
Object methodName,
Expand Down
Expand Up @@ -25,7 +25,7 @@
import org.jruby.truffle.runtime.methods.InternalMethod;
import org.jruby.util.cli.Options;

public abstract class CachedBoxedMethodMissingDispatchNode extends CachedDispatchNode {
public class CachedBoxedMethodMissingDispatchNode extends CachedDispatchNode {

private final RubyClass expectedClass;
private final Assumption unmodifiedAssumption;
Expand Down Expand Up @@ -73,17 +73,8 @@ public CachedBoxedMethodMissingDispatchNode(
}
}

public CachedBoxedMethodMissingDispatchNode(CachedBoxedMethodMissingDispatchNode prev) {
super(prev);
expectedClass = prev.expectedClass;
unmodifiedAssumption = prev.unmodifiedAssumption;
method = prev.method;
callNode = prev.callNode;
indirectCallNode = prev.indirectCallNode;
}

@Specialization
public Object dispatch(
@Override
public Object executeDispatch(
VirtualFrame frame,
Object receiverObject,
Object methodName,
Expand Down
Expand Up @@ -20,7 +20,7 @@
import org.jruby.truffle.runtime.core.RubyClass;
import org.jruby.truffle.runtime.core.RubyProc;

public abstract class CachedBoxedReturnMissingDispatchNode extends CachedDispatchNode {
public class CachedBoxedReturnMissingDispatchNode extends CachedDispatchNode {

private final RubyClass expectedClass;
private final Assumption unmodifiedAssumption;
Expand All @@ -39,14 +39,8 @@ public CachedBoxedReturnMissingDispatchNode(
this.next = next;
}

public CachedBoxedReturnMissingDispatchNode(CachedBoxedReturnMissingDispatchNode prev) {
super(prev);
expectedClass = prev.expectedClass;
unmodifiedAssumption = prev.unmodifiedAssumption;
}

@Specialization
public Object dispatch(
@Override
public Object executeDispatch(
VirtualFrame frame,
Object receiverObject,
Object methodName,
Expand Down
Expand Up @@ -23,7 +23,7 @@
import org.jruby.truffle.runtime.core.RubySymbol;
import org.jruby.truffle.runtime.methods.InternalMethod;

public abstract class CachedBoxedSymbolDispatchNode extends CachedDispatchNode {
public class CachedBoxedSymbolDispatchNode extends CachedDispatchNode {

private final Assumption unmodifiedAssumption;

Expand Down Expand Up @@ -61,17 +61,8 @@ public CachedBoxedSymbolDispatchNode(
}
}

public CachedBoxedSymbolDispatchNode(CachedBoxedSymbolDispatchNode prev) {
super(prev);
unmodifiedAssumption = prev.unmodifiedAssumption;
value = prev.value;
method = prev.method;
callNode = prev.callNode;
indirectCallNode = prev.indirectCallNode;
}

@Specialization
public Object dispatch(
@Override
public Object executeDispatch(
VirtualFrame frame,
Object receiverObject,
Object methodName,
Expand Down
Expand Up @@ -23,7 +23,7 @@
import org.jruby.truffle.runtime.core.RubyProc;
import org.jruby.truffle.runtime.methods.InternalMethod;

public abstract class CachedUnboxedDispatchNode extends CachedDispatchNode {
public class CachedUnboxedDispatchNode extends CachedDispatchNode {

private final Class<?> expectedClass;
private final Assumption unmodifiedAssumption;
Expand Down Expand Up @@ -59,18 +59,8 @@ public CachedUnboxedDispatchNode(
}
}

public CachedUnboxedDispatchNode(CachedUnboxedDispatchNode prev) {
super(prev);
expectedClass = prev.expectedClass;
unmodifiedAssumption = prev.unmodifiedAssumption;
value = prev.value;
method = prev.method;
callNode = prev.callNode;
indirectCallNode = prev.indirectCallNode;
}

@Specialization
public Object dispatch(
@Override
public Object executeDispatch(
VirtualFrame frame,
Object receiverObject,
Object methodName,
Expand Down
Expand Up @@ -77,7 +77,7 @@ public DispatchAction getDispatchAction() {

public void forceUncached() {
adoptChildren();
first.replace(UncachedDispatchNodeFactory.create(context, ignoreVisibility, null, null, null, null, null));
first.replace(new UncachedDispatchNode(context, ignoreVisibility, dispatchAction));
}

}
Expand Up @@ -26,11 +26,6 @@
import org.jruby.truffle.runtime.core.RubyProc;
import org.jruby.truffle.runtime.methods.InternalMethod;

@NodeChildren({
@NodeChild(value="receiver", type=Node.class),
@NodeChild(value="methodName", type=Node.class),
@NodeChild(value="blockObject", type=Node.class),
@NodeChild(value="arguments", type=Node.class)})
public abstract class DispatchNode extends RubyNode {

private final DispatchAction dispatchAction;
Expand Down
Expand Up @@ -28,7 +28,7 @@
import org.jruby.truffle.runtime.core.RubyProc;
import org.jruby.truffle.runtime.methods.InternalMethod;

public abstract class UncachedDispatchNode extends DispatchNode {
public class UncachedDispatchNode extends DispatchNode {

private final boolean ignoreVisibility;

Expand All @@ -47,8 +47,8 @@ public UncachedDispatchNode(RubyContext context, boolean ignoreVisibility, Dispa
toJavaStringNode = ToJavaStringNodeFactory.create(context, null, null);
}

@Specialization
public Object dispatch(
@Override
public Object executeDispatch(
VirtualFrame frame,
Object receiverObject,
Object name,
Expand Down
Expand Up @@ -54,8 +54,7 @@ public Object executeDispatch(

if (depth == Options.TRUFFLE_DISPATCH_POLYMORPHIC_MAX.load()) {
return getHeadNode().getFirstDispatchNode()
.replace(UncachedDispatchNodeFactory.create(getContext(), ignoreVisibility, getDispatchAction(),
null, null, null, null))
.replace(new UncachedDispatchNode(getContext(), ignoreVisibility, getDispatchAction()))
.executeDispatch(frame, receiverObject,
methodName, blockObject, argumentsObjects);
}
Expand Down Expand Up @@ -128,21 +127,19 @@ private Object doUnboxedObject(
throw new UnsupportedOperationException();
}

final CachedBooleanDispatchNode newDispatch = CachedBooleanDispatchNodeFactory.create(getContext(),
final CachedBooleanDispatchNode newDispatch = new CachedBooleanDispatchNode(getContext(),
methodName, first,
falseUnmodifiedAssumption, null, falseMethod,
trueUnmodifiedAssumption, null, trueMethod, indirect, getDispatchAction(),
null, null, null, null);
trueUnmodifiedAssumption, null, trueMethod, indirect, getDispatchAction());

first.replace(newDispatch);

return newDispatch.executeDispatch(frame, receiverObject,
methodName, blockObject, argumentsObjects);
} else {
final CachedUnboxedDispatchNode newDispatch = CachedUnboxedDispatchNodeFactory.create(getContext(),
final CachedUnboxedDispatchNode newDispatch = new CachedUnboxedDispatchNode(getContext(),
methodName, first, receiverObject.getClass(),
getContext().getCoreLibrary().getLogicalClass(receiverObject).getUnmodifiedAssumption(), null, method, indirect, getDispatchAction(), null, null, null,
null);
getContext().getCoreLibrary().getLogicalClass(receiverObject).getUnmodifiedAssumption(), null, method, indirect, getDispatchAction());

first.replace(newDispatch);

Expand Down Expand Up @@ -177,11 +174,10 @@ private Object doRubyBasicObject(
final DispatchNode newDispatch;

if (receiverObject instanceof RubySymbol) {
newDispatch = CachedBoxedSymbolDispatchNodeFactory.create(getContext(), methodName, first, null, method, indirect, getDispatchAction(),
null, null, null, null);
newDispatch = new CachedBoxedSymbolDispatchNode(getContext(), methodName, first, null, method, indirect, getDispatchAction());
} else {
newDispatch = CachedBoxedDispatchNodeFactory.create(getContext(), methodName, first,
getContext().getCoreLibrary().getMetaClass(receiverObject), null, method, indirect, getDispatchAction(), null, null, null, null);
newDispatch = new CachedBoxedDispatchNode(getContext(), methodName, first,
getContext().getCoreLibrary().getMetaClass(receiverObject), null, method, indirect, getDispatchAction());
}

first.replace(newDispatch);
Expand All @@ -201,9 +197,9 @@ private Object doRubyBasicObject(

// The module, the "receiver" is an instance of its singleton class.
// But we want to check the module assumption, not its singleton class assumption.
final DispatchNode newDispatch = CachedBoxedDispatchNodeFactory.create(getContext(), methodName, first,
final DispatchNode newDispatch = new CachedBoxedDispatchNode(getContext(), methodName, first,
module.getSingletonClass(null), module.getUnmodifiedAssumption(), constant.getValue(),
null, indirect, getDispatchAction(), null, null, null, null);
null, indirect, getDispatchAction());

first.replace(newDispatch);
return newDispatch.executeDispatch(frame, receiverObject,
Expand All @@ -221,8 +217,8 @@ private DispatchNode createConstantMissingNode(

switch (missingBehavior) {
case RETURN_MISSING: {
return first.replace(CachedBoxedReturnMissingDispatchNodeFactory.create(getContext(), methodName, first,
receiverObject.getMetaClass(), indirect, getDispatchAction(), null, null, null, null));
return first.replace(new CachedBoxedReturnMissingDispatchNode(getContext(), methodName, first,
receiverObject.getMetaClass(), indirect, getDispatchAction()));
}

case CALL_CONST_MISSING: {
Expand All @@ -234,12 +230,11 @@ private DispatchNode createConstantMissingNode(
}

if (Options.TRUFFLE_DISPATCH_METAPROGRAMMING_ALWAYS_UNCACHED.load()) {
return first.replace(UncachedDispatchNodeFactory.create(getContext(), ignoreVisibility,
null, null, null, null, null));
return first.replace(new UncachedDispatchNode(getContext(), ignoreVisibility, getDispatchAction()));
}

return first.replace(CachedBoxedMethodMissingDispatchNodeFactory.create(getContext(), methodName, first,
receiverObject.getMetaClass(), method, Options.TRUFFLE_DISPATCH_METAPROGRAMMING_ALWAYS_INDIRECT.load(), getDispatchAction(), null, null, null, null));
return first.replace(new CachedBoxedMethodMissingDispatchNode(getContext(), methodName, first,
receiverObject.getMetaClass(), method, Options.TRUFFLE_DISPATCH_METAPROGRAMMING_ALWAYS_INDIRECT.load(), getDispatchAction()));
}

default: {
Expand All @@ -255,8 +250,8 @@ private DispatchNode createMethodMissingNode(

switch (missingBehavior) {
case RETURN_MISSING: {
return first.replace(CachedBoxedReturnMissingDispatchNodeFactory.create(getContext(), methodName, first,
getContext().getCoreLibrary().getMetaClass(receiverObject), indirect, getDispatchAction(), null, null, null, null));
return first.replace(new CachedBoxedReturnMissingDispatchNode(getContext(), methodName, first,
getContext().getCoreLibrary().getMetaClass(receiverObject), indirect, getDispatchAction()));
}

case CALL_METHOD_MISSING: {
Expand All @@ -268,12 +263,11 @@ private DispatchNode createMethodMissingNode(
}

if (Options.TRUFFLE_DISPATCH_METAPROGRAMMING_ALWAYS_UNCACHED.load()) {
return first.replace(UncachedDispatchNodeFactory.create(getContext(), ignoreVisibility, getDispatchAction(),
null, null, null, null));
return first.replace(new UncachedDispatchNode(getContext(), ignoreVisibility, getDispatchAction()));
}

return first.replace(CachedBoxedMethodMissingDispatchNodeFactory.create(getContext(), methodName, first,
getContext().getCoreLibrary().getMetaClass(receiverObject), method, Options.TRUFFLE_DISPATCH_METAPROGRAMMING_ALWAYS_INDIRECT.load(), getDispatchAction(), null, null, null, null));
return first.replace(new CachedBoxedMethodMissingDispatchNode(getContext(), methodName, first,
getContext().getCoreLibrary().getMetaClass(receiverObject), method, Options.TRUFFLE_DISPATCH_METAPROGRAMMING_ALWAYS_INDIRECT.load(), getDispatchAction()));
}

default: {
Expand Down

2 comments on commit 99a2573

@nirvdrum
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What prompted this change?

@chrisseaton
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The DSL wasn't really doing anything any more.

Originally we were filtering some types in the specialisation signature (which went in a commit before this one) but that meant we had to have a fallback case, which was cumbersome. It was also useful in some other interop work we are doing on a separate branch, but that now works a different way as well.

Please sign in to comment.