Mercurial > hg > truffle
diff truffle/com.oracle.truffle.object.basic/src/com/oracle/truffle/object/basic/DefaultStrategy.java @ 22288:47172a9b40ac
Object model refactoring, add Shape#defineProperty
author | Andreas Woess <andreas.woess@oracle.com> |
---|---|
date | Wed, 07 Oct 2015 19:15:14 +0200 |
parents | dc83cc1f94f2 |
children | cf203af4610c |
line wrap: on
line diff
--- a/truffle/com.oracle.truffle.object.basic/src/com/oracle/truffle/object/basic/DefaultStrategy.java Wed Oct 07 20:27:40 2015 +0200 +++ b/truffle/com.oracle.truffle.object.basic/src/com/oracle/truffle/object/basic/DefaultStrategy.java Wed Oct 07 19:15:14 2015 +0200 @@ -22,6 +22,8 @@ */ package com.oracle.truffle.object.basic; +import java.util.Objects; + import com.oracle.truffle.api.object.DynamicObject; import com.oracle.truffle.api.object.Layout; import com.oracle.truffle.api.object.Location; @@ -32,15 +34,16 @@ import com.oracle.truffle.object.LocationImpl; import com.oracle.truffle.object.ShapeImpl; import com.oracle.truffle.object.ShapeImpl.BaseAllocator; -import java.util.Objects; -class DefaultStrategy implements LayoutStrategy { +class DefaultStrategy extends LayoutStrategy { + @Override public boolean updateShape(DynamicObject object) { assert object.getShape().isValid(); return false; } - public Shape returnCached(Shape newShape) { + @Override + public Shape ensureValid(Shape newShape) { assert newShape.isValid(); return newShape; } @@ -52,39 +55,33 @@ return true; } + @Override public Shape ensureSpace(Shape shape, Location location) { Objects.requireNonNull(location); assert assertLocationInRange(shape, location); return shape; } + @Override public boolean isAutoExtArray() { return false; } - public Property generalizeProperty(DynamicObject object, Property oldProperty, Object value) { - Shape oldShape = object.getShape(); - Location oldLocation = oldProperty.getLocation(); - Location newLocation = ((BasicAllocator) oldShape.allocator()).locationForValueUpcast(value, oldLocation); - Property newProperty = oldProperty.relocate(newLocation); - Shape newShape = oldShape.replaceProperty(oldProperty, newProperty); - newProperty.setSafe(object, value, oldShape, newShape); - return newProperty; - } - - public Property generalizeProperty(DynamicObject object, Property oldProperty, Object value, Shape currentShape, Shape oldNewShape) { + @Override + public ShapeAndProperty generalizeProperty(Property oldProperty, Object value, Shape currentShape, Shape nextShape) { Location oldLocation = oldProperty.getLocation(); Location newLocation = ((BasicAllocator) currentShape.allocator()).locationForValueUpcast(value, oldLocation); Property newProperty = oldProperty.relocate(newLocation); - Shape newShape = oldNewShape.replaceProperty(oldProperty, newProperty); - newProperty.setSafe(object, value, currentShape, newShape); - return newProperty; + Shape newShape = nextShape.replaceProperty(oldProperty, newProperty); + return new ShapeAndProperty(newShape, newProperty); } + @Override public BaseAllocator createAllocator(Shape shape) { return new DefaultAllocatorImpl((ShapeImpl) shape); } + @Override public BaseAllocator createAllocator(Layout layout) { return new DefaultAllocatorImpl((LayoutImpl) layout); }