Skip to content

Commit

Permalink
[Truffle] A much better solution to constant lookup invalidation.
Browse files Browse the repository at this point in the history
  • Loading branch information
eregon committed Oct 22, 2014
1 parent 2167c97 commit 760e9c0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
Expand Up @@ -39,10 +39,19 @@ public abstract class CachedBoxedDispatchNode extends CachedDispatchNode {

public CachedBoxedDispatchNode(RubyContext context, Object cachedName, DispatchNode next,
RubyClass expectedClass, Object value, RubyMethod method) {
this(context, cachedName, next, expectedClass, expectedClass.getUnmodifiedAssumption(), value, method);
}

/**
* Allows to give the assumption, which is different than the expectedClass assumption for constant lookup.
*/
public CachedBoxedDispatchNode(RubyContext context, Object cachedName, DispatchNode next,
RubyClass expectedClass, Assumption unmodifiedAssumption,
Object value, RubyMethod method) {
super(context, cachedName, next);

this.expectedClass = expectedClass;
this.unmodifiedAssumption = expectedClass.getUnmodifiedAssumption();
this.unmodifiedAssumption = unmodifiedAssumption;
this.next = next;
this.value = value;
this.method = method;
Expand Down
Expand Up @@ -201,8 +201,11 @@ private Object doRubyBasicObject(
methodName, blockObject, argumentsObjects, dispatchAction);
}

// 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,
module.getSingletonClass(null), constant.getValue(), null, null, null, null, null, null, null, null);
module.getSingletonClass(null), module.getUnmodifiedAssumption(), constant.getValue(),
null, null, null, null, null, null, null, null);

first.replace(newDispatch);
return newDispatch.executeDispatch(frame, methodReceiverObject, lexicalScope, receiverObject,
Expand Down
Expand Up @@ -352,11 +352,6 @@ private void newVersion(Set<RubyModule> alreadyInvalidated) {
for (RubyModule dependent : dependents) {
dependent.newVersion(alreadyInvalidated);
}

// Also invalidate the singleton class, as modules are identified by it in constant lookup cache
if (getMetaClass() != getLogicalClass()) {
getMetaClass().newVersion();
}
}

public void addDependent(RubyModule dependent) {
Expand Down

0 comments on commit 760e9c0

Please sign in to comment.