/** * Set the given variable index into the specified object. The "real" class * and index are pass in to provide functional access. * * @param self the object into which to set the variable * @param realClass the "real" class for the object * @param index the index of the variable * @param value the variable's value */ public static void setVariable(RubyBasicObject self, RubyClass realClass, int index, Object value) { while (true) { int currentStamp = self.varTableStamp; // spin-wait if odd if((currentStamp & 0x01) != 0) continue; Object[] currentTable = (Object[]) UnsafeHolder.U.getObjectVolatile(self, RubyBasicObject.VAR_TABLE_OFFSET); if (currentTable == null || index >= currentTable.length) { if (!createTableUnsafe(self, currentStamp, realClass, currentTable, index, value)) continue; } else { if (!updateTable(self, currentStamp, currentTable, index, value)) continue; } break; } }
/** * Set this variable into the given object using Unsafe to ensure * safe creation or growth of the variable table. * * @param object the object into which to set this variable * @param value the variable's value */ public void set(Object object, Object value) { ((RubyBasicObject) object).ensureInstanceVariablesSettable(); setVariable((RubyBasicObject) object, realClass, index, value); }
newVariableAccessor = new NonvolatileVariableAccessor(realClass, name, newIndex, id); } else {
newVariableAccessor = new NonvolatileVariableAccessor(realClass, name, newIndex, id); } else {
/** * Set the given variable index into the specified object. The "real" class * and index are pass in to provide functional access. * * @param self the object into which to set the variable * @param realClass the "real" class for the object * @param index the index of the variable * @param value the variable's value */ public static void setVariable(RubyBasicObject self, RubyClass realClass, int index, Object value) { while (true) { int currentStamp = self.varTableStamp; // spin-wait if odd if((currentStamp & 0x01) != 0) continue; Object[] currentTable = (Object[]) UnsafeHolder.U.getObjectVolatile(self, RubyBasicObject.VAR_TABLE_OFFSET); if (currentTable == null || index >= currentTable.length) { if (!createTableUnsafe(self, currentStamp, realClass, currentTable, index, value)) continue; } else { if (!updateTable(self, currentStamp, currentTable, index, value)) continue; } break; } }
/** * Set this variable into the given object using Unsafe to ensure * safe creation or growth of the variable table. * * @param object the object into which to set this variable * @param value the variable's value */ public void set(Object object, Object value) { ((RubyBasicObject) object).ensureInstanceVariablesSettable(); setVariable((RubyBasicObject) object, realClass, index, value); }
/** * Set the given variable index into the specified object. The "real" class * and index are pass in to provide functional access. This version checks * if self has been frozen before proceeding to set the variable. * * @param self the object into which to set the variable * @param realClass the "real" class for the object * @param index the index of the variable * @param value the variable's value */ public static void setVariableChecked(RubyBasicObject self, RubyClass realClass, int index, Object value) { self.ensureInstanceVariablesSettable(); setVariable(self, realClass, index, value); }
/** * Set the given variable index into the specified object. The "real" class * and index are pass in to provide functional access. This version checks * if self has been frozen before proceeding to set the variable. * * @param self the object into which to set the variable * @param realClass the "real" class for the object * @param index the index of the variable * @param value the variable's value */ public static void setVariableChecked(RubyBasicObject self, RubyClass realClass, int index, Object value) { self.ensureInstanceVariablesSettable(); setVariable(self, realClass, index, value); }