Skip to content

Commit f54fc9e

Browse files
committed
Added node cost and reportPolymorphicSpecialize to MessageSendNode
Signed-off-by: Stefan Marr <[email protected]>
1 parent 41f27ab commit f54fc9e

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

src/trufflesom/interpreter/nodes/MessageSendNode.java

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,6 @@ public Object doPreEvaluated(final VirtualFrame frame,
171171
}
172172
continue;
173173
}
174-
// cache guard
175-
// --> apply cache
176174
cache = cache.next;
177175
}
178176

@@ -188,7 +186,31 @@ public String toString() {
188186

189187
@Override
190188
public NodeCost getCost() {
191-
return NodeCost.NONE;
189+
if (!triedEager) {
190+
return NodeCost.UNINITIALIZED;
191+
}
192+
193+
GuardedDispatchNode cache = dispatchCache;
194+
195+
if (cache instanceof GenericDispatchNode) {
196+
return NodeCost.MEGAMORPHIC;
197+
}
198+
199+
int cacheSize = 0;
200+
while (cache != null) {
201+
cache = cache.next;
202+
cacheSize += 1;
203+
}
204+
205+
if (cacheSize == 0) {
206+
return NodeCost.UNINITIALIZED;
207+
}
208+
209+
if (cacheSize == 1) {
210+
return NodeCost.MONOMORPHIC;
211+
}
212+
213+
return NodeCost.POLYMORPHIC;
192214
}
193215

194216
private PreevaluatedExpression specialize(final Object[] arguments) {
@@ -246,6 +268,7 @@ private PreevaluatedExpression specialize(final Object[] arguments) {
246268
}
247269

248270
if (first != null) {
271+
reportPolymorphicSpecialize();
249272
node.next = node.insertHere(first);
250273
}
251274
dispatchCache = insert(node);
@@ -256,6 +279,7 @@ private PreevaluatedExpression specialize(final Object[] arguments) {
256279
// thus, this callsite is considered to be megaprophic, and we generalize it.
257280
GenericDispatchNode generic = new GenericDispatchNode(selector, universe);
258281
dispatchCache = insert(generic);
282+
reportPolymorphicSpecialize();
259283
return generic;
260284
}
261285

0 commit comments

Comments
 (0)