Class LocalAccessor
To use a local accessor, declare a ConstantOperand
on the operation. The corresponding
builder method for the operation will take a BytecodeLocal
argument for the local to be
accessed. At run time, a LocalAccessor
for the local will be supplied as a parameter to
the operation.
Local accessors are useful to implement behaviour that cannot be implemented with the builtin
local operations (like StoreLocal). For example, if an operation produces multiple outputs, it
can write one of the outputs to a local using a local accessor. Prefer builtin operations when
possible, since they automatically work with boxing elimination
. Local accessors should be preferred over BytecodeNode
helpers like
BytecodeNode.getLocalValue(int, Frame, int)
, since the helpers use extra indirection.
All of the accessor methods take a bytecode node
and the current
frame
. The bytecode node should be the current bytecode node and correspond
to the root that declares the local; it should be compilation-final. The frame should contain the
local.
Example usage:
@Operation @ConstantOperand(type = LocalAccessor.class) public static final class GetLocal { @Specialization public static Object perform(VirtualFrame frame, LocalAccessor accessor, @Bind BytecodeNode bytecodeNode) { return accessor.getObject(bytecodeNode, frame); } }
- Since:
- 24.2
-
Method Summary
Modifier and TypeMethodDescriptionvoid
clear
(BytecodeNode bytecodeNode, VirtualFrame frame) Clears the local from the frame.static LocalAccessor
constantOf
(BytecodeLocal local) Obtains aLocalAccessor
.boolean
boolean
getBoolean
(BytecodeNode bytecodeNode, VirtualFrame frame) Loads a boolean from the local.byte
getByte
(BytecodeNode bytecodeNode, VirtualFrame frame) Loads a byte from the local.double
getDouble
(BytecodeNode bytecodeNode, VirtualFrame frame) Loads a double from the local.float
getFloat
(BytecodeNode bytecodeNode, VirtualFrame frame) Loads a float from the local.int
getInt
(BytecodeNode bytecodeNode, VirtualFrame frame) Loads an int from the local.getLocalInfo
(BytecodeNode bytecodeNode) Returns the info associated with the local.getLocalName
(BytecodeNode bytecodeNode) Returns the name associated with the local.long
getLong
(BytecodeNode bytecodeNode, VirtualFrame frame) Loads a long from the local.getObject
(BytecodeNode bytecodeNode, VirtualFrame frame) Loads an object from the local.int
hashCode()
boolean
isCleared
(BytecodeNode bytecodeNode, VirtualFrame frame) Checks whether the local has beencleared
(and a new value has not been set).void
setBoolean
(BytecodeNode bytecodeNode, VirtualFrame frame, boolean value) Stores a short into the local.void
setByte
(BytecodeNode bytecodeNode, VirtualFrame frame, byte value) Stores a byte into the local.void
setDouble
(BytecodeNode bytecodeNode, VirtualFrame frame, double value) Stores a double into the local.void
setFloat
(BytecodeNode bytecodeNode, VirtualFrame frame, float value) Stores a float into the local.void
setInt
(BytecodeNode bytecodeNode, VirtualFrame frame, int value) Stores an int into the local.void
setLong
(BytecodeNode bytecodeNode, VirtualFrame frame, long value) Stores a long into the local.void
setObject
(BytecodeNode bytecodeNode, VirtualFrame frame, Object value) Stores an object into the local.toString()
Returns a string representation of aLocalAccessor
.
-
Method Details
-
toString
Returns a string representation of aLocalAccessor
. -
getObject
Loads an object from the local.- Since:
- 24.2
-
getBoolean
public boolean getBoolean(BytecodeNode bytecodeNode, VirtualFrame frame) throws UnexpectedResultException Loads a boolean from the local.- Throws:
UnexpectedResultException
- Since:
- 24.2
-
getByte
Loads a byte from the local.- Throws:
UnexpectedResultException
- Since:
- 24.2
-
getInt
Loads an int from the local.- Throws:
UnexpectedResultException
- Since:
- 24.2
-
getLong
Loads a long from the local.- Throws:
UnexpectedResultException
- Since:
- 24.2
-
getFloat
public float getFloat(BytecodeNode bytecodeNode, VirtualFrame frame) throws UnexpectedResultException Loads a float from the local.- Throws:
UnexpectedResultException
- Since:
- 24.2
-
getDouble
public double getDouble(BytecodeNode bytecodeNode, VirtualFrame frame) throws UnexpectedResultException Loads a double from the local.- Throws:
UnexpectedResultException
- Since:
- 24.2
-
setObject
Stores an object into the local.- Since:
- 24.2
-
setBoolean
Stores a short into the local.- Since:
- 24.2
-
setByte
Stores a byte into the local.- Since:
- 24.2
-
setInt
Stores an int into the local.- Since:
- 24.2
-
setLong
Stores a long into the local.- Since:
- 24.2
-
setFloat
Stores a float into the local.- Since:
- 24.2
-
setDouble
Stores a double into the local.- Since:
- 24.2
-
clear
Clears the local from the frame.Clearing the slot marks the frame slot as
illegal
. An exception will be thrown if it is read before being set. Clearing does not insert adefault local value
, if specified.- Since:
- 24.2
-
isCleared
Checks whether the local has beencleared
(and a new value has not been set).This method also returns
true
if a local has not been initialized and nodefault local value
is specified.- Since:
- 24.2
-
getLocalName
Returns the name associated with the local.- Since:
- 24.2
- See Also:
-
getLocalInfo
Returns the info associated with the local.- Since:
- 24.2
- See Also:
-
constantOf
Obtains aLocalAccessor
. This method is invoked by the generated code and should not be called directly.- Since:
- 24.2
-
equals
-
hashCode
public int hashCode()
-