@Specialization( guards = "object.getShape() == cachedShape", assumptions = "cachedShape.getValidAssumption()", limit = "CACHE_LIMIT") @ExplodeLoop protected void shareCached( DynamicObject object, @Cached("ensureSharedClasses(object.getShape())") Shape cachedShape, @Cached("createShareInternalFieldsNode()") ShareInternalFieldsNode shareInternalFieldsNode, @Cached("createReadAndShareFieldNodes(getObjectProperties(cachedShape))") ReadAndShareFieldNode[] readAndShareFieldNodes, @Cached("createSharedShape(object)") Shape sharedShape) { assert !SharedObjects.isShared(cachedShape); // Mark the object as shared first to avoid recursion object.setShapeAndGrow(cachedShape, sharedShape); shareInternalFieldsNode.executeShare(object); for (ReadAndShareFieldNode readAndShareFieldNode : readAndShareFieldNodes) { readAndShareFieldNode.executeReadFieldAndShare(object); } }
protected static Shape ensureSharedClasses(Shape shape) { final ObjectType objectType = shape.getObjectType(); SharedObjects.writeBarrier(Layouts.BASIC_OBJECT.getLogicalClass(objectType)); SharedObjects.writeBarrier(Layouts.BASIC_OBJECT.getMetaClass(objectType)); return shape; }
@Specialization(contains = {"shareCached", "updateShapeAndShare"}) protected void shareUncached(DynamicObject object) { SharedObjects.writeBarrier(object); }