Mercurial > hg > truffle
diff graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/NodeUtil.java @ 19141:67d9e635102f
Truffle/Instrumentation: refine checks for safe node replacement
author | Michael Van De Vanter <michael.van.de.vanter@oracle.com> |
---|---|
date | Tue, 03 Feb 2015 11:48:25 -0800 |
parents | f5b83e7b2b4c |
children | 73811d1b4cd0 |
line wrap: on
line diff
--- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/NodeUtil.java Tue Feb 03 18:30:07 2015 +0100 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/NodeUtil.java Tue Feb 03 11:48:25 2015 -0800 @@ -676,26 +676,24 @@ } /** - * Determines whether a proposed child replacement would be type safe. - * - * @param parent non-null node - * @param oldChild non-null existing child of parent - * @param newChild non-null proposed replacement for existing child + * Determines whether a proposed child replacement would be safe: structurally and type. */ public static boolean isReplacementSafe(Node parent, Node oldChild, Node newChild) { assert newChild != null; - final NodeField field = findChildField(parent, oldChild); - if (field == null) { - throw new IllegalArgumentException(); + if (parent != null) { + final NodeField field = findChildField(parent, oldChild); + if (field != null) { + switch (field.getKind()) { + case CHILD: + return field.getType().isAssignableFrom(newChild.getClass()); + case CHILDREN: + return field.getType().getComponentType().isAssignableFrom(newChild.getClass()); + default: + throw new IllegalStateException(); + } + } } - switch (field.getKind()) { - case CHILD: - return field.getType().isAssignableFrom(newChild.getClass()); - case CHILDREN: - return field.getType().getComponentType().isAssignableFrom(newChild.getClass()); - default: - throw new IllegalArgumentException(); - } + return false; } /** Returns all declared fields in the class hierarchy. */