Skip to content

Commit e9d60f4

Browse files
committed
rework attempt to not pollute the append profiles in interpreter
1 parent f3c95b1 commit e9d60f4

File tree

1 file changed

+20
-15
lines changed
  • graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/builtins

1 file changed

+20
-15
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/builtins/ListNodes.java

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -283,35 +283,40 @@ Object doGeneric(VirtualFrame frame, Object object) {
283283
*/
284284
@GenerateUncached
285285
public abstract static class AppendNode extends PNodeWithContext {
286+
private static final BranchProfile[] DISABLED = new BranchProfile[] { BranchProfile.getUncached() };
286287

287288
public abstract void execute(PList list, Object value);
288289

289-
protected static boolean[] flagContainer(boolean flag) {
290-
boolean[] container = new boolean[1];
291-
container[0] = flag;
292-
return container;
290+
static BranchProfile[] getUpdateStoreProfile() {
291+
return new BranchProfile[1];
292+
}
293+
294+
static BranchProfile[] getUpdateStoreProfileUncached() {
295+
return DISABLED;
293296
}
294297

295298
@Specialization
296299
public void appendObjectGeneric(PList list, Object value,
297-
@Cached SequenceStorageNodes.AppendNode appendInInterpreterNode,
298300
@Cached SequenceStorageNodes.AppendNode appendNode,
299-
@Cached(value = "flagContainer(false)", uncached = "flagContainer(true)", dimensions = 1) boolean[] triedToCompile,
300-
@Cached BranchProfile updateStoreProfile) {
301-
if (CompilerDirectives.inInterpreter() && !triedToCompile[0] && list.getOrigin() != null) {
302-
SequenceStorage newStore = appendInInterpreterNode.execute(list.getSequenceStorage(), value, ListGeneralizationNode.SUPPLIER);
301+
@Cached(value = "getUpdateStoreProfile()", uncached = "getUpdateStoreProfileUncached()", dimensions = 1) BranchProfile[] updateStoreProfile) {
302+
if (updateStoreProfile[0] == null) {
303+
// Executed for the first time. We don't pollute the AppendNode specializations,
304+
// yet, in case we're transitioning exactly once, because we'll pontentially pass
305+
// that information on to the list origin and it'll never happen again.
306+
CompilerDirectives.transferToInterpreterAndInvalidate();
307+
SequenceStorage newStore = SequenceStorageNodes.AppendNode.getUncached().execute(list.getSequenceStorage(), value, ListGeneralizationNode.SUPPLIER);
308+
updateStoreProfile[0] = BranchProfile.create();
303309
list.setSequenceStorage(newStore);
304310
if (list.getOrigin() != null && newStore instanceof BasicSequenceStorage) {
305311
list.getOrigin().reportUpdatedCapacity((BasicSequenceStorage) newStore);
306312
}
307313
} else {
308-
if (!triedToCompile[0]) {
309-
CompilerDirectives.transferToInterpreterAndInvalidate();
310-
triedToCompile[0] = true;
311-
}
312314
SequenceStorage newStore = appendNode.execute(list.getSequenceStorage(), value, ListGeneralizationNode.SUPPLIER);
313-
if (list.getSequenceStorage() != newStore) {
314-
updateStoreProfile.enter();
315+
if (CompilerDirectives.inInterpreter() && list.getOrigin() != null && newStore instanceof BasicSequenceStorage) {
316+
list.setSequenceStorage(newStore);
317+
list.getOrigin().reportUpdatedCapacity((BasicSequenceStorage) newStore);
318+
} else if (list.getSequenceStorage() != newStore) {
319+
updateStoreProfile[0].enter();
315320
list.setSequenceStorage(newStore);
316321
}
317322
}

0 commit comments

Comments
 (0)