changeset 22148:4125eb882b7e

Merge.
author Jaroslav Tulach <jaroslav.tulach@oracle.com>
date Mon, 14 Sep 2015 13:33:15 +0200
parents 5857f5ee9486 (current diff) 72a6b0e49d31 (diff)
children b84a11723d64
files
diffstat 7 files changed, 65 insertions(+), 90 deletions(-) [+]
line wrap: on
line diff
--- a/truffle/com.oracle.truffle.api.object/src/com/oracle/truffle/api/object/DynamicObject.java	Mon Sep 14 13:33:03 2015 +0200
+++ b/truffle/com.oracle.truffle.api.object/src/com/oracle/truffle/api/object/DynamicObject.java	Mon Sep 14 13:33:15 2015 +0200
@@ -103,24 +103,6 @@
     public abstract void define(Object key, Object value, int flags, LocationFactory locationFactory);
 
     /**
-     * Change property flags.
-     *
-     * @param key property identifier
-     * @param newFlags flags to be set
-     * @return {@code true} if successful or {@code false} if property not found
-     */
-    public abstract boolean changeFlags(Object key, int newFlags);
-
-    /**
-     * Change property flags.
-     *
-     * @param key property identifier
-     * @param flagsUpdateFunction function updating old flags to new flags
-     * @return {@code true} if successful or {@code false} if property not found
-     */
-    public abstract boolean changeFlags(Object key, FlagsFunction flagsUpdateFunction);
-
-    /**
      * Delete property.
      *
      * @param key property identifier
@@ -167,14 +149,4 @@
      * @param currentShape the object's current shape (must equal {@link #getShape()})
      */
     public abstract DynamicObject copy(Shape currentShape);
-
-    /**
-     * Represents an operation on a single {@code int}-valued operand that produces an {@code int}
-     * -valued result.
-     *
-     * For Java 7 compatibility (equivalent to IntUnaryOperator).
-     */
-    public interface FlagsFunction {
-        int apply(int t);
-    }
 }
--- a/truffle/com.oracle.truffle.api.object/src/com/oracle/truffle/api/object/Shape.java	Mon Sep 14 13:33:03 2015 +0200
+++ b/truffle/com.oracle.truffle.api.object/src/com/oracle/truffle/api/object/Shape.java	Mon Sep 14 13:33:15 2015 +0200
@@ -225,20 +225,6 @@
      */
     public abstract Object getMutex();
 
-    public abstract int getObjectArraySize();
-
-    public abstract int getObjectFieldSize();
-
-    public abstract int getPrimitiveArraySize();
-
-    public abstract int getPrimitiveFieldSize();
-
-    public abstract int getObjectArrayCapacity();
-
-    public abstract int getPrimitiveArrayCapacity();
-
-    public abstract boolean hasPrimitiveArray();
-
     /**
      * Are these two shapes related, i.e. do they have the same root?
      *
@@ -247,15 +233,35 @@
      */
     public abstract boolean isRelated(Shape other);
 
+    /**
+     * Try to merge two related shapes to a more general shape that has the same properties and can
+     * store at least the values of both shapes.
+     *
+     * @return this, other, or a new shape that is compatible with both shapes
+     */
     public abstract Shape tryMerge(Shape other);
 
+    /**
+     * Utility class to allocate locations in an object layout.
+     */
     public abstract static class Allocator {
         protected abstract Location locationForValue(Object value, boolean useFinal, boolean nonNull);
 
+        /**
+         * Create a new location compatible with the given initial value.
+         *
+         * @param value the initial value this location is going to be assigned
+         */
         public final Location locationForValue(Object value) {
             return locationForValue(value, false, value != null);
         }
 
+        /**
+         * Create a new location compatible with the given initial value.
+         *
+         * @param value the initial value this location is going to be assigned
+         * @param modifiers additional restrictions and semantics
+         */
         public final Location locationForValue(Object value, EnumSet<LocationModifier> modifiers) {
             assert value != null || !modifiers.contains(LocationModifier.NonNull);
             return locationForValue(value, modifiers.contains(LocationModifier.Final), modifiers.contains(LocationModifier.NonNull));
@@ -263,22 +269,45 @@
 
         protected abstract Location locationForType(Class<?> type, boolean useFinal, boolean nonNull);
 
+        /**
+         * Create a new location for a fixed type. It can only be assigned to values of this type.
+         *
+         * @param type the Java type this location must be compatible with (may be primitive)
+         */
         public final Location locationForType(Class<?> type) {
             return locationForType(type, false, false);
         }
 
+        /**
+         * Create a new location for a fixed type.
+         *
+         * @param type the Java type this location must be compatible with (may be primitive)
+         * @param modifiers additional restrictions and semantics
+         */
         public final Location locationForType(Class<?> type, EnumSet<LocationModifier> modifiers) {
             return locationForType(type, modifiers.contains(LocationModifier.Final), modifiers.contains(LocationModifier.NonNull));
         }
 
+        /**
+         * Creates a new location from a constant value. The value is stored in the shape rather
+         * than in the object.
+         */
         public abstract Location constantLocation(Object value);
 
+        /**
+         * Creates a new declared location with a default value. A declared location only assumes a
+         * type after the first set (initialization).
+         */
         public abstract Location declaredLocation(Object value);
 
+        /**
+         * Reserves space for the given location, so that it will not be available to subsequently
+         * allocated locations.
+         */
         public abstract Allocator addLocation(Location location);
 
         /**
-         * Creates an copy of this allocator.
+         * Creates an copy of this allocator state.
          */
         public abstract Allocator copy();
     }
--- a/truffle/com.oracle.truffle.object.basic/src/com/oracle/truffle/object/basic/DefaultStrategy.java	Mon Sep 14 13:33:03 2015 +0200
+++ b/truffle/com.oracle.truffle.object.basic/src/com/oracle/truffle/object/basic/DefaultStrategy.java	Mon Sep 14 13:33:15 2015 +0200
@@ -41,8 +41,8 @@
 
     private static boolean assertLocationInRange(Shape shape, Location location) {
         BasicLayout layout = (BasicLayout) shape.getLayout();
-        assert (shape.getPrimitiveFieldSize() + ((LocationImpl) location).primitiveFieldCount() <= layout.getPrimitiveFieldCount());
-        assert (shape.getObjectFieldSize() + ((LocationImpl) location).objectFieldCount() <= layout.getObjectFieldCount());
+        assert (((ShapeImpl) shape).getPrimitiveFieldSize() + ((LocationImpl) location).primitiveFieldCount() <= layout.getPrimitiveFieldCount());
+        assert (((ShapeImpl) shape).getObjectFieldSize() + ((LocationImpl) location).objectFieldCount() <= layout.getObjectFieldCount());
         return true;
     }
 
--- a/truffle/com.oracle.truffle.object.basic/src/com/oracle/truffle/object/basic/DynamicObjectBasic.java	Mon Sep 14 13:33:03 2015 +0200
+++ b/truffle/com.oracle.truffle.object.basic/src/com/oracle/truffle/object/basic/DynamicObjectBasic.java	Mon Sep 14 13:33:15 2015 +0200
@@ -91,8 +91,8 @@
     @Override
     protected final void growPrimitiveStore(Shape oldShape, Shape newShape) {
         assert ((ShapeImpl) newShape).hasPrimitiveArray();
-        int oldPrimitiveCapacity = oldShape.getPrimitiveArrayCapacity();
-        int newPrimitiveCapacity = newShape.getPrimitiveArrayCapacity();
+        int oldPrimitiveCapacity = ((ShapeImpl) oldShape).getPrimitiveArrayCapacity();
+        int newPrimitiveCapacity = ((ShapeImpl) newShape).getPrimitiveArrayCapacity();
         if (newPrimitiveCapacity == 0) {
             // due to obsolescence, we might have to reserve an empty primitive array slot
             this.setPrimitiveStore(null, newShape);
@@ -116,10 +116,10 @@
     @Override
     protected final void resizeObjectStore(Shape oldShape, Shape newShape) {
         Object[] newObjectStore = null;
-        int destinationCapacity = newShape.getObjectArrayCapacity();
+        int destinationCapacity = ((ShapeImpl) newShape).getObjectArrayCapacity();
         if (destinationCapacity != 0) {
             newObjectStore = new Object[destinationCapacity];
-            int sourceCapacity = oldShape.getObjectArrayCapacity();
+            int sourceCapacity = ((ShapeImpl) oldShape).getObjectArrayCapacity();
             if (sourceCapacity != 0) {
                 Object[] oldObjectStore = getObjectStore(newShape);
                 for (int i = 0; i < Math.min(sourceCapacity, destinationCapacity); ++i) {
@@ -148,12 +148,12 @@
 
     @Override
     protected final void resizePrimitiveStore(Shape oldShape, Shape newShape) {
-        assert newShape.hasPrimitiveArray();
+        assert ((ShapeImpl) newShape).hasPrimitiveArray();
         long[] newPrimitiveArray = null;
-        int destinationCapacity = newShape.getPrimitiveArrayCapacity();
+        int destinationCapacity = ((ShapeImpl) newShape).getPrimitiveArrayCapacity();
         if (destinationCapacity != 0) {
             newPrimitiveArray = new long[destinationCapacity];
-            int sourceCapacity = oldShape.getPrimitiveArrayCapacity();
+            int sourceCapacity = ((ShapeImpl) oldShape).getPrimitiveArrayCapacity();
             if (sourceCapacity != 0) {
                 long[] oldPrimitiveArray = this.getPrimitiveStore(newShape);
                 for (int i = 0; i < Math.min(sourceCapacity, destinationCapacity); ++i) {
@@ -184,11 +184,11 @@
     @Override
     protected final boolean checkExtensionArrayInvariants(Shape newShape) {
         assert getShape() == newShape;
-        assert (getObjectStore(newShape) == null && newShape.getObjectArrayCapacity() == 0) ||
-                        (getObjectStore(newShape) != null && getObjectStore(newShape).length == newShape.getObjectArrayCapacity());
-        if (newShape.hasPrimitiveArray()) {
-            assert (getPrimitiveStore(newShape) == null && newShape.getPrimitiveArrayCapacity() == 0) ||
-                            (getPrimitiveStore(newShape) != null && getPrimitiveStore(newShape).length == newShape.getPrimitiveArrayCapacity());
+        assert (getObjectStore(newShape) == null && ((ShapeImpl) newShape).getObjectArrayCapacity() == 0) ||
+                        (getObjectStore(newShape) != null && getObjectStore(newShape).length == ((ShapeImpl) newShape).getObjectArrayCapacity());
+        if (((ShapeImpl) newShape).hasPrimitiveArray()) {
+            assert (getPrimitiveStore(newShape) == null && ((ShapeImpl) newShape).getPrimitiveArrayCapacity() == 0) ||
+                            (getPrimitiveStore(newShape) != null && getPrimitiveStore(newShape).length == ((ShapeImpl) newShape).getPrimitiveArrayCapacity());
         }
         return true;
     }
@@ -200,7 +200,7 @@
         if (this.getObjectStore(currentShape) != null) {
             clone.setObjectStore(this.getObjectStore(currentShape).clone(), currentShape);
         }
-        if (currentShape.hasPrimitiveArray() && this.getPrimitiveStore(currentShape) != null) {
+        if (((ShapeImpl) currentShape).hasPrimitiveArray() && this.getPrimitiveStore(currentShape) != null) {
             clone.setPrimitiveStore(this.getPrimitiveStore(currentShape).clone(), currentShape);
         }
         return clone;
--- a/truffle/com.oracle.truffle.object/src/com/oracle/truffle/object/DynamicObjectImpl.java	Mon Sep 14 13:33:03 2015 +0200
+++ b/truffle/com.oracle.truffle.object/src/com/oracle/truffle/object/DynamicObjectImpl.java	Mon Sep 14 13:33:15 2015 +0200
@@ -184,7 +184,6 @@
         }
     }
 
-    @Override
     @TruffleBoundary
     public boolean changeFlags(Object id, int newFlags) {
         Shape oldShape = getShape();
@@ -201,24 +200,6 @@
         }
     }
 
-    @Override
-    @TruffleBoundary
-    public boolean changeFlags(Object id, FlagsFunction updateFunction) {
-        Shape oldShape = getShape();
-        Property existing = oldShape.getProperty(id);
-        if (existing != null) {
-            int newFlags = updateFunction.apply(existing.getFlags());
-            if (existing.getFlags() != newFlags) {
-                Property newProperty = existing.copyWithFlags(newFlags);
-                Shape newShape = oldShape.replaceProperty(existing, newProperty);
-                this.setShape(newShape);
-            }
-            return true;
-        } else {
-            return false;
-        }
-    }
-
     public String debugDump(int level) {
         return debugDump(0, level);
     }
--- a/truffle/com.oracle.truffle.object/src/com/oracle/truffle/object/ShapeImpl.java	Mon Sep 14 13:33:03 2015 +0200
+++ b/truffle/com.oracle.truffle.object/src/com/oracle/truffle/object/ShapeImpl.java	Mon Sep 14 13:33:15 2015 +0200
@@ -178,37 +178,30 @@
         }
     }
 
-    @Override
     public final int getObjectArraySize() {
         return objectArraySize;
     }
 
-    @Override
     public final int getObjectFieldSize() {
         return objectFieldSize;
     }
 
-    @Override
     public final int getPrimitiveFieldSize() {
         return primitiveFieldSize;
     }
 
-    @Override
     public final int getObjectArrayCapacity() {
         return objectArrayCapacity;
     }
 
-    @Override
     public final int getPrimitiveArrayCapacity() {
         return primitiveArrayCapacity;
     }
 
-    @Override
     public final int getPrimitiveArraySize() {
         return primitiveArraySize;
     }
 
-    @Override
     public final boolean hasPrimitiveArray() {
         return hasPrimitiveArray;
     }
--- a/truffle/com.oracle.truffle.object/src/com/oracle/truffle/object/debug/ShapeProfiler.java	Mon Sep 14 13:33:03 2015 +0200
+++ b/truffle/com.oracle.truffle.object/src/com/oracle/truffle/object/debug/ShapeProfiler.java	Mon Sep 14 13:33:15 2015 +0200
@@ -116,12 +116,12 @@
 
         public void profile(Shape shape) {
             jsObjects++;
-            oac += shape.getObjectArrayCapacity();
-            oas += shape.getObjectArraySize();
-            ofs += shape.getObjectFieldSize();
-            pac += shape.getPrimitiveArrayCapacity();
-            pas += shape.getPrimitiveArraySize();
-            pfs += shape.getPrimitiveFieldSize();
+            oac += ((ShapeImpl) shape).getObjectArrayCapacity();
+            oas += ((ShapeImpl) shape).getObjectArraySize();
+            ofs += ((ShapeImpl) shape).getObjectFieldSize();
+            pac += ((ShapeImpl) shape).getPrimitiveArrayCapacity();
+            pas += ((ShapeImpl) shape).getPrimitiveArraySize();
+            pfs += ((ShapeImpl) shape).getPrimitiveFieldSize();
         }
 
         public void add(ShapeStats stats) {