# HG changeset patch # User Christian Wimmer # Date 1385150113 28800 # Node ID c6ab6ae1b360a433abc1c1987686b0e255be7516 # Parent a4eb86dc383eaa9bd0d4cb2986ff9b3b1384f43b Allow subclasses of NewInstanceNode and NewArrayNode to provide the default values used by escape analysis diff -r a4eb86dc383e -r c6ab6ae1b360 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/NewArrayNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/NewArrayNode.java Fri Nov 22 11:53:36 2013 -0800 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/NewArrayNode.java Fri Nov 22 11:55:13 2013 -0800 @@ -34,8 +34,6 @@ */ public class NewArrayNode extends AbstractNewArrayNode implements VirtualizableAllocation { - private final ResolvedJavaType elementType; - /** * Constructs a new NewArrayNode. * @@ -46,7 +44,6 @@ */ public NewArrayNode(ResolvedJavaType elementType, ValueNode length, boolean fillContents) { super(StampFactory.exactNonNull(elementType.getArrayClass()), length, fillContents); - this.elementType = elementType; } /** @@ -55,7 +52,7 @@ * @return the element type of the array */ public ResolvedJavaType elementType() { - return elementType; + return ObjectStamp.typeOrNull(this).getComponentType(); } @Override @@ -64,14 +61,19 @@ final int constantLength = length().asConstant().asInt(); if (constantLength >= 0 && constantLength < tool.getMaximumEntryCount()) { ValueNode[] state = new ValueNode[constantLength]; - ConstantNode defaultForKind = constantLength == 0 ? null : ConstantNode.defaultForKind(elementType().getKind(), graph()); + ConstantNode defaultForKind = constantLength == 0 ? null : defaultElementValue(); for (int i = 0; i < constantLength; i++) { state[i] = defaultForKind; } - VirtualObjectNode virtualObject = new VirtualArrayNode(elementType, constantLength); + VirtualObjectNode virtualObject = new VirtualArrayNode(elementType(), constantLength); tool.createVirtualObject(virtualObject, state, null); tool.replaceWithVirtual(virtualObject); } } } + + /* Factored out in a separate method so that subclasses can override it. */ + protected ConstantNode defaultElementValue() { + return ConstantNode.defaultForKind(elementType().getKind(), graph()); + } } diff -r a4eb86dc383e -r c6ab6ae1b360 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/NewInstanceNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/NewInstanceNode.java Fri Nov 22 11:53:36 2013 -0800 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/NewInstanceNode.java Fri Nov 22 11:55:13 2013 -0800 @@ -36,7 +36,7 @@ * The {@code NewInstanceNode} represents the allocation of an instance class object. */ @NodeInfo(nameTemplate = "New {p#instanceClass/s}") -public final class NewInstanceNode extends DeoptimizingFixedWithNextNode implements Canonicalizable, Lowerable, VirtualizableAllocation { +public class NewInstanceNode extends DeoptimizingFixedWithNextNode implements Canonicalizable, Lowerable, VirtualizableAllocation { private final ResolvedJavaType instanceClass; private final boolean fillContents; @@ -96,13 +96,18 @@ ResolvedJavaField[] fields = virtualObject.getFields(); ValueNode[] state = new ValueNode[fields.length]; for (int i = 0; i < state.length; i++) { - state[i] = ConstantNode.defaultForKind(fields[i].getType().getKind(), graph()); + state[i] = defaultFieldValue(fields[i]); } tool.createVirtualObject(virtualObject, state, null); tool.replaceWithVirtual(virtualObject); } } + /* Factored out in a separate method so that subclasses can override it. */ + protected ConstantNode defaultFieldValue(ResolvedJavaField field) { + return ConstantNode.defaultForKind(field.getType().getKind(), graph()); + } + @Override public boolean canDeoptimize() { return true;