Skip to content

Commit d46946e

Browse files
committed
Address truffle-interpreted-performance warnings
* By making the necessary inlined nodes/profiles @exclusive, since alternatives (merging specializations, creating new nodes) are complicated and time-intensive.
1 parent 7010d2a commit d46946e

File tree

21 files changed

+82
-67
lines changed

21 files changed

+82
-67
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2126,13 +2126,14 @@ static Object sumDoubleIterator(Node inliningTarget, PDoubleSequenceIterator ite
21262126
return result;
21272127
}
21282128

2129+
// @Exclusive for truffle-interpreted-performance
21292130
@Fallback
21302131
static Object sumGeneric(VirtualFrame frame, Node inliningTarget, Object iterator, Object start,
2131-
@Shared @Cached InlinedLoopConditionProfile loopProfilePrimitive,
2132-
@Shared @Cached InlinedLoopConditionProfile loopProfileGeneric,
2132+
@Exclusive @Cached InlinedLoopConditionProfile loopProfilePrimitive,
2133+
@Exclusive @Cached InlinedLoopConditionProfile loopProfileGeneric,
21332134
@Cached PyIterNextNode nextNode,
21342135
@Shared @Cached PyNumberAddNode addNode,
2135-
@Shared @Cached InlinedConditionProfile resultFitsInInt,
2136+
@Exclusive @Cached InlinedConditionProfile resultFitsInInt,
21362137
@Exclusive @Cached InlinedBranchProfile seenObject,
21372138
@Exclusive @Cached InlinedBranchProfile seenInt,
21382139
@Exclusive @Cached InlinedBranchProfile seenDouble,

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextDictBuiltins.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ abstract static class PyDict_Merge extends CApiTernaryBuiltinNode {
524524
@Specialization(guards = {"override != 0"})
525525
static int merge(PDict a, Object b, @SuppressWarnings("unused") int override,
526526
@Bind Node inliningTarget,
527-
@Shared @Cached PyObjectGetAttr getKeys,
527+
@Exclusive @Cached PyObjectGetAttr getKeys,
528528
@Exclusive @Cached PyObjectGetAttr getUpdate,
529529
@Shared @Cached CallNode callNode,
530530
@Cached PRaiseNode raiseNode) {
@@ -561,10 +561,11 @@ static int merge(PDict a, PDict b, @SuppressWarnings("unused") int override,
561561
return 0;
562562
}
563563

564+
// @Exclusive for truffle-interpreted-performance
564565
@Specialization(guards = {"override == 0", "!isDict(b)"})
565566
static int merge(PDict a, Object b, @SuppressWarnings("unused") int override,
566567
@Bind Node inliningTarget,
567-
@Shared @Cached PyObjectGetAttr getKeys,
568+
@Exclusive @Cached PyObjectGetAttr getKeys,
568569
@Shared @Cached CallNode callNode,
569570
@Cached ConstructListNode listNode,
570571
@Cached GetItemNode getKeyNode,

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/array/ArrayBuiltins.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -734,16 +734,17 @@ abstract static class SetItemNode extends SqAssItemBuiltinNode {
734734
static void setitem(VirtualFrame frame, PArray self, int index, Object value,
735735
@Bind Node inliningTarget,
736736
@Cached ArrayNodes.PutValueNode putValueNode,
737-
@Shared @Cached PRaiseNode raiseNode) {
737+
@Exclusive @Cached PRaiseNode raiseNode) {
738738
checkBounds(inliningTarget, raiseNode, ErrorMessages.ARRAY_ASSIGN_OUT_OF_BOUNDS, index, self.getLength());
739739
putValueNode.execute(frame, inliningTarget, self, index, value);
740740
}
741741

742+
// @Exclusive for truffle-interpreted-performance
742743
@Specialization(guards = "isNoValue(value)")
743744
static void delitem(PArray self, int index, @SuppressWarnings("unused") Object value,
744745
@Bind Node inliningTarget,
745746
@Cached DeleteArraySliceNode deleteSliceNode,
746-
@Shared @Cached PRaiseNode raiseNode) {
747+
@Exclusive @Cached PRaiseNode raiseNode) {
747748
checkBounds(inliningTarget, raiseNode, ErrorMessages.ARRAY_ASSIGN_OUT_OF_BOUNDS, index, self.getLength());
748749
self.checkCanResize(inliningTarget, raiseNode);
749750
deleteSliceNode.execute(inliningTarget, self, index, 1);
@@ -754,10 +755,11 @@ static void delitem(PArray self, int index, @SuppressWarnings("unused") Object v
754755
@GenerateNodeFactory
755756
abstract static class SetSubscriptNode extends MpAssSubscriptBuiltinNode {
756757

758+
// @Exclusive for truffle-interpreted-performance
757759
@Specialization(guards = {"!isPSlice(idx)", "!isNoValue(value)"})
758760
static void setitem(VirtualFrame frame, PArray self, Object idx, Object value,
759761
@Bind Node inliningTarget,
760-
@Shared @Cached PyNumberIndexNode indexNode,
762+
@Exclusive @Cached PyNumberIndexNode indexNode,
761763
@Shared @Cached("forArrayAssign()") NormalizeIndexNode normalizeIndexNode,
762764
@Cached ArrayNodes.PutValueNode putValueNode) {
763765
int index = normalizeIndexNode.execute(indexNode.execute(frame, inliningTarget, idx), self.getLength());
@@ -767,15 +769,16 @@ static void setitem(VirtualFrame frame, PArray self, Object idx, Object value,
767769
@Specialization(guards = {"!isPSlice(idx)", "isNoValue(value)"})
768770
static void delitem(VirtualFrame frame, PArray self, Object idx, @SuppressWarnings("unused") Object value,
769771
@Bind Node inliningTarget,
770-
@Shared @Cached PyNumberIndexNode indexNode,
772+
@Exclusive @Cached PyNumberIndexNode indexNode,
771773
@Shared @Cached("forArrayAssign()") NormalizeIndexNode normalizeIndexNode,
772-
@Shared @Cached DeleteArraySliceNode deleteSliceNode,
774+
@Exclusive @Cached DeleteArraySliceNode deleteSliceNode,
773775
@Exclusive @Cached PRaiseNode raiseNode) {
774776
self.checkCanResize(inliningTarget, raiseNode);
775777
int index = normalizeIndexNode.execute(indexNode.execute(frame, inliningTarget, idx), self.getLength());
776778
deleteSliceNode.execute(inliningTarget, self, index, 1);
777779
}
778780

781+
// @Exclusive for truffle-interpreted-performance
779782
@Specialization
780783
static void setitem(PArray self, PSlice slice, Object other,
781784
@Bind Node inliningTarget,
@@ -794,7 +797,7 @@ static void setitem(PArray self, PSlice slice, Object other,
794797
@Cached InlinedByteValueProfile itemShiftProfile,
795798
@Cached SliceNodes.SliceUnpack sliceUnpack,
796799
@Cached SliceNodes.AdjustIndices adjustIndices,
797-
@Shared @Cached DeleteArraySliceNode deleteSliceNode,
800+
@Exclusive @Cached DeleteArraySliceNode deleteSliceNode,
798801
@Cached ArrayNodes.ShiftNode shiftNode,
799802
@Cached ArrayNodes.SetLengthNode setLengthNode,
800803
@Exclusive @Cached PRaiseNode raiseNode) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/BytesCommonBuiltins.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -286,20 +286,21 @@ public abstract static class ConcatNode extends SqConcatBuiltinNode {
286286
static PBytesLike add(PBytesLike self, PBytesLike other,
287287
@Bind Node inliningTarget,
288288
@Shared @CachedLibrary(limit = "3") PythonBufferAccessLibrary bufferLib,
289-
@Shared @Cached BytesNodes.CreateBytesNode create,
290-
@Shared @Cached PRaiseNode raiseNode) {
289+
@Exclusive @Cached BytesNodes.CreateBytesNode create,
290+
@Exclusive @Cached PRaiseNode raiseNode) {
291291
return concatBuffers(self, self, other, inliningTarget, bufferLib, create, raiseNode);
292292
}
293293

294+
// @Exclusive for truffle-interpreted-performance
294295
@Specialization(limit = "3")
295296
static PBytesLike add(VirtualFrame frame, Object self, Object other,
296297
@Bind Node inliningTarget,
297298
@Cached("createFor($node)") IndirectCallData indirectCallData,
298299
@Cached GetBytesStorage getBytesStorage,
299300
@CachedLibrary("other") PythonBufferAcquireLibrary bufferAcquireLib,
300301
@Shared @CachedLibrary(limit = "3") PythonBufferAccessLibrary bufferLib,
301-
@Shared @Cached BytesNodes.CreateBytesNode create,
302-
@Shared @Cached PRaiseNode raiseNode) {
302+
@Exclusive @Cached BytesNodes.CreateBytesNode create,
303+
@Exclusive @Cached PRaiseNode raiseNode) {
303304
Object otherBuffer;
304305
try {
305306
otherBuffer = bufferAcquireLib.acquireReadonly(other, frame, indirectCallData);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
import java.nio.charset.StandardCharsets;
5959
import java.util.logging.Level;
6060

61+
import com.oracle.truffle.api.dsl.Cached.Exclusive;
6162
import org.graalvm.collections.Pair;
6263

6364
import com.oracle.graal.python.PythonLanguage;
@@ -862,7 +863,7 @@ static long doPIntToInt64Lossy(PInt obj, int signed, int targetTypeSize, boolean
862863
static Object doGeneric(Object obj, int signed, int targetTypeSize, boolean exact,
863864
@Bind Node inliningTarget,
864865
@Cached PyNumberIndexNode indexNode,
865-
@Shared("raiseNode") @Cached PRaiseNode raiseNode) {
866+
@Exclusive @Cached PRaiseNode raiseNode) {
866867
Object result = indexNode.execute(null, inliningTarget, obj);
867868
/*
868869
* The easiest would be to recursively use this node and ensure that this generic case

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,22 +123,23 @@ abstract static class SetValueHashingStorageNode extends PNodeWithContext {
123123

124124
@Specialization
125125
static HashingStorage doEconomicStorage(VirtualFrame frame, Node inliningTarget, EconomicMapStorage map, Object value,
126-
@Shared("putNode") @Cached ObjectHashMap.PutNode putNode,
127-
@Shared("loopProfile") @Cached InlinedLoopConditionProfile loopProfile) {
126+
@Exclusive @Cached ObjectHashMap.PutNode putNode,
127+
@Exclusive @Cached InlinedLoopConditionProfile loopProfile) {
128128
// We want to avoid calling __hash__() during map.put
129129
map.setValueForAllKeys(frame, inliningTarget, value, putNode, loopProfile);
130130
return map;
131131
}
132132

133+
// @Exclusive for truffle-interpreted-performance
133134
@Specialization(guards = "!isEconomicMapStorage(map)")
134135
@InliningCutoff
135136
static HashingStorage doGeneric(VirtualFrame frame, Node inliningTarget, HashingStorage map, Object value,
136137
@Cached HashingStorageSetItem setItem,
137138
@Cached HashingStorageGetIterator getIterator,
138139
@Cached HashingStorageIteratorNext itNext,
139140
@Cached HashingStorageIteratorKey itKey,
140-
@Shared("putNode") @Cached PutNode putNode,
141-
@Shared("loopProfile") @Cached InlinedLoopConditionProfile loopProfile) {
141+
@Exclusive @Cached PutNode putNode,
142+
@Exclusive @Cached InlinedLoopConditionProfile loopProfile) {
142143
HashingStorageIterator it = getIterator.execute(inliningTarget, map);
143144
while (itNext.execute(inliningTarget, map, it)) {
144145
Object key = itKey.execute(inliningTarget, map, it);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1710,7 +1710,7 @@ static void singleStep(SequenceStorage self, SliceInfo sinfo, SequenceStorage va
17101710
@Exclusive @Cached InlinedConditionProfile memoryError,
17111711
@Exclusive @Cached InlinedConditionProfile negGrowth,
17121712
@Exclusive @Cached InlinedConditionProfile posGrowth,
1713-
@Shared @Cached PRaiseNode raiseNode) {
1713+
@Exclusive @Cached PRaiseNode raiseNode) {
17141714
int start = sinfo.start;
17151715
int stop = sinfo.stop;
17161716
int step = sinfo.step;
@@ -1735,7 +1735,7 @@ static void multiStep(SequenceStorage self, SliceInfo sinfo, SequenceStorage val
17351735
@Exclusive @Cached MemMoveNode memove,
17361736
@Cached SetItemScalarNode setLeftItemNode,
17371737
@Cached GetItemScalarNode getRightItemNode,
1738-
@Shared @Cached PRaiseNode raiseNode,
1738+
@Exclusive @Cached PRaiseNode raiseNode,
17391739
@Exclusive @Cached CopyNode copyNode) {
17401740
int start = sinfo.start;
17411741
int step = sinfo.step;
@@ -2616,7 +2616,7 @@ SequenceStorage doArrayBasedManaged(ArrayBasedSequenceStorage s, int times,
26162616
@SuppressWarnings("truffle-static-method")
26172617
SequenceStorage doGeneric(SequenceStorage s, int times,
26182618
@Bind Node inliningTarget,
2619-
@Shared @Cached PRaiseNode raiseNode,
2619+
@Exclusive @Cached PRaiseNode raiseNode,
26202620
@Exclusive @Cached CreateEmptyNode createEmptyNode,
26212621
@Cached GetItemScalarNode getItemNode,
26222622
@Cached SetItemScalarNode setItemNode,

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/PrepareExceptionNode.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ static Object doExceptionOrCreate(VirtualFrame frame, Object type, Object value,
104104
@Cached BuiltinFunctions.IsInstanceNode isInstanceNode,
105105
@Cached InlinedConditionProfile isInstanceProfile,
106106
@Shared @Cached IsSubtypeNode isSubtypeNode,
107-
@Shared @Cached PRaiseNode raiseNode,
107+
@Exclusive @Cached PRaiseNode raiseNode,
108108
@Shared("callCtor") @Cached CallNode callConstructor) {
109109
checkExceptionClass(inliningTarget, type, isSubtypeNode, raiseNode);
110110
if (isInstanceProfile.profile(inliningTarget, isInstanceNode.executeWith(frame, value, type))) {
@@ -125,7 +125,7 @@ static Object doCreate(VirtualFrame frame, Object type, @SuppressWarnings("unuse
125125
@SuppressWarnings("unused") @Exclusive @Cached IsTypeNode isTypeNode,
126126
@Exclusive @Cached PyExceptionInstanceCheckNode check,
127127
@Shared @Cached IsSubtypeNode isSubtypeNode,
128-
@Shared @Cached PRaiseNode raiseNode,
128+
@Exclusive @Cached PRaiseNode raiseNode,
129129
@Shared("callCtor") @Cached CallNode callConstructor) {
130130
checkExceptionClass(inliningTarget, type, isSubtypeNode, raiseNode);
131131
Object instance = callConstructor.execute(frame, type);
@@ -143,7 +143,7 @@ static Object doCreateTuple(VirtualFrame frame, Object type, PTuple value,
143143
@Exclusive @Cached PyExceptionInstanceCheckNode check,
144144
@Cached SequenceNodes.GetObjectArrayNode getObjectArrayNode,
145145
@Shared @Cached IsSubtypeNode isSubtypeNode,
146-
@Shared @Cached PRaiseNode raiseNode,
146+
@Exclusive @Cached PRaiseNode raiseNode,
147147
@Shared("callCtor") @Cached CallNode callConstructor) {
148148
checkExceptionClass(inliningTarget, type, isSubtypeNode, raiseNode);
149149
Object[] args = getObjectArrayNode.execute(inliningTarget, value);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/list/ListBuiltins.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,18 +374,19 @@ public abstract static class SetItemNode extends SqAssItemBuiltinNode {
374374
@Specialization(guards = "!isNoValue(value)")
375375
static void doInt(Object self, int index, Object value,
376376
@Bind Node inliningTarget,
377-
@Shared @Cached GetListStorageNode getStorageNode,
377+
@Exclusive @Cached GetListStorageNode getStorageNode,
378378
@Cached ListNodes.UpdateListStorageNode updateStorageNode,
379379
@Cached("createForList()") SequenceStorageNodes.SetItemNode setItemNode) {
380380
var sequenceStorage = getStorageNode.execute(inliningTarget, self);
381381
var newStorage = setItemNode.execute(sequenceStorage, index, value);
382382
updateStorageNode.execute(inliningTarget, self, sequenceStorage, newStorage);
383383
}
384384

385+
// @Exclusive for truffle-interpreted-performance
385386
@Specialization(guards = "isNoValue(value)")
386387
static void doGeneric(Object list, int index, @SuppressWarnings("unused") Object value,
387388
@Bind Node inliningTarget,
388-
@Shared @Cached GetListStorageNode getStorageNode,
389+
@Exclusive @Cached GetListStorageNode getStorageNode,
389390
@Cached NormalizeIndexNode normalizeIndexNode,
390391
@Cached SequenceStorageNodes.DeleteItemNode deleteItemNode) {
391392
var sequenceStorage = getStorageNode.execute(inliningTarget, list);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/mmap/MMapBuiltins.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@
141141
import com.oracle.truffle.api.dsl.Bind;
142142
import com.oracle.truffle.api.dsl.Cached;
143143
import com.oracle.truffle.api.dsl.Cached.Exclusive;
144-
import com.oracle.truffle.api.dsl.Cached.Shared;
145144
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
146145
import com.oracle.truffle.api.dsl.GenerateUncached;
147146
import com.oracle.truffle.api.dsl.NodeFactory;
@@ -431,8 +430,8 @@ static void doSingle(VirtualFrame frame, PMMap self, Object idxObj, Object value
431430
@CachedLibrary("context.getPosixSupport()") PosixSupportLibrary posixSupportLib,
432431
@Cached PyIndexCheckNode checkNode,
433432
@Cached PyNumberAsSizeNode asSizeNode,
434-
@Shared @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
435-
@Shared @Cached PRaiseNode raiseNode) {
433+
@Exclusive @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
434+
@Exclusive @Cached PRaiseNode raiseNode) {
436435
// NB: sq_ass_item and mp_ass_subscript implementations behave differently even with
437436
// integer indices
438437
if (self.isClosed()) {
@@ -467,6 +466,7 @@ static void doSingle(VirtualFrame frame, PMMap self, Object idxObj, Object value
467466
}
468467
}
469468

469+
// @Exclusive for truffle-interpreted-performance
470470
@Specialization
471471
static void doSlice(VirtualFrame frame, PMMap self, PSlice slice, Object valueObj,
472472
@Bind Node inliningTarget,
@@ -477,8 +477,8 @@ static void doSlice(VirtualFrame frame, PMMap self, PSlice slice, Object valueOb
477477
@Cached SliceNodes.SliceUnpack sliceUnpack,
478478
@Cached SliceNodes.AdjustIndices adjustIndices,
479479
@Cached InlinedConditionProfile step1Profile,
480-
@Shared @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
481-
@Shared @Cached PRaiseNode raiseNode) {
480+
@Exclusive @Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
481+
@Exclusive @Cached PRaiseNode raiseNode) {
482482
if (self.isClosed()) {
483483
throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.ValueError, MMAP_CLOSED_OR_INVALID);
484484
}

0 commit comments

Comments
 (0)