We should revisit and document the Truffle stack walking API.
The stack trace API consists of the following elements:
- class FrameInstance
- class FrameInstance.FrameAccess
- class FrameInstanceVisitor
- method TruffleRuntime#getCurrentFrame()
- method TruffleRuntime#getCallerFrame()
- method TruffleRuntime#iterateFrames(FrameInstanceVisitor)
The following things should be considered:
A) The naming in FrameInstance and FrameInstanceVisitor might be misleading, as they are not just containing a frame but also the CallTarget and the CallNode which is usually called a stack frame in other APIs. So the more established StackFrameElement could be used instead.
A new API could look like:
- T TruffleRuntime#iterateStackFrameElements(int skipElements, StackElementVisitor visitor)
- StackElement TruffleRuntime#peekStackFrameElement(int skipElements)
Please feel free to comment on that.
B) Add javadoc to the API. ASCII art similar to below could be useful.
C) FrameInstance#isVirtualFrame is currently never true in the default runtime. Its true for the topmost frame in the Graal runtime. @lukasstadler Maybe you can comment what the use-case is for this method?
D) In FrameInstance#getFrame(FrameAccess, boolean slowPath) whats the purpose of slowpath? @lukasstadler Do you want to comment on that? Maybe we can solve this in a different way by checking a CompilerDirective in graal?
E) We should revisit the question of what FrameInstance#getCallNode() should return.
First grouping option (current state):
===============
getCurrentFrame(): | CallTarget | FrameInstance
===============
getCallerFrame(): | CallNode | FrameInstance
| CallTarget |
===============
| CallNode | FrameInstance
| CallTarget |
===============
...
===============
| CallNode | FrameInstance
Initial call: | CallTarget |
===============
Second grouping option:
===============
getCurrentFrame(): | CallTarget | FrameInstance
| CallNode |
===============
getCallerFrame(): | CallTarget | FrameInstance
| CallNode |
===============
| CallTarget | FrameInstance
| CallNode |
===============
...
===============
Initial call: | CallTarget |
===============
As far as I understand the first has the advantage that you can easily find the current line number where execution is currently at for the frame. And the second option would have the advantage that you find out how you were called (some languages tend to print stack traces with a called-as note).
We should revisit and document the Truffle stack walking API.
The stack trace API consists of the following elements:
The following things should be considered:
A) The naming in FrameInstance and FrameInstanceVisitor might be misleading, as they are not just containing a frame but also the CallTarget and the CallNode which is usually called a stack frame in other APIs. So the more established StackFrameElement could be used instead.
A new API could look like:
Please feel free to comment on that.
B) Add javadoc to the API. ASCII art similar to below could be useful.
C) FrameInstance#isVirtualFrame is currently never true in the default runtime. Its true for the topmost frame in the Graal runtime. @lukasstadler Maybe you can comment what the use-case is for this method?
D) In FrameInstance#getFrame(FrameAccess, boolean slowPath) whats the purpose of slowpath? @lukasstadler Do you want to comment on that? Maybe we can solve this in a different way by checking a CompilerDirective in graal?
E) We should revisit the question of what FrameInstance#getCallNode() should return.
First grouping option (current state):
Second grouping option:
As far as I understand the first has the advantage that you can easily find the current line number where execution is currently at for the frame. And the second option would have the advantage that you find out how you were called (some languages tend to print stack traces with a called-as note).