changeset 18626:ce46f909c176

OM: record replaceProperty transitions
author Andreas Woess <andreas.woess@jku.at>
date Thu, 04 Dec 2014 19:31:45 +0100
parents 073e7f314516
children 196cf131ed32
files graal/com.oracle.truffle.object/src/com/oracle/truffle/object/ShapeImpl.java graal/com.oracle.truffle.object/src/com/oracle/truffle/object/Transition.java
diffstat 2 files changed, 13 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.truffle.object/src/com/oracle/truffle/object/ShapeImpl.java	Thu Dec 04 19:24:14 2014 +0100
+++ b/graal/com.oracle.truffle.object/src/com/oracle/truffle/object/ShapeImpl.java	Thu Dec 04 19:31:45 2014 +0100
@@ -526,10 +526,6 @@
         return getKeyList();
     }
 
-    public final void setTypeTransition(ShapeImpl successorShape, Property before, Property after) {
-        getTransitionMapForWrite().put(new Transition.PropertyTypeTransition(before, after), successorShape);
-    }
-
     @Override
     public final boolean isValid() {
         return getValidAssumption().isValid();
@@ -686,14 +682,20 @@
      * Duplicate shape exchanging existing property with new property.
      */
     @Override
-    public final ShapeImpl replaceProperty(Property oldProperty, Property newProp) {
+    public final ShapeImpl replaceProperty(Property oldProperty, Property newProperty) {
+        Transition replacePropertyTransition = new Transition.ReplacePropertyTransition(oldProperty, newProperty);
+        ShapeImpl cachedShape = getTransitionMapForRead().get(replacePropertyTransition);
+        if (cachedShape != null) {
+            return (ShapeImpl) layout.getStrategy().returnCached(cachedShape);
+        }
+
         ShapeImpl top = this;
         List<Transition> transitionList = new ArrayList<>();
         boolean found = false;
         while (top != getRoot() && !found) {
             Transition transition = top.getTransitionFromParent();
             transitionList.add(transition);
-            if (transition instanceof AddPropertyTransition && ((AddPropertyTransition) transition).getProperty().getKey().equals(newProp.getKey())) {
+            if (transition instanceof AddPropertyTransition && ((AddPropertyTransition) transition).getProperty().getKey().equals(newProperty.getKey())) {
                 found = true;
             }
             top = top.parent;
@@ -701,12 +703,13 @@
         ShapeImpl newShape = top;
         for (ListIterator<Transition> iterator = transitionList.listIterator(transitionList.size()); iterator.hasPrevious();) {
             Transition transition = iterator.previous();
-            if (transition instanceof AddPropertyTransition && ((AddPropertyTransition) transition).getProperty().getKey().equals(newProp.getKey())) {
-                newShape = newShape.addProperty(newProp);
+            if (transition instanceof AddPropertyTransition && ((AddPropertyTransition) transition).getProperty().getKey().equals(newProperty.getKey())) {
+                newShape = newShape.addProperty(newProperty);
             } else {
                 newShape = newShape.applyTransition(transition, false);
             }
         }
+        addIndirectTransition(replacePropertyTransition, newShape);
         return newShape;
     }
 
--- a/graal/com.oracle.truffle.object/src/com/oracle/truffle/object/Transition.java	Thu Dec 04 19:24:14 2014 +0100
+++ b/graal/com.oracle.truffle.object/src/com/oracle/truffle/object/Transition.java	Thu Dec 04 19:31:45 2014 +0100
@@ -133,10 +133,10 @@
         }
     }
 
-    public static final class PropertyTypeTransition extends PropertyTransition {
+    public static final class ReplacePropertyTransition extends PropertyTransition {
         private final Property after;
 
-        public PropertyTypeTransition(Property before, Property after) {
+        public ReplacePropertyTransition(Property before, Property after) {
             super(before);
             this.after = after;
         }