Mercurial > hg > truffle
changeset 22366:78306843f20c
minor Shape refactoring
author | Andreas Woess <andreas.woess@oracle.com> |
---|---|
date | Fri, 13 Nov 2015 15:36:25 +0100 |
parents | c9ba649b0dc1 |
children | 1b48778cee21 |
files | truffle/com.oracle.truffle.object.basic/src/com/oracle/truffle/object/basic/ShapeBasic.java truffle/com.oracle.truffle.object/src/com/oracle/truffle/object/ShapeImpl.java |
diffstat | 2 files changed, 10 insertions(+), 46 deletions(-) [+] |
line wrap: on
line diff
--- a/truffle/com.oracle.truffle.object.basic/src/com/oracle/truffle/object/basic/ShapeBasic.java Fri Nov 13 14:41:11 2015 +0100 +++ b/truffle/com.oracle.truffle.object.basic/src/com/oracle/truffle/object/basic/ShapeBasic.java Fri Nov 13 15:36:25 2015 +0100 @@ -24,7 +24,6 @@ import com.oracle.truffle.api.object.Layout; import com.oracle.truffle.api.object.ObjectType; -import com.oracle.truffle.api.object.Property; import com.oracle.truffle.object.PropertyMap; import com.oracle.truffle.object.ShapeImpl; import com.oracle.truffle.object.Transition; @@ -43,9 +42,4 @@ protected ShapeImpl createShape(Layout layout, Object sharedData, ShapeImpl parent, ObjectType objectType, PropertyMap propertyMap, Transition transition, Allocator allocator, int id) { return new ShapeBasic(layout, sharedData, parent, objectType, propertyMap, transition, allocator, id); } - - @Override - public ShapeImpl replaceProperty(Property oldProperty, Property newProperty) { - return directReplaceProperty(oldProperty, newProperty); - } }
--- a/truffle/com.oracle.truffle.object/src/com/oracle/truffle/object/ShapeImpl.java Fri Nov 13 14:41:11 2015 +0100 +++ b/truffle/com.oracle.truffle.object/src/com/oracle/truffle/object/ShapeImpl.java Fri Nov 13 15:36:25 2015 +0100 @@ -313,10 +313,14 @@ } protected final ShapeImpl queryTransition(Transition transition) { + return queryTransition(transition, true); + } + + protected final ShapeImpl queryTransition(Transition transition, boolean ensureValid) { ShapeImpl cachedShape = this.getTransitionMapForRead().get(transition); if (cachedShape != null) { // Shape already exists? shapeCacheHitCount.inc(); - return layout.getStrategy().ensureValid(cachedShape); + return ensureValid ? layout.getStrategy().ensureValid(cachedShape) : cachedShape; } shapeCacheMissCount.inc(); @@ -334,7 +338,7 @@ public ShapeImpl addProperty(Property property) { assert isValid(); onPropertyTransition(property); - return addPropertyInternal(property); + return addPropertyInternal(property, true); } private void onPropertyTransition(Property property) { @@ -385,12 +389,12 @@ * * @see #addProperty(Property) */ - private ShapeImpl addPropertyInternal(Property prop) { + private ShapeImpl addPropertyInternal(Property prop, boolean ensureValid) { CompilerAsserts.neverPartOfCompilation(); assert prop.isShadow() || !(this.hasProperty(prop.getKey())) : "duplicate property " + prop.getKey(); AddPropertyTransition addTransition = new AddPropertyTransition(prop); - ShapeImpl cachedShape = queryTransition(addTransition); + ShapeImpl cachedShape = queryTransition(addTransition, ensureValid); if (cachedShape != null) { return cachedShape; } @@ -709,7 +713,7 @@ public final ShapeImpl applyTransition(Transition transition, boolean append) { if (transition instanceof AddPropertyTransition) { - return append ? append(((AddPropertyTransition) transition).getProperty()) : addProperty(((AddPropertyTransition) transition).getProperty()); + return append ? append(((AddPropertyTransition) transition).getProperty()) : addPropertyInternal(((AddPropertyTransition) transition).getProperty(), false); } else if (transition instanceof ObjectTypeTransition) { return changeType(((ObjectTypeTransition) transition).getObjectType()); } else if (transition instanceof ReservePrimitiveArrayTransition) { @@ -738,41 +742,7 @@ */ @Override public ShapeImpl replaceProperty(Property oldProperty, Property newProperty) { - return indirectReplaceProperty(oldProperty, newProperty); - } - - protected final ShapeImpl indirectReplaceProperty(Property oldProperty, Property newProperty) { - assert oldProperty.getKey().equals(newProperty.getKey()); - - Transition replacePropertyTransition = new Transition.IndirectReplacePropertyTransition(oldProperty, newProperty); - ShapeImpl cachedShape = queryTransition(replacePropertyTransition); - if (cachedShape != null) { - return 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(newProperty.getKey())) { - found = true; - } - top = top.parent; - } - 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(newProperty.getKey())) { - newShape = newShape.addProperty(newProperty); - } else { - newShape = newShape.applyTransition(transition, false); - } - } - - addIndirectTransition(replacePropertyTransition, newShape); - return newShape; + return directReplaceProperty(oldProperty, newProperty); } protected final ShapeImpl directReplaceProperty(Property oldProperty, Property newProperty) {