Skip to content

Commit 4de47af

Browse files
committed
HashingCollectionNodes: add generic case specialization when the inline cache limit is exceeded for the cached specialization
1 parent cd61162 commit 4de47af

File tree

1 file changed

+41
-9
lines changed

1 file changed

+41
-9
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/HashingCollectionNodes.java

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import com.oracle.graal.python.builtins.objects.common.HashingCollectionNodesFactory.GetDictStorageNodeGen;
4646
import com.oracle.graal.python.nodes.PGuards;
4747
import com.oracle.graal.python.nodes.PNodeWithContext;
48+
import com.oracle.truffle.api.CompilerDirectives;
4849
import com.oracle.truffle.api.dsl.Cached;
4950
import com.oracle.truffle.api.dsl.ImportStatic;
5051
import com.oracle.truffle.api.dsl.Specialization;
@@ -53,14 +54,27 @@ public abstract class HashingCollectionNodes {
5354

5455
@ImportStatic(PGuards.class)
5556
public abstract static class LenNode extends PNodeWithContext {
57+
private @Child HashingStorageNodes.LenNode lenNode;
58+
59+
public HashingStorageNodes.LenNode getLenNode() {
60+
if (lenNode == null) {
61+
CompilerDirectives.transferToInterpreterAndInvalidate();
62+
lenNode = insert(HashingStorageNodes.LenNode.create());
63+
}
64+
return lenNode;
65+
}
5666

5767
public abstract int execute(PHashingCollection c);
5868

5969
@Specialization(limit = "4", guards = {"c.getClass() == cachedClass"})
60-
int doWithStorage(PHashingCollection c,
61-
@Cached("c.getClass()") Class<? extends PHashingCollection> cachedClass,
62-
@Cached("create()") HashingStorageNodes.LenNode lenNode) {
63-
return lenNode.execute(cachedClass.cast(c).getDictStorage());
70+
int getLenCached(PHashingCollection c,
71+
@Cached("c.getClass()") Class<? extends PHashingCollection> cachedClass) {
72+
return getLenNode().execute(cachedClass.cast(c).getDictStorage());
73+
}
74+
75+
@Specialization(replaces = "getLenCached")
76+
int getLenGeneric(PHashingCollection c) {
77+
return getLenNode().execute(c.getDictStorage());
6478
}
6579

6680
public static LenNode create() {
@@ -70,14 +84,27 @@ public static LenNode create() {
7084

7185
@ImportStatic(PGuards.class)
7286
public abstract static class SetItemNode extends PNodeWithContext {
87+
private @Child HashingStorageNodes.SetItemNode setItemNode;
88+
89+
public HashingStorageNodes.SetItemNode getSetItemNode() {
90+
if (setItemNode == null) {
91+
CompilerDirectives.transferToInterpreterAndInvalidate();
92+
setItemNode = insert(HashingStorageNodes.SetItemNode.create());
93+
}
94+
return setItemNode;
95+
}
7396

7497
public abstract void execute(PHashingCollection c, Object key, Object value);
7598

7699
@Specialization(limit = "4", guards = {"c.getClass() == cachedClass"})
77-
void doWithStorage(PHashingCollection c, Object key, Object value,
78-
@Cached("c.getClass()") Class<? extends PHashingCollection> cachedClass,
79-
@Cached("create()") HashingStorageNodes.SetItemNode setNode) {
80-
cachedClass.cast(c).setDictStorage(setNode.execute(cachedClass.cast(c).getDictStorage(), key, value));
100+
void doSetItemCached(PHashingCollection c, Object key, Object value,
101+
@Cached("c.getClass()") Class<? extends PHashingCollection> cachedClass) {
102+
cachedClass.cast(c).setDictStorage(getSetItemNode().execute(cachedClass.cast(c).getDictStorage(), key, value));
103+
}
104+
105+
@Specialization(replaces = "doSetItemCached")
106+
void doSetItemGeneric(PHashingCollection c, Object key, Object value) {
107+
c.setDictStorage(getSetItemNode().execute(c.getDictStorage(), key, value));
81108
}
82109

83110
public static SetItemNode create() {
@@ -91,11 +118,16 @@ public abstract static class GetDictStorageNode extends PNodeWithContext {
91118
public abstract HashingStorage execute(PHashingCollection c);
92119

93120
@Specialization(limit = "4", guards = {"c.getClass() == cachedClass"})
94-
HashingStorage doWithStorage(PHashingCollection c,
121+
HashingStorage getStorageCached(PHashingCollection c,
95122
@Cached("c.getClass()") Class<? extends PHashingCollection> cachedClass) {
96123
return cachedClass.cast(c).getDictStorage();
97124
}
98125

126+
@Specialization(replaces = "getStorageCached")
127+
HashingStorage getStorageGeneric(PHashingCollection c) {
128+
return c.getDictStorage();
129+
}
130+
99131
public static GetDictStorageNode create() {
100132
return GetDictStorageNodeGen.create();
101133
}

0 commit comments

Comments
 (0)