Skip to content

Commit aee0431

Browse files
committed
Lock around node creation and insertion
1 parent 8812bb6 commit aee0431

File tree

1 file changed

+28
-9
lines changed

1 file changed

+28
-9
lines changed

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

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050

5151
import java.math.BigInteger;
5252
import java.util.Arrays;
53+
import java.util.concurrent.locks.Lock;
5354

5455
import com.oracle.graal.python.PythonLanguage;
5556
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
@@ -659,9 +660,15 @@ private <A, T extends Node> T insertChildNode(Node[] nodes, int nodeIndex, Class
659660
@SuppressWarnings("unchecked")
660661
private <A, T extends Node> T doInsertChildNode(Node[] nodes, int nodeIndex, NodeFunction<A, T> nodeSupplier, A argument) {
661662
CompilerDirectives.transferToInterpreterAndInvalidate();
662-
T newNode = nodeSupplier.apply(argument);
663-
nodes[nodeIndex] = insert(newNode);
664-
return newNode;
663+
Lock lock = getLock();
664+
lock.lock();
665+
try {
666+
T newNode = nodeSupplier.apply(argument);
667+
nodes[nodeIndex] = insert(newNode);
668+
return newNode;
669+
} finally {
670+
lock.unlock();
671+
}
665672
}
666673

667674
@SuppressWarnings("unchecked")
@@ -688,9 +695,15 @@ private <T extends Node, U> T insertChildNodeInt(Node[] nodes, int nodeIndex, Cl
688695
@SuppressWarnings("unchecked")
689696
private <T extends Node> T doInsertChildNodeInt(Node[] nodes, int nodeIndex, IntNodeFunction<T> nodeSupplier, int argument) {
690697
CompilerDirectives.transferToInterpreterAndInvalidate();
691-
T newNode = nodeSupplier.apply(argument);
692-
nodes[nodeIndex] = insert(newNode);
693-
return newNode;
698+
Lock lock = getLock();
699+
lock.lock();
700+
try {
701+
T newNode = nodeSupplier.apply(argument);
702+
nodes[nodeIndex] = insert(newNode);
703+
return newNode;
704+
} finally {
705+
lock.unlock();
706+
}
694707
}
695708

696709
@SuppressWarnings("unchecked")
@@ -705,9 +718,15 @@ private <T extends Node, U extends T> U insertChildNode(Node[] nodes, int nodeIn
705718
@SuppressWarnings("unchecked")
706719
private <T extends Node> T doInsertChildNode(Node[] nodes, int nodeIndex, NodeSupplier<T> nodeSupplier) {
707720
CompilerDirectives.transferToInterpreterAndInvalidate();
708-
T newNode = nodeSupplier.get();
709-
nodes[nodeIndex] = insert(newNode);
710-
return newNode;
721+
Lock lock = getLock();
722+
lock.lock();
723+
try {
724+
T newNode = nodeSupplier.get();
725+
nodes[nodeIndex] = insert(newNode);
726+
return newNode;
727+
} finally {
728+
lock.unlock();
729+
}
711730
}
712731

713732
@SuppressWarnings("unchecked")

0 commit comments

Comments
 (0)