Package com.oracle.truffle.api
Class TruffleStackTrace
java.lang.Object
java.lang.Throwable
java.lang.Exception
com.oracle.truffle.api.TruffleStackTrace
- All Implemented Interfaces:
Serializable
Represents a guest language stack trace.
A TruffleStackTrace is automatically added when a
Throwable
passes through a
call target
. ControlFlowException
and PolyglotException
do not
get a TruffleStackTrace. An internal or host Throwable
is added a TruffleStackTrace, as
long as suppression is not disabled for this throwable, via a Throwable added to the list of
suppressed exceptions.
A guest language stack trace element is automatically added by the Truffle runtime every time the
Throwable
passes through a call target
. This is incremental and
therefore efficient if the exception is later caught in the same compilation unit.
Note that if the Throwable is caught, its stack trace should be filled eagerly with
fillIn(Throwable)
, unless it can be guaranteed to be re-thrown in the same
call target
, or that the stack trace will not be used.
See getStackTrace(Throwable)
to retrieve the guest language stack trace from a
Throwable
.
- Since:
- 19.0
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic TruffleStackTrace
Fills in the guest language stack frames from the current frames on the stack.static List
<TruffleStackTraceElement> getAsynchronousStackTrace
(CallTarget target, Frame frame) Returns asynchronous guest language stack frames that led to the execution of givenCallTarget
on the givenFrame
.static List
<TruffleStackTraceElement> getStackTrace
(Throwable throwable) Returns the guest language frames that are stored in this throwable ornull
if no guest language frames can ever be stored in this throwable.toString()
Methods inherited from class java.lang.Throwable
addSuppressed, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace
-
Method Details
-
fillInStackTrace
- Overrides:
fillInStackTrace
in classThrowable
- Since:
- 19.0
-
toString
-
getStackTrace
Returns the guest language frames that are stored in this throwable ornull
if no guest language frames can ever be stored in this throwable. This method fills in the stacktrace by callingfillIn(Throwable)
, so it is not necessary to callfillIn(Throwable)
before. The returned list is not modifiable. The number of stack trace elements that are filled in can be customized by thestackTraceElementLimit
parameter of theAbstractTruffleException constructor
.- Parameters:
throwable
- theThrowable
instance to look for guest language frames- Throws:
NullPointerException
- if theThrowable
isnull
- Since:
- 19.0
-
getAsynchronousStackTrace
public static List<TruffleStackTraceElement> getAsynchronousStackTrace(CallTarget target, Frame frame) Returns asynchronous guest language stack frames that led to the execution of givenCallTarget
on the givenFrame
. Returnsnull
if no asynchronous stack is known. Call this with a context entered only.Languages might not provide asynchronous stack frames by default for performance reasons. Instruments might need to instruct languages to provide the asynchronous stacks.
- Returns:
- a list of asynchronous frames, or
null
. - Since:
- 20.1.0
-
fillIn
Fills in the guest language stack frames from the current frames on the stack. If the stack was already filled before then this method has no effect. The number stack trace elements that are filled in can be customized by thestackTraceElementLimit
parameter of theAbstractTruffleException constructor
. The implementation attaches a lightweight exception object as a suppressed exception to internal and host (but not guest) exceptions.- Parameters:
throwable
- theThrowable
to fill- Throws:
NullPointerException
- if theThrowable
is null- Since:
- 19.0
-