@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); } }
/** Special constructor for class Class */ public static DynamicObject createClassClass(RubyContext context) { final ModuleFields model = new ModuleFields(context, null, "Class"); final DynamicObject rubyClass = LAYOUT.newInstance(LAYOUT.createShape(new ObjectType())); final DynamicObjectFactory factory = Layouts.CLASS.createClassShape(rubyClass, rubyClass); rubyClass.setShapeAndGrow(rubyClass.getShape(), factory.getShape()); assert RubyGuards.isRubyModule(rubyClass); assert RubyGuards.isRubyClass(rubyClass); model.rubyModuleObject = rubyClass; Layouts.CLASS.setInstanceFactoryUnsafe(rubyClass, factory); Layouts.MODULE.setFields(rubyClass, model); model.name = model.givenBaseName; assert RubyGuards.isRubyModule(rubyClass); assert RubyGuards.isRubyClass(rubyClass); assert Layouts.MODULE.getFields(rubyClass) == model; assert Layouts.BASIC_OBJECT.getLogicalClass(rubyClass) == rubyClass; return rubyClass; }