Mercurial > hg > truffle
diff truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/NodeUtil.java @ 22080:65e9fbb40e51
avoid publishing unadopted children in node replacement to fix potential race
author | Andreas Woess <andreas.woess@oracle.com> |
---|---|
date | Thu, 13 Aug 2015 18:22:22 +0200 |
parents | b2d1c8ff592a |
children | dc83cc1f94f2 |
line wrap: on
line diff
--- a/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/NodeUtil.java Thu Aug 13 16:59:39 2015 +0200 +++ b/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/NodeUtil.java Thu Aug 13 18:22:22 2015 +0200 @@ -199,12 +199,19 @@ } public static boolean replaceChild(Node parent, Node oldChild, Node newChild) { + return replaceChild(parent, oldChild, newChild, false); + } + + static boolean replaceChild(Node parent, Node oldChild, Node newChild, boolean adopt) { CompilerAsserts.neverPartOfCompilation(); NodeClass nodeClass = parent.getNodeClass(); for (NodeFieldAccessor nodeField : nodeClass.getChildFields()) { if (nodeField.getObject(parent) == oldChild) { assert assertAssignable(nodeField, newChild); + if (adopt) { + parent.adoptHelper(newChild); + } nodeField.putObject(parent, newChild); return true; } @@ -217,6 +224,9 @@ for (int i = 0; i < array.length; i++) { if (array[i] == oldChild) { assert assertAssignable(nodeField, newChild); + if (adopt) { + parent.adoptHelper(newChild); + } array[i] = newChild; return true; }