changeset 11682:976ebd1973d1

The runtime might not always be able to report an array length
author Christian Wimmer <christian.wimmer@oracle.com>
date Tue, 17 Sep 2013 10:31:22 -0700
parents 39f98ffd187f
children 7aed6a236e0b
files graal/com.oracle.graal.api.meta.test/src/com/oracle/graal/api/meta/test/TestMetaAccessProvider.java graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/DelegatingMetaAccessProvider.java graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/MetaAccessProvider.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotRuntime.java graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/ArrayLengthNode.java
diffstat 5 files changed, 16 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.api.meta.test/src/com/oracle/graal/api/meta/test/TestMetaAccessProvider.java	Tue Sep 17 17:09:43 2013 +0200
+++ b/graal/com.oracle.graal.api.meta.test/src/com/oracle/graal/api/meta/test/TestMetaAccessProvider.java	Tue Sep 17 10:31:22 2013 -0700
@@ -107,15 +107,13 @@
     @Test
     public void lookupArrayLengthTest() {
         for (Constant c : constants) {
+            Integer actual = runtime.lookupArrayLength(c);
             if (c.getKind() != Kind.Object || c.isNull() || !c.asObject().getClass().isArray()) {
-                try {
-                    int length = runtime.lookupArrayLength(c);
-                    fail("Expected " + IllegalArgumentException.class.getName() + " for " + c + ", not " + length);
-                } catch (IllegalArgumentException e) {
-                    // pass
-                }
+                assertNull(actual);
             } else {
-                assertEquals(Array.getLength(c.asObject()), runtime.lookupArrayLength(c));
+                assertNotNull(actual);
+                int actualInt = actual;
+                assertEquals(Array.getLength(c.asObject()), actualInt);
             }
         }
     }
--- a/graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/DelegatingMetaAccessProvider.java	Tue Sep 17 17:09:43 2013 +0200
+++ b/graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/DelegatingMetaAccessProvider.java	Tue Sep 17 10:31:22 2013 -0700
@@ -67,7 +67,7 @@
         return delegate.constantEquals(x, y);
     }
 
-    public int lookupArrayLength(Constant array) {
+    public Integer lookupArrayLength(Constant array) {
         return delegate.lookupArrayLength(array);
     }
 
--- a/graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/MetaAccessProvider.java	Tue Sep 17 17:09:43 2013 +0200
+++ b/graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/MetaAccessProvider.java	Tue Sep 17 10:31:22 2013 -0700
@@ -79,11 +79,11 @@
     boolean constantEquals(Constant x, Constant y);
 
     /**
-     * Returns the length of an array that is wrapped in a {@link Constant} object.
-     * 
-     * @throws IllegalArgumentException if {@code array} is not an array
+     * Returns the length of an array that is wrapped in a {@link Constant} object. If {@code array}
+     * is not an array, or the array length is not available at this point, the return value is
+     * {@code null}.
      */
-    int lookupArrayLength(Constant array);
+    Integer lookupArrayLength(Constant array);
 
     /**
      * Reads a value of this kind using a base address and a displacement.
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotRuntime.java	Tue Sep 17 17:09:43 2013 +0200
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotRuntime.java	Tue Sep 17 10:31:22 2013 -0700
@@ -476,9 +476,9 @@
     }
 
     @Override
-    public int lookupArrayLength(Constant array) {
+    public Integer lookupArrayLength(Constant array) {
         if (array.getKind() != Kind.Object || array.isNull() || !array.asObject().getClass().isArray()) {
-            throw new IllegalArgumentException(array + " is not an array");
+            return null;
         }
         return Array.getLength(array.asObject());
     }
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/ArrayLengthNode.java	Tue Sep 17 17:09:43 2013 +0200
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/ArrayLengthNode.java	Tue Sep 17 10:31:22 2013 -0700
@@ -55,7 +55,10 @@
         if (runtime != null && array().isConstant() && !array().isNullConstant()) {
             Constant constantValue = array().asConstant();
             if (constantValue != null && constantValue.isNonNull()) {
-                return ConstantNode.forInt(runtime.lookupArrayLength(constantValue), graph());
+                Integer constantLength = runtime.lookupArrayLength(constantValue);
+                if (constantLength != null) {
+                    return ConstantNode.forInt(constantLength, graph());
+                }
             }
         }
         return this;