Search in sources :

Example 76 with DynamicObject

use of com.oracle.truffle.api.object.DynamicObject in project graal by oracle.

the class LayoutStrategy method reshapeAfterDelete.

/**
 * @since 0.17 or earlier
 */
protected void reshapeAfterDelete(DynamicObjectImpl object, ShapeImpl oldShape, ShapeImpl newShape, ShapeImpl deletedParentShape) {
    DynamicObject original = object.cloneWithShape(oldShape);
    object.setShapeAndResize(newShape);
    object.copyProperties(original, deletedParentShape);
}
Also used : DynamicObject(com.oracle.truffle.api.object.DynamicObject)

Example 77 with DynamicObject

use of com.oracle.truffle.api.object.DynamicObject in project graal by oracle.

the class ShapeProfiler method dump.

public void dump(PrintWriter out) {
    ShapeStats globalStats = new ShapeStats("Cumulative results for all shapes");
    for (DynamicObject obj : queue) {
        Shape shape = obj.getShape();
        globalStats.profile(shape);
    }
    globalStats.dump(out);
}
Also used : Shape(com.oracle.truffle.api.object.Shape) DynamicObject(com.oracle.truffle.api.object.DynamicObject)

Example 78 with DynamicObject

use of com.oracle.truffle.api.object.DynamicObject in project graal by oracle.

the class ShapeProfiler method dump.

public void dump(PrintWriter out, int topResults) {
    if (topResults > 0) {
        IdentityHashMap<Shape, ShapeStats> shapeMap = new IdentityHashMap<>();
        for (DynamicObject obj : queue) {
            Shape shape = obj.getShape();
            ShapeStats stats = shapeMap.get(shape);
            if (stats == null) {
                shapeMap.put(shape, stats = new ShapeStats(createLabel(shape)));
            }
            stats.profile(shape);
        }
        List<ShapeStats> allStats = new ArrayList<>(shapeMap.values());
        Collections.sort(allStats, new Comparator<ShapeStats>() {

            public int compare(ShapeStats a, ShapeStats b) {
                return Long.compare(b.objects, a.objects);
            }
        });
        int top = Math.min(topResults, allStats.size());
        ShapeStats avgStats = new ShapeStats("Cumulative results for top " + top + " shapes");
        for (int i = 0; i < top; i++) {
            ShapeStats stats = allStats.get(i);
            stats.setLabel("Shape " + (i + 1) + ": " + stats.getLabel());
            stats.dump(out);
            avgStats.add(stats);
        }
        avgStats.dump(out);
    }
    // Dump also cumulative results.
    dump(out);
}
Also used : Shape(com.oracle.truffle.api.object.Shape) DynamicObject(com.oracle.truffle.api.object.DynamicObject) IdentityHashMap(java.util.IdentityHashMap) ArrayList(java.util.ArrayList)

Example 79 with DynamicObject

use of com.oracle.truffle.api.object.DynamicObject in project graal by oracle.

the class DynamicObjectBasic method reshape.

@Override
protected final void reshape(ShapeImpl newShape) {
    reshapeCount.inc();
    ShapeImpl oldShape = getShape();
    ShapeImpl commonAncestor = ShapeImpl.findCommonAncestor(oldShape, newShape);
    if (ObjectStorageOptions.TraceReshape) {
        int limit = 200;
        PrintStream out = System.out;
        out.printf("RESHAPE\nOLD %s\nNEW %s\nLCA %s\nDIFF %s\n---\n", oldShape.toStringLimit(limit), newShape.toStringLimit(limit), commonAncestor.toStringLimit(limit), ShapeImpl.diff(oldShape, newShape));
    }
    DynamicObject original = this.cloneWithShape(oldShape);
    setShapeAndGrow(oldShape, newShape);
    assert !((newShape.hasPrimitiveArray() && newShape.getPrimitiveArrayCapacity() == 0)) || getPrimitiveStore(newShape) == null;
    copyProperties(original, commonAncestor);
    assert checkExtensionArrayInvariants(newShape);
}
Also used : PrintStream(java.io.PrintStream) DynamicObject(com.oracle.truffle.api.object.DynamicObject) ShapeImpl(com.oracle.truffle.object.ShapeImpl)

Example 80 with DynamicObject

use of com.oracle.truffle.api.object.DynamicObject in project graal by oracle.

the class Debug method dumpObject.

static String dumpObject(DynamicObject object, int level, int levelStop) {
    List<Property> properties = object.getShape().getPropertyListInternal(true);
    StringBuilder sb = new StringBuilder(properties.size() * 10);
    sb.append("{\n");
    for (Property property : properties) {
        indent(sb, level + 1);
        sb.append(property.getKey());
        sb.append('[').append(property.getLocation()).append(']');
        Object value = property.get(object, false);
        if (value instanceof DynamicObject) {
            if (level < levelStop) {
                value = dumpObject((DynamicObject) value, level + 1, levelStop);
            } else {
                value = value.toString();
            }
        }
        sb.append(": ");
        sb.append(value);
        if (property != properties.get(properties.size() - 1)) {
            sb.append(",");
        }
        sb.append("\n");
    }
    indent(sb, level);
    sb.append("}");
    return sb.toString();
}
Also used : DynamicObject(com.oracle.truffle.api.object.DynamicObject) DynamicObject(com.oracle.truffle.api.object.DynamicObject) Property(com.oracle.truffle.api.object.Property)

Aggregations

DynamicObject (com.oracle.truffle.api.object.DynamicObject)100 Test (org.junit.Test)91 Location (com.oracle.truffle.api.object.Location)17 Shape (com.oracle.truffle.api.object.Shape)16 DynamicObjectFactory (com.oracle.truffle.api.object.DynamicObjectFactory)8 ObjectLocation (com.oracle.truffle.api.object.ObjectLocation)7 Property (com.oracle.truffle.api.object.Property)7 ObjectType (com.oracle.truffle.api.object.ObjectType)6 IncompatibleLocationException (com.oracle.truffle.api.object.IncompatibleLocationException)4 Layout (com.oracle.truffle.api.object.Layout)4 FinalLocationException (com.oracle.truffle.api.object.FinalLocationException)2 PropertyBuilder (com.oracle.truffle.object.dsl.processor.model.PropertyBuilder)2 VariableElement (javax.lang.model.element.VariableElement)2 LocationFactory (com.oracle.truffle.api.object.LocationFactory)1 ShapeImpl (com.oracle.truffle.object.ShapeImpl)1 DefaultLayoutFactory (com.oracle.truffle.object.basic.DefaultLayoutFactory)1 PrintStream (java.io.PrintStream)1 ArrayList (java.util.ArrayList)1 IdentityHashMap (java.util.IdentityHashMap)1