changeset 14710:6fd5f25b546c

keep the guard alive when removing ReadNodes without usages
author Lukas Stadler <lukas.stadler@oracle.com>
date Fri, 21 Mar 2014 10:45:16 +0100
parents d3225562f0d8
children ba4b79da6351
files graal/com.oracle.graal.jtt/src/com/oracle/graal/jtt/except/BC_getfield1.java graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/ReadNode.java graal/com.oracle.graal.virtual/src/com/oracle/graal/virtual/phases/ea/ReadEliminationClosure.java
diffstat 3 files changed, 67 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.graal.jtt/src/com/oracle/graal/jtt/except/BC_getfield1.java	Fri Mar 21 10:45:16 2014 +0100
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2007, 2012, 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.jtt.except;
+
+import com.oracle.graal.jtt.*;
+
+import org.junit.*;
+
+public class BC_getfield1 extends JTTTest {
+
+    private int field = 13;
+
+    public static void test(BC_getfield1 arg) {
+        @SuppressWarnings("unused")
+        int i = arg.field;
+    }
+
+    @Test
+    public void run0() throws Throwable {
+        runTest("test", (Object) null);
+    }
+
+    @Test
+    public void run1() throws Throwable {
+        // tests that the null check isn't removed along with the read
+        runTest(EMPTY, true, true, "test", (Object) null);
+    }
+
+    @Test
+    public void run2() throws Throwable {
+        runTest("test", new BC_getfield1());
+    }
+
+}
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/ReadNode.java	Thu Mar 20 17:36:43 2014 -0700
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/ReadNode.java	Fri Mar 21 10:45:16 2014 +0100
@@ -71,8 +71,14 @@
     public static ValueNode canonicalizeRead(ValueNode read, LocationNode location, ValueNode object, CanonicalizerTool tool, boolean compressible) {
         MetaAccessProvider metaAccess = tool.getMetaAccess();
         if (read.usages().isEmpty()) {
-            // Read without usages can be safely removed.
-            return null;
+            GuardingNode guard = ((Access) read).getGuard();
+            if (guard != null && !(guard instanceof FixedNode)) {
+                // The guard is necessary even if the read goes away.
+                return read.graph().add(new ValueAnchorNode((ValueNode) guard));
+            } else {
+                // Read without usages or guard can be safely removed.
+                return null;
+            }
         }
         if (tool.canonicalizeReads()) {
             if (metaAccess != null && object != null && object.isConstant()) {
--- a/graal/com.oracle.graal.virtual/src/com/oracle/graal/virtual/phases/ea/ReadEliminationClosure.java	Thu Mar 20 17:36:43 2014 -0700
+++ b/graal/com.oracle.graal.virtual/src/com/oracle/graal/virtual/phases/ea/ReadEliminationClosure.java	Fri Mar 21 10:45:16 2014 +0100
@@ -94,6 +94,9 @@
                 ReadCacheEntry identifier = new ReadCacheEntry(object, read.location());
                 ValueNode cachedValue = state.getCacheEntry(identifier);
                 if (cachedValue != null) {
+                    if (read.getGuard() != null && !(read.getGuard() instanceof FixedNode)) {
+                        effects.addFixedNodeBefore(new ValueAnchorNode((ValueNode) read.getGuard()), read);
+                    }
                     effects.replaceAtUsages(read, cachedValue);
                     addScalarAlias(read, cachedValue);
                     deleted = true;