Skip to content

Commit 44f207b

Browse files
committed
Fix race in function call target creation
1 parent 1b2e651 commit 44f207b

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/PBytecodeRootNode.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -786,15 +786,19 @@ private <T extends Node, U> T insertChildNodeInt(Node[] nodes, int nodeIndex, Cl
786786
if (expectedClass.isInstance(node)) {
787787
return (T) node;
788788
}
789-
return doInsertChildNodeInt(nodes, nodeIndex, nodeSupplier, argument);
789+
return doInsertChildNodeInt(nodes, nodeIndex, expectedClass, nodeSupplier, argument);
790790
}
791791

792792
@SuppressWarnings("unchecked")
793-
private <T extends Node> T doInsertChildNodeInt(Node[] nodes, int nodeIndex, IntNodeFunction<T> nodeSupplier, int argument) {
793+
private <T extends Node, U> T doInsertChildNodeInt(Node[] nodes, int nodeIndex, Class<U> expectedClass, IntNodeFunction<T> nodeSupplier, int argument) {
794794
CompilerDirectives.transferToInterpreterAndInvalidate();
795795
Lock lock = getLock();
796796
lock.lock();
797797
try {
798+
Node node = nodes[nodeIndex];
799+
if (expectedClass.isInstance(node)) {
800+
return (T) node;
801+
}
798802
T newNode = nodeSupplier.apply(argument);
799803
doInsertChildNode(nodes, nodeIndex, newNode);
800804
return newNode;
@@ -809,15 +813,19 @@ private <T extends Node, U extends T> U insertChildNode(Node[] nodes, int nodeIn
809813
if (node != null && node.getClass() == cachedClass) {
810814
return CompilerDirectives.castExact(node, cachedClass);
811815
}
812-
return CompilerDirectives.castExact(doInsertChildNode(nodes, nodeIndex, nodeSupplier), cachedClass);
816+
return CompilerDirectives.castExact(doInsertChildNode(nodes, nodeIndex, cachedClass, nodeSupplier), cachedClass);
813817
}
814818

815819
@SuppressWarnings("unchecked")
816-
private <T extends Node> T doInsertChildNode(Node[] nodes, int nodeIndex, NodeSupplier<T> nodeSupplier) {
820+
private <T extends Node, U> T doInsertChildNode(Node[] nodes, int nodeIndex, Class<U> cachedClass, NodeSupplier<T> nodeSupplier) {
817821
CompilerDirectives.transferToInterpreterAndInvalidate();
818822
Lock lock = getLock();
819823
lock.lock();
820824
try {
825+
Node node = nodes[nodeIndex];
826+
if (node != null && node.getClass() == cachedClass) {
827+
return (T) node;
828+
}
821829
T newNode = nodeSupplier.get();
822830
doInsertChildNode(nodes, nodeIndex, newNode);
823831
return newNode;
@@ -835,7 +843,7 @@ private <T extends Node> T insertChildNode(Node[] nodes, int nodeIndex, T uncach
835843
if (node != null && node.getClass() == cachedClass) {
836844
return CompilerDirectives.castExact(node, cachedClass);
837845
}
838-
return CompilerDirectives.castExact(doInsertChildNode(nodes, nodeIndex, nodeSupplier), cachedClass);
846+
return CompilerDirectives.castExact(doInsertChildNode(nodes, nodeIndex, cachedClass, nodeSupplier), cachedClass);
839847
}
840848

841849
private void doInsertChildNode(Node[] nodes, int nodeIndex, Node newNode) {

0 commit comments

Comments
 (0)