changeset 16889:3d190fc2e081

Consider the offset when performing read elimination on unsafes
author Tom Rodriguez <tom.rodriguez@oracle.com>
date Thu, 21 Aug 2014 18:02:22 -0700
parents 8f4150982bc3
children 39e70c987476
files graal/com.oracle.graal.virtual/src/com/oracle/graal/virtual/phases/ea/ReadEliminationBlockState.java graal/com.oracle.graal.virtual/src/com/oracle/graal/virtual/phases/ea/ReadEliminationClosure.java
diffstat 2 files changed, 29 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.virtual/src/com/oracle/graal/virtual/phases/ea/ReadEliminationBlockState.java	Thu Aug 21 17:50:00 2014 -0700
+++ b/graal/com.oracle.graal.virtual/src/com/oracle/graal/virtual/phases/ea/ReadEliminationBlockState.java	Thu Aug 21 18:02:22 2014 -0700
@@ -84,6 +84,32 @@
         }
     }
 
+    /**
+     * CacheEntry describing an Unsafe memory reference. The memory location and the location
+     * identity are separate so both must be considered when looking for optimizable memory
+     * accesses.
+     *
+     */
+    static class UnsafeLoadCacheEntry extends CacheEntry<ValueNode> {
+
+        private LocationIdentity locationIdentity;
+
+        public UnsafeLoadCacheEntry(ValueNode object, ValueNode location, LocationIdentity locationIdentity) {
+            super(object, location);
+            this.locationIdentity = locationIdentity;
+        }
+
+        @Override
+        public CacheEntry<ValueNode> duplicateWithObject(ValueNode newObject) {
+            return new UnsafeLoadCacheEntry(newObject, identity, locationIdentity);
+        }
+
+        @Override
+        public boolean conflicts(LocationIdentity other) {
+            return locationIdentity == other;
+        }
+    }
+
     static class ReadCacheEntry extends CacheEntry<LocationNode> {
 
         public ReadCacheEntry(ValueNode object, LocationNode identity) {
--- a/graal/com.oracle.graal.virtual/src/com/oracle/graal/virtual/phases/ea/ReadEliminationClosure.java	Thu Aug 21 17:50:00 2014 -0700
+++ b/graal/com.oracle.graal.virtual/src/com/oracle/graal/virtual/phases/ea/ReadEliminationClosure.java	Thu Aug 21 18:02:22 2014 -0700
@@ -37,6 +37,7 @@
 import com.oracle.graal.virtual.phases.ea.ReadEliminationBlockState.CacheEntry;
 import com.oracle.graal.virtual.phases.ea.ReadEliminationBlockState.LoadCacheEntry;
 import com.oracle.graal.virtual.phases.ea.ReadEliminationBlockState.ReadCacheEntry;
+import com.oracle.graal.virtual.phases.ea.ReadEliminationBlockState.UnsafeLoadCacheEntry;
 
 public class ReadEliminationClosure extends EffectsClosure<ReadEliminationBlockState> {
 
@@ -121,7 +122,7 @@
                 UnsafeLoadNode load = (UnsafeLoadNode) node;
                 if (load.offset().isConstant() && load.getLocationIdentity() != LocationIdentity.ANY_LOCATION) {
                     ValueNode object = GraphUtil.unproxify(load.object());
-                    LoadCacheEntry identifier = new LoadCacheEntry(object, load.getLocationIdentity());
+                    UnsafeLoadCacheEntry identifier = new UnsafeLoadCacheEntry(object, load.offset(), load.getLocationIdentity());
                     ValueNode cachedValue = state.getCacheEntry(identifier);
                     if (cachedValue != null) {
                         effects.replaceAtUsages(load, cachedValue);
@@ -136,7 +137,7 @@
                 UnsafeStoreNode write = (UnsafeStoreNode) node;
                 if (write.offset().isConstant() && write.getLocationIdentity() != LocationIdentity.ANY_LOCATION) {
                     ValueNode object = GraphUtil.unproxify(write.object());
-                    LoadCacheEntry identifier = new LoadCacheEntry(object, write.getLocationIdentity());
+                    UnsafeLoadCacheEntry identifier = new UnsafeLoadCacheEntry(object, write.offset(), write.getLocationIdentity());
                     ValueNode cachedValue = state.getCacheEntry(identifier);
 
                     ValueNode value = getScalarAlias(write.value());