Skip to content


Browse files Browse the repository at this point in the history
[Truffle] Fix depth detection in unresolved dispatch.
We used to detect the depth of a dispatch chain by counting the number
of parents between the node and the DispatchHeadNode. That no longer
works now we are using the DSL for dispatch nodes, as they form their
own chain. This was causing megamorphic dispatch to be created either
too early or not at all, as the correct depth was either hit too early
or jumped over entirely.

This patch maintains depth manually.
  • Loading branch information
chrisseaton committed Oct 30, 2014
1 parent 894e802 commit af2cd60
Showing 1 changed file with 5 additions and 15 deletions.
Expand Up @@ -24,6 +24,8 @@

public final class UnresolvedDispatchNode extends DispatchNode {

private int depth = 0;

private final boolean ignoreVisibility;
private final Dispatch.MissingBehavior missingBehavior;

Expand All @@ -46,14 +48,16 @@ public Object executeDispatch(
Dispatch.DispatchAction dispatchAction) {

if (getDepth() == Options.TRUFFLE_DISPATCH_POLYMORPHIC_MAX.load()) {
if (depth == Options.TRUFFLE_DISPATCH_POLYMORPHIC_MAX.load()) {
return getHeadNode().getFirstDispatchNode()
.replace(UncachedDispatchNodeFactory.create(getContext(), ignoreVisibility,
null, null, null, null, null, null, null))
.executeDispatch(frame, methodReceiverObject, lexicalScope, receiverObject,
methodName, blockObject, argumentsObjects, dispatchAction);


final DispatchNode first = getHeadNode().getFirstDispatchNode();

if (receiverObject instanceof RubyBasicObject) {
Expand Down Expand Up @@ -276,18 +280,4 @@ private DispatchNode createMethodMissingNode(

private int getDepth() {
final DispatchHeadNode head = getHeadNode();
Node parent = getParent();

int depth = 1;

while (parent != head) {
parent = parent.getParent();

return depth;


0 comments on commit af2cd60

Please sign in to comment.