Skip to content

Commit 0dbe780

Browse files
committed
Fix: do not use adopted nodes in uncached default nodes
1 parent c2e1ae4 commit 0dbe780

File tree

1 file changed

+83
-54
lines changed

1 file changed

+83
-54
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/object/PythonObjectLibrary.java

Lines changed: 83 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -278,71 +278,95 @@ public static long hash(double receiver) {
278278
return DefaultPythonDoubleExports.hash(receiver);
279279
}
280280

281-
private static class DefaultNodes extends Node {
282-
private static final byte REVERSE_COMP = 0b001;
283-
private static final byte LEFT_COMPARE = 0b010;
284-
private static final byte SUBT_COMPARE = 0b100;
285-
286-
@Child private IsSubtypeNode isSubtype;
287-
@Child private IsSameTypeNode isSameType;
288-
@Child private GetClassNode getClassNode;
289-
@Child private PRaiseNode raiseNode;
290-
@CompilationFinal byte state = 0;
291-
292-
protected IsSubtypeNode getIsSubtypeNode() {
293-
if (isSubtype == null) {
294-
CompilerDirectives.transferToInterpreterAndInvalidate();
295-
reportPolymorphicSpecialize();
296-
isSubtype = insert(IsSubtypeNode.create());
281+
private abstract static class DefaultNodes extends Node {
282+
283+
protected abstract IsSubtypeNode getIsSubtypeNode();
284+
285+
protected abstract IsSameTypeNode getIsSameTypeNode();
286+
287+
protected abstract GetClassNode getGetClassNode();
288+
289+
protected abstract PRaiseNode getRaiseNode();
290+
291+
protected abstract void enterReverseCompare();
292+
293+
protected abstract void enterLeftCompare();
294+
295+
protected abstract void enterSubtypeCompare();
296+
297+
private static final class CachedDefaultNodes extends DefaultNodes {
298+
private static final byte REVERSE_COMP = 0b001;
299+
private static final byte LEFT_COMPARE = 0b010;
300+
private static final byte SUBT_COMPARE = 0b100;
301+
302+
@Child private IsSubtypeNode isSubtype;
303+
@Child private IsSameTypeNode isSameType;
304+
@Child private GetClassNode getClassNode;
305+
@Child private PRaiseNode raiseNode;
306+
@CompilationFinal byte state = 0;
307+
308+
@Override
309+
protected IsSubtypeNode getIsSubtypeNode() {
310+
if (isSubtype == null) {
311+
CompilerDirectives.transferToInterpreterAndInvalidate();
312+
reportPolymorphicSpecialize();
313+
isSubtype = insert(IsSubtypeNode.create());
314+
}
315+
return isSubtype;
297316
}
298-
return isSubtype;
299-
}
300317

301-
protected IsSameTypeNode getIsSameTypeNode() {
302-
if (isSameType == null) {
303-
CompilerDirectives.transferToInterpreterAndInvalidate();
304-
isSameType = insert(IsSameTypeNodeGen.create());
318+
@Override
319+
protected IsSameTypeNode getIsSameTypeNode() {
320+
if (isSameType == null) {
321+
CompilerDirectives.transferToInterpreterAndInvalidate();
322+
isSameType = insert(IsSameTypeNodeGen.create());
323+
}
324+
return isSameType;
305325
}
306-
return isSameType;
307-
}
308326

309-
private GetClassNode getGetClassNode() {
310-
if (getClassNode == null) {
311-
CompilerDirectives.transferToInterpreterAndInvalidate();
312-
getClassNode = insert(GetClassNode.create());
327+
@Override
328+
protected GetClassNode getGetClassNode() {
329+
if (getClassNode == null) {
330+
CompilerDirectives.transferToInterpreterAndInvalidate();
331+
getClassNode = insert(GetClassNode.create());
332+
}
333+
return getClassNode;
313334
}
314-
return getClassNode;
315-
}
316335

317-
protected PRaiseNode getRaiseNode() {
318-
if (raiseNode == null) {
319-
CompilerDirectives.transferToInterpreterAndInvalidate();
320-
raiseNode = insert(PRaiseNode.create());
336+
@Override
337+
protected PRaiseNode getRaiseNode() {
338+
if (raiseNode == null) {
339+
CompilerDirectives.transferToInterpreterAndInvalidate();
340+
raiseNode = insert(PRaiseNode.create());
341+
}
342+
return raiseNode;
321343
}
322-
return raiseNode;
323-
}
324344

325-
protected void enterReverseCompare() {
326-
if ((state & REVERSE_COMP) == 0) {
327-
CompilerDirectives.transferToInterpreterAndInvalidate();
328-
reportPolymorphicSpecialize();
329-
state |= REVERSE_COMP;
345+
@Override
346+
protected void enterReverseCompare() {
347+
if ((state & REVERSE_COMP) == 0) {
348+
CompilerDirectives.transferToInterpreterAndInvalidate();
349+
reportPolymorphicSpecialize();
350+
state |= REVERSE_COMP;
351+
}
330352
}
331-
}
332353

333-
protected void enterLeftCompare() {
334-
if ((state & LEFT_COMPARE) == 0) {
335-
CompilerDirectives.transferToInterpreterAndInvalidate();
336-
reportPolymorphicSpecialize();
337-
state |= LEFT_COMPARE;
354+
@Override
355+
protected void enterLeftCompare() {
356+
if ((state & LEFT_COMPARE) == 0) {
357+
CompilerDirectives.transferToInterpreterAndInvalidate();
358+
reportPolymorphicSpecialize();
359+
state |= LEFT_COMPARE;
360+
}
338361
}
339-
}
340362

341-
protected void enterSubtypeCompare() {
342-
if ((state & SUBT_COMPARE) == 0) {
343-
CompilerDirectives.transferToInterpreterAndInvalidate();
344-
reportPolymorphicSpecialize();
345-
state |= SUBT_COMPARE;
363+
@Override
364+
protected void enterSubtypeCompare() {
365+
if ((state & SUBT_COMPARE) == 0) {
366+
CompilerDirectives.transferToInterpreterAndInvalidate();
367+
reportPolymorphicSpecialize();
368+
state |= SUBT_COMPARE;
369+
}
346370
}
347371
}
348372

@@ -359,6 +383,11 @@ protected IsSameTypeNode getIsSameTypeNode() {
359383
return IsSameTypeNodeGen.getUncached();
360384
}
361385

386+
@Override
387+
protected GetClassNode getGetClassNode() {
388+
return GetClassNode.getUncached();
389+
}
390+
362391
@Override
363392
protected PRaiseNode getRaiseNode() {
364393
return PRaiseNode.getUncached();
@@ -378,7 +407,7 @@ protected void enterSubtypeCompare() {
378407
}
379408

380409
private static DefaultNodes create() {
381-
return new DefaultNodes();
410+
return new CachedDefaultNodes();
382411
}
383412

384413
private static DefaultNodes getUncached() {

0 commit comments

Comments
 (0)