# HG changeset patch # User Lukas Stadler # Date 1395395116 -3600 # Node ID 6fd5f25b546c35cf51f46b068ab9ec4e24d98c2f # Parent d3225562f0d88d30b77059c08ad6c45c1db77770 keep the guard alive when removing ReadNodes without usages diff -r d3225562f0d8 -r 6fd5f25b546c graal/com.oracle.graal.jtt/src/com/oracle/graal/jtt/except/BC_getfield1.java --- /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()); + } + +} diff -r d3225562f0d8 -r 6fd5f25b546c graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/ReadNode.java --- 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()) { diff -r d3225562f0d8 -r 6fd5f25b546c graal/com.oracle.graal.virtual/src/com/oracle/graal/virtual/phases/ea/ReadEliminationClosure.java --- 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;