Class BytecodeLocation

java.lang.Object
com.oracle.truffle.api.bytecode.BytecodeLocation

public final class BytecodeLocation extends Object
A materialized bytecode location.

The current bytecode location can be bound using @Bind BytecodeLocation location in operations. In order to avoid the overhead of the BytecodeLocation allocation, e.g. for exceptional cases, it is possible to create the bytecode location lazily from two fields: @Bind BytecodeNode bytecode and @Bind("$bytecodeIndex") int bci. This avoids the eager allocation of the bytecode location. To create a bytecode location when it is needed the get(Node, int) method can be used.

Since:
24.2
  • Method Details

    • getBytecodeIndex

      public int getBytecodeIndex()
      Returns the bytecode index. This index is not stable and should only be used for debugging purposes. The bytecode index is only meaningful when coupled with a particular bytecode node.
      Since:
      24.2
    • getBytecodeNode

      public BytecodeNode getBytecodeNode()
      Returns the BytecodeNode associated with this location. The bytecode index is only valid for the returned node.
      Since:
      24.2
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
      Since:
      24.2
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
      Since:
      24.2
    • toString

      public String toString()
      Overrides:
      toString in class Object
      Since:
      24.2
    • dump

      public String dump()
      Dumps the bytecode debug information, highlighting this location in the result.
      Returns:
      dump string
      Since:
      24.2
      See Also:
    • update

      public BytecodeLocation update()
      Updates this location to the newest bytecode node of the parent bytecode root node, translating the bytecode index to the new bytecode node in the process. It is useful to update the location if source information or instrumentations were materialized in the meantime. Note that the bytecode index may be different in the updated location.
      Since:
      24.2
    • ensureSourceInformation

      public BytecodeLocation ensureSourceInformation()
      Ensures source information available for this location and updates this location to a new location of the bytecode node with source information. Materialization of source information may be an expensive operation if the source information was not yet materialized yet.
      Since:
      24.2
    • getSourceLocation

      public SourceSection getSourceLocation()
      Computes the most concrete source location of this bytecode location.
      Since:
      24.2
      See Also:
    • getSourceLocations

      public SourceSection[] getSourceLocations()
      Computes all source locations of this bytecode location. Returns an empty array if no source locations are available. The list is ordered from most to least concrete.
      Since:
      24.2
      See Also:
    • getInstruction

      public Instruction getInstruction()
      Returns the bytecode instruction at this location, which provides additional debug information for debugging and tracing.
      Since:
      24.2
    • getExceptionHandlers

      public List<ExceptionHandler> getExceptionHandlers()
      Returns all exception handlers that span over this bytecode location. Returns an empty list if no exception handlers span over this location.
      Since:
      24.2
    • getSourceInformation

      public List<SourceInformation> getSourceInformation()
      Returns all source informations available at this location.
      Since:
      24.2
    • get

      public static BytecodeLocation get(FrameInstance frameInstance)
      Gets the bytecode location for a given FrameInstance. Frame instances are invalid as soon as the execution of a frame is continued. A bytecode location can be used to materialize an execution location in a bytecode interpreter, which can be used after the FrameInstance is no longer valid.
      Parameters:
      frameInstance - the frame instance
      Returns:
      the corresponding bytecode location or null if no location can be found.
      Since:
      24.2
    • get

      public static BytecodeLocation get(Node location, int bci)
      Creates a BytecodeLocation associated with the given node and bci.
      Parameters:
      location - a node in the interpreter (can be bound using @Bind BytecodeNode bytecode)
      bci - a bytecode index (can be bound using @Bind("$bytecodeIndex") int bci)
      Returns:
      the BytecodeLocation or null if location is not adopted by a BytecodeNode.
      Since:
      24.2
    • get

      public static BytecodeLocation get(TruffleStackTraceElement element)
      Creates a BytecodeLocation associated with a TruffleStackTraceElement.
      Returns:
      the BytecodeLocation or null if no bytecode interpreter can be found in the stack trace element.
      Since:
      24.2