/** * We lazily stand up the object ID since it forces us to stand up * per-object state for a given object. We also check for ObjectSpace here, * and normally we do not register a given object ID into ObjectSpace due * to the high cost associated with constructing the related weakref. Most * uses of id/object_id will only ever need it to be a unique identifier, * and the id2ref behavior provided by ObjectSpace is considered internal * and not generally supported. * * @param objectIdAccessor The variable accessor to use for storing the * generated object ID * @return The generated object ID */ protected synchronized long initObjectId(RubyBasicObject self, VariableAccessor objectIdAccessor) { Ruby runtime = self.getRuntime(); long id; if (runtime.isObjectSpaceEnabled()) { id = runtime.getObjectSpace().createAndRegisterObjectId(self); } else { id = ObjectSpace.calculateObjectId(self); } // we use a direct path here to avoid frozen checks setObjectId(realClass, self, objectIdAccessor.getIndex(), id); return id; }
setObjectId(realClass, self, objectIdAccessor.getIndex(), id);
setObjectId(realClass, self, objectIdAccessor.getIndex(), id);
setObjectId(realClass, self, objectIdAccessor.getIndex(), id);