changeset 13122:c6ab6ae1b360

Allow subclasses of NewInstanceNode and NewArrayNode to provide the default values used by escape analysis
author Christian Wimmer <christian.wimmer@oracle.com>
date Fri, 22 Nov 2013 11:55:13 -0800
parents a4eb86dc383e
children a4593e99f1ea
files graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/NewArrayNode.java graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/NewInstanceNode.java
diffstat 2 files changed, 15 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- 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());
+    }
 }
--- 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;