# HG changeset patch # User twisti # Date 1375226202 25200 # Node ID 3e407b9c3b13b7c206a220108edbb092c15791b1 # Parent 19a7856e3ab9d59650ecc8bcf7c400868ae4d2e5 GRAAL-375: volatile read is moved out of loop diff -r 19a7856e3ab9 -r 3e407b9c3b13 graal/com.oracle.graal.virtual/src/com/oracle/graal/virtual/phases/ea/PEReadEliminationClosure.java --- a/graal/com.oracle.graal.virtual/src/com/oracle/graal/virtual/phases/ea/PEReadEliminationClosure.java Tue Jul 30 16:15:01 2013 -0700 +++ b/graal/com.oracle.graal.virtual/src/com/oracle/graal/virtual/phases/ea/PEReadEliminationClosure.java Tue Jul 30 16:16:42 2013 -0700 @@ -55,27 +55,35 @@ if (!deleted) { if (node instanceof LoadFieldNode) { LoadFieldNode load = (LoadFieldNode) node; - ValueNode object = GraphUtil.unproxify(load.object()); - ValueNode cachedValue = state.getReadCache(object, load.field()); - if (cachedValue != null) { - effects.replaceAtUsages(load, cachedValue); - state.addScalarAlias(load, cachedValue); - deleted = true; + if (!load.isVolatile()) { + ValueNode object = GraphUtil.unproxify(load.object()); + ValueNode cachedValue = state.getReadCache(object, load.field()); + if (cachedValue != null) { + effects.replaceAtUsages(load, cachedValue); + state.addScalarAlias(load, cachedValue); + deleted = true; + } else { + state.addReadCache(object, load.field(), load); + } } else { - state.addReadCache(object, load.field(), load); + processIdentity(state, ANY_LOCATION); } } else if (node instanceof StoreFieldNode) { StoreFieldNode store = (StoreFieldNode) node; - ValueNode object = GraphUtil.unproxify(store.object()); - ValueNode cachedValue = state.getReadCache(object, store.field()); + if (!store.isVolatile()) { + ValueNode object = GraphUtil.unproxify(store.object()); + ValueNode cachedValue = state.getReadCache(object, store.field()); - ValueNode value = state.getScalarAlias(store.value()); - if (GraphUtil.unproxify(value) == GraphUtil.unproxify(cachedValue)) { - effects.deleteFixedNode(store); - deleted = true; + ValueNode value = state.getScalarAlias(store.value()); + if (GraphUtil.unproxify(value) == GraphUtil.unproxify(cachedValue)) { + effects.deleteFixedNode(store); + deleted = true; + } + state.killReadCache(store.field()); + state.addReadCache(object, store.field(), value); + } else { + processIdentity(state, ANY_LOCATION); } - state.killReadCache(store.field()); - state.addReadCache(object, store.field(), value); } else if (node instanceof MemoryCheckpoint.Single) { METRIC_MEMORYCHECKOINT.increment(); LocationIdentity identity = ((MemoryCheckpoint.Single) node).getLocationIdentity(); diff -r 19a7856e3ab9 -r 3e407b9c3b13 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 Tue Jul 30 16:15:01 2013 -0700 +++ b/graal/com.oracle.graal.virtual/src/com/oracle/graal/virtual/phases/ea/ReadEliminationClosure.java Tue Jul 30 16:16:42 2013 -0700 @@ -55,29 +55,37 @@ boolean deleted = false; if (node instanceof LoadFieldNode) { LoadFieldNode load = (LoadFieldNode) node; - ValueNode object = GraphUtil.unproxify(load.object()); - LoadCacheEntry identifier = new LoadCacheEntry(object, load.field()); - ValueNode cachedValue = state.getCacheEntry(identifier); - if (cachedValue != null) { - effects.replaceAtUsages(load, cachedValue); - state.addScalarAlias(load, cachedValue); - deleted = true; + if (!load.isVolatile()) { + ValueNode object = GraphUtil.unproxify(load.object()); + LoadCacheEntry identifier = new LoadCacheEntry(object, load.field()); + ValueNode cachedValue = state.getCacheEntry(identifier); + if (cachedValue != null) { + effects.replaceAtUsages(load, cachedValue); + state.addScalarAlias(load, cachedValue); + deleted = true; + } else { + state.addCacheEntry(identifier, load); + } } else { - state.addCacheEntry(identifier, load); + processIdentity(state, ANY_LOCATION); } } else if (node instanceof StoreFieldNode) { StoreFieldNode store = (StoreFieldNode) node; - ValueNode object = GraphUtil.unproxify(store.object()); - LoadCacheEntry identifier = new LoadCacheEntry(object, store.field()); - ValueNode cachedValue = state.getCacheEntry(identifier); + if (!store.isVolatile()) { + ValueNode object = GraphUtil.unproxify(store.object()); + LoadCacheEntry identifier = new LoadCacheEntry(object, store.field()); + ValueNode cachedValue = state.getCacheEntry(identifier); - ValueNode value = state.getScalarAlias(store.value()); - if (GraphUtil.unproxify(value) == GraphUtil.unproxify(cachedValue)) { - effects.deleteFixedNode(store); - deleted = true; + ValueNode value = state.getScalarAlias(store.value()); + if (GraphUtil.unproxify(value) == GraphUtil.unproxify(cachedValue)) { + effects.deleteFixedNode(store); + deleted = true; + } + state.killReadCache((LocationIdentity) store.field()); + state.addCacheEntry(identifier, value); + } else { + processIdentity(state, ANY_LOCATION); } - state.killReadCache((LocationIdentity) store.field()); - state.addCacheEntry(identifier, value); } else if (node instanceof ReadNode) { ReadNode read = (ReadNode) node; if (read.location() instanceof ConstantLocationNode) { @@ -104,13 +112,14 @@ effects.deleteFixedNode(write); deleted = true; } - state.killReadCache(write.location().getLocationIdentity()); + processIdentity(state, write.location().getLocationIdentity()); state.addCacheEntry(identifier, value); } else { - state.killReadCache(write.location().getLocationIdentity()); + processIdentity(state, write.location().getLocationIdentity()); } } else if (node instanceof MemoryCheckpoint.Single) { - processIdentity(state, ((MemoryCheckpoint.Single) node).getLocationIdentity()); + LocationIdentity identity = ((MemoryCheckpoint.Single) node).getLocationIdentity(); + processIdentity(state, identity); } else if (node instanceof MemoryCheckpoint.Multi) { for (LocationIdentity identity : ((MemoryCheckpoint.Multi) node).getLocationIdentities()) { processIdentity(state, identity);