Top Description Fields Constructors Methods
org.jruby.runtime.ivars

public abstract Class VariableAccessor

extends Object
Class Inheritance
Known Direct Subclasses
org.jruby.runtime.ivars.FieldVariableAccessor, org.jruby.runtime.ivars.StampedVariableAccessor
Imports
org.jruby.Ruby, .RubyBasicObject, .RubyClass, org.jruby.ir.operands.UndefinedValue, org.jruby.runtime.ThreadContext, org.jruby.runtime.builtin.IRubyObject, java.lang.invoke.MethodHandles, .VarHandle

Abstraction of an accessor for instance or internal variables on Ruby objects. Subclasses specialize this implementation appropriate to the current JVM's capabilities and the mechanism for laying out variables.

Field Summary

Modifier and TypeField and Description
protected final int
classId

the symbol of the class associated with this variable

public static final VariableAccessor
DUMMY_ACCESSOR

a dummy accessor that will always return null

protected final int
index

the index allocated for it in the variable table

protected final String
name

the name of the variable

protected final RubyClass
realClass

the "real" class associated with this variable

pack-priv static final VarHandle
pack-priv static final VarHandle

Constructor Summary

AccessConstructor and Description
public
VariableAccessor(RubyClass
the "real" class
realClass
,
String
the variable's name
name
,
int
the variable's index
index
,
int
the class's symbol
classId
)

Construct a new VariableAccessor for the given "real" class, name, variable index, and class symbol.

Method Summary

Modifier and TypeMethod and Description
public Object

Returns:

the variable's value
get
(Object
the object from which to retrieve this variable
object
)

Retrieve the variable's value from the given object.

public int

Returns:

this variable's class's id
getClassId
()

Get the symbol of the class associated with this variable.

public int

Returns:

this variable's index
getIndex
()

Get the index allocated for this variable.

public String

Returns:

this variable's name
getName
()

Get the name of this variable.

public IRubyObject

Returns:

the variable's value
getOrNil
(Object
the object from which to retrieve this variable
object
,
ThreadContext context)

Retrieve the variable's value from the given object.

public Object
getOrUndefined(Object object)

Retrieve object or IR %undefined

public static Object

Returns:

the variable's value
getVariable
(RubyBasicObject
the object from which to retrieve the variable
object
,
int
the index of the variable
index
)

Retrieve the variable's value from the given object.

public void
set(Object
the object into which to set this variable
object
,
Object
the value of the variable
value
)

Set the value for this variable in the given object.

public String

Returns:

a string representation of this VariableAccessor
toString
()

Overrides java.lang.Object.toString.

Produce a string representation of this VariableAccessor.

public boolean

Returns:

true if this is the correct accessor for the given object, false otherwise
verify
(Object
the object for which to test this accessor
object
)

Verify if this is the correct accessor for the given object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

classIdback to summary
protected final int classId

the symbol of the class associated with this variable

DUMMY_ACCESSORback to summary
public static final VariableAccessor DUMMY_ACCESSOR

a dummy accessor that will always return null

indexback to summary
protected final int index

the index allocated for it in the variable table

nameback to summary
protected final String name

the name of the variable

realClassback to summary
protected final RubyClass realClass

the "real" class associated with this variable

STAMP_HANDLEback to summary
pack-priv static final VarHandle STAMP_HANDLE
VAR_TABLE_HANDLEback to summary
pack-priv static final VarHandle VAR_TABLE_HANDLE

Constructor Detail

VariableAccessorback to summary
public VariableAccessor(RubyClass realClass, String name, int index, int classId)

Construct a new VariableAccessor for the given "real" class, name, variable index, and class symbol.

Parameters
realClass:RubyClass

the "real" class

name:String

the variable's name

index:int

the variable's index

classId:int

the class's symbol

Method Detail

getback to summary
public Object get(Object object)

Retrieve the variable's value from the given object.

Parameters
object:Object

the object from which to retrieve this variable

Returns:Object

the variable's value

getClassIdback to summary
public int getClassId()

Get the symbol of the class associated with this variable.

Returns:int

this variable's class's id

getIndexback to summary
public int getIndex()

Get the index allocated for this variable.

Returns:int

this variable's index

getNameback to summary
public String getName()

Get the name of this variable.

Returns:String

this variable's name

getOrNilback to summary
public IRubyObject getOrNil(Object object, ThreadContext context)

Retrieve the variable's value from the given object.

Parameters
object:Object

the object from which to retrieve this variable

Returns:IRubyObject

the variable's value

getOrUndefinedback to summary
public Object getOrUndefined(Object object)

Retrieve object or IR %undefined

getVariableback to summary
public static Object getVariable(RubyBasicObject object, int index)

Retrieve the variable's value from the given object. This version is static, allowing it to be more direct, and accepts nnly with RubyBasicObject and subclasses along with the direct index of the variable.

Parameters
object:RubyBasicObject

the object from which to retrieve the variable

index:int

the index of the variable

Returns:Object

the variable's value

setback to summary
public void set(Object object, Object value)

Set the value for this variable in the given object.

Parameters
object:Object

the object into which to set this variable

value:Object

the value of the variable

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Produce a string representation of this VariableAccessor.

Returns:String

a string representation of this VariableAccessor

Annotations
@Override
verifyback to summary
public boolean verify(Object object)

Verify if this is the correct accessor for the given object.

Parameters
object:Object

the object for which to test this accessor

Returns:boolean

true if this is the correct accessor for the given object, false otherwise