# HG changeset patch # User Bernhard Urban # Date 1379620400 -7200 # Node ID 661e10237142b66e18674e0cb460445a5a1ede93 # Parent ea4e9cbaa0c95eaf96f32ad83d06f10afae9061d FloatingReadPhase: add interface to access memory state diff -r ea4e9cbaa0c9 -r 661e10237142 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/MemoryMap.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/MemoryMap.java Thu Sep 19 21:53:20 2013 +0200 @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2013, 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.nodes; + +import com.oracle.graal.api.meta.*; +import com.oracle.graal.graph.*; + +public interface MemoryMap { + + Node getLastLocationAccess(LocationIdentity locationIdentity); +} diff -r ea4e9cbaa0c9 -r 661e10237142 graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/FloatingReadPhase.java --- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/FloatingReadPhase.java Thu Sep 19 21:53:20 2013 +0200 +++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/FloatingReadPhase.java Thu Sep 19 21:53:20 2013 +0200 @@ -27,6 +27,7 @@ import java.util.*; import com.oracle.graal.api.meta.*; +import com.oracle.graal.graph.*; import com.oracle.graal.nodes.*; import com.oracle.graal.nodes.PhiNode.PhiType; import com.oracle.graal.nodes.extended.*; @@ -37,24 +38,25 @@ public class FloatingReadPhase extends Phase { - private static class MemoryMap { + public static class MemoryMapImpl implements MemoryMap { private IdentityHashMap lastMemorySnapshot; - public MemoryMap(MemoryMap memoryMap) { + public MemoryMapImpl(MemoryMapImpl memoryMap) { lastMemorySnapshot = new IdentityHashMap<>(memoryMap.lastMemorySnapshot); } - public MemoryMap(StartNode start) { + public MemoryMapImpl(StartNode start) { this(); lastMemorySnapshot.put(ANY_LOCATION, start); } - public MemoryMap() { + public MemoryMapImpl() { lastMemorySnapshot = new IdentityHashMap<>(); } - private ValueNode getLastLocationAccess(LocationIdentity locationIdentity) { + @Override + public ValueNode getLastLocationAccess(LocationIdentity locationIdentity) { ValueNode lastLocationAccess; if (locationIdentity == FINAL_LOCATION) { return null; @@ -78,7 +80,7 @@ protected void run(StructuredGraph graph) { Map> modifiedInLoops = new IdentityHashMap<>(); ReentrantNodeIterator.apply(new CollectMemoryCheckpointsClosure(modifiedInLoops), graph.start(), new HashSet(), null); - ReentrantNodeIterator.apply(new FloatingReadClosure(modifiedInLoops), graph.start(), new MemoryMap(graph.start()), null); + ReentrantNodeIterator.apply(new FloatingReadClosure(modifiedInLoops), graph.start(), new MemoryMapImpl(graph.start()), null); } private static class CollectMemoryCheckpointsClosure extends NodeIteratorClosure> { @@ -133,7 +135,7 @@ } - private static class FloatingReadClosure extends NodeIteratorClosure { + private static class FloatingReadClosure extends NodeIteratorClosure { private final Map> modifiedInLoops; @@ -142,7 +144,7 @@ } @Override - protected MemoryMap processNode(FixedNode node, MemoryMap state) { + protected MemoryMapImpl processNode(FixedNode node, MemoryMapImpl state) { if (node instanceof FloatableAccessNode) { processFloatable((FloatableAccessNode) node, state); } else if (node instanceof MemoryCheckpoint.Single) { @@ -151,27 +153,28 @@ processCheckpoint((MemoryCheckpoint.Multi) node, state); } assert MemoryCheckpoint.TypeAssertion.correctType(node) : node; + return state; } - private static void processCheckpoint(MemoryCheckpoint.Single checkpoint, MemoryMap state) { - LocationIdentity identity = checkpoint.getLocationIdentity(); + private static void processCheckpoint(MemoryCheckpoint.Single checkpoint, MemoryMapImpl state) { + processIdentity(checkpoint.getLocationIdentity(), checkpoint, state); + } + + private static void processCheckpoint(MemoryCheckpoint.Multi checkpoint, MemoryMapImpl state) { + for (LocationIdentity identity : checkpoint.getLocationIdentities()) { + processIdentity(identity, checkpoint, state); + } + } + + private static void processIdentity(LocationIdentity identity, MemoryCheckpoint checkpoint, MemoryMapImpl state) { if (identity == ANY_LOCATION) { state.lastMemorySnapshot.clear(); } state.lastMemorySnapshot.put(identity, (ValueNode) checkpoint); } - private static void processCheckpoint(MemoryCheckpoint.Multi checkpoint, MemoryMap state) { - for (LocationIdentity identity : checkpoint.getLocationIdentities()) { - if (identity == ANY_LOCATION) { - state.lastMemorySnapshot.clear(); - } - state.lastMemorySnapshot.put(identity, (ValueNode) checkpoint); - } - } - - private static void processFloatable(FloatableAccessNode accessNode, MemoryMap state) { + private static void processFloatable(FloatableAccessNode accessNode, MemoryMapImpl state) { StructuredGraph graph = accessNode.graph(); assert accessNode.getNullCheck() == false; LocationIdentity locationIdentity = accessNode.location().getLocationIdentity(); @@ -190,11 +193,11 @@ } @Override - protected MemoryMap merge(MergeNode merge, List states) { - MemoryMap newState = new MemoryMap(); + protected MemoryMapImpl merge(MergeNode merge, List states) { + MemoryMapImpl newState = new MemoryMapImpl(); Set keys = new HashSet<>(); - for (MemoryMap other : states) { + for (MemoryMapImpl other : states) { keys.addAll(other.lastMemorySnapshot.keySet()); } assert !keys.contains(FINAL_LOCATION); @@ -203,7 +206,7 @@ int mergedStatesCount = 0; boolean isPhi = false; ValueNode merged = null; - for (MemoryMap state : states) { + for (MemoryMapImpl state : states) { ValueNode last = state.getLastLocationAccess(key); if (isPhi) { ((PhiNode) merged).addInput(last); @@ -230,8 +233,8 @@ } @Override - protected MemoryMap afterSplit(AbstractBeginNode node, MemoryMap oldState) { - MemoryMap result = new MemoryMap(oldState); + protected MemoryMapImpl afterSplit(AbstractBeginNode node, MemoryMapImpl oldState) { + MemoryMapImpl result = new MemoryMapImpl(oldState); if (node.predecessor() instanceof InvokeWithExceptionNode) { /* * InvokeWithException cannot be the lastLocationAccess for a FloatingReadNode. @@ -247,7 +250,7 @@ } @Override - protected Map processLoop(LoopBeginNode loop, MemoryMap initialState) { + protected Map processLoop(LoopBeginNode loop, MemoryMapImpl initialState) { Set modifiedLocations = modifiedInLoops.get(loop); if (modifiedLocations.contains(ANY_LOCATION)) { // create phis for all locations if ANY is modified in the loop @@ -263,9 +266,9 @@ initialState.lastMemorySnapshot.put(location, phi); } - LoopInfo loopInfo = ReentrantNodeIterator.processLoop(this, loop, initialState); + LoopInfo loopInfo = ReentrantNodeIterator.processLoop(this, loop, initialState); - for (Map.Entry entry : loopInfo.endStates.entrySet()) { + for (Map.Entry entry : loopInfo.endStates.entrySet()) { int endIndex = loop.phiPredecessorIndex(entry.getKey()); for (Map.Entry phiEntry : phis.entrySet()) { LocationIdentity key = phiEntry.getKey(); @@ -273,9 +276,9 @@ phi.initializeValueAt(endIndex, entry.getValue().getLastLocationAccess(key)); } } - for (Map.Entry entry : loopInfo.exitStates.entrySet()) { + for (Map.Entry entry : loopInfo.exitStates.entrySet()) { LoopExitNode exit = entry.getKey(); - MemoryMap state = entry.getValue(); + MemoryMapImpl state = entry.getValue(); for (LocationIdentity location : modifiedLocations) { ValueNode lastAccessAtExit = state.lastMemorySnapshot.get(location); if (lastAccessAtExit != null) {