# HG changeset patch # User Andreas Woess # Date 1417717905 -3600 # Node ID ce46f909c1765d4556623bf3c6c35b4c4bc9c9f9 # Parent 073e7f314516c17ca1aa0c820bbcb20542934dd1 OM: record replaceProperty transitions diff -r 073e7f314516 -r ce46f909c176 graal/com.oracle.truffle.object/src/com/oracle/truffle/object/ShapeImpl.java --- 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 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 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; } diff -r 073e7f314516 -r ce46f909c176 graal/com.oracle.truffle.object/src/com/oracle/truffle/object/Transition.java --- 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; }