forked from bytecodealliance/wasmtime
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make backtrace creation more accurate to support GC (#268)
When creating a backtrace while running some continuation `c` with parent `p` (another continuation or the main stack), the following happens at the moment: After traversing the stack frames of `c`, we need to traverse the stack frames of `p`. To this end, we look at the `StackLimits` object of `p`. The `last_wasm_exit_{fp, pc}` fields therein tell us the frame pointer and program counter at the point where we stopped execution in `p`. This must have been at a `resume` Wasm instruction that resumed `c`. This FP and PC allows us to travese the stack frames of `p`. Note that the fields in `StackLimits` are updated by the various stack switching instructions. The `last_wasm_exit_{fp,pc}` fields are only ever used for creating backtraces, they do not influence control flow at all. Since #223, the `last_wasm_exit_pc` field in `StackLimits` is set on `resume` by using the CLIF instruction `get_instruction_pointer`, which I introduced specifically for that use case. This CLIF instruction will give us a PC value that will be associated with the Wasm `resume` instruction under consideration. This ensures that the backtraces we create mention the right Wasm instructions. That's good enough for our current use case, where backtraces are used mostly to show where things went wrong on a trap. However, in the future, when we want to support GC, we *also* need to use backtraces to obtain stack maps, do identify live objects on continuation stacks. At that point, the current approach becomes too coarse: Currently, the `last_wasm_exit_pc` value we create is associated with the right *Wasm* instruction (namely, a `resume`), but with the wrong *CLIF* instruction: The PC saved in `last_wasm_exit_pc` will be associated with the `get_instruction_pointer` CLIF instruction that created it. However, logically, it must be associated with the `stack_switch` CLIF instruction where execution actually switched from `p` to `c`, and where it would subsequently continue if we were to switch back to the parent `p`. Only the `stack_switch` instruction will have the most recent/correct stack map describing where live values are located in the stack frame that executed `resume`. This PR rectifies this situation as follows: Instead of maintaining the fields `last_wasm_exit_{fp, pc}` in `StackLimits`, we now load the required PC and FP values directly from the control context of the corresponding Fiber (i.e., the memory area that saves PC, SP, FP used to actually switch stacks). In other words, to create backtraces, we get the necessary information about where execution continues in the parent stack directly from the source of truth (i.e., the control context), rather than duplicating this information in `StackLimits` just for backtrace creation. Thus, the fields `last_wasm_exit_{fp, pc}` are removed from `StackLimits` and no longer need to be updated on `resume`. Further, the `get_instruction_pointer` CLIF instruction, and corresponding `GetRip` x64 `MInst`, which I introduced in #223, are removed.
- Loading branch information
1 parent
010c5c5
commit 1ff5534
Showing
13 changed files
with
154 additions
and
168 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.