# HG changeset patch # User Doug Simon # Date 1411472400 -7200 # Node ID 55a924683e72e6f18eb54fcad53bbdce5769335d # Parent bd760d193008be8d6e9341475743cdbec3c92f8e removed generated inputs/successors iterators and Position related methods diff -r bd760d193008 -r 55a924683e72 graal/com.oracle.graal.graph/src/com/oracle/graal/graph/Node.java --- a/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/Node.java Tue Sep 23 13:19:30 2014 +0200 +++ b/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/Node.java Tue Sep 23 13:40:00 2014 +0200 @@ -189,8 +189,6 @@ return graph; } - private static final boolean USE_GENERATED_NODE_ITERATORS = Boolean.getBoolean("graal.useGeneratedNodeIterators"); - /** * Returns an {@link NodeClassIterable iterable} which can be used to traverse all non-null * input edges of this node. @@ -198,12 +196,6 @@ * @return an {@link NodeClassIterable iterable} for all non-null input edges. */ public NodeClassIterable inputs() { - if (USE_GENERATED_NODES) { - if (!USE_GENERATED_NODE_ITERATORS) { - return new NodeRefIterable(this, true); - } - return inputsV2(); - } return getNodeClass().getInputIterable(this); } @@ -214,12 +206,6 @@ * @return an {@link NodeClassIterable iterable} for all non-null successor edges. */ public NodeClassIterable successors() { - if (USE_GENERATED_NODES) { - if (!USE_GENERATED_NODE_ITERATORS) { - return new NodeRefIterable(this, false); - } - return successorsV2(); - } return getNodeClass().getSuccessorIterable(this); } @@ -1007,155 +993,4 @@ } } } - - // NEW API IMPLEMENTED BY GENERATED METHODS - NOT YET USED - - public NodeClassIterable inputsV2() { - return NodeClassIterable.Empty; - } - - /** - * Determines if this node's inputs contain a given node. - * - * @param other - */ - public boolean inputsContains(Node other) { - return false; - } - - /** - * Determines if this node's successors contain a given node. - * - * @param other - */ - public boolean successorsContains(Node other) { - return false; - } - - public NodeClassIterable successorsV2() { - return NodeClassIterable.Empty; - } - - public Collection getFirstLevelInputs() { - return Collections.emptyList(); - } - - public Collection getFirstLevelSuccessors() { - return Collections.emptyList(); - } - - /** - * Gets an input or successor of this node at a given position. - * - * @param pos - */ - public Node getNodeAt(Position pos) { - throw new NoSuchElementException(); - } - - /** - * Gets the number of {@link Node} and {@link NodeList} fields in this node that are - * {@link Input}s or {@link OptionalInput}s. - * - * @return {@code L << 16 | N} where {@code N} is the number of {@link Node} fields and - * {@code L} is the number of {@link NodeList} fields - */ - public int getInputsCount() { - return 0; - } - - /** - * Gets the number of {@link Node} and {@link NodeList} fields in this node that are - * {@link Successor}s. - * - * @return {@code L << 16 | N} where {@code N} is the number of {@link Node} fields and - * {@code L} is the number of {@link NodeList} fields - */ - public int getSuccessorsCount() { - return 0; - } - - /** - * Gets an input of this node at a given index. - * - * @param index index of an input {@link Node} field. This value must be in the range of the - * number of {@link Node} fields returned by {@link #getInputsCount()}. - */ - public Node getInputNodeAt(int index) { - throw new NoSuchElementException(); - } - - /** - * Gets a successor of this node at a given index. - * - * @param index index of a successor {@link Node} field. This value must be in the range of the - * number of {@link Node} fields returned by {@link #getSuccessorsCount()}. - */ - public Node getSuccessorNodeAt(int index) { - throw new NoSuchElementException(); - } - - /** - * Gets an input list at a given index. - * - * @param index index of an input {@link NodeList} field. This value must be in the range of the - * number of {@link NodeList} fields returned by {@link #getInputsCount()}. - */ - public NodeList getInputNodeListAt(int index) { - throw new NoSuchElementException(); - } - - /** - * Gets a successor list at a given index. - * - * @param index index of a successor {@link NodeList} field. This value must be in the range of - * the number of {@link NodeList} fields returned by {@link #getSuccessorsCount()}. - */ - public NodeList getSuccessorNodeListAt(int index) { - throw new NoSuchElementException(); - } - - /** - * Updates an input or successor of this node at a given position. The existing, non-null input - * or successor at {@code position} is notified of the change via - * {@link #updateUsages(Node, Node)} or {@link #updatePredecessor(Node, Node)}. - * - * @param position - * @param value - */ - public void updateNodeAt(Position position, Node value) { - throw new NoSuchElementException(); - } - - /** - * Sets an input or successor of this node at a given position without notifying the existing - * input or successor at {@code position} of the change. - * - * @param position - * @param value - */ - public void initializeNodeAt(Position position, Node value) { - throw new NoSuchElementException(); - } - - /** - * @param pos - */ - public InputType getInputTypeAt(Position pos) { - throw new NoSuchElementException(); - } - - /** - * @param pos - */ - public String getNameOf(Position pos) { - throw new NoSuchElementException(); - } - - /** - * @param pos - */ - public boolean isOptionalInputAt(Position pos) { - throw new NoSuchElementException(); - } } diff -r bd760d193008 -r 55a924683e72 graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeAllRefsIterator.java --- a/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeAllRefsIterator.java Tue Sep 23 13:19:30 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,64 +0,0 @@ -/* - * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.graph; - -import com.oracle.graal.graph.Node.Input; - -/** - * An iterator over the references to a given {@link Node}'s {@linkplain Input inputs}. - * - * An iterator of this type will return null values. - */ -public final class NodeAllRefsIterator extends NodeRefIterator { - - public NodeAllRefsIterator(Node node, int nodeFields, int nodeListFields, boolean isInputs) { - super(node, nodeFields, nodeListFields, isInputs); - } - - @Override - protected void forward() { - assert needsForward; - needsForward = false; - if (index < nodeFields) { - index++; - if (index < nodeFields) { - nextElement = getNode(index); - return; - } - } else { - subIndex++; - } - - while (index < allNodeRefFields) { - if (subIndex == 0) { - list = getNodeList(index - nodeFields); - } - if (subIndex < list.size()) { - nextElement = list.get(subIndex); - return; - } - subIndex = 0; - index++; - } - } -} diff -r bd760d193008 -r 55a924683e72 graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeClass.java --- a/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeClass.java Tue Sep 23 13:19:30 2014 +0200 +++ b/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeClass.java Tue Sep 23 13:40:00 2014 +0200 @@ -53,8 +53,6 @@ // Timers for creation of a NodeClass instance private static final DebugTimer Init = Debug.timer("NodeClass.Init"); - private static final DebugTimer Init_PositionFieldOrderLoad = Debug.timer("NodeClass.Init.PositionFieldOrderLoad"); - private static final DebugTimer Init_PositionFieldOrderSort = Debug.timer("NodeClass.Init.PositionFieldOrderSort"); private static final DebugTimer Init_FieldScanning = Debug.timer("NodeClass.Init.FieldScanning"); private static final DebugTimer Init_Offsets = Debug.timer("NodeClass.Init.Offsets"); private static final DebugTimer Init_Naming = Debug.timer("NodeClass.Init.Naming"); @@ -151,42 +149,10 @@ this(clazz, new DefaultCalcOffset(), null, 0); } - /** - * Defines the order of fields in a node class accessed via {@link Position}s. - * - * This is required so that field positions are consistent in a configuration that mixes - * (runtime) field offsets with (annotation processing time) field iterators. - */ - public interface PositionFieldOrder { - /** - * Gets a field ordering specified by an ordered field name list. The only guarantee - * provided by this method is that all {@link NodeList} fields are preceded by all non - * {@link NodeList} fields. - * - * @param input specified whether input or successor field order is being requested - */ - String[] getOrderedFieldNames(boolean input); - } - - private static long[] sortedOffsets(boolean input, PositionFieldOrder pfo, Map names, ArrayList list1, ArrayList list2) { + private static long[] sortedOffsets(ArrayList list1, ArrayList list2) { if (list1.isEmpty() && list2.isEmpty()) { return new long[0]; } - if (pfo != null) { - try (TimerCloseable t = Init_PositionFieldOrderSort.start()) { - - List fields = Arrays.asList(pfo.getOrderedFieldNames(input)); - long[] offsets = new long[fields.size()]; - assert list1.size() + list2.size() == fields.size(); - for (Map.Entry e : names.entrySet()) { - int index = fields.indexOf(e.getValue()); - if (index != -1) { - offsets[index] = e.getKey(); - } - } - return offsets; - } - } return sortedLongCopy(list1, list2); } @@ -211,9 +177,7 @@ isLeafNode = scanner.inputOffsets.isEmpty() && scanner.inputListOffsets.isEmpty() && scanner.successorOffsets.isEmpty() && scanner.successorListOffsets.isEmpty(); - PositionFieldOrder pfo = lookupPositionFieldOrder(clazz); - - inputOffsets = sortedOffsets(true, pfo, scanner.fieldNames, scanner.inputOffsets, scanner.inputListOffsets); + inputOffsets = sortedOffsets(scanner.inputOffsets, scanner.inputListOffsets); inputTypes = new InputType[inputOffsets.length]; inputOptional = new boolean[inputOffsets.length]; @@ -223,7 +187,7 @@ inputOptional[i] = scanner.optionalInputs.contains(inputOffsets[i]); } directSuccessorCount = scanner.successorOffsets.size(); - successorOffsets = sortedOffsets(false, pfo, scanner.fieldNames, scanner.successorOffsets, scanner.successorListOffsets); + successorOffsets = sortedOffsets(scanner.successorOffsets, scanner.successorListOffsets); dataOffsets = sortedLongCopy(scanner.dataOffsets); dataTypes = new Class[dataOffsets.length]; @@ -298,20 +262,6 @@ nodeIterableCount = Debug.metric("NodeIterable_%s", shortName); } - private PositionFieldOrder lookupPositionFieldOrder(Class clazz) throws GraalInternalError { - if (USE_GENERATED_NODES && !isAbstract(clazz.getModifiers()) && !isLeafNode) { - try (TimerCloseable t = Init_PositionFieldOrderLoad.start()) { - String name = clazz.getName().replace('$', '_') + "Gen$FieldOrder"; - try { - return (PositionFieldOrder) Class.forName(name, true, getClazz().getClassLoader()).newInstance(); - } catch (Exception e) { - throw new GraalInternalError("Could not find generated class " + name + " for " + getClazz()); - } - } - } - return null; - } - /** * Gets the {@linkplain GeneratedNode generated} node class (if any) described by the object. */ @@ -999,9 +949,6 @@ } public Node get(Node node, Position pos) { - if (Node.USE_GENERATED_NODES) { - return node.getNodeAt(pos); - } long offset = pos.isInput() ? inputOffsets[pos.getIndex()] : successorOffsets[pos.getIndex()]; if (pos.getSubIndex() == NOT_ITERABLE) { return getNode(node, offset); @@ -1180,11 +1127,6 @@ } public void set(Node node, Position pos, Node x) { - if (Node.USE_GENERATED_NODES) { - node.updateNodeAt(pos, x); - return; - } - long offset = pos.isInput() ? inputOffsets[pos.getIndex()] : successorOffsets[pos.getIndex()]; if (pos.getSubIndex() == NOT_ITERABLE) { Node old = getNode(node, offset); @@ -1209,10 +1151,6 @@ } public void initializePosition(Node node, Position pos, Node x) { - if (Node.USE_GENERATED_NODES) { - node.initializeNodeAt(pos, x); - return; - } long offset = pos.isInput() ? inputOffsets[pos.getIndex()] : successorOffsets[pos.getIndex()]; if (pos.getSubIndex() == NOT_ITERABLE) { assert x == null || fieldTypes.get((pos.isInput() ? inputOffsets : successorOffsets)[pos.getIndex()]).isAssignableFrom(x.getClass()) : this + ".set(node, pos, " + x + ")"; diff -r bd760d193008 -r 55a924683e72 graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeClassIterable.java --- a/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeClassIterable.java Tue Sep 23 13:19:30 2014 +0200 +++ b/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeClassIterable.java Tue Sep 23 13:40:00 2014 +0200 @@ -40,15 +40,4 @@ * Returns an iterator that produces all values, including null values. */ NodePosIterator withNullIterator(); - - NodeClassIterable Empty = new NodeClassIterable() { - - public NodeRefIterator withNullIterator() { - return NodeRefIterator.Empty; - } - - public NodeRefIterator iterator() { - return NodeRefIterator.Empty; - } - }; } diff -r bd760d193008 -r 55a924683e72 graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeRefIterable.java --- a/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeRefIterable.java Tue Sep 23 13:19:30 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,77 +0,0 @@ -/* - * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.graph; - -import static com.oracle.graal.graph.Graph.*; - -import com.oracle.graal.graph.Node.*; - -/** - * An iterator over the references to a given {@link Node}'s {@linkplain Input inputs} or - * {@linkplain Successor successors}. - */ -public final class NodeRefIterable implements NodeClassIterable { - - protected final Node node; - - /** - * Specifies if {@link #iterator()} and {@link #withNullIterator()} iterate over - * {@linkplain Input inputs} or {@linkplain Successor successors}. - */ - protected final boolean isInputs; - - public NodeRefIterable(Node node, boolean isInputs) { - this.isInputs = isInputs; - this.node = node; - } - - @Override - public NodePosIterator iterator() { - int count = isInputs ? node.getInputsCount() : node.getSuccessorsCount(); - if (count == 0) { - return NodeRefIterator.Empty; - } - int nodeFields = count & 0xFFFF; - int nodeListFields = (count >> 16) & 0xFFFF; - if (MODIFICATION_COUNTS_ENABLED) { - return new NodeRefWithModCountIterator(node, nodeFields, nodeListFields, isInputs); - } else { - return new NodeRefIterator(node, nodeFields, nodeListFields, isInputs); - } - } - - public NodePosIterator withNullIterator() { - int count = isInputs ? node.getInputsCount() : node.getSuccessorsCount(); - if (count == 0) { - return NodeRefIterator.Empty; - } - int nodeFields = count & 0xFFFF; - int nodeListFields = (count >> 16) & 0xFFFF; - return new NodeAllRefsIterator(node, nodeFields, nodeListFields, isInputs); - } - - @Override - public boolean contains(Node other) { - return isInputs ? node.inputsContains(other) : node.successorsContains(other); - } -} diff -r bd760d193008 -r 55a924683e72 graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeRefIterator.java --- a/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeRefIterator.java Tue Sep 23 13:19:30 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,202 +0,0 @@ -/* - * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.graph; - -import java.util.*; - -import com.oracle.graal.graph.Node.Input; -import com.oracle.graal.graph.Node.Successor; - -/** - * An iterator over the references to a {@link Node}'s {@linkplain Input inputs} and - * {@linkplain Successor successors}. - * - * An iterator of this type will not return null values, unless the field values are modified - * concurrently. Concurrent modifications are detected by an assertion on a best-effort basis. - */ -public class NodeRefIterator implements NodePosIterator { - - public static final NodeRefIterator Empty = new NodeRefIterator(); - - protected final Node node; - - /** - * The total number of {@link Node} and {@link NodeList} fields. - */ - protected final int allNodeRefFields; - - /** - * The number of {@link Node} fields. - */ - protected final int nodeFields; - - /** - * Specifies if this iterator iterates over {@linkplain Input inputs} or {@linkplain Successor - * successors}. - */ - protected final boolean isInputs; - - /** - * Current field iteration index. - */ - protected int index; - - /** - * Current iteration index within a {@link NodeList} if {@link #index} denotes a - * {@link NodeList} field. - */ - protected int subIndex; - - protected Node nextElement; - protected boolean needsForward; - protected NodeList list; - - /** - * Creates an iterator over a node's references (i.e., {@linkplain Input inputs} or - * {@linkplain Successor successors}) to other nodes. The {@link Node} fields are iterated - * before the {@link NodeList} fields. All elements of these NodeLists will be visited by the - * iterator as well. - * - * @param nodeFields the number of {@link Node} fields in the class hierarchy of the node being - * iterated - * @param nodeListFields the number of {@link NodeList} fields in the class hierarchy of the - * node being iterated - */ - protected NodeRefIterator(Node node, int nodeFields, int nodeListFields, boolean isInputs) { - this.node = node; - this.allNodeRefFields = nodeListFields + nodeFields; - this.nodeFields = nodeFields; - this.isInputs = isInputs; - this.needsForward = true; - index = -1; - subIndex = 0; - } - - /** - * Constructor for {@link #Empty}. - */ - private NodeRefIterator() { - this(null, 0, 0, false); - // This constructor must only be used to construct Empty - assert Empty == null; - // This must be set here to prevent multiple threads racing to - // call forward() which never needs to be done for Empty. - this.needsForward = false; - // Ensure hasNext() will always return false. - this.index = 0; - } - - /** - * Gets the value of a {@link Node} field in the node. - * - * @param at the index of the Node field whose value is being requested. This is guaranteed to - * be between 0 and the {@code nodeFields} value this iterator was constructed with - */ - protected Node getNode(int at) { - return isInputs ? node.getInputNodeAt(at) : node.getSuccessorNodeAt(at); - } - - /** - * Gets the value of a {@link NodeList} field in the node. - * - * @param at the index of the {@link NodeList} field whose value is being requested. This is - * guaranteed to be between 0 and the {@code nodeListFields} value this iterator was - * constructed with - */ - protected NodeList getNodeList(int at) { - return isInputs ? node.getInputNodeListAt(at) : node.getSuccessorNodeListAt(at); - } - - protected void forward() { - needsForward = false; - if (index < nodeFields) { - index++; - while (index < nodeFields) { - nextElement = getNode(index); - if (nextElement != null) { - return; - } - index++; - } - } else { - subIndex++; - } - while (index < allNodeRefFields) { - if (subIndex == 0) { - list = getNodeList(index - nodeFields); - } - assert list == getNodeList(index - nodeFields); - while (subIndex < list.size()) { - nextElement = list.get(subIndex); - if (nextElement != null) { - return; - } - subIndex++; - } - subIndex = 0; - index++; - } - return; - } - - private Node nextElement() { - if (needsForward) { - forward(); - } - needsForward = true; - if (index < allNodeRefFields) { - return nextElement; - } - throw new NoSuchElementException(); - } - - @Override - public boolean hasNext() { - if (needsForward) { - forward(); - } - return index < allNodeRefFields; - } - - @Override - public Node next() { - return nextElement(); - } - - public Position nextPosition() { - if (needsForward) { - forward(); - } - needsForward = true; - if (index < nodeFields) { - return new Position(isInputs, index, Node.NOT_ITERABLE); - } else { - return new Position(isInputs, index, subIndex); - } - } - - @Override - public void remove() { - throw new UnsupportedOperationException(); - } -} diff -r bd760d193008 -r 55a924683e72 graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeRefWithModCountIterator.java --- a/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeRefWithModCountIterator.java Tue Sep 23 13:19:30 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,71 +0,0 @@ -/* - * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.graph; - -import static com.oracle.graal.graph.Graph.*; - -import com.oracle.graal.graph.Node.Input; - -/** - * An iterator over the references to a given {@link Node}'s {@linkplain Input inputs}. - * - * An iterator of this type will not return null values, unless the field values are modified - * concurrently. Concurrent modifications are detected by an assertion on a best-effort basis. - */ -public final class NodeRefWithModCountIterator extends NodeRefIterator { - - private final int modCount; - - public NodeRefWithModCountIterator(Node node, int nodeFields, int nodeListFields, boolean isInputs) { - super(node, nodeFields, nodeListFields, isInputs); - assert MODIFICATION_COUNTS_ENABLED; - this.modCount = node.modCount(); - } - - @Override - public boolean hasNext() { - try { - return super.hasNext(); - } finally { - assert modCount == node.modCount() : "must not be modified"; - } - } - - @Override - public Node next() { - try { - return super.next(); - } finally { - assert modCount == node.modCount() : "must not be modified"; - } - } - - @Override - public Position nextPosition() { - try { - return super.nextPosition(); - } finally { - assert modCount == node.modCount(); - } - } -} diff -r bd760d193008 -r 55a924683e72 graal/com.oracle.graal.graph/src/com/oracle/graal/graph/Position.java --- a/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/Position.java Tue Sep 23 13:19:30 2014 +0200 +++ b/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/Position.java Tue Sep 23 13:40:00 2014 +0200 @@ -56,47 +56,27 @@ } public Node get(Node node) { - if (Node.USE_GENERATED_NODES) { - return node.getNodeAt(this); - } return node.getNodeClass().get(node, this); } public InputType getInputType(Node node) { - if (Node.USE_GENERATED_NODES) { - return node.getInputTypeAt(this); - } return node.getNodeClass().getInputType(this); } public String getInputName(Node node) { - if (Node.USE_GENERATED_NODES) { - return node.getNameOf(this); - } return node.getNodeClass().getName(this); } public boolean isInputOptional(Node node) { - if (Node.USE_GENERATED_NODES) { - return node.isOptionalInputAt(this); - } return node.getNodeClass().isInputOptional(this); } public void set(Node node, Node value) { - if (Node.USE_GENERATED_NODES) { - node.updateNodeAt(this, value); - } else { - node.getNodeClass().set(node, this, value); - } + node.getNodeClass().set(node, this, value); } public void initialize(Node node, Node value) { - if (Node.USE_GENERATED_NODES) { - node.initializeNodeAt(this, value); - } else { - node.getNodeClass().initializePosition(node, this, value); - } + node.getNodeClass().initializePosition(node, this, value); } @Override diff -r bd760d193008 -r 55a924683e72 graal/com.oracle.graal.nodeinfo.processor/src/com/oracle/graal/nodeinfo/processor/GraphNodeGenerator.java --- a/graal/com.oracle.graal.nodeinfo.processor/src/com/oracle/graal/nodeinfo/processor/GraphNodeGenerator.java Tue Sep 23 13:19:30 2014 +0200 +++ b/graal/com.oracle.graal.nodeinfo.processor/src/com/oracle/graal/nodeinfo/processor/GraphNodeGenerator.java Tue Sep 23 13:40:00 2014 +0200 @@ -22,7 +22,6 @@ */ package com.oracle.graal.nodeinfo.processor; -import static com.oracle.graal.nodeinfo.processor.GraphNodeGenerator.NodeRefsType.*; import static com.oracle.truffle.dsl.processor.java.ElementUtils.*; import static java.util.Arrays.*; import static javax.lang.model.element.Modifier.*; @@ -47,7 +46,7 @@ */ public class GraphNodeGenerator { - private static final boolean GENERATE_ASSERTIONS = false; + @SuppressWarnings("unused") private static final boolean GENERATE_ASSERTIONS = false; private final GraphNodeProcessor env; private final Types types; @@ -58,10 +57,10 @@ private final TypeElement Successor; final TypeElement Node; - private final TypeElement NodeList; + @SuppressWarnings("unused") private final TypeElement NodeList; private final TypeElement NodeInputList; private final TypeElement NodeSuccessorList; - private final TypeElement Position; + @SuppressWarnings("unused") private final TypeElement Position; private final List inputFields = new ArrayList<>(); private final List inputListFields = new ArrayList<>(); @@ -333,53 +332,7 @@ boolean hasSuccessors = !successorFields.isEmpty() || !successorListFields.isEmpty(); if (hasInputs || hasSuccessors) { - createGetNodeAtMethod(); - createGetInputTypeAtMethod(); - createGetNameOfMethod(); - createUpdateOrInitializeNodeAtMethod(false); - createUpdateOrInitializeNodeAtMethod(true); createIsLeafNodeMethod(); - createPositionAccessibleFieldOrderClass(packageElement); - - if (!inputListFields.isEmpty() || !successorListFields.isEmpty()) { - createGetNodeListAtPositionMethod(); - createSetNodeListAtMethod(); - } - } - - if (hasInputs) { - createIsOptionalInputAtMethod(); - createGetFirstLevelPositionsMethod(Inputs, inputFields, inputListFields); - - createContainsMethod(Inputs, inputFields, inputListFields); - createIterableMethod(Inputs); - - CodeTypeElement inputsIteratorClass = createIteratorClass(Inputs, packageElement, inputFields, inputListFields); - createAllIteratorClass(Inputs, inputsIteratorClass.asType(), packageElement, inputFields, inputListFields); - createWithModCountIteratorClass(Inputs, inputsIteratorClass.asType(), packageElement); - createIterableClass(Inputs, packageElement); - createGetNodeAtMethod(NodeRefsType.Inputs, inputFields); - createCountMethod(NodeRefsType.Inputs, inputFields.size(), inputListFields.size()); - if (!inputListFields.isEmpty()) { - createGetNodeListAtIndexMethod(NodeRefsType.Inputs, inputListFields); - } - } - - if (hasSuccessors) { - createGetFirstLevelPositionsMethod(Successors, successorFields, successorListFields); - - createContainsMethod(Successors, successorFields, successorListFields); - createIterableMethod(Successors); - - CodeTypeElement successorsIteratorClass = createIteratorClass(Successors, packageElement, successorFields, successorListFields); - createAllIteratorClass(Successors, successorsIteratorClass.asType(), packageElement, successorFields, successorListFields); - createWithModCountIteratorClass(Successors, successorsIteratorClass.asType(), packageElement); - createIterableClass(Successors, packageElement); - createGetNodeAtMethod(NodeRefsType.Successors, successorFields); - createCountMethod(NodeRefsType.Successors, successorFields.size(), successorListFields.size()); - if (!successorListFields.isEmpty()) { - createGetNodeListAtIndexMethod(NodeRefsType.Successors, successorListFields); - } } } compilationUnit.add(genClass); @@ -442,6 +395,7 @@ genClassName = null; } + @SuppressWarnings("unused") private CodeVariableElement addParameter(CodeExecutableElement method, TypeMirror type, String name) { return addParameter(method, type, name, true); } @@ -478,255 +432,6 @@ checkOnlyInGenNode(method); } - private ExecutableElement createIsOptionalInputAtMethod() { - CodeExecutableElement method = new CodeExecutableElement(modifiers(PUBLIC), getType(boolean.class), "isOptionalInputAt"); - addParameter(method, Position.asType(), "pos"); - CodeTreeBuilder b = method.createBuilder(); - if (GENERATE_ASSERTIONS) { - b.startAssert().string("pos.isInput()").end(); - } - if (!optionalInputs.isEmpty()) { - b.startSwitch().string("pos.getIndex()").end().startBlock(); - int index = 0; - for (VariableElement f : concat(inputFields, inputListFields)) { - if (optionalInputs.contains(f)) { - b.startCase().string(String.valueOf(index)).end(); - } - index++; - } - b.startStatement().string("return true").end(); - b.end(); - } - b.startReturn().string("false").end(); - genClass.add(method); - checkOnlyInGenNode(method); - return method; - } - - private ExecutableElement createGetFirstLevelPositionsMethod(NodeRefsType nodeRefsType, List nodeFields, List nodeListFields) { - DeclaredType collectionOfPosition = types.getDeclaredType((TypeElement) types.asElement(getType(Collection.class)), Position.asType()); - CodeExecutableElement method = new CodeExecutableElement(modifiers(PUBLIC), collectionOfPosition, "getFirstLevel" + nodeRefsType); - CodeTreeBuilder b = method.createBuilder(); - b.startReturn().startNew(getTypeElement("com.oracle.graal.graph.FirstLevelPositionCollection").asType()); - b.string(String.valueOf(nodeFields.size())); - b.string(String.valueOf(nodeListFields.size())); - b.string(String.valueOf(nodeRefsType == NodeRefsType.Inputs)); - b.end().end(); - genClass.add(method); - checkOnlyInGenNode(method); - return method; - } - - private CodeTypeElement createIteratorClass(NodeRefsType nodeRefsType, PackageElement packageElement, List nodeFields, List nodeListFields) { - String name = nodeRefsType + "Iterator"; - CodeTypeElement cls = new CodeTypeElement(modifiers(PRIVATE), ElementKind.CLASS, packageElement, name); - cls.setSuperClass(getType("com.oracle.graal.graph.NodeRefIterator")); - - // Constructor - CodeExecutableElement ctor = new CodeExecutableElement(Collections.emptySet(), null, name); - CodeTreeBuilder b = ctor.createBuilder(); - b.startStatement().startSuperCall(); - b.string(genClassName, ".this"); - b.string(String.valueOf(nodeFields.size())); - b.string(String.valueOf(nodeListFields.size())); - b.string(String.valueOf(nodeRefsType == NodeRefsType.Inputs)); - b.end().end(); - cls.add(ctor); - - // Methods overriding those in NodeRefIterator - createGetFieldMethod(cls, nodeFields, Node.asType(), "getNode"); - createGetFieldMethod(cls, nodeListFields, types.getDeclaredType(NodeList, types.getWildcardType(Node.asType(), null)), "getNodeList"); - genClass.add(cls); - return cls; - } - - private void createContainsMethod(NodeRefsType nodeRefsType, List nodeFields, List nodeListFields) { - CodeExecutableElement method = new CodeExecutableElement(modifiers(PUBLIC, FINAL), getType(boolean.class), nodeRefsType.name().toLowerCase() + "Contains"); - addParameter(method, Node.asType(), "n"); - CodeTreeBuilder b = method.createBuilder(); - for (VariableElement f : nodeFields) { - b.startIf().string("n == " + f).end().startBlock(); - b.startStatement().string("return true").end(); - b.end(); - } - for (VariableElement f : nodeListFields) { - b.startIf().string(f + ".contains(n)").end().startBlock(); - b.startStatement().string("return true").end(); - b.end(); - } - b.startStatement().string("return false").end(); - genClass.add(method); - checkOnlyInGenNode(method); - } - - private static final String API_TAG = "V2"; - - private void createIterableMethod(NodeRefsType nodeRefsType) { - CodeExecutableElement method = new CodeExecutableElement(modifiers(PUBLIC, FINAL), getType("com.oracle.graal.graph.NodeClassIterable"), (nodeRefsType == Inputs ? "inputs" : "successors") + - API_TAG); - CodeTreeBuilder b = method.createBuilder(); - b.startStatement().string("return new " + nodeRefsType + "Iterable()").end(); - genClass.add(method); - checkOnlyInGenNode(method); - } - - private void createGetNodeAtMethod() { - CodeExecutableElement method = new CodeExecutableElement(modifiers(PUBLIC, FINAL), Node.asType(), "getNodeAt"); - addParameter(method, Position.asType(), "pos"); - CodeTreeBuilder b = method.createBuilder(); - b.startIf().string("pos.isInput()").end().startBlock(); - createGetNodeAt(b, inputFields, inputListFields); - b.end(); - b.startElseBlock(); - createGetNodeAt(b, successorFields, successorListFields); - b.end(); - genClass.add(method); - checkOnlyInGenNode(method); - } - - private void createCountMethod(NodeRefsType nodeRefsType, int nodesCount, int nodeListsCount) { - CodeExecutableElement method = new CodeExecutableElement(modifiers(PUBLIC, FINAL), getType(int.class), "get" + nodeRefsType + "Count"); - CodeTreeBuilder b = method.createBuilder(); - - b.startStatement().string("return " + (nodeListsCount << 16 | nodesCount), " /* (" + nodeListsCount + " << 16 | " + nodesCount + ") */").end(); - genClass.add(method); - checkOnlyInGenNode(method); - } - - private void createGetNodeAtMethod(NodeRefsType nodeRefsType, List nodes) { - CodeExecutableElement method = new CodeExecutableElement(modifiers(PUBLIC, FINAL), Node.asType(), "get" + nodeRefsType.singular() + "NodeAt"); - addParameter(method, getType(int.class), "index"); - CodeTreeBuilder b = method.createBuilder(); - boolean justOne = nodes.size() == 1; - if (!justOne) { - b.startSwitch().string("index").end().startBlock(); - } else if (GENERATE_ASSERTIONS) { - b.startAssert().string("index == 0").end(); - } - int index = 0; - for (VariableElement f : nodes) { - if (!justOne) { - b.startCase().string(String.valueOf(index)).end(); - } - b.startReturn(); - if (!isAssignableWithErasure(f, Node)) { - b.cast(((DeclaredType) Node.asType()).asElement().getSimpleName().toString()); - } - b.string(genClassName + ".this." + f.getSimpleName()); - b.end(); - index++; - } - if (!justOne) { - b.end(); - b.startThrow().startNew(getType(NoSuchElementException.class)).end().end(); - } - genClass.add(method); - checkOnlyInGenNode(method); - } - - private void createGetNodeListAtIndexMethod(NodeRefsType nodeRefsType, List nodeLists) { - CodeExecutableElement method = new CodeExecutableElement(modifiers(PUBLIC, FINAL), types.getDeclaredType(NodeList, types.getWildcardType(Node.asType(), null)), "get" + - nodeRefsType.singular() + "NodeListAt"); - addParameter(method, getType(int.class), "index"); - CodeTreeBuilder b = method.createBuilder(); - - boolean justOne = nodeLists.size() == 1; - if (!justOne) { - b.startSwitch().string("index").end().startBlock(); - } else if (GENERATE_ASSERTIONS) { - b.startAssert().string("index == 0").end(); - } - int index = 0; - for (VariableElement f : nodeLists) { - if (!justOne) { - b.startCase().string(String.valueOf(index)).end(); - } - b.startReturn(); - b.string(genClassName + ".this." + f.getSimpleName()); - b.end(); - index++; - } - if (!justOne) { - b.end(); - b.startThrow().startNew(getType(NoSuchElementException.class)).end().end(); - } - genClass.add(method); - checkOnlyInGenNode(method); - } - - private void createGetNodeListAtPositionMethod() { - CodeExecutableElement method = new CodeExecutableElement(modifiers(PUBLIC, FINAL), types.getDeclaredType(NodeList, types.getWildcardType(Node.asType(), null)), "getNodeListAt"); - addParameter(method, Position.asType(), "pos"); - CodeTreeBuilder b = method.createBuilder(); - b.startIf().string("pos.isInput()").end().startBlock(); - createGetNodeListAt(b, inputFields, inputListFields); - b.end(); - b.startElseBlock(); - createGetNodeListAt(b, successorFields, successorListFields); - b.end(); - genClass.add(method); - checkOnlyInGenNode(method); - } - - private void createSetNodeListAtMethod() { - CodeExecutableElement method = new CodeExecutableElement(modifiers(PUBLIC, FINAL), getType(void.class), "setNodeListAt"); - - DeclaredType suppress = (DeclaredType) getType(SuppressWarnings.class); - CodeAnnotationMirror suppressMirror = new CodeAnnotationMirror(suppress); - suppressMirror.setElementValue(suppressMirror.findExecutableElement("value"), new CodeAnnotationValue("unchecked")); - method.getAnnotationMirrors().add(suppressMirror); - - addParameter(method, Position.asType(), "pos"); - addParameter(method, types.getDeclaredType(NodeList, types.getWildcardType(Node.asType(), null)), "list"); - CodeTreeBuilder b = method.createBuilder(); - b.startIf().string("pos.isInput()").end().startBlock(); - createSetNodeListAt(b, inputFields, inputListFields); - b.end(); - b.startElseBlock(); - createSetNodeListAt(b, successorFields, successorListFields); - b.end(); - genClass.add(method); - checkOnlyInGenNode(method); - } - - private void createGetNameOfMethod() { - CodeExecutableElement method = new CodeExecutableElement(modifiers(PUBLIC, FINAL), getType(String.class), "getNameOf"); - addParameter(method, Position.asType(), "pos"); - CodeTreeBuilder b = method.createBuilder(); - - b.startIf().string("pos.isInput()").end().startBlock(); - createGetNameOf(b, inputFields, inputListFields); - b.end(); - b.startElseBlock(); - createGetNameOf(b, successorFields, successorListFields); - b.end(); - genClass.add(method); - checkOnlyInGenNode(method); - } - - private void createGetInputTypeAtMethod() { - CodeExecutableElement method = new CodeExecutableElement(modifiers(PUBLIC, FINAL), getType(InputType.class), "getInputTypeAt"); - addParameter(method, Position.asType(), "pos"); - CodeTreeBuilder b = method.createBuilder(); - if (GENERATE_ASSERTIONS) { - b.startAssert().string("pos.isInput()").end(); - } - boolean hasNodes = !inputFields.isEmpty(); - boolean hasNodeLists = !inputListFields.isEmpty(); - if (hasNodeLists || hasNodes) { - int index = 0; - for (VariableElement f : concat(inputFields, inputListFields)) { - b.startIf().string("pos.getIndex() == " + index).end().startBlock(); - b.startStatement().string("return ").staticReference(getType(InputType.class), inputTypes.get(f).getSimpleName().toString()).end(); - b.end(); - index++; - } - } - b.startThrow().startNew(getType(NoSuchElementException.class)).end().end(); - genClass.add(method); - checkOnlyInGenNode(method); - } - private boolean hidesField(String name) { for (VariableElement field : concat(inputFields, inputListFields, successorFields, successorListFields, dataFields)) { if (field.getSimpleName().contentEquals(name)) { @@ -735,142 +440,4 @@ } return false; } - - private void createUpdateOrInitializeNodeAtMethod(boolean isInitialization) { - CodeExecutableElement method = new CodeExecutableElement(modifiers(PUBLIC, FINAL), getType(void.class), (isInitialization ? "initialize" : "update") + "NodeAt"); - addParameter(method, Position.asType(), "pos"); - addParameter(method, Node.asType(), "newValue"); - CodeTreeBuilder b = method.createBuilder(); - b.startIf().string("pos.isInput()").end().startBlock(); - createUpdateOrInitializeNodeAt(b, inputFields, inputListFields, isInitialization); - b.end(); - b.startElseBlock(); - createUpdateOrInitializeNodeAt(b, successorFields, successorListFields, isInitialization); - b.end(); - genClass.add(method); - checkOnlyInGenNode(method); - } - - private void createGetNodeAt(CodeTreeBuilder b, List nodes, List nodeLists) { - boolean hasNodes = !nodes.isEmpty(); - boolean hasNodeLists = !nodeLists.isEmpty(); - if (!hasNodeLists && !hasNodes) { - b.startThrow().startNew(getType(NoSuchElementException.class)).end().end(); - } else { - if (hasNodes) { - if (!hasNodeLists) { - if (GENERATE_ASSERTIONS) { - b.startAssert().string("pos.getSubIndex() == NOT_ITERABLE").end(); - } - } else { - b.startIf().string("pos.getSubIndex() == NOT_ITERABLE").end().startBlock(); - } - b.declaration("int", "at", "pos.getIndex()"); - createGetFieldCases(b, nodes, Node.asType(), null); - if (hasNodeLists) { - b.end(); - } - } - - if (hasNodeLists) { - if (!hasNodes) { - if (GENERATE_ASSERTIONS) { - b.startAssert().string("pos.getSubIndex() != NOT_ITERABLE").end(); - } - } else { - b.startElseBlock(); - } - b.declaration("int", "at", "pos.getIndex() - " + nodes.size()); - createGetFieldCases(b, nodeLists, Node.asType(), ".get(pos.getSubIndex())"); - if (hasNodes) { - b.end(); - } - } - } - } - - private void createGetNodeListAt(CodeTreeBuilder b, List nodes, List nodeLists) { - boolean hasNodeLists = !nodeLists.isEmpty(); - if (!hasNodeLists) { - b.startThrow().startNew(getType(NoSuchElementException.class)).end().end(); - } else { - if (GENERATE_ASSERTIONS) { - b.startAssert().string("pos.getSubIndex() == NODE_LIST").end(); - } - b.declaration("int", "at", "pos.getIndex() - " + nodes.size()); - createGetFieldCases(b, nodeLists, Node.asType(), ""); - } - } - - private void createSetNodeListAt(CodeTreeBuilder b, List nodes, List nodeLists) { - boolean hasNodeLists = !nodeLists.isEmpty(); - if (!hasNodeLists) { - b.startThrow().startNew(getType(NoSuchElementException.class)).end().end(); - } else { - if (GENERATE_ASSERTIONS) { - b.startAssert().string("pos.getSubIndex() == NODE_LIST").end(); - } - b.declaration("int", "at", "pos.getIndex() - " + nodes.size()); - createSetNodeListAtCases(b, nodeLists, Node.asType(), ""); - } - } - - private void createGetNameOf(CodeTreeBuilder b, List nodes, List nodeLists) { - boolean hasNodes = !nodes.isEmpty(); - boolean hasNodeLists = !nodeLists.isEmpty(); - if (hasNodeLists || hasNodes) { - int index = 0; - for (VariableElement f : nodes) { - b.startIf().string("pos.getIndex() == " + index).end().startBlock(); - b.startStatement().string("return \"" + f.getSimpleName() + "\"").end(); - b.end(); - index++; - } - for (VariableElement f : nodeLists) { - b.startIf().string("pos.getIndex() == " + index).end().startBlock(); - b.startStatement().string("return \"" + f.getSimpleName() + "\"").end(); - b.end(); - index++; - } - } - b.startThrow().startNew(getType(NoSuchElementException.class)).end().end(); - } - - private void createUpdateOrInitializeNodeAt(CodeTreeBuilder b, List nodes, List nodeLists, boolean isInitialization) { - boolean hasNodes = !nodes.isEmpty(); - boolean hasNodeLists = !nodeLists.isEmpty(); - if (nodes.isEmpty() && nodeLists.isEmpty()) { - b.startThrow().startNew(getType(NoSuchElementException.class)).end().end(); - } else { - if (hasNodes) { - if (!hasNodeLists) { - if (GENERATE_ASSERTIONS) { - b.startAssert().string("pos.getSubIndex() == NOT_ITERABLE").end(); - } - } else { - b.startIf().string("pos.getSubIndex() == NOT_ITERABLE").end().startBlock(); - } - b.declaration("int", "at", "pos.getIndex()"); - createUpdateOrInitializeFieldCases(b, nodes, isInitialization, false); - if (hasNodeLists) { - b.end(); - } - } - - if (hasNodeLists) { - if (!hasNodes) { - if (GENERATE_ASSERTIONS) { - b.startAssert().string("pos.getSubIndex() != NOT_ITERABLE").end(); - } - } else { - b.startElseBlock(); - } - b.declaration("int", "at", "pos.getIndex() - " + nodes.size()); - createUpdateOrInitializeFieldCases(b, nodeLists, isInitialization, true); - if (hasNodes) { - b.end(); - } - } - } - } }