# HG changeset patch # User Christian Wimmer # Date 1379439082 25200 # Node ID 976ebd1973d194fd0eff4976e512ac20649c9d5f # Parent 39f98ffd187f76f76b5fd8d99a037f3875288bb4 The runtime might not always be able to report an array length diff -r 39f98ffd187f -r 976ebd1973d1 graal/com.oracle.graal.api.meta.test/src/com/oracle/graal/api/meta/test/TestMetaAccessProvider.java --- 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); } } } diff -r 39f98ffd187f -r 976ebd1973d1 graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/DelegatingMetaAccessProvider.java --- 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); } diff -r 39f98ffd187f -r 976ebd1973d1 graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/MetaAccessProvider.java --- 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. diff -r 39f98ffd187f -r 976ebd1973d1 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotRuntime.java --- 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()); } diff -r 39f98ffd187f -r 976ebd1973d1 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/ArrayLengthNode.java --- 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;