Package org.jruby.runtime.ivars
Class NonvolatileVariableAccessor
java.lang.Object
org.jruby.runtime.ivars.VariableAccessor
org.jruby.runtime.ivars.NonvolatileVariableAccessor
A VariableAccessor that directly updates instance variables without an explicit memory fence
or synchronization.
If the table itself must be created for the first time or grown to accommodate a new variable,
those operations will be done in a thread-safe (volatile, atomic) way. However updates of an
entry in an existing table will not have any explicit memory fence or synchronization.
-
Field Summary
Fields inherited from class org.jruby.runtime.ivars.VariableAccessor
classId, DUMMY_ACCESSOR, index, name, realClass -
Constructor Summary
ConstructorsConstructorDescriptionNonvolatileVariableAccessor(RubyClass realClass, String name, int index, int classId) Construct a new NonvolatileVariableAccessor for the given "real" class, variable name, variable index, and class ID. -
Method Summary
Modifier and TypeMethodDescriptionprivate static booleancreateTableUnsafe(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.voidSet this variable into the given object using Unsafe to ensure safe creation or growth of the variable table.static voidsetVariable(RubyBasicObject self, RubyClass realClass, int index, Object value) Set the given variable index into the specified object.static voidsetVariableChecked(RubyBasicObject self, RubyClass realClass, int index, Object value) Set the given variable index into the specified object.private static booleanupdateTable(RubyBasicObject self, int currentStamp, Object[] currentTable, int index, Object value) Update the given table table directly.Methods inherited from class org.jruby.runtime.ivars.VariableAccessor
get, getClassId, getIndex, getName, getVariable, toString, verify
-
Constructor Details
-
NonvolatileVariableAccessor
Construct a new NonvolatileVariableAccessor for the given "real" class, variable name, variable index, and class ID.- Parameters:
realClass- the "real" classname- the variable's nameindex- the variable's indexclassId- the class's ID
-
-
Method Details
-
set
Set this variable into the given object using Unsafe to ensure safe creation or growth of the variable table.- Overrides:
setin classVariableAccessor- Parameters:
object- the object into which to set this variablevalue- 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 variablerealClass- the "real" class for the objectindex- the index of the variablevalue- the variable's value
-
setVariable
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 variablerealClass- the "real" class for the objectindex- the index of the variablevalue- 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 variablecurrentStamp- the current variable table stamprealClass- the "real" class for the objectcurrentTable- the current tableindex- the index of the variablevalue- the variable's value- Returns:
- whether the update was successful, for CAS retrying
-
updateTable
private static boolean updateTable(RubyBasicObject self, int currentStamp, Object[] currentTable, int index, Object value) Update the given table table directly.- Parameters:
self- the object into which to set the variablecurrentStamp- the current variable table stampcurrentTable- the current tableindex- the index of the variablevalue- the variable's value- Returns:
- whether the update was successful, for CAS retrying
-