Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Reflectoring of message sending dispatch chains to simplify guards
The refactoring is general cleanup, removal of code duplication, but also a change in how guards in the dispatch chain and the chain itself works. Now, we have simple unstructured chain. Before, the chain was structured, by having first all primitives, then a test node, and then all object types. Don't think this was really a working thing, because the type check was costing in the interpreter at every object check again, because of the checked cast. In the compiled code, the check was bad, because it was not a leaf-type, and thus, required code for traversing the type hierarchy. This is now gone, we try to have guards and checked casts only on leaf-types to reduce the cost of guards. In the interpreter, this hopefully also reduces the cost of dispatching. However guards are now in their own classes `DispatchGuard`, which means there is an extra virtual dispatch, which might be an issue for interpreter performance. Further changes include the use of the object layout for objects with fields as guard critierion. This means, we can hopefully move more of the guards into the dispatch chain, and avoid duplicated guards. This however also means that handling invalidation of object layouts is part of this chain. Objects with old layouts are handled in the uninitialized node of the dispatch chain. After transfering an object to the new layout, lookup is retried to avoid adding duplicate entries to the dispatch chain. Super, lexically bound, and receiver sends are now all handled with the same uninitialized node hierarchy, to avoid incomplete implementation (missing #dnu support for super, missing dispatch chain length, etc) Signed-off-by: Stefan Marr <git@stefan-marr.de>
- Loading branch information
Showing
20 changed files
with
589 additions
and
676 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 0 additions & 42 deletions
42
src/som/interpreter/nodes/dispatch/AbstractCachedDnuNode.java
This file was deleted.
Oops, something went wrong.
24 changes: 2 additions & 22 deletions
24
src/som/interpreter/nodes/dispatch/AbstractDispatchNode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,13 @@ | ||
package som.interpreter.nodes.dispatch; | ||
|
||
import com.oracle.truffle.api.CallTarget; | ||
import com.oracle.truffle.api.Truffle; | ||
import com.oracle.truffle.api.frame.VirtualFrame; | ||
import com.oracle.truffle.api.nodes.DirectCallNode; | ||
import com.oracle.truffle.api.nodes.Node; | ||
|
||
|
||
public abstract class AbstractDispatchNode extends Node implements DispatchChain { | ||
public abstract class AbstractDispatchNode | ||
extends Node implements DispatchChain { | ||
public static final int INLINE_CACHE_SIZE = 6; | ||
|
||
public abstract Object executeDispatch( | ||
final VirtualFrame frame, final Object[] arguments); | ||
|
||
public abstract static class AbstractCachedDispatchNode | ||
extends AbstractDispatchNode { | ||
|
||
@Child protected DirectCallNode cachedMethod; | ||
@Child protected AbstractDispatchNode nextInCache; | ||
|
||
public AbstractCachedDispatchNode(final CallTarget methodCallTarget, | ||
final AbstractDispatchNode nextInCache) { | ||
this.cachedMethod = Truffle.getRuntime().createDirectCallNode(methodCallTarget); | ||
this.nextInCache = nextInCache; | ||
} | ||
|
||
@Override | ||
public final int lengthOfDispatchChain() { | ||
return 1 + nextInCache.lengthOfDispatchChain(); | ||
} | ||
} | ||
} |
20 changes: 0 additions & 20 deletions
20
src/som/interpreter/nodes/dispatch/AbstractDispatchWithLookupNode.java
This file was deleted.
Oops, something went wrong.
43 changes: 43 additions & 0 deletions
43
src/som/interpreter/nodes/dispatch/CachedDispatchNode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package som.interpreter.nodes.dispatch; | ||
|
||
import com.oracle.truffle.api.CallTarget; | ||
import com.oracle.truffle.api.CompilerDirectives; | ||
import com.oracle.truffle.api.Truffle; | ||
import com.oracle.truffle.api.frame.VirtualFrame; | ||
import com.oracle.truffle.api.nodes.DirectCallNode; | ||
import com.oracle.truffle.api.nodes.InvalidAssumptionException; | ||
|
||
|
||
public final class CachedDispatchNode extends AbstractDispatchNode { | ||
|
||
@Child private DirectCallNode cachedMethod; | ||
@Child private AbstractDispatchNode nextInCache; | ||
|
||
private final DispatchGuard guard; | ||
|
||
public CachedDispatchNode(final CallTarget methodCallTarget, | ||
final DispatchGuard guard, final AbstractDispatchNode nextInCache) { | ||
this.cachedMethod = Truffle.getRuntime().createDirectCallNode(methodCallTarget); | ||
this.guard = guard; | ||
this.nextInCache = nextInCache; | ||
} | ||
|
||
@Override | ||
public Object executeDispatch(final VirtualFrame frame, final Object[] arguments) { | ||
try { | ||
if (guard.entryMatches(arguments[0])) { | ||
return cachedMethod.call(frame, arguments); | ||
} else { | ||
return nextInCache.executeDispatch(frame, arguments); | ||
} | ||
} catch (InvalidAssumptionException e) { | ||
CompilerDirectives.transferToInterpreter(); | ||
return replace(nextInCache).executeDispatch(frame, arguments); | ||
} | ||
} | ||
|
||
@Override | ||
public int lengthOfDispatchChain() { | ||
return 1 + nextInCache.lengthOfDispatchChain(); | ||
} | ||
} |
56 changes: 0 additions & 56 deletions
56
src/som/interpreter/nodes/dispatch/CachedDispatchSObjectCheckNode.java
This file was deleted.
Oops, something went wrong.
65 changes: 0 additions & 65 deletions
65
src/som/interpreter/nodes/dispatch/CachedDispatchSimpleCheckNode.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.