Skip to content

Commit

Permalink
[Truffle] Use declarative guards for checking classes in the IC.
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisseaton committed Jan 8, 2015
1 parent ef46083 commit f2b1582
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 48 deletions.
Expand Up @@ -103,24 +103,13 @@ public CachedBoxedDispatchNode(CachedBoxedDispatchNode prev) {
indirectCallNode = prev.indirectCallNode;
}

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

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

// Check the class has not been modified

try {
Expand Down Expand Up @@ -170,6 +159,14 @@ public Object dispatch(
}
}

protected final boolean guardClass(
RubyBasicObject receiverObject,
Object methodName,
Object blockObject,
Object argumentsObjects) {
return receiverObject.getMetaClass() == expectedClass;
}

@Fallback
public Object dispatch(
VirtualFrame frame,
Expand Down
Expand Up @@ -83,24 +83,13 @@ public CachedBoxedMethodMissingDispatchNode(CachedBoxedMethodMissingDispatchNode
indirectCallNode = prev.indirectCallNode;
}

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

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

// Check the class has not been modified

try {
Expand Down Expand Up @@ -177,6 +166,14 @@ public Object dispatch(
}
}

protected final boolean guardClass(
RubyBasicObject receiverObject,
Object methodName,
Object blockObject,
Object argumentsObjects) {
return receiverObject.getMetaClass() == expectedClass;
}

@Fallback
public Object dispatch(
VirtualFrame frame,
Expand Down
Expand Up @@ -45,24 +45,13 @@ public CachedBoxedReturnMissingDispatchNode(CachedBoxedReturnMissingDispatchNode
unmodifiedAssumption = prev.unmodifiedAssumption;
}

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

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

// Check the class has not been modified

try {
Expand All @@ -89,6 +78,14 @@ public Object dispatch(
}
}

protected final boolean guardClass(
RubyBasicObject receiverObject,
Object methodName,
Object blockObject,
Object argumentsObjects) {
return receiverObject.getMetaClass() == expectedClass;
}

@Fallback
public Object dispatch(
VirtualFrame frame,
Expand Down
Expand Up @@ -69,24 +69,13 @@ public CachedUnboxedDispatchNode(CachedUnboxedDispatchNode prev) {
indirectCallNode = prev.indirectCallNode;
}

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

if (receiverObject.getClass() != expectedClass) {
return next.executeDispatch(
frame,
receiverObject,
methodName,
blockObject,
argumentsObjects);
}

// Check the class has not been modified

try {
Expand Down Expand Up @@ -134,6 +123,14 @@ public Object dispatch(
}
}

protected final boolean guardClass(
Object receiverObject,
Object methodName,
Object blockObject,
Object argumentsObjects) {
return receiverObject.getClass() == expectedClass;
}

@Fallback
public Object fallback(
VirtualFrame frame,
Expand Down

0 comments on commit f2b1582

Please sign in to comment.