Class SynchronizedVariableAccessor

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

public class SynchronizedVariableAccessor extends VariableAccessor
A VariableAccessor that uses synchronization to ensure the variable table is updated safely.
  • Constructor Details

    • SynchronizedVariableAccessor

      public SynchronizedVariableAccessor(RubyClass realClass, String name, int index, int classId)
      Construct a new SynchronizedVariableAccessor 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 synchronization 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
    • ensureTable

      private static Object[] ensureTable(RubyBasicObject self, RubyClass realClass, int index)
      Ensure the variable table is ready to receive the given variable index.
      Parameters:
      self - the object that holds the variable table
      realClass - the "real" class of the object
      index - the variable's index
      Returns:
      the variable table, prepared to set the given index
    • createTable

      private static Object[] createTable(RubyBasicObject self, RubyClass realClass)
      Create a new table for the given object sufficient in size to accommodate all known variables.
      Parameters:
      self - the object to hold the table
      realClass - the "real" class for the object
      Returns:
      the newly-created table
    • growTable

      private static Object[] growTable(RubyBasicObject self, RubyClass realClass, Object[] currentTable)
      Grow an existing table to accommodate all known variables.
      Parameters:
      self - the object to hold the table
      realClass - the "real" class for the object
      currentTable - the current table
      Returns:
      the expanded table