diff options
author | Björn Gustavsson <[email protected]> | 2019-08-22 13:40:54 +0200 |
---|---|---|
committer | GitHub <[email protected]> | 2019-08-22 13:40:54 +0200 |
commit | cabdfc991278d6322564ef7342e80b3dd3cdbc92 (patch) | |
tree | 1f8e3b6e13563ae43dd047fda505320a24cc057d /erts/emulator/beam/macros.tab | |
parent | d670fe64723ed348c8829a6528292cdc9d0ad5a1 (diff) | |
parent | 07a323813a47f92abf05bdf2255dc1354e82c55c (diff) | |
download | otp-cabdfc991278d6322564ef7342e80b3dd3cdbc92.tar.gz otp-cabdfc991278d6322564ef7342e80b3dd3cdbc92.tar.bz2 otp-cabdfc991278d6322564ef7342e80b3dd3cdbc92.zip |
Merge pull request #2351 from bjorng/bjorn/erts/optimize-cp-management/OTP-15077
Optimize continuation pointer management
Diffstat (limited to 'erts/emulator/beam/macros.tab')
-rw-r--r-- | erts/emulator/beam/macros.tab | 46 |
1 files changed, 42 insertions, 4 deletions
diff --git a/erts/emulator/beam/macros.tab b/erts/emulator/beam/macros.tab index 1b5e5f66b0..9d183e1f41 100644 --- a/erts/emulator/beam/macros.tab +++ b/erts/emulator/beam/macros.tab @@ -104,14 +104,52 @@ GC_TEST_PRESERVE(NeedHeap, Live, PreserveTerm) { // Make sure that there are NeedStack + NeedHeap + 1 words available -// on the combined heap/stack segment, then allocates NeedHeap + 1 -// words on the stack and saves CP. +// on the combined heap/stack segment, then decrement the stack +// pointer by (NeedStack + 1) words. Finally clear the word reserved +// for the continuation pointer at the top of the stack. +// +// Stack frame layout: +// +// +-----------+ +// y(N) | Term | +// +-----------+ +// . +// . +// . +// +-----------+ +// y(0) | Term | +// +-----------+ +// E ==> | NIL or CP | +// +-----------+ +// +// When the function owning the stack frame is the currently executing +// function, the word at the top of the stack is NIL. When calling +// another function, the continuation pointer will be stored in the +// word at the top of the stack. When returning to the function +// owning the stack frame, the word at the stack top will again be set +// to NIL. + AH(NeedStack, NeedHeap, Live) { unsigned needed = $NeedStack + 1; $GC_TEST(needed, $NeedHeap, $Live); E -= needed; - *E = make_cp(c_p->cp); - c_p->cp = 0; + *E = NIL; +} + +// Save the continuation pointer in the reserved slot at the +// top of the stack as preparation for doing a function call. + +SAVE_CONTINUATION_POINTER(IP) { + ASSERT(VALID_INSTR(*($IP))); + *E = (BeamInstr) ($IP); +} + +// Return to the function whose continuation pointer is stored +// at the top of the stack and set that word to NIL. + +RETURN() { + SET_I(cp_val(*E)); + *E = NIL; } NEXT0() { |