changeset 20145:80fda5775d0c

folding a TypeCheckNode can only be done if the stamp of the input object denotes an exact type
author Doug Simon <doug.simon@oracle.com>
date Thu, 02 Apr 2015 19:21:59 +0200
parents 921eeb012866
children a927a3ccfd0d
files graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/TypeCheckNode.java graal/com.oracle.graal.replacements.test/src/com/oracle/graal/replacements/test/InstanceOfTest.java
diffstat 2 files changed, 19 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/TypeCheckNode.java	Thu Apr 02 17:32:26 2015 +0200
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/TypeCheckNode.java	Thu Apr 02 19:21:59 2015 +0200
@@ -100,7 +100,8 @@
             return result;
         }
         if (type().equals(inputType)) {
-            if (!nonNull) {
+            boolean mightBeNull = !nonNull;
+            if (exactType && mightBeNull) {
                 // the instanceof matches if the object is non-null, so return true
                 // depending on the null-ness.
                 return LogicNegationNode.create(new IsNullNode(forValue));
@@ -114,7 +115,7 @@
             return null;
         }
         if (type.equals(inputType)) {
-            if (nonNull) {
+            if (nonNull && exactType) {
                 // the type matches, so return true
                 return LogicConstantNode.tautology();
             }
--- a/graal/com.oracle.graal.replacements.test/src/com/oracle/graal/replacements/test/InstanceOfTest.java	Thu Apr 02 17:32:26 2015 +0200
+++ b/graal/com.oracle.graal.replacements.test/src/com/oracle/graal/replacements/test/InstanceOfTest.java	Thu Apr 02 19:21:59 2015 +0200
@@ -396,4 +396,20 @@
         test("isArrayOfD", cArray);
         test("isArrayOfD", dArray);
     }
+
+    @SuppressWarnings("unchecked")
+    public static <T> String arrayCopyTypeName(T[] original) {
+        Class<? extends T[]> newType = (Class<? extends T[]>) original.getClass();
+        if (newType == (Object) Object[].class) {
+            return Object[].class.getName();
+        } else {
+            return newType.getName();
+        }
+    }
+
+    @Test
+    public void testArrayCopy() {
+        test("arrayCopyTypeName", (Object) new Object[]{"one", "two", "three"});
+        test("arrayCopyTypeName", (Object) new String[]{"one", "two", "three"});
+    }
 }