Class StampedVariableAccessor

java.lang.Object
org.jruby.runtime.ivars.VariableAccessor
org.jruby.runtime.ivars.StampedVariableAccessor

public class StampedVariableAccessor extends VariableAccessor
A variable accessor that uses a stamped volatile int and Unsafe methods to ensure thread-friendly table updating.
  • Constructor Details

    • StampedVariableAccessor

      public StampedVariableAccessor(RubyClass realClass, String name, int index, int classId)
      Construct a new StampedVariableAccessor for the given "real" class, variable name, variable index, and class ID.
      Parameters:
      realClass - the "real" class
      name - the variable's name
      index - the variable's index
      classId - the class's ID
  • Method Details

    • set

      public void set(Object object, Object value)
      Set this variable into the given object using Unsafe to ensure safe updating of the variable table.
      Overrides:
      set in class VariableAccessor
      Parameters:
      object - the object into which to set this variable
      value - the variable's value
    • setVariableChecked

      public static void setVariableChecked(RubyBasicObject self, RubyClass realClass, int index, Object 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.
      Parameters:
      self - the object into which to set the variable
      realClass - the "real" class for the object
      index - the index of the variable
      value - the variable's value
    • setVariable

      public static void setVariable(RubyBasicObject self, RubyClass realClass, int index, Object value)
      Set the given variable index into the specified object. The "real" class and index are pass in to provide functional access.
      Parameters:
      self - the object into which to set the variable
      realClass - the "real" class for the object
      index - the index of the variable
      value - the variable's value
    • createTableUnsafe

      private static boolean createTableUnsafe(RubyBasicObject self, int currentStamp, RubyClass realClass, Object[] currentTable, int index, Object value)
      Create or exapand a table for the given object, using Unsafe CAS and ordering operations to ensure visibility.
      Parameters:
      self - the object into which to set the variable
      currentStamp - the current variable table stamp
      realClass - the "real" class for the object
      currentTable - the current table
      index - the index of the variable
      value - the variable's value
      Returns:
      whether the update was successful, for CAS retrying
    • updateTableUnsafe

      private static boolean updateTableUnsafe(RubyBasicObject self, int currentStamp, Object[] currentTable, int index, Object value)
      Update the given table table for the given object, using Unsafe fence or volatile operations to ensure visibility.
      Parameters:
      self - the object into which to set the variable
      currentStamp - the current variable table stamp
      currentTable - the current table
      index - the index of the variable
      value - the variable's value
      Returns:
      whether the update was successful, for CAS retrying