Package org.jruby.runtime.ivars
Class VariableTableManager
java.lang.Object
org.jruby.runtime.ivars.VariableTableManager
This class encapculates all logic relating to the management of instance
variable tables in RubyBasicObject instances.
The logic originally lived in both RubyBasicObject and RubyClass, tightly
coupled to each and difficult to follow as it bounced back and forth. We
moved the logic here for a couple reasons:
- To have a single place from which we could follow ivar logic.
- To make it easier to swap in new implementations of instance variable logic as we work toward reifying ivars into fields.
- To remove rather noisy logic from RubyBasicObject and RubyClass.
-
Constructor Summary
ConstructorsConstructorDescriptionVariableTableManager
(RubyClass realClass) Construct a new VariableTable Manager for the given "real" class. -
Method Summary
Modifier and TypeMethodDescriptionclearVariable
(RubyBasicObject object, String name) void
deserializeVariables
(RubyBasicObject object, ObjectInputStream ois) final Object
getFFIHandle
(RubyBasicObject self) Retrieve the FFI ext handle for the given object.Deprecated.Retrieve the read accessor for FFI handle.Retrieve the write accessor for FFI handle.Deprecated.Retrieve the read accessor for object group.Retrieve the write accessor for object group.long
getObjectId
(RubyBasicObject self) Get the object_id from a given RubyBasicObject, possibly allocating space for it.Deprecated.Retrieve the read accessor for object_id for reads.Retrieve the write accessor for object_id.getVariableAccessorForJavaMappedVar
(String name, boolean unwrap, Class<?> unwrapType, Class<?> fieldType, MethodHandle getter, MethodHandle setter) Get the variable accessor for the given name with intent to use it for reading.getVariableAccessorForRubyVar
(String name, MethodHandle getter, MethodHandle setter) Get the variable accessor for the given name with intent to use it for writing.Get the map of all current variable accessors with intent to read from it.String[]
Get an array of all the known instance variable names.Get a Map representing all variables registered in the variable table.int
Get the size of the variable table, excluding extra vars (object_id, etc).int
Get the size of the variable table, including extra vars (object_etc, etc).boolean
hasInstanceVariables
(RubyBasicObject object) boolean
Whether this table has been used to allocate space for an object_id.boolean
hasVariables
(RubyBasicObject object) Returns true if object has any variables, defined as: instance variables class variables constants internal variables, such as those used when marshaling Ranges and Exceptionsvoid
requestFieldStorage
(String name, Class<?> fieldType, Boolean unwrap, Class<?> toType) This is internal API, don't call this directly if you aren't in the JRuby codebase, it may change Request that the listed ivars (no @ in name) have field storage when we are reifiedvoid
Actually requests field storage for the ivar once we are reified This is internal API, don't call this directly if you aren't in the JRuby codebase, it may changevoid
serializeVariables
(RubyBasicObject object, ObjectOutputStream oos) final void
setFFIHandle
(RubyBasicObject self, Object value) Set the FFI handle for the given object.void
setVariableInternal
(RubyBasicObject self, int index, Object value) Virtual entry point for setting a variable into an object.static void
setVariableInternal
(RubyClass realClass, RubyBasicObject self, int index, Object value) Static entry point for setting a variable in an object.void
syncVariables
(RubyBasicObject self, IRubyObject other) Sync one this object's variables with other's - this is used to make rbClone work correctly.
-
Constructor Details
-
VariableTableManager
Construct a new VariableTable Manager for the given "real" class.- Parameters:
realClass
- the "real" class associated with this table
-
-
Method Details
-
getRealClass
-
getVariableAccessorsForRead
Get the map of all current variable accessors with intent to read from it.- Returns:
- a map of current variable accessors
-
hasObjectID
public boolean hasObjectID()Whether this table has been used to allocate space for an object_id.- Returns:
- true if object_id has been allocated; false otherwise
-
getObjectId
Get the object_id from a given RubyBasicObject, possibly allocating space for it.- Parameters:
self
- the object from which to get object_id- Returns:
- the object's object_id (possibly new)
-
setVariableInternal
Virtual entry point for setting a variable into an object.- Parameters:
self
- the object into which to set the valueindex
- the index allocated for the valuevalue
- the value
-
setVariableInternal
public static void setVariableInternal(RubyClass realClass, RubyBasicObject self, int index, Object value) Static entry point for setting a variable in an object.- Parameters:
realClass
- the "real" class of the objectself
- the object into which to set the variableindex
- the index allocated for the variablevalue
- the value of the variable
-
requestFieldStorage
This is internal API, don't call this directly if you aren't in the JRuby codebase, it may change Request that the listed ivars (no @ in name) have field storage when we are reified -
requestFieldStorage
Actually requests field storage for the ivar once we are reified This is internal API, don't call this directly if you aren't in the JRuby codebase, it may change -
getVariableAccessorForWrite
Get the variable accessor for the given name with intent to use it for writing.- Parameters:
name
- the name of the variable- Returns:
- an accessor appropriate for writing
-
getVariableAccessorForRubyVar
public VariableAccessor getVariableAccessorForRubyVar(String name, MethodHandle getter, MethodHandle setter) -
getVariableAccessorForJavaMappedVar
public VariableAccessor getVariableAccessorForJavaMappedVar(String name, boolean unwrap, Class<?> unwrapType, Class<?> fieldType, MethodHandle getter, MethodHandle setter) -
getVariableAccessorForRead
Get the variable accessor for the given name with intent to use it for reading.- Parameters:
name
- the name of the variable- Returns:
- an accessor appropriate for reading
-
getObjectIdAccessorForRead
Retrieve the read accessor for object_id for reads. If no object_id has been prepared, this will return a dummy accessor that just returns null.- Returns:
- the read accessor for object_id
-
getObjectIdAccessorForWrite
Retrieve the write accessor for object_id.- Returns:
- the write accessor for object_id
-
getFFIHandleAccessorForRead
Retrieve the read accessor for FFI handle. If no object_id has been prepared, this will return a dummy accessor that just returns null.- Returns:
- the read accessor for FFI handle
-
getFFIHandleAccessorForWrite
Retrieve the write accessor for FFI handle.- Returns:
- the write accessor for FFI handle
-
getObjectGroupAccessorForRead
Retrieve the read accessor for object group. If no object_id has been prepared, this will return a dummy accessor that just returns null.- Returns:
- the read accessor for object group
-
getObjectGroupAccessorForWrite
Retrieve the write accessor for object group.- Returns:
- the write accessor for object group
-
getFFIHandle
Retrieve the FFI ext handle for the given object.- Parameters:
self
- the object- Returns:
- the object's FFI handle
-
setFFIHandle
Set the FFI handle for the given object.- Parameters:
self
- the objectself
- the object's FFI handle
-
getVariableTableSize
public int getVariableTableSize()Get the size of the variable table, excluding extra vars (object_id, etc).- Returns:
- the variable table's size, excluding extras
-
getVariableTableSizeWithExtras
public int getVariableTableSizeWithExtras()Get the size of the variable table, including extra vars (object_etc, etc).- Returns:
-
getVariableTableCopy
Get a Map representing all variables registered in the variable table.- Returns:
- a map of names to accessors for all variables
-
getVariableNames
Get an array of all the known instance variable names. The offset into the array indicates the offset of the variable's value in the per-object variable array.- Returns:
- a copy of the array of known instance variable names
-
syncVariables
Sync one this object's variables with other's - this is used to make rbClone work correctly.- Parameters:
self
- the object into which to sync variablesother
- the object from which to sync variables
-
hasVariables
Returns true if object has any variables, defined as:- instance variables
- class variables
- constants
- internal variables, such as those used when marshaling Ranges and Exceptions
- Returns:
- true if object has any variables, else false
-
hasInstanceVariables
-
serializeVariables
- Throws:
IOException
-
deserializeVariables
public void deserializeVariables(RubyBasicObject object, ObjectInputStream ois) throws IOException, ClassNotFoundException - Throws:
IOException
ClassNotFoundException
-
clearVariable
-
duplicate
-
getObjectIdAccessorField
Deprecated.Retrieve the lazy accessor (VariableAccessorField) for object_id.- Returns:
- the lazy accessor for object_id
-
getFFIHandleAccessorField
Deprecated.Retrieve the lazy accessor (VariableAccessorField) for FFI handle.- Returns:
- the lazy accessor for FFI handle
-
getObjectGroupAccessorField
Deprecated.Retrieve the lazy accessor (VariableAccessorField) for object group.- Returns:
- the lazy accessor for object group
-
getFFIHandleAccessorForRead()
orgetFFIHandleAccessorForWrite()