Skip to content

Commit efcc353

Browse files
committed
Use constant for inline cache limits.
1 parent b2e91a6 commit efcc353

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

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

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ abstract static class SequenceStorageBaseNode extends PBaseNode {
159159
protected static final int DEFAULT_CAPACITY = 8;
160160

161161
protected static final int MAX_SEQUENCE_STORAGES = 12;
162+
protected static final int MAX_ARRAY_STORAGES = 9;
162163

163164
protected static boolean isByteStorage(NativeSequenceStorage store) {
164165
return store.getElementType() == ListStorageType.Byte;
@@ -590,7 +591,7 @@ private Node getReadNode() {
590591
}
591592

592593
@ImportStatic(ListStorageType.class)
593-
abstract static class GetItemSliceNode extends PBaseNode {
594+
abstract static class GetItemSliceNode extends SequenceStorageBaseNode {
594595

595596
@Child private Node readNode;
596597
@Child private Node executeNode;
@@ -603,7 +604,7 @@ protected EmptySequenceStorage doEmpty(EmptySequenceStorage storage, int start,
603604
return EmptySequenceStorage.INSTANCE;
604605
}
605606

606-
@Specialization(limit = "5", guards = {"storage.getClass() == cachedClass"})
607+
@Specialization(limit = "MAX_ARRAY_STORAGES", guards = {"storage.getClass() == cachedClass"})
607608
protected SequenceStorage doManagedStorage(BasicSequenceStorage storage, int start, int stop, int step, int length,
608609
@Cached("storage.getClass()") Class<? extends BasicSequenceStorage> cachedClass) {
609610
return cachedClass.cast(storage).getSliceInBound(start, stop, step, length);
@@ -975,7 +976,7 @@ abstract static class SetStorageSliceNode extends SequenceStorageBaseNode {
975976

976977
public abstract void execute(SequenceStorage s, SliceInfo info, SequenceStorage iterable);
977978

978-
@Specialization(limit = "9", guards = {"self.getClass() == cachedClass", "self.getClass() == sequence.getClass()", "replacesWholeSequence(cachedClass, self, info)"})
979+
@Specialization(limit = "MAX_ARRAY_STORAGES", guards = {"self.getClass() == cachedClass", "self.getClass() == sequence.getClass()", "replacesWholeSequence(cachedClass, self, info)"})
979980
void doWholeSequence(BasicSequenceStorage self, @SuppressWarnings("unused") SliceInfo info, BasicSequenceStorage sequence,
980981
@Cached("self.getClass()") Class<? extends BasicSequenceStorage> cachedClass) {
981982
BasicSequenceStorage selfProfiled = cachedClass.cast(self);
@@ -2154,39 +2155,39 @@ SequenceStorage doZeroRepeat(SequenceStorage s, @SuppressWarnings("unused") int
21542155
return storageTypeProfile.profile(s).createEmpty(0);
21552156
}
21562157

2157-
@Specialization(limit = "2", guards = {"times > 0", "!isNative(s)", "s.getClass() == cachedClass"})
2158+
@Specialization(limit = "MAX_ARRAY_STORAGES", guards = {"times > 0", "!isNative(s)", "s.getClass() == cachedClass"})
21582159
SequenceStorage doManaged(BasicSequenceStorage s, int times,
21592160
@Cached("create()") BranchProfile outOfMemProfile,
21602161
@Cached("s.getClass()") Class<? extends SequenceStorage> cachedClass) {
21612162
try {
21622163
SequenceStorage profiled = cachedClass.cast(s);
21632164
Object arr1 = profiled.getInternalArrayObject();
21642165
int len = profiled.length();
2165-
SequenceStorage repeated = profiled.createEmpty(Math.multiplyExact(len, times));
2166+
int newLength = Math.multiplyExact(len, times);
2167+
SequenceStorage repeated = profiled.createEmpty(newLength);
21662168
Object destArr = repeated.getInternalArrayObject();
21672169
repeat(destArr, arr1, len, times);
2168-
repeated.setNewLength(len * times);
2170+
repeated.setNewLength(newLength);
21692171
return repeated;
21702172
} catch (OutOfMemoryError | ArithmeticException e) {
21712173
outOfMemProfile.enter();
21722174
throw raise(MemoryError);
21732175
}
21742176
}
21752177

2176-
@Specialization(replaces = "doManaged", limit = "2", guards = {"times > 0", "s.getClass() == cachedClass"})
2178+
@Specialization(replaces = "doManaged", guards = "times > 0")
21772179
SequenceStorage doGeneric(SequenceStorage s, int times,
21782180
@Cached("create()") BranchProfile outOfMemProfile,
2179-
@Cached("s.getClass()") Class<? extends SequenceStorage> cachedClass) {
2181+
@Cached("create()") LenNode lenNode) {
21802182
try {
2181-
SequenceStorage profiled = cachedClass.cast(s);
2182-
int len = profiled.length();
2183+
int len = lenNode.execute(s);
21832184

21842185
ObjectSequenceStorage repeated = new ObjectSequenceStorage(Math.multiplyExact(len, times));
21852186

21862187
// TODO avoid temporary array
21872188
Object[] values = new Object[len];
21882189
for (int i = 0; i < len; i++) {
2189-
values[i] = getGetItemNode().execute(profiled, i);
2190+
values[i] = getGetItemNode().execute(s, i);
21902191
}
21912192

21922193
Object destArr = repeated.getInternalArrayObject();
@@ -2538,7 +2539,7 @@ SequenceStorage doEmpty(EmptySequenceStorage s, Object val,
25382539
return recursive.execute(newStorage, val);
25392540
}
25402541

2541-
@Specialization(limit = "9", guards = "s.getClass() == cachedClass")
2542+
@Specialization(limit = "MAX_ARRAY_STORAGES", guards = "s.getClass() == cachedClass")
25422543
SequenceStorage doManaged(BasicSequenceStorage s, Object val,
25432544
@Cached("s.getClass()") Class<? extends BasicSequenceStorage> cachedClass,
25442545
@Cached("create()") SetItemScalarNode setItemNode) {

0 commit comments

Comments
 (0)