# HG changeset patch # User Lukas Stadler # Date 1337072854 -7200 # Node ID 332a3c0d7b3b38f06bf1222c154c35b84544e350 # Parent 028c9ce0fc0f97c9e6b5f83b38ad05896ab29c47 remove array length input from LoadIndexedNode and StoreIndexedNode diff -r 028c9ce0fc0f -r 332a3c0d7b3b graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/ri/HotSpotRuntime.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/ri/HotSpotRuntime.java Tue May 15 10:03:33 2012 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/ri/HotSpotRuntime.java Tue May 15 11:07:34 2012 +0200 @@ -287,7 +287,7 @@ if (n instanceof ArrayLengthNode) { ArrayLengthNode arrayLengthNode = (ArrayLengthNode) n; - SafeReadNode safeReadArrayLength = safeReadArrayLength(arrayLengthNode.graph(), arrayLengthNode.array(), arrayLengthNode.stamp(), StructuredGraph.INVALID_GRAPH_ID); + SafeReadNode safeReadArrayLength = safeReadArrayLength(arrayLengthNode.array(), StructuredGraph.INVALID_GRAPH_ID); graph.replaceFixedWithFixed(arrayLengthNode, safeReadArrayLength); safeReadArrayLength.lower(tool); } else if (n instanceof LoadFieldNode) { @@ -341,7 +341,8 @@ } } else if (n instanceof LoadIndexedNode) { LoadIndexedNode loadIndexed = (LoadIndexedNode) n; - Node boundsCheck = createBoundsCheck(loadIndexed, tool, loadIndexed.leafGraphId()); + + Node boundsCheck = createBoundsCheck(loadIndexed, tool); CiKind elementKind = loadIndexed.elementKind(); LocationNode arrayLocation = createArrayLocation(graph, elementKind, loadIndexed.index()); @@ -350,7 +351,7 @@ graph.replaceFixedWithFixed(loadIndexed, memoryRead); } else if (n instanceof StoreIndexedNode) { StoreIndexedNode storeIndexed = (StoreIndexedNode) n; - Node boundsCheck = createBoundsCheck(storeIndexed, tool, storeIndexed.leafGraphId()); + Node boundsCheck = createBoundsCheck(storeIndexed, tool); CiKind elementKind = storeIndexed.elementKind(); LocationNode arrayLocation = createArrayLocation(graph, elementKind, storeIndexed.index()); @@ -466,8 +467,17 @@ return IndexedLocationNode.create(LocationNode.getArrayLocation(elementKind), elementKind, config.getArrayOffset(elementKind), index, graph); } - private static Node createBoundsCheck(AccessIndexedNode n, CiLoweringTool tool, long leafGraphId) { - return tool.createGuard(n.graph().unique(new CompareNode(n.index(), Condition.BT, n.length())), RiDeoptReason.BoundsCheckException, RiDeoptAction.InvalidateReprofile, leafGraphId); + private SafeReadNode safeReadArrayLength(ValueNode array, long leafGraphId) { + return safeRead(array.graph(), CiKind.Int, array, config.arrayLengthOffset, StampFactory.positiveInt(), leafGraphId); + } + + private Node createBoundsCheck(AccessIndexedNode n, CiLoweringTool tool) { + SafeReadNode arrayLength = safeReadArrayLength(n.array(), n.leafGraphId()); + Node guard = tool.createGuard(n.graph().unique(new CompareNode(n.index(), Condition.BT, arrayLength)), RiDeoptReason.BoundsCheckException, RiDeoptAction.InvalidateReprofile, n.leafGraphId()); + + ((StructuredGraph) n.graph()).addBeforeFixed(n, arrayLength); + arrayLength.lower(tool); + return guard; } @Override @@ -521,10 +531,6 @@ return safeRead(graph, CiKind.Object, value, config.hubOffset, StampFactory.objectNonNull(), leafGraphId); } - private SafeReadNode safeReadArrayLength(Graph graph, ValueNode value, Stamp stamp, long leafGraphId) { - return safeRead(graph, CiKind.Int, value, config.arrayLengthOffset, stamp, leafGraphId); - } - private static SafeReadNode safeRead(Graph graph, CiKind kind, ValueNode value, int offset, Stamp stamp, long leafGraphId) { return graph.add(new SafeReadNode(value, LocationNode.create(LocationNode.FINAL_LOCATION, kind, offset, graph), stamp, leafGraphId)); } diff -r 028c9ce0fc0f -r 332a3c0d7b3b graal/com.oracle.graal.java/src/com/oracle/graal/java/GraphBuilderPhase.java --- a/graal/com.oracle.graal.java/src/com/oracle/graal/java/GraphBuilderPhase.java Tue May 15 10:03:33 2012 +0200 +++ b/graal/com.oracle.graal.java/src/com/oracle/graal/java/GraphBuilderPhase.java Tue May 15 11:07:34 2012 +0200 @@ -302,8 +302,7 @@ ValueNode index = frameState.ipop(); ValueNode array = frameState.apop(); - ValueNode length = append(currentGraph.add(new ArrayLengthNode(array))); - ValueNode v = append(currentGraph.add(new LoadIndexedNode(array, index, length, kind, graphId))); + ValueNode v = append(currentGraph.add(new LoadIndexedNode(array, index, kind, graphId))); frameState.push(kind.stackKind(), v); } @@ -313,8 +312,7 @@ ValueNode value = frameState.pop(kind.stackKind()); ValueNode index = frameState.ipop(); ValueNode array = frameState.apop(); - ValueNode length = append(currentGraph.add(new ArrayLengthNode(array))); - StoreIndexedNode result = currentGraph.add(new StoreIndexedNode(array, index, length, kind, value, graphId)); + StoreIndexedNode result = currentGraph.add(new StoreIndexedNode(array, index, kind, value, graphId)); append(result); } diff -r 028c9ce0fc0f -r 332a3c0d7b3b graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/AccessIndexedNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/AccessIndexedNode.java Tue May 15 10:03:33 2012 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/AccessIndexedNode.java Tue May 15 11:07:34 2012 +0200 @@ -35,7 +35,6 @@ public abstract class AccessIndexedNode extends AccessArrayNode implements TypeFeedbackProvider { @Input private ValueNode index; - @Input private ValueNode length; private final CiKind elementType; private final long leafGraphId; @@ -43,22 +42,16 @@ return index; } - public ValueNode length() { - return length; - } - /** * Create an new AccessIndexedNode. * @param kind the result kind of the access * @param array the instruction producing the array * @param index the instruction producing the index - * @param length the instruction producing the length * @param elementKind the type of the elements of the array */ - protected AccessIndexedNode(Stamp stamp, ValueNode array, ValueNode index, ValueNode length, CiKind elementKind, long leafGraphId) { + protected AccessIndexedNode(Stamp stamp, ValueNode array, ValueNode index, CiKind elementKind, long leafGraphId) { super(stamp, array); this.index = index; - this.length = length; this.elementType = elementKind; this.leafGraphId = leafGraphId; } @@ -78,6 +71,5 @@ @Override public void typeFeedback(TypeFeedbackTool tool) { tool.addScalar(index()).constantBound(Condition.GE, CiConstant.INT_0); - tool.addScalar(index()).valueBound(Condition.LT, length, tool.queryScalar(length)); } } diff -r 028c9ce0fc0f -r 332a3c0d7b3b graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/LoadIndexedNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/LoadIndexedNode.java Tue May 15 10:03:33 2012 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/LoadIndexedNode.java Tue May 15 11:07:34 2012 +0200 @@ -42,11 +42,10 @@ * Creates a new LoadIndexedNode. * @param array the instruction producing the array * @param index the instruction producing the index - * @param length the instruction producing the length * @param elementKind the element type */ - public LoadIndexedNode(ValueNode array, ValueNode index, ValueNode length, CiKind elementKind, long leafGraphId) { - super(createStamp(array, elementKind), array, index, length, elementKind, leafGraphId); + public LoadIndexedNode(ValueNode array, ValueNode index, CiKind elementKind, long leafGraphId) { + super(createStamp(array, elementKind), array, index, elementKind, leafGraphId); } private static Stamp createStamp(ValueNode array, CiKind kind) { diff -r 028c9ce0fc0f -r 332a3c0d7b3b graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/StoreIndexedNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/StoreIndexedNode.java Tue May 15 10:03:33 2012 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/StoreIndexedNode.java Tue May 15 11:07:34 2012 +0200 @@ -58,12 +58,11 @@ * Creates a new StoreIndexedNode. * @param array the node producing the array * @param index the node producing the index - * @param length the node producing the length * @param elementKind the element type * @param value the value to store into the array */ - public StoreIndexedNode(ValueNode array, ValueNode index, ValueNode length, CiKind elementKind, ValueNode value, long leafGraphId) { - super(StampFactory.illegal(), array, index, length, elementKind, leafGraphId); + public StoreIndexedNode(ValueNode array, ValueNode index, CiKind elementKind, ValueNode value, long leafGraphId) { + super(StampFactory.illegal(), array, index, elementKind, leafGraphId); this.value = value; }