# HG changeset patch # User Andreas Woess # Date 1444241115 -7200 # Node ID cf203af4610c25642a6db00a8fd98e20e8f515b0 # Parent 47172a9b40aca2ee252d5c6505314fc11bd17ae4 avoid unnecessary casts diff -r 47172a9b40ac -r cf203af4610c truffle/com.oracle.truffle.object.basic/src/com/oracle/truffle/object/basic/DefaultStrategy.java --- a/truffle/com.oracle.truffle.object.basic/src/com/oracle/truffle/object/basic/DefaultStrategy.java Wed Oct 07 19:15:14 2015 +0200 +++ b/truffle/com.oracle.truffle.object.basic/src/com/oracle/truffle/object/basic/DefaultStrategy.java Wed Oct 07 20:05:15 2015 +0200 @@ -25,7 +25,6 @@ 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; import com.oracle.truffle.api.object.Property; import com.oracle.truffle.api.object.Shape; @@ -43,20 +42,20 @@ } @Override - public Shape ensureValid(Shape newShape) { + public ShapeImpl ensureValid(ShapeImpl newShape) { assert newShape.isValid(); return newShape; } - private static boolean assertLocationInRange(Shape shape, Location location) { + private static boolean assertLocationInRange(ShapeImpl shape, Location location) { BasicLayout layout = (BasicLayout) shape.getLayout(); - assert (((ShapeImpl) shape).getPrimitiveFieldSize() + ((LocationImpl) location).primitiveFieldCount() <= layout.getPrimitiveFieldCount()); - assert (((ShapeImpl) shape).getObjectFieldSize() + ((LocationImpl) location).objectFieldCount() <= layout.getObjectFieldCount()); + assert (shape.getPrimitiveFieldSize() + ((LocationImpl) location).primitiveFieldCount() <= layout.getPrimitiveFieldCount()); + assert (shape.getObjectFieldSize() + ((LocationImpl) location).objectFieldCount() <= layout.getObjectFieldCount()); return true; } @Override - public Shape ensureSpace(Shape shape, Location location) { + public ShapeImpl ensureSpace(ShapeImpl shape, Location location) { Objects.requireNonNull(location); assert assertLocationInRange(shape, location); return shape; @@ -68,7 +67,7 @@ } @Override - public ShapeAndProperty generalizeProperty(Property oldProperty, Object value, Shape currentShape, Shape nextShape) { + public ShapeAndProperty generalizeProperty(Property oldProperty, Object value, ShapeImpl currentShape, ShapeImpl nextShape) { Location oldLocation = oldProperty.getLocation(); Location newLocation = ((BasicAllocator) currentShape.allocator()).locationForValueUpcast(value, oldLocation); Property newProperty = oldProperty.relocate(newLocation); @@ -77,13 +76,13 @@ } @Override - public BaseAllocator createAllocator(Shape shape) { - return new DefaultAllocatorImpl((ShapeImpl) shape); + public BaseAllocator createAllocator(ShapeImpl shape) { + return new DefaultAllocatorImpl(shape); } @Override - public BaseAllocator createAllocator(Layout layout) { - return new DefaultAllocatorImpl((LayoutImpl) layout); + public BaseAllocator createAllocator(LayoutImpl layout) { + return new DefaultAllocatorImpl(layout); } public static class DefaultAllocatorImpl extends BasicAllocator { diff -r 47172a9b40ac -r cf203af4610c truffle/com.oracle.truffle.object/src/com/oracle/truffle/object/LayoutStrategy.java --- a/truffle/com.oracle.truffle.object/src/com/oracle/truffle/object/LayoutStrategy.java Wed Oct 07 19:15:14 2015 +0200 +++ b/truffle/com.oracle.truffle.object/src/com/oracle/truffle/object/LayoutStrategy.java Wed Oct 07 20:05:15 2015 +0200 @@ -23,7 +23,6 @@ package com.oracle.truffle.object; import com.oracle.truffle.api.object.DynamicObject; -import com.oracle.truffle.api.object.Layout; import com.oracle.truffle.api.object.Location; import com.oracle.truffle.api.object.Property; import com.oracle.truffle.api.object.Shape; @@ -32,17 +31,17 @@ public abstract class LayoutStrategy { public abstract boolean updateShape(DynamicObject object); - public abstract Shape ensureValid(Shape newShape); + public abstract ShapeImpl ensureValid(ShapeImpl newShape); - public abstract Shape ensureSpace(Shape shape, Location location); + public abstract ShapeImpl ensureSpace(ShapeImpl shape, Location location); public abstract boolean isAutoExtArray(); - public abstract BaseAllocator createAllocator(Layout shape); + public abstract BaseAllocator createAllocator(LayoutImpl shape); - public abstract BaseAllocator createAllocator(Shape shape); + public abstract BaseAllocator createAllocator(ShapeImpl shape); - protected abstract ShapeAndProperty generalizeProperty(Property oldProperty, Object value, Shape currentShape, Shape nextShape); + protected abstract ShapeAndProperty generalizeProperty(Property oldProperty, Object value, ShapeImpl currentShape, ShapeImpl nextShape); public static class ShapeAndProperty { private final Shape shape; diff -r 47172a9b40ac -r cf203af4610c truffle/com.oracle.truffle.object/src/com/oracle/truffle/object/PropertyImpl.java --- a/truffle/com.oracle.truffle.object/src/com/oracle/truffle/object/PropertyImpl.java Wed Oct 07 19:15:14 2015 +0200 +++ b/truffle/com.oracle.truffle.object/src/com/oracle/truffle/object/PropertyImpl.java Wed Oct 07 20:05:15 2015 +0200 @@ -228,7 +228,7 @@ oldShape = store.getShape(); } LayoutStrategy strategy = ((LayoutImpl) currentShape.getLayout()).getStrategy(); - LayoutStrategy.ShapeAndProperty newShapeAndProperty = strategy.generalizeProperty(this, value, oldShape, nextShape); + LayoutStrategy.ShapeAndProperty newShapeAndProperty = strategy.generalizeProperty(this, value, (ShapeImpl) oldShape, (ShapeImpl) nextShape); if (store.updateShape()) { oldShape = store.getShape(); } diff -r 47172a9b40ac -r cf203af4610c truffle/com.oracle.truffle.object/src/com/oracle/truffle/object/ShapeImpl.java --- a/truffle/com.oracle.truffle.object/src/com/oracle/truffle/object/ShapeImpl.java Wed Oct 07 19:15:14 2015 +0200 +++ b/truffle/com.oracle.truffle.object/src/com/oracle/truffle/object/ShapeImpl.java Wed Oct 07 20:05:15 2015 +0200 @@ -314,7 +314,7 @@ ShapeImpl cachedShape = this.getTransitionMapForRead().get(transition); if (cachedShape != null) { // Shape already exists? shapeCacheHitCount.inc(); - return (ShapeImpl) layout.getStrategy().ensureValid(cachedShape); + return layout.getStrategy().ensureValid(cachedShape); } shapeCacheMissCount.inc(); @@ -352,7 +352,7 @@ public ShapeImpl defineProperty(Object key, Object value, int flags, LocationFactory locationFactory) { ShapeImpl oldShape = this; if (!oldShape.isValid()) { - oldShape = (ShapeImpl) layout.getStrategy().ensureValid(oldShape); + oldShape = layout.getStrategy().ensureValid(oldShape); } PropertyImpl existing = (PropertyImpl) oldShape.getProperty(key); if (existing == null) { @@ -393,7 +393,7 @@ return cachedShape; } - ShapeImpl oldShape = (ShapeImpl) layout.getStrategy().ensureSpace(this, prop.getLocation()); + ShapeImpl oldShape = layout.getStrategy().ensureSpace(this, prop.getLocation()); ShapeImpl newShape = makeShapeWithAddedProperty(oldShape, addTransition); oldShape.addDirectTransition(addTransition, newShape); @@ -460,7 +460,7 @@ return cachedShape; } - ShapeImpl oldShape = (ShapeImpl) layout.getStrategy().ensureSpace(this, layout.getPrimitiveArrayLocation()); + ShapeImpl oldShape = layout.getStrategy().ensureSpace(this, layout.getPrimitiveArrayLocation()); ShapeImpl newShape = makeShapeWithPrimitiveExtensionArray(oldShape, transition); oldShape.addDirectTransition(transition, newShape); return newShape;