Class BytecodeFrame
BytecodeFrame is intended for use cases where the frame escapes or outlives the root node
invocation. Prefer using a built-in operation or LocalAccessor to access the frame
whenever possible.
There are a few ways to capture the frame:
BytecodeNode.createCopiedFrame(int, Frame)captures a copy.BytecodeNode.createMaterializedFrame(int, MaterializedFrame)captures the original frame.get(FrameInstance, FrameAccess)captures a frame from aFrameInstance. It captures the original frame ifFrameInstance.FrameAccess.READ_WRITEorFrameInstance.FrameAccess.MATERIALIZEis requested. Otherwise, it captures either the original frame or a copy.get(TruffleStackTraceElement)captures a frame from aTruffleStackTraceElement. It captures either the original frame or a copy.getNonVirtual(FrameInstance)captures the original frame from aFrameInstance, if it is non-virtual.getNonVirtual(TruffleStackTraceElement)captures the original frame from aTruffleStackTraceElement, if it is non-virtual and available in the stack trace.
Note: if the interpreter uses block scoping, any
non-copied BytecodeFrame is only valid until the interpreter continues execution. The
frame must not be used after this point; doing so can cause undefined behaviour.
If you need to access the frame after execution continues, you should capture a copy or
explicitly copy() the captured bytecode frame. This restriction also applies to frames
created by methods like get(TruffleStackTraceElement), which do not specify
whether they capture the original frame or a copy.
- Since:
- 25.1
-
Method Summary
Modifier and TypeMethodDescriptioncopy()Returns a copy of this frame.static BytecodeFrameget(FrameInstance frameInstance, FrameInstance.FrameAccess access) Creates a bytecode frame from the given frame instance.static BytecodeFrameget(TruffleStackTraceElement element) Creates a bytecode frame from the given stack trace element.getArgument(int argumentIndex) Returns the value of the argument at the given index.intReturns the number of arguments in the captured frame.intReturns the bytecode index associated with the captured frame.Returns the bytecode node associated with the captured frame.Returns theinfoobject associated with the frame's descriptor.intReturns the number of live locals in the captured frame.Object[]Returns the names associated with the live locals, if provided.getLocalValue(int localOffset) Returns the value of the local at the given offset.Returns the bytecode location associated with the captured frame.static BytecodeFramegetNonVirtual(FrameInstance frameInstance) Attempts to create a bytecode frame from the given frame instance.static BytecodeFramegetNonVirtual(TruffleStackTraceElement element) Attempts to create a bytecode frame from the given stack trace element.voidsetArgument(int argumentIndex, Object value) Updates the value of the local at the given offset.voidsetLocalValue(int localOffset, Object value) Updates the value of the local at the given offset.
-
Method Details
-
copy
Returns a copy of this frame. This method can be used to snapshot the current state of a bytecode frame, in case it may be modified or become invalid in the future.- Returns:
- a copy of this frame that is always valid and will not observe updates
- Since:
- 25.1
-
getLocation
Returns the bytecode location associated with the captured frame. This location is only valid until the bytecode interpreter resumes execution.- Since:
- 25.1
-
getBytecodeNode
Returns the bytecode node associated with the captured frame.- Since:
- 25.1
-
getBytecodeIndex
public int getBytecodeIndex()Returns the bytecode index associated with the captured frame.- Since:
- 25.1
-
getLocalCount
public int getLocalCount()Returns the number of live locals in the captured frame.- Since:
- 25.1
-
getLocalValue
Returns the value of the local at the given offset. The offset should be between 0 andgetLocalCount().- Since:
- 25.1
-
setLocalValue
Updates the value of the local at the given offset. The offset should be between 0 andgetLocalCount().This method will throw an
AssertionErrorif the captured frame does not support writes.- Since:
- 25.1
-
getLocalNames
Returns the names associated with the live locals, if provided.- Since:
- 25.1
-
getArgumentCount
public int getArgumentCount()Returns the number of arguments in the captured frame.- Since:
- 25.1
-
getArgument
Returns the value of the argument at the given index. The offset should be between 0 andgetArgumentCount().- Since:
- 25.1
-
setArgument
Updates the value of the local at the given offset. The offset should be between 0 andgetArgumentCount().- Since:
- 25.1
-
getFrameDescriptorInfo
-
get
Creates a bytecode frame from the given frame instance.- Parameters:
frameInstance- the frame instanceaccess- the access mode to use when capturing the frame- Returns:
- a bytecode frame, or null if the frame instance is missing location info.
- Since:
- 25.1
-
getNonVirtual
Attempts to create a bytecode frame from the given frame instance. Returns null if the corresponding frame is virtual. The frame can be read from, written to, and escaped.This method can be used to probe for a frame that can safely escape without forcing materialization. For example, if a language needs to capture local variables from a stack frame, it's often more efficient to use an existing non-virtual frame rather than create a copy of all variables.
- Parameters:
frameInstance- the frame instance- Returns:
- a bytecode frame or null if the frame is virtual or if the frame instance is missing location info.
- Since:
- 25.1
-
get
Creates a bytecode frame from the given stack trace element.This method will return null unless the interpreter specifies
GenerateBytecode.captureFramesForTrace(), which indicates whether frames should be captured.- Parameters:
element- the stack trace element- Returns:
- a bytecode frame, or null if the frame was not captured or the stack trace element is missing location information.
- Since:
- 25.1
-
getNonVirtual
Attempts to create a bytecode frame from the given stack trace element. Returns null if the corresponding frame is virtual. The frame can be read from, written to, and escaped.This method can be used to probe for a frame that can safely escape without forcing materialization. For example, if a language needs to capture local variables from a stack frame, it's often more efficient to use an existing non-virtual frame rather than create a copy of all variables.
- Parameters:
element- the stack trace element- Returns:
- a bytecode frame or null if the frame is virtual/unavailable or if the frame instance is missing location info.
- Since:
- 25.1
-