Skip to content

Commit

Permalink
Showing 2 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -13,25 +13,28 @@
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.InvalidAssumptionException;
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.object.Shape;

import org.jruby.truffle.nodes.RubyGuards;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.layouts.Layouts;

public class CachedBoxedReturnMissingDispatchNode extends CachedDispatchNode {

private final DynamicObject expectedClass;
private final Shape expectedShape;
private final Assumption unmodifiedAssumption;

public CachedBoxedReturnMissingDispatchNode(
RubyContext context,
Object cachedName,
DispatchNode next,
Shape expectedShape,
DynamicObject expectedClass,
boolean indirect,
DispatchAction dispatchAction) {
super(context, cachedName, next, indirect, dispatchAction);
assert RubyGuards.isRubyClass(expectedClass);
this.expectedClass = expectedClass;
this.expectedShape = expectedShape;
unmodifiedAssumption = Layouts.MODULE.getFields(expectedClass).getUnmodifiedAssumption();
this.next = next;
}
@@ -40,7 +43,7 @@ public CachedBoxedReturnMissingDispatchNode(
protected boolean guard(Object methodName, Object receiver) {
return guardName(methodName) &&
(receiver instanceof DynamicObject) &&
Layouts.BASIC_OBJECT.getMetaClass(((DynamicObject) receiver)) == expectedClass;
((DynamicObject) receiver).getShape() == expectedShape;
}

@Override
Original file line number Diff line number Diff line change
@@ -235,9 +235,12 @@ private DispatchNode createMethodMissingNode(
DispatchNode first,
Object methodName,
Object receiverObject) {
// TODO (eregon, 26 Aug. 2015): should handle primitive types as well
final Shape shape = (receiverObject instanceof DynamicObject) ? ((DynamicObject) receiverObject).getShape() : null;

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

@@ -253,9 +256,6 @@ private DispatchNode createMethodMissingNode(
return new UncachedDispatchNode(getContext(), ignoreVisibility, getDispatchAction(), missingBehavior);
}

// TODO (eregon, 26 Aug. 2015): should handle primitive types as well
final Shape shape = (receiverObject instanceof DynamicObject) ? ((DynamicObject) receiverObject).getShape() : null;

return new CachedBoxedMethodMissingDispatchNode(getContext(), methodName, first, shape,
getContext().getCoreLibrary().getMetaClass(receiverObject), method, DISPATCH_METAPROGRAMMING_ALWAYS_INDIRECT, getDispatchAction());
}

0 comments on commit 83c2aaa

Please sign in to comment.