changeset 10589:17c5cc84560b

Factor out common code of NewArrayNode and DynamicNewArrayNode.
author Roland Schatz <roland.schatz@oracle.com>
date Tue, 02 Jul 2013 10:17:35 +0200
parents b0b368d38b40
children 5acc3f3016b7
files graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/AbstractNewArrayNode.java graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/DynamicNewArrayNode.java graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/NewArrayNode.java
diffstat 3 files changed, 98 insertions(+), 70 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/AbstractNewArrayNode.java	Tue Jul 02 10:17:35 2013 +0200
@@ -0,0 +1,91 @@
+/*
+ * Copyright (c) 2009, 2011, 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.nodes.java;
+
+import com.oracle.graal.graph.*;
+import com.oracle.graal.nodes.*;
+import com.oracle.graal.nodes.spi.*;
+import com.oracle.graal.nodes.type.*;
+
+/**
+ * The {@code AbstractNewArrayNode} is used for all 1-dimensional array allocations.
+ */
+public class AbstractNewArrayNode extends FixedWithNextNode implements Canonicalizable, Lowerable, ArrayLengthProvider, Node.IterableNodeType {
+
+    @Input private ValueNode length;
+    private final boolean fillContents;
+
+    @Override
+    public ValueNode length() {
+        return length;
+    }
+
+    /**
+     * Constructs a new AbstractNewArrayNode.
+     * 
+     * @param stamp the stamp of the newly created array
+     * @param length the node that produces the length for this allocation.
+     * @param fillContents determines whether the array elements should be initialized to zero/null.
+     */
+    protected AbstractNewArrayNode(Stamp stamp, ValueNode length, boolean fillContents) {
+        super(stamp);
+        this.length = length;
+        this.fillContents = fillContents;
+    }
+
+    /**
+     * @return <code>true</code> if the elements of the array will be initialized.
+     */
+    public boolean fillContents() {
+        return fillContents;
+    }
+
+    /**
+     * The list of node which produce input for this instruction.
+     */
+    public ValueNode dimension(int index) {
+        assert index == 0;
+        return length();
+    }
+
+    /**
+     * The rank of the array allocated by this node, i.e. how many array dimensions.
+     */
+    public int dimensionCount() {
+        return 1;
+    }
+
+    @Override
+    public ValueNode canonical(CanonicalizerTool tool) {
+        if (usages().isEmpty() && length.integerStamp().isPositive()) {
+            return null;
+        } else {
+            return this;
+        }
+    }
+
+    @Override
+    public void lower(LoweringTool tool, LoweringType loweringType) {
+        tool.getRuntime().lower(this, tool);
+    }
+}
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/DynamicNewArrayNode.java	Mon Jul 01 15:46:27 2013 -0400
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/DynamicNewArrayNode.java	Tue Jul 02 10:17:35 2013 +0200
@@ -31,21 +31,17 @@
  * The {@code DynamicNewArrayNode} is used for allocation of arrays when the type is not a
  * compile-time constant.
  */
-public class DynamicNewArrayNode extends FixedWithNextNode implements Canonicalizable, Lowerable, ArrayLengthProvider {
+public class DynamicNewArrayNode extends AbstractNewArrayNode implements Canonicalizable {
 
     @Input private ValueNode elementType;
-    @Input private ValueNode length;
-    private final boolean fillContents;
 
     public DynamicNewArrayNode(ValueNode elementType, ValueNode length) {
         this(elementType, length, true);
     }
 
     public DynamicNewArrayNode(ValueNode elementType, ValueNode length, boolean fillContents) {
-        super(StampFactory.objectNonNull());
-        this.length = length;
+        super(StampFactory.objectNonNull(), length, fillContents);
         this.elementType = elementType;
-        this.fillContents = fillContents;
     }
 
     public ValueNode getElementType() {
@@ -53,31 +49,17 @@
     }
 
     @Override
-    public ValueNode length() {
-        return length;
-    }
-
-    public boolean fillContents() {
-        return fillContents;
-    }
-
-    @Override
     public ValueNode canonical(CanonicalizerTool tool) {
         if (elementType.isConstant()) {
             Class<?> elementClass = (Class<?>) elementType.asConstant().asObject();
             if (elementClass != null && !(elementClass.equals(void.class))) {
                 ResolvedJavaType javaType = tool.runtime().lookupJavaType(elementClass);
-                return graph().add(new NewArrayNode(javaType, length, fillContents));
+                return graph().add(new NewArrayNode(javaType, length(), fillContents()));
             }
         }
         return this;
     }
 
-    @Override
-    public void lower(LoweringTool tool, LoweringType loweringType) {
-        tool.getRuntime().lower(this, tool);
-    }
-
     @NodeIntrinsic
     public static native Object newArray(Class<?> componentType, int length);
 }
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/NewArrayNode.java	Mon Jul 01 15:46:27 2013 -0400
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/NewArrayNode.java	Tue Jul 02 10:17:35 2013 +0200
@@ -23,25 +23,18 @@
 package com.oracle.graal.nodes.java;
 
 import com.oracle.graal.api.meta.*;
-import com.oracle.graal.graph.*;
 import com.oracle.graal.nodes.*;
 import com.oracle.graal.nodes.spi.*;
 import com.oracle.graal.nodes.type.*;
 import com.oracle.graal.nodes.virtual.*;
 
 /**
- * The {@code NewArrayNode} is used for all 1-dimensional array allocations.
+ * The {@code NewArrayNode} is used for all array allocations where the element type is know at
+ * compile time.
  */
-public class NewArrayNode extends FixedWithNextNode implements Canonicalizable, Lowerable, VirtualizableAllocation, ArrayLengthProvider, Node.IterableNodeType {
+public class NewArrayNode extends AbstractNewArrayNode implements VirtualizableAllocation {
 
-    @Input private ValueNode length;
     private final ResolvedJavaType elementType;
-    private final boolean fillContents;
-
-    @Override
-    public ValueNode length() {
-        return length;
-    }
 
     /**
      * Constructs a new NewArrayNode.
@@ -52,25 +45,8 @@
      * @param fillContents determines whether the array elements should be initialized to zero/null.
      */
     public NewArrayNode(ResolvedJavaType elementType, ValueNode length, boolean fillContents) {
-        super(StampFactory.exactNonNull(elementType.getArrayClass()));
-        this.length = length;
+        super(StampFactory.exactNonNull(elementType.getArrayClass()), length, fillContents);
         this.elementType = elementType;
-        this.fillContents = fillContents;
-    }
-
-    /**
-     * @return <code>true</code> if the elements of the array will be initialized.
-     */
-    public boolean fillContents() {
-        return fillContents;
-    }
-
-    /**
-     * The list of node which produce input for this instruction.
-     */
-    public ValueNode dimension(int index) {
-        assert index == 0;
-        return length();
     }
 
     /**
@@ -82,27 +58,6 @@
         return elementType;
     }
 
-    /**
-     * The rank of the array allocated by this node, i.e. how many array dimensions.
-     */
-    public int dimensionCount() {
-        return 1;
-    }
-
-    @Override
-    public ValueNode canonical(CanonicalizerTool tool) {
-        if (usages().isEmpty() && length.integerStamp().isPositive()) {
-            return null;
-        } else {
-            return this;
-        }
-    }
-
-    @Override
-    public void lower(LoweringTool tool, LoweringType loweringType) {
-        tool.getRuntime().lower(this, tool);
-    }
-
     @Override
     public void virtualize(VirtualizerTool tool) {
         if (length().asConstant() != null) {