# HG changeset patch # User Tom Rodriguez # Date 1393362820 28800 # Node ID 9d864856336a5b896651f46d5fff6ccc6717bb47 # Parent f8639746e94249a8d96e25d4ed5b5375fe9c46e5 support canonicalization of arraylength in ReadNode diff -r f8639746e942 -r 9d864856336a graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/Kind.java --- a/graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/Kind.java Tue Feb 25 13:07:48 2014 -0800 +++ b/graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/Kind.java Tue Feb 25 13:13:40 2014 -0800 @@ -147,6 +147,15 @@ } /** + * Checks whether this represent an Object of some sort. + * + * @return {@code true} if this is {@link #Object} or {@link #NarrowOop}. + */ + public boolean isObject() { + return this == Kind.Object || this == Kind.NarrowOop; + } + + /** * Returns the kind corresponding to the Java type string. * * @param typeString the Java type string diff -r f8639746e942 -r 9d864856336a graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/LocationIdentity.java --- a/graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/LocationIdentity.java Tue Feb 25 13:07:48 2014 -0800 +++ b/graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/LocationIdentity.java Tue Feb 25 13:13:40 2014 -0800 @@ -41,4 +41,8 @@ */ LocationIdentity FINAL_LOCATION = new NamedLocationIdentity("FINAL_LOCATION"); + /** + * Denotes the location of the length field of a Java array. + */ + LocationIdentity ARRAY_LENGTH_LOCATION = new NamedLocationIdentity("[].length"); } diff -r f8639746e942 -r 9d864856336a graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotLoweringProvider.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotLoweringProvider.java Tue Feb 25 13:07:48 2014 -0800 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotLoweringProvider.java Tue Feb 25 13:13:40 2014 -0800 @@ -104,7 +104,7 @@ if (n instanceof ArrayLengthNode) { ArrayLengthNode arrayLengthNode = (ArrayLengthNode) n; ValueNode array = arrayLengthNode.array(); - ReadNode arrayLengthRead = graph.add(new ReadNode(array, ConstantLocationNode.create(FINAL_LOCATION, Kind.Int, config.arrayLengthOffset, graph), StampFactory.positiveInt(), + ReadNode arrayLengthRead = graph.add(new ReadNode(array, ConstantLocationNode.create(ARRAY_LENGTH_LOCATION, Kind.Int, config.arrayLengthOffset, graph), StampFactory.positiveInt(), BarrierType.NONE, false)); arrayLengthRead.setGuard(createNullCheck(array, arrayLengthNode, tool)); graph.replaceFixedWithFixed(arrayLengthNode, arrayLengthRead); diff -r f8639746e942 -r 9d864856336a graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/ConstantNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/ConstantNode.java Tue Feb 25 13:07:48 2014 -0800 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/ConstantNode.java Tue Feb 25 13:13:40 2014 -0800 @@ -22,6 +22,7 @@ */ package com.oracle.graal.nodes; +import java.lang.reflect.*; import java.util.*; import com.oracle.graal.api.meta.*; @@ -36,7 +37,7 @@ * The {@code ConstantNode} represents a {@link Constant constant}. */ @NodeInfo(shortName = "Const", nameTemplate = "Const({p#rawvalue})") -public final class ConstantNode extends FloatingNode implements LIRLowerable { +public final class ConstantNode extends FloatingNode implements LIRLowerable, ArrayLengthProvider { private static final DebugMetric ConstantNodes = Debug.metric("ConstantNodes"); @@ -355,4 +356,14 @@ return super.toString(verbosity); } } + + public ValueNode length() { + if (value.getKind().isObject()) { + Object object = value.asObject(); + if (object != null && object.getClass().isArray()) { + return forIntegerKind(Kind.Int, Array.getLength(object), graph()); + } + } + return null; + } } diff -r f8639746e942 -r 9d864856336a graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/DirectCallTargetNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/DirectCallTargetNode.java Tue Feb 25 13:07:48 2014 -0800 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/DirectCallTargetNode.java Tue Feb 25 13:13:40 2014 -0800 @@ -36,6 +36,6 @@ @Override public String targetName() { - return "Direct#" + ((JavaMethod) target()).getName(); + return MetaUtil.format("Direct#%h.%n", target()); } } diff -r f8639746e942 -r 9d864856336a graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/PiArrayNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/PiArrayNode.java Tue Feb 25 13:07:48 2014 -0800 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/PiArrayNode.java Tue Feb 25 13:13:40 2014 -0800 @@ -30,7 +30,7 @@ /** * A {@link PiNode} that also provides an array length in addition to a more refined stamp. A usage - * that reads the array length, such as an {@link ArrayLengthNode}, can be canonicalized base on + * that reads the array length, such as an {@link ArrayLengthNode}, can be canonicalized based on * this information. */ public final class PiArrayNode extends PiNode implements ArrayLengthProvider { diff -r f8639746e942 -r 9d864856336a graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/ReadNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/ReadNode.java Tue Feb 25 13:07:48 2014 -0800 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/ReadNode.java Tue Feb 25 13:13:40 2014 -0800 @@ -74,26 +74,35 @@ // Read without usages can be safely removed. return null; } - if (tool.canonicalizeReads() && metaAccess != null && object != null && object.isConstant()) { - if (location.getLocationIdentity() == LocationIdentity.FINAL_LOCATION && location instanceof ConstantLocationNode) { - long displacement = ((ConstantLocationNode) location).getDisplacement(); - Kind kind = location.getValueKind(); - if (object.kind() == Kind.Object) { - Object base = object.asConstant().asObject(); - if (base != null) { - Constant constant = tool.getConstantReflection().readUnsafeConstant(kind, base, displacement, compressible); - if (constant != null) { - return ConstantNode.forConstant(constant, metaAccess, read.graph()); + if (tool.canonicalizeReads()) { + if (metaAccess != null && object != null && object.isConstant()) { + if (location.getLocationIdentity() == LocationIdentity.FINAL_LOCATION && location instanceof ConstantLocationNode) { + long displacement = ((ConstantLocationNode) location).getDisplacement(); + Kind kind = location.getValueKind(); + if (object.kind() == Kind.Object) { + Object base = object.asConstant().asObject(); + if (base != null) { + Constant constant = tool.getConstantReflection().readUnsafeConstant(kind, base, displacement, compressible); + if (constant != null) { + return ConstantNode.forConstant(constant, metaAccess, read.graph()); + } + } + } else if (object.kind().isNumericInteger()) { + long base = object.asConstant().asLong(); + if (base != 0L) { + Constant constant = tool.getConstantReflection().readUnsafeConstant(kind, null, base + displacement, compressible); + if (constant != null) { + return ConstantNode.forConstant(constant, metaAccess, read.graph()); + } } } - } else if (object.kind().isNumericInteger()) { - long base = object.asConstant().asLong(); - if (base != 0L) { - Constant constant = tool.getConstantReflection().readUnsafeConstant(kind, null, base + displacement, compressible); - if (constant != null) { - return ConstantNode.forConstant(constant, metaAccess, read.graph()); - } - } + } + } + if (location.getLocationIdentity() == LocationIdentity.ARRAY_LENGTH_LOCATION && object instanceof ArrayLengthProvider) { + ValueNode length = ((ArrayLengthProvider) object).length(); + if (length != null) { + // TODO Does this need a PiCastNode to the positive range? + return length; } } } diff -r f8639746e942 -r 9d864856336a graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/MethodCallTargetNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/MethodCallTargetNode.java Tue Feb 25 13:07:48 2014 -0800 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/MethodCallTargetNode.java Tue Feb 25 13:13:40 2014 -0800 @@ -160,7 +160,7 @@ if (targetMethod() == null) { return "??Invalid!"; } - return targetMethod().getName(); + return MetaUtil.format("%h.%n", targetMethod()); } public static MethodCallTargetNode find(StructuredGraph graph, ResolvedJavaMethod method) { diff -r f8639746e942 -r 9d864856336a graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/virtual/AllocatedObjectNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/virtual/AllocatedObjectNode.java Tue Feb 25 13:07:48 2014 -0800 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/virtual/AllocatedObjectNode.java Tue Feb 25 13:13:40 2014 -0800 @@ -22,6 +22,7 @@ */ package com.oracle.graal.nodes.virtual; +import com.oracle.graal.nodes.*; import com.oracle.graal.nodes.calc.*; import com.oracle.graal.nodes.spi.*; import com.oracle.graal.nodes.type.*; @@ -30,7 +31,7 @@ * Selects one object from a {@link CommitAllocationNode}. The object is identified by its * {@link VirtualObjectNode}. */ -public class AllocatedObjectNode extends FloatingNode implements Virtualizable { +public class AllocatedObjectNode extends FloatingNode implements Virtualizable, ArrayLengthProvider { @Input private VirtualObjectNode virtualObject; @Input private CommitAllocationNode commit; @@ -57,4 +58,11 @@ public void virtualize(VirtualizerTool tool) { tool.replaceWithVirtual(getVirtualObject()); } + + public ValueNode length() { + if (virtualObject instanceof ArrayLengthProvider) { + return ((ArrayLengthProvider) virtualObject).length(); + } + return null; + } } diff -r f8639746e942 -r 9d864856336a graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/virtual/VirtualArrayNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/virtual/VirtualArrayNode.java Tue Feb 25 13:07:48 2014 -0800 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/virtual/VirtualArrayNode.java Tue Feb 25 13:13:40 2014 -0800 @@ -30,7 +30,7 @@ import com.oracle.graal.nodes.spi.*; @NodeInfo(nameTemplate = "VirtualArray {p#componentType/s}[{p#length}]") -public class VirtualArrayNode extends VirtualObjectNode { +public class VirtualArrayNode extends VirtualObjectNode implements ArrayLengthProvider { private final ResolvedJavaType componentType; private final int length; @@ -144,4 +144,8 @@ public ValueNode getMaterializedRepresentation(FixedNode fixed, ValueNode[] entries, LockState locks) { return new AllocatedObjectNode(this); } + + public ValueNode length() { + return ConstantNode.forInt(length, graph()); + } }