Skip to content

Commit 2b54080

Browse files
committed
ObjectHashMap: move get into a GetNode
1 parent ca8745f commit 2b54080

File tree

2 files changed

+110
-44
lines changed

2 files changed

+110
-44
lines changed

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

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -163,66 +163,65 @@ static boolean maySideEffect(PythonObject o, LookupInheritedAttributeNode.Dynami
163163
@Specialization
164164
static HashingStorage setItemTruffleString(EconomicMapStorage self, TruffleString key, Object value, ThreadState state,
165165
@Shared("tsHash") @Cached TruffleString.HashCodeNode hashCodeNode,
166-
@Shared("putProfiles") @Cached ObjectHashMap.PutProfiles profiles,
166+
@Shared("putNode") @Cached ObjectHashMap.PutNode putNode,
167167
@Shared("gotState") @Cached ConditionProfile gotState) {
168168
VirtualFrame frame = gotState.profile(state == null) ? null : PArguments.frameForCall(state);
169-
DictKey newKey = new DictKey(key, PyObjectHashNode.hash(key, hashCodeNode));
170-
self.map.put(frame, key, PyObjectHashNode.hash(key, hashCodeNode), assertNoJavaString(value), profiles);
169+
putNode.put(state, self.map, key, PyObjectHashNode.hash(key, hashCodeNode), assertNoJavaString(value));
171170
return self;
172171
}
173172

174173
@Specialization(guards = {"isBuiltinString(key, isBuiltinClassProfile)"}, limit = "1")
175174
static HashingStorage setItemPString(EconomicMapStorage self, PString key, Object value, ThreadState state,
176175
@Shared("stringMaterialize") @Cached StringMaterializeNode stringMaterializeNode,
177176
@Shared("tsHash") @Cached TruffleString.HashCodeNode hashCodeNode,
178-
@Shared("putProfiles") @Cached ObjectHashMap.PutProfiles profiles,
177+
@Shared("putNode") @Cached ObjectHashMap.PutNode putNode,
179178
@Shared("gotState") @Cached ConditionProfile gotState,
180179
@Shared("builtinProfile") @Cached IsBuiltinClassProfile isBuiltinClassProfile) {
181180
final TruffleString k = stringMaterializeNode.execute(key);
182-
return setItemTruffleString(self, k, value, state, hashCodeNode, profiles, gotState);
181+
return setItemTruffleString(self, k, value, state, hashCodeNode, putNode, gotState);
183182
}
184183

185184
@Specialization(guards = {"!hasSideEffect(self)", "!isBuiltin(key,builtinProfile) || !isBuiltin(value,builtinProfile)",
186185
"maySideEffect(key, lookup) || maySideEffect(value, lookup)"}, limit = "1")
187186
static HashingStorage setItemPythonObjectWithSideEffect(EconomicMapStorage self, PythonObject key, PythonObject value, ThreadState state,
188-
@Shared("putProfiles") @Cached ObjectHashMap.PutProfiles profiles,
187+
@Shared("putNode") @Cached ObjectHashMap.PutNode putNode,
189188
@Shared("hashNode") @Cached PyObjectHashNode hashNode,
190189
@Shared("lookup") @Cached LookupInheritedAttributeNode.Dynamic lookup,
191190
@Shared("builtinProfile") @Cached IsBuiltinClassProfile builtinProfile,
192191
@Shared("gotState") @Cached ConditionProfile gotState) {
193192
convertToSideEffectMap(self);
194-
return setItemGeneric(self, key, value, state, profiles, hashNode, gotState);
193+
return setItemGeneric(self, key, value, state, putNode, hashNode, gotState);
195194
}
196195

197196
@Specialization(guards = {"!hasSideEffect(self)", "!isBuiltin(key,builtinProfile)", "maySideEffect(key, lookup)"}, limit = "1")
198197
static HashingStorage setItemPythonObjectWithSideEffect(EconomicMapStorage self, PythonObject key, Object value, ThreadState state,
199-
@Shared("putProfiles") @Cached ObjectHashMap.PutProfiles profiles,
198+
@Shared("putNode") @Cached ObjectHashMap.PutNode putNode,
200199
@Shared("hashNode") @Cached PyObjectHashNode hashNode,
201200
@Shared("lookup") @Cached LookupInheritedAttributeNode.Dynamic lookup,
202201
@Shared("builtinProfile") @Cached IsBuiltinClassProfile builtinProfile,
203202
@Shared("gotState") @Cached ConditionProfile gotState) {
204203
convertToSideEffectMap(self);
205-
return setItemGeneric(self, key, value, state, profiles, hashNode, gotState);
204+
return setItemGeneric(self, key, value, state, putNode, hashNode, gotState);
206205
}
207206

208207
@Specialization(guards = {"!hasSideEffect(self)", "!isBuiltin(value,builtinProfile)", "maySideEffect(value, lookup)"}, limit = "1")
209208
static HashingStorage setItemPythonObjectWithSideEffect(EconomicMapStorage self, Object key, PythonObject value, ThreadState state,
210-
@Shared("putProfiles") @Cached ObjectHashMap.PutProfiles profiles,
209+
@Shared("putNode") @Cached ObjectHashMap.PutNode putNode,
211210
@Shared("hashNode") @Cached PyObjectHashNode hashNode,
212211
@Shared("lookup") @Cached LookupInheritedAttributeNode.Dynamic lookup,
213212
@Shared("builtinProfile") @Cached IsBuiltinClassProfile builtinProfile,
214213
@Shared("gotState") @Cached ConditionProfile gotState) {
215214
convertToSideEffectMap(self);
216-
return setItemGeneric(self, key, value, state, profiles, hashNode, gotState);
215+
return setItemGeneric(self, key, value, state, putNode, hashNode, gotState);
217216
}
218217

219218
@Specialization(replaces = {"setItemPString", "setItemTruffleString"})
220219
static HashingStorage setItemGeneric(EconomicMapStorage self, Object key, Object value, ThreadState state,
221-
@Shared("putProfiles") @Cached ObjectHashMap.PutProfiles profiles,
220+
@Shared("putNode") @Cached ObjectHashMap.PutNode putNode,
222221
@Shared("hashNode") @Cached PyObjectHashNode hashNode,
223222
@Shared("gotState") @Cached ConditionProfile gotState) {
224223
VirtualFrame frame = gotState.profile(state == null) ? null : PArguments.frameForCall(state);
225-
self.map.put(frame, key, hashNode.execute(frame, key), assertNoJavaString(value), profiles);
224+
putNode.put(state, self.map, key, hashNode.execute(frame, key), assertNoJavaString(value));
226225
return self;
227226
}
228227
}
@@ -328,7 +327,7 @@ public static class EqualsWithState {
328327
@Specialization
329328
static boolean equalSameType(EconomicMapStorage self, EconomicMapStorage other, ThreadState state,
330329
@CachedLibrary("self") HashingStorageLibrary thisLib,
331-
@Shared("getNode") @Cached ObjectHashMap.GetNode getNode,
330+
@Shared("getNode") @Cached ObjectHashMap.GetNode getNode,
332331
@Shared("eqNode") @Cached PyObjectRichCompareBool.EqNode eqNode,
333332
@Shared("selfEntriesLoop") @Cached LoopConditionProfile loopProfile,
334333
@Shared("selfEntriesLoopExit") @Cached LoopConditionProfile earlyExitProfile,
@@ -403,7 +402,7 @@ static int compareSameType(EconomicMapStorage self, EconomicMapStorage other, Th
403402
@CachedLibrary("self") HashingStorageLibrary thisLib,
404403
@Shared("selfEntriesLoop") @Cached LoopConditionProfile loopProfile,
405404
@Shared("selfEntriesLoopExit") @Cached LoopConditionProfile earlyExitProfile,
406-
@Shared("getNode") @Cached ObjectHashMap.GetNode getNode,
405+
@Shared("getNode") @Cached ObjectHashMap.GetNode getNode,
407406
@Shared("gotState") @Cached ConditionProfile gotState) {
408407
int size = self.map.size();
409408
int size2 = other.map.size();
@@ -476,8 +475,8 @@ public static class IntersectWithState {
476475
@Specialization
477476
static HashingStorage intersectSameType(EconomicMapStorage self, EconomicMapStorage other, ThreadState state,
478477
@CachedLibrary("self") HashingStorageLibrary thisLib,
479-
@Shared("putProfiles") @Cached ObjectHashMap.PutProfiles putProfiles,
480-
@Shared("getNode") @Cached ObjectHashMap.GetNode getNode,
478+
@Shared("putNode") @Cached ObjectHashMap.PutNode putNode,
479+
@Shared("getNode") @Cached ObjectHashMap.GetNode getNode,
481480
@Shared("selfEntriesLoop") @Cached LoopConditionProfile loopProfile,
482481
@Shared("gotState") @Cached ConditionProfile gotState) {
483482
EconomicMapStorage result = EconomicMapStorage.create();
@@ -489,7 +488,7 @@ static HashingStorage intersectSameType(EconomicMapStorage self, EconomicMapStor
489488
LoopNode.reportLoopCount(thisLib, size);
490489
while (loopProfile.inject(advance(cursor))) {
491490
if (getNode.get(state, other.map, getDictKey(cursor)) != null) {
492-
result.map.put(frame, getDictKey(cursor), getValue(cursor), putProfiles);
491+
putNode.put(state, result.map, getDictKey(cursor), getValue(cursor));
493492
}
494493
}
495494
return result;
@@ -498,7 +497,7 @@ static HashingStorage intersectSameType(EconomicMapStorage self, EconomicMapStor
498497
@Specialization
499498
static HashingStorage intersectGeneric(EconomicMapStorage self, HashingStorage other, @SuppressWarnings("unused") ThreadState state,
500499
@CachedLibrary("self") HashingStorageLibrary thisLib,
501-
@Shared("putProfiles") @Cached ObjectHashMap.PutProfiles putProfiles,
500+
@Shared("putNode") @Cached ObjectHashMap.PutNode putNode,
502501
@Shared("selfEntriesLoop") @Cached LoopConditionProfile loopProfile,
503502
@Shared("otherHLib") @CachedLibrary(limit = "2") HashingStorageLibrary hlib,
504503
@Shared("gotState") @Cached ConditionProfile gotState) {
@@ -511,7 +510,7 @@ static HashingStorage intersectGeneric(EconomicMapStorage self, HashingStorage o
511510
LoopNode.reportLoopCount(thisLib, size);
512511
while (loopProfile.inject(advance(cursor))) {
513512
if (hlib.hasKey(other, getKey(cursor))) {
514-
result.map.put(frame, getDictKey(cursor), getValue(cursor), putProfiles);
513+
putNode.put(state, result.map, getDictKey(cursor), getValue(cursor));
515514
}
516515
}
517516
return result;
@@ -523,8 +522,8 @@ public static class DiffWithState {
523522
@Specialization
524523
static HashingStorage diffSameType(EconomicMapStorage self, EconomicMapStorage other, ThreadState state,
525524
@CachedLibrary("self") HashingStorageLibrary thisLib,
526-
@Shared("putProfiles") @Cached ObjectHashMap.PutProfiles putProfiles,
527-
@Shared("getNode") @Cached ObjectHashMap.GetNode getNode,
525+
@Shared("putNode") @Cached ObjectHashMap.PutNode putNode,
526+
@Shared("getNode") @Cached ObjectHashMap.GetNode getNode,
528527
@Shared("selfEntriesLoop") @Cached LoopConditionProfile loopProfile,
529528
@Shared("gotState") @Cached ConditionProfile gotState) {
530529
EconomicMapStorage result = EconomicMapStorage.create();
@@ -536,7 +535,7 @@ static HashingStorage diffSameType(EconomicMapStorage self, EconomicMapStorage o
536535
LoopNode.reportLoopCount(thisLib, size);
537536
while (loopProfile.inject(advance(cursor))) {
538537
if (getNode.get(state, other.map, getDictKey(cursor)) == null) {
539-
result.map.put(frame, getDictKey(cursor), getValue(cursor), putProfiles);
538+
putNode.put(state, result.map, getDictKey(cursor), getValue(cursor));
540539
}
541540
}
542541
return result;
@@ -545,7 +544,7 @@ static HashingStorage diffSameType(EconomicMapStorage self, EconomicMapStorage o
545544
@Specialization
546545
static HashingStorage diffGeneric(EconomicMapStorage self, HashingStorage other, @SuppressWarnings("unused") ThreadState state,
547546
@CachedLibrary("self") HashingStorageLibrary thisLib,
548-
@Shared("putProfiles") @Cached ObjectHashMap.PutProfiles profiles,
547+
@Shared("putNode") @Cached ObjectHashMap.PutNode putNode,
549548
@Shared("selfEntriesLoop") @Cached LoopConditionProfile loopProfile,
550549
@Shared("otherHLib") @CachedLibrary(limit = "2") HashingStorageLibrary hlib,
551550
@Shared("gotState") @Cached ConditionProfile gotState) {
@@ -558,7 +557,7 @@ static HashingStorage diffGeneric(EconomicMapStorage self, HashingStorage other,
558557
LoopNode.reportLoopCount(thisLib, size);
559558
while (loopProfile.profile(advance(cursor))) {
560559
if (!hlib.hasKey(other, getKey(cursor))) {
561-
result.map.put(frame, getDictKey(cursor), getValue(cursor), profiles);
560+
putNode.put(state, result.map, getDictKey(cursor), getValue(cursor));
562561
}
563562
}
564563
return result;

0 commit comments

Comments
 (0)