Skip to content

Commit e01509b

Browse files
committed
remove unnecessary lengthWithState from HashingStorageLibrary
1 parent ac34d9d commit e01509b

File tree

9 files changed

+27
-100
lines changed

9 files changed

+27
-100
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/MarshalModuleBuiltins.java

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@
5959
import com.oracle.graal.python.builtins.objects.complex.PComplex;
6060
import com.oracle.graal.python.builtins.objects.dict.PDict;
6161
import com.oracle.graal.python.builtins.objects.floats.PFloat;
62-
import com.oracle.graal.python.builtins.objects.function.PArguments;
6362
import com.oracle.graal.python.builtins.objects.ints.PInt;
6463
import com.oracle.graal.python.builtins.objects.list.PList;
6564
import com.oracle.graal.python.builtins.objects.object.PythonObjectLibrary;
@@ -400,11 +399,10 @@ void handlePList(VirtualFrame frame, PList l, int version, DataOutputStream buff
400399

401400
@Specialization(limit = "1")
402401
void handlePDict(VirtualFrame frame, PDict d, int version, DataOutputStream buffer,
403-
@Cached("createBinaryProfile()") ConditionProfile hasFrame,
404402
@CachedLibrary("d.getDictStorage()") HashingStorageLibrary lib) {
405403
writeByte(TYPE_DICT, version, buffer);
406404
HashingStorage dictStorage = d.getDictStorage();
407-
int len = lib.lengthWithFrame(dictStorage, hasFrame, frame);
405+
int len = lib.length(dictStorage);
408406
writeInt(len, version, buffer);
409407
for (DictEntry entry : lib.entries(dictStorage)) {
410408
getRecursiveNode().execute(frame, entry.key, version, buffer);
@@ -413,7 +411,7 @@ void handlePDict(VirtualFrame frame, PDict d, int version, DataOutputStream buff
413411
}
414412

415413
@Specialization
416-
void handlePCode(@SuppressWarnings("unused") VirtualFrame frame, PCode c, int version, DataOutputStream buffer) {
414+
void handlePCode(PCode c, int version, DataOutputStream buffer) {
417415
writeByte(TYPE_CODE, version, buffer);
418416
writeString(getSourceCode(c), version, buffer);
419417
writeString(c.getFilename(), version, buffer);
@@ -431,16 +429,10 @@ private static String getSourceCode(PCode c) {
431429

432430
@Specialization(limit = "1")
433431
void handlePSet(VirtualFrame frame, PSet s, int version, DataOutputStream buffer,
434-
@Cached("createBinaryProfile()") ConditionProfile hasFrame,
435432
@CachedLibrary("s.getDictStorage()") HashingStorageLibrary lib) {
436433
writeByte(TYPE_SET, version, buffer);
437-
int len;
438434
HashingStorage dictStorage = s.getDictStorage();
439-
if (hasFrame.profile(frame != null)) {
440-
len = lib.lengthWithState(dictStorage, PArguments.getThreadState(frame));
441-
} else {
442-
len = lib.length(dictStorage);
443-
}
435+
int len = lib.length(dictStorage);
444436
writeInt(len, version, buffer);
445437
for (DictEntry entry : lib.entries(dictStorage)) {
446438
getRecursiveNode().execute(frame, entry.key, version, buffer);
@@ -449,16 +441,10 @@ void handlePSet(VirtualFrame frame, PSet s, int version, DataOutputStream buffer
449441

450442
@Specialization(limit = "1")
451443
void handlePForzenSet(VirtualFrame frame, PFrozenSet s, int version, DataOutputStream buffer,
452-
@Cached("createBinaryProfile()") ConditionProfile hasFrame,
453444
@CachedLibrary("s.getDictStorage()") HashingStorageLibrary lib) {
454445
writeByte(TYPE_FROZENSET, version, buffer);
455-
int len;
456446
HashingStorage dictStorage = s.getDictStorage();
457-
if (hasFrame.profile(frame != null)) {
458-
len = lib.lengthWithState(dictStorage, PArguments.getThreadState(frame));
459-
} else {
460-
len = lib.length(dictStorage);
461-
}
447+
int len = lib.length(dictStorage);
462448
writeInt(len, version, buffer);
463449
for (DictEntry entry : lib.entries(dictStorage)) {
464450
getRecursiveNode().execute(frame, entry.key, version, buffer);

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -326,13 +326,7 @@ static HashingStorage generalize(DynamicObjectStorage self, Object key, Object v
326326
// To avoid calling the costly length message we use SIZE_THRESHOLD
327327
newStore = new HashMapStorage(SIZE_THRESHOLD);
328328
} else {
329-
int len;
330-
if (gotState.profile(state != null)) {
331-
len = lib.lengthWithState(self, state);
332-
} else {
333-
len = lib.length(self);
334-
}
335-
newStore = EconomicMapStorage.create(len);
329+
newStore = EconomicMapStorage.create(lib.length(self));
336330
}
337331

338332
newStore = lib.addAllToOther(self, newStore);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ static boolean equalGeneric(EconomicMapStorage self, HashingStorage other, Threa
445445
@CachedLibrary(limit = "2") HashingStorageLibrary otherlib,
446446
@CachedLibrary(limit = "2") PythonObjectLibrary compareLib1,
447447
@CachedLibrary(limit = "2") PythonObjectLibrary compareLib2) {
448-
if (self.map.size() != otherlib.lengthWithState(other, state)) {
448+
if (self.map.size() != otherlib.length(other)) {
449449
return false;
450450
}
451451
MapCursor<DictKey, Object> cursor = self.map.getEntries();

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

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -330,19 +330,12 @@ public HashingStorage addAllToOther(HashingStorage other,
330330

331331
@ExportMessage
332332
public boolean equalsWithState(HashingStorage other, ThreadState state,
333-
@CachedLibrary(limit = "2") HashingStorageLibrary lib,
334-
@Exclusive @Cached("createBinaryProfile()") ConditionProfile gotState) {
333+
@CachedLibrary(limit = "2") HashingStorageLibrary lib) {
335334
if (this == other) {
336335
return true;
337336
}
338-
if (gotState.profile(state != null)) {
339-
if (lib.lengthWithState(this, state) == lib.lengthWithState(other, state)) {
340-
return lib.compareEntriesWithState(this, other, state) == 0;
341-
}
342-
} else {
343-
if (lib.length(this) == lib.length(other)) {
344-
return lib.compareEntries(this, other) == 0;
345-
}
337+
if (lib.length(this) == lib.length(other)) {
338+
return lib.compareEntries(this, other) == 0;
346339
}
347340
return false;
348341

@@ -417,19 +410,12 @@ HashingStorage[] doit(HashingStorage[] accumulator, Object key,
417410
@ExportMessage
418411
public int compareEntriesWithState(HashingStorage other, ThreadState state,
419412
@CachedLibrary(limit = "2") HashingStorageLibrary lib,
420-
@Cached TestKeyValueEqual testNode,
421-
@Exclusive @Cached("createBinaryProfile()") ConditionProfile gotState) {
413+
@Cached TestKeyValueEqual testNode) {
422414
if (this == other) {
423415
return 0;
424416
}
425-
int otherLen, selfLen;
426-
if (gotState.profile(state != null)) {
427-
otherLen = lib.lengthWithState(other, state);
428-
selfLen = lib.lengthWithState(this, state);
429-
} else {
430-
otherLen = lib.length(other);
431-
selfLen = lib.length(this);
432-
}
417+
int otherLen = lib.length(other);
418+
int selfLen = lib.length(this);
433419
if (selfLen > otherLen) {
434420
return 1;
435421
}
@@ -506,8 +492,8 @@ public boolean isDisjointWithState(HashingStorage other, ThreadState state,
506492
@Exclusive @Cached("createBinaryProfile()") ConditionProfile selfIsShorterProfile,
507493
@Cached IsDisjointForEachNode isDisjointForEachNode) {
508494
try {
509-
int selfLen = libSelf.lengthWithState(this, state);
510-
int otherLen = libOther.lengthWithState(other, state);
495+
int selfLen = libSelf.length(this);
496+
int otherLen = libOther.length(other);
511497
if (selfIsShorterProfile.profile(selfLen < otherLen)) {
512498
libSelf.forEach(this, isDisjointForEachNode, new IsDisjoinForEachAcc(other, libOther, state));
513499
} else {

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

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -76,34 +76,11 @@
7676
*/
7777
@GenerateLibrary
7878
public abstract class HashingStorageLibrary extends Library {
79-
/**
80-
* @return the length of {@code self}
81-
*/
82-
public int lengthWithState(HashingStorage self, ThreadState state) {
83-
if (state == null) {
84-
CompilerDirectives.transferToInterpreterAndInvalidate();
85-
throw new AbstractMethodError("HashingStorageLibrary.lengthWithState");
86-
}
87-
return length(self);
88-
}
8979

9080
/**
91-
* @see #lengthWithState(HashingStorage, ThreadState)
92-
*/
93-
public int length(HashingStorage self) {
94-
return lengthWithState(self, null);
95-
}
96-
97-
/**
98-
* @see #lengthWithState(HashingStorage, ThreadState)
81+
* @return the length of {@code self}
9982
*/
100-
public final int lengthWithFrame(HashingStorage self, ConditionProfile hasFrameProfile, VirtualFrame frame) {
101-
if (hasFrameProfile.profile(frame != null)) {
102-
return lengthWithState(self, PArguments.getThreadState(frame));
103-
} else {
104-
return length(self);
105-
}
106-
}
83+
public abstract int length(HashingStorage self);
10784

10885
/**
10986
* Implementers <i>must</i> call {@code __hash__} on the key if that could be visible, to comply
@@ -294,7 +271,7 @@ public final <T> T forEach(HashingStorage self, ForEachNode<T> node, T arg) {
294271

295272
/**
296273
* Determines if the storage has elements with a potential side effect on access.
297-
*
274+
*
298275
* @return {@code true} if the storage has elements with a potential side effect, otherwise
299276
* {@code false}.
300277
*/

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/dict/DictValuesBuiltins.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,9 @@ protected List<? extends NodeFactory<? extends PythonBuiltinBaseNode>> getNodeFa
6666
@GenerateNodeFactory
6767
public abstract static class LenNode extends PythonBuiltinNode {
6868
@Specialization(limit = "1")
69-
static Object run(VirtualFrame frame, PDictView self,
70-
@Cached ConditionProfile hasFrameProfile,
69+
static Object run(PDictView self,
7170
@CachedLibrary("self.getWrappedDict().getDictStorage()") HashingStorageLibrary lib) {
72-
return lib.lengthWithFrame(self.getWrappedDict().getDictStorage(), hasFrameProfile, frame);
71+
return lib.length(self.getWrappedDict().getDictStorage());
7372
}
7473
}
7574

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/dict/PDict.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,10 @@ static boolean hasBuiltinLen(PDict self, LookupInheritedAttributeNode.Dynamic lo
115115
}, limit = "1")
116116
static int doBuiltin(PDict self, ThreadState state,
117117
@CachedLibrary("self.getDictStorage()") HashingStorageLibrary storageLib,
118-
@Shared("gotState") @Cached ConditionProfile gotState,
119118
@SuppressWarnings("unused") @Cached IsBuiltinClassProfile profile,
120119
@SuppressWarnings("unused") @Cached LookupInheritedAttributeNode.Dynamic lookupSelf,
121120
@SuppressWarnings("unused") @Cached LookupAttributeInMRONode.Dynamic lookupDict) {
122-
if (gotState.profile(state == null)) {
123-
return storageLib.length(self.storage);
124-
} else {
125-
return storageLib.lengthWithState(self.storage, state);
126-
}
121+
return storageLib.length(self.storage);
127122
}
128123

129124
@Specialization(replaces = "doBuiltin")

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/set/BaseSetBuiltins.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -266,11 +266,9 @@ static boolean isSuperSetGeneric(VirtualFrame frame, PBaseSet self, Object other
266266
protected abstract static class BaseIsDisjointNode extends PythonBinaryBuiltinNode {
267267

268268
@Specialization(guards = "self == other", limit = "2")
269-
static boolean isDisjointSameObject(VirtualFrame frame, PBaseSet self, @SuppressWarnings("unused") PBaseSet other,
270-
@Cached("createBinaryProfile()") ConditionProfile hasFrame,
269+
static boolean isDisjointSameObject(PBaseSet self, @SuppressWarnings("unused") PBaseSet other,
271270
@CachedLibrary("self.getDictStorage()") HashingStorageLibrary lib) {
272-
ThreadState state = PArguments.getThreadStateOrNull(frame, hasFrame);
273-
return lib.lengthWithState(self.getDictStorage(), state) == 0;
271+
return lib.length(self.getDictStorage()) == 0;
274272
}
275273

276274
@Specialization(guards = {"self != other", "cannotBeOverridden(pLib.getLazyPythonClass(other))"}, limit = "2")
@@ -360,8 +358,8 @@ static boolean isLessThan(VirtualFrame frame, PBaseSet self, PBaseSet other,
360358
@CachedLibrary(limit = "2") HashingStorageLibrary hlib,
361359
@Cached ConditionProfile hasFrameProfile,
362360
@Cached ConditionProfile sizeProfile) {
363-
final int len1 = hlib.lengthWithFrame(self.getDictStorage(), hasFrameProfile, frame);
364-
final int len2 = hlib.lengthWithFrame(other.getDictStorage(), hasFrameProfile, frame);
361+
final int len1 = hlib.length(self.getDictStorage());
362+
final int len2 = hlib.length(other.getDictStorage());
365363
if (sizeProfile.profile(len1 >= len2)) {
366364
return false;
367365
}
@@ -384,8 +382,8 @@ static boolean isGreaterThan(VirtualFrame frame, PBaseSet self, PBaseSet other,
384382
@CachedLibrary(limit = "2") HashingStorageLibrary hlib,
385383
@Cached ConditionProfile hasFrameProfile,
386384
@Cached ConditionProfile sizeProfile) {
387-
final int len1 = hlib.lengthWithFrame(self.getDictStorage(), hasFrameProfile, frame);
388-
final int len2 = hlib.lengthWithFrame(other.getDictStorage(), hasFrameProfile, frame);
385+
final int len1 = hlib.length(self.getDictStorage());
386+
final int len2 = hlib.length(other.getDictStorage());
389387
if (sizeProfile.profile(len1 <= len2)) {
390388
return false;
391389
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/set/PBaseSet.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,10 @@
3131
import com.oracle.graal.python.builtins.objects.common.PHashingCollection;
3232
import com.oracle.graal.python.builtins.objects.function.PArguments.ThreadState;
3333
import com.oracle.graal.python.builtins.objects.object.PythonObjectLibrary;
34-
import com.oracle.truffle.api.dsl.Cached;
35-
import com.oracle.truffle.api.dsl.Cached.Exclusive;
3634
import com.oracle.truffle.api.library.CachedLibrary;
3735
import com.oracle.truffle.api.library.ExportLibrary;
3836
import com.oracle.truffle.api.library.ExportMessage;
3937
import com.oracle.truffle.api.object.Shape;
40-
import com.oracle.truffle.api.profiles.ConditionProfile;
4138

4239
@ExportLibrary(PythonObjectLibrary.class)
4340
public abstract class PBaseSet extends PHashingCollection {
@@ -52,12 +49,7 @@ public PBaseSet(Object clazz, Shape instanceShape, HashingStorage set) {
5249

5350
@ExportMessage(limit = "1")
5451
int lengthWithState(ThreadState state,
55-
@Exclusive @Cached ConditionProfile gotState,
5652
@CachedLibrary("this.getDictStorage()") HashingStorageLibrary lib) {
57-
if (gotState.profile(state != null)) {
58-
return lib.lengthWithState(storage, state);
59-
} else {
60-
return lib.length(storage);
61-
}
53+
return lib.length(storage);
6254
}
6355
}

0 commit comments

Comments
 (0)