Skip to content

Print RET_BIG stack closures

Sven Tennie requested to merge wip/print_big_ret_stack_closures into master

This part was missing from Printer.c. I hope it will be useful for the works on stack decoding and stack cloning (AKA "cold stack").

Testing is a bit difficult, because Printer.c functions are only used in development / for debugging.

This program provokes a BIG_RET closure to be on the stack (continuation of bigFun).

{-# LANGUAGE BangPatterns #-}
module Main where

import System.IO.Unsafe (unsafePerformIO)
import System.Mem (performGC)
printStacky_return_int:: Int
printStacky_return_int = unsafePerformIO $ do
    performGC
    return 42

main :: IO ()
main = do
        let
            a2 = 1 +1
            a3 = 1 +1
            a4 = 1 +1
            a5 = 1 +1
            a6 = 1 +1
            a7 = 1 +1
            a8 = 1 +1
            a9 = 1 +1
            a10 = 1 +1
            a11 = 1 +1
            a12 = 1 +1
            a13 = 1 +1
            a14 = 1 +1
            a15 = 1 +1
            a16 = 1 +1
            a17 = 1 +1
            a18 = 1 +1
            a19 = 1 +1
            a20 = 1 +1
            a21 = 1 +1
            a22 = 1 +1
            a23 = 1 +1
            a24 = 1 +1
            a25 = 1 +1
            a26 = 1 +1
            a27 = 1 +1
            a28 = 1 +1
            a29 = 1 +1
            a30 = 1 +1
            a31 = 1 +1
            a32 = 1 +1
            a33 = 1 +1
            a34 = 1 +1
            a35 = 1 +1
            a36 = 1 +1
            a37 = 1 +1
            a38 = 1 +1
            a39 = 1 +1
            a40 = 1 +1
            a41 = 1 +1
            a42 = 1 +1
            a43 = 1 +1
            a44 = 1 +1
            a45 = 1 +1
            a46 = 1 +1
            a47 = 1 +1
            a48 = 1 +1
            a49 = 1 +1
            a50 = 1 +1
            a51 = 1 +1
            a52 = 1 +1
            a53 = 1 +1
            a54 = 1 +1
            a55 = 1 +1
            a56 = 1 +1
            a57 = 1 +1
            a58 = 1 +1
            a59 = 1 +1
            a60 = 1 +1
            a61 = 1 +1
            a62 = 1 +1
            a63 = 1 +1
            a64 = 1 +1
            a65 = 1 +1

        bigFun (printStacky_return_int) a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 a16 a17 a18 a19 a20 a21 a22 a23 a24 a25 a26 a27 a28 a29 a30 a31 a32 a33 a34 a35 a36 a37 a38 a39 a40 a41 a42 a43 a44 a45 a46 a47 a48 a49 a50 a51 a52 a53 a54 a55 a56 a57 a58 a59 a60 a61 a62 a63 a64 a65

        return ()


bigFun !a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 a16 a17 a18 a19 a20 a21 a22 a23 a24 a25 a26 a27 a28 a29 a30 a31 a32 a33 a34 a35 a36 a37 a38 a39 a40 a41 a42 a43 a44 a45 a46 a47 a48 a49 a50 a51 a52 a53 a54 a55 a56 a57 a58 a59 a60 a61 a62 a63 a64 a65 =
    do
        print $ a1 + a2 + a3 + a4 + a5 + a6 + a7 + a8 + a9 + a10 + a11 + a12 + a13 + a14 + a15 + a16 + a17 + a18 + a19 + a20 + a21 + a22 + a23 + a24 + a25 + a26 + a27 + a28 + a29 + a30 + a31 + a32 + a33 + a34 + a35 + a36 + a37 + a38 + a39 + a40 + a41 + a42 + a43 + a44 + a45 + a46 + a47 + a48 + a49 + a50 + a51 + a52 + a53 + a54 + a55 + a56 + a57 + a58 + a59 + a60 + a61 + a62 + a63 + a64 + a65
        print "I'm a BIG_RET!"

And I changed Scav.c lines 1822 and following to:

void
scavenge_stack(StgPtr p, StgPtr stack_end)
{
#if defined(DEBUG)
  printStackChunk(p, stack_end);
#endif
  const StgRetInfoTable* info;
  StgWord bitmap;
  StgWord size;
...

Thus, every scavenging of the stack prints the stack and the test program triggers a garbage collection (which includes scavenging).

The output is:

RET_SMALL (0x5612a0)
RET_SMALL (0x421740)
   stk[81] (0x42001fe1b8) = 0x42001061f8 -- Object 0x42001061f8 = 0x42001061f8: THUNK(0x406170)
RET_SMALL (0x4957a0)
0x42001fe1c8: MARKED_UPDATE_FRAME(0x769a40,0x4200105668)
RET_BIG (0x42001fe1d8)
   stk[76] (0x42001fe1e0) = 0x80a440 -- Object 0x80a440 = 0x80a440: base:GHC.Show.C:Show(0x80a423, 0x80a429, 0x80a43a)
   stk[75] (0x42001fe1e8) = 0x8018c8 -- Object 0x8018c8 = 0x8018c8: base:GHC.Num.C:Num(0x8018a2, 0x8018aa, 0x8018b2, 0x8018b9, 0x801861, 0x801899, 0x8018c1)
   stk[74] (0x42001fe1f0) = 0x42001045b0 -- Object 0x42001045b0 = 0x42001045b0: THUNK(0x4062b8)
   stk[73] (0x42001fe1f8) = 0x42001045a0 -- Object 0x42001045a0 = 0x42001045a0: THUNK(0x416db0)
   stk[72] (0x42001fe200) = 0x4200104590 -- Object 0x4200104590 = 0x4200104590: THUNK(0x416d60)
   stk[71] (0x42001fe208) = 0x4200104580 -- Object 0x4200104580 = 0x4200104580: THUNK(0x416d10)
   stk[70] (0x42001fe210) = 0x4200104570 -- Object 0x4200104570 = 0x4200104570: THUNK(0x416cc0)
   stk[69] (0x42001fe218) = 0x4200104560 -- Object 0x4200104560 = 0x4200104560: THUNK(0x416c70)
   stk[68] (0x42001fe220) = 0x4200104550 -- Object 0x4200104550 = 0x4200104550: THUNK(0x416c20)
   stk[67] (0x42001fe228) = 0x4200104540 -- Object 0x4200104540 = 0x4200104540: THUNK(0x416bd0)
   stk[66] (0x42001fe230) = 0x4200104530 -- Object 0x4200104530 = 0x4200104530: THUNK(0x416b80)
   stk[65] (0x42001fe238) = 0x4200104520 -- Object 0x4200104520 = 0x4200104520: THUNK(0x416b30)
   stk[64] (0x42001fe240) = 0x4200104510 -- Object 0x4200104510 = 0x4200104510: THUNK(0x416ae0)
   stk[63] (0x42001fe248) = 0x4200104500 -- Object 0x4200104500 = 0x4200104500: THUNK(0x416a90)
   stk[62] (0x42001fe250) = 0x42001044f0 -- Object 0x42001044f0 = 0x42001044f0: THUNK(0x416a40)
   stk[61] (0x42001fe258) = 0x42001044e0 -- Object 0x42001044e0 = 0x42001044e0: THUNK(0x4169f0)
   stk[60] (0x42001fe260) = 0x42001044d0 -- Object 0x42001044d0 = 0x42001044d0: THUNK(0x4169a0)
   stk[59] (0x42001fe268) = 0x42001044c0 -- Object 0x42001044c0 = 0x42001044c0: THUNK(0x416950)
   stk[58] (0x42001fe270) = 0x42001044b0 -- Object 0x42001044b0 = 0x42001044b0: THUNK(0x416900)
   stk[57] (0x42001fe278) = 0x42001044a0 -- Object 0x42001044a0 = 0x42001044a0: THUNK(0x4168b0)
   stk[56] (0x42001fe280) = 0x4200104490 -- Object 0x4200104490 = 0x4200104490: THUNK(0x416860)
   stk[55] (0x42001fe288) = 0x4200104480 -- Object 0x4200104480 = 0x4200104480: THUNK(0x416810)
   stk[54] (0x42001fe290) = 0x4200104470 -- Object 0x4200104470 = 0x4200104470: THUNK(0x4167c0)
   stk[53] (0x42001fe298) = 0x4200104460 -- Object 0x4200104460 = 0x4200104460: THUNK(0x416770)
   stk[52] (0x42001fe2a0) = 0x4200104450 -- Object 0x4200104450 = 0x4200104450: THUNK(0x416720)
   stk[51] (0x42001fe2a8) = 0x4200104440 -- Object 0x4200104440 = 0x4200104440: THUNK(0x4166d0)
   stk[50] (0x42001fe2b0) = 0x4200104430 -- Object 0x4200104430 = 0x4200104430: THUNK(0x416680)
   stk[49] (0x42001fe2b8) = 0x4200104420 -- Object 0x4200104420 = 0x4200104420: THUNK(0x416630)
   stk[48] (0x42001fe2c0) = 0x4200104410 -- Object 0x4200104410 = 0x4200104410: THUNK(0x4165e0)
   stk[47] (0x42001fe2c8) = 0x4200104400 -- Object 0x4200104400 = 0x4200104400: THUNK(0x416590)
   stk[46] (0x42001fe2d0) = 0x42001043f0 -- Object 0x42001043f0 = 0x42001043f0: THUNK(0x416540)
   stk[45] (0x42001fe2d8) = 0x42001043e0 -- Object 0x42001043e0 = 0x42001043e0: THUNK(0x4164f0)
   stk[44] (0x42001fe2e0) = 0x42001043d0 -- Object 0x42001043d0 = 0x42001043d0: THUNK(0x4164a0)
   stk[43] (0x42001fe2e8) = 0x42001043c0 -- Object 0x42001043c0 = 0x42001043c0: THUNK(0x416450)
   stk[42] (0x42001fe2f0) = 0x42001043b0 -- Object 0x42001043b0 = 0x42001043b0: THUNK(0x416400)
   stk[41] (0x42001fe2f8) = 0x42001043a0 -- Object 0x42001043a0 = 0x42001043a0: THUNK(0x4163b0)
   stk[40] (0x42001fe300) = 0x4200104390 -- Object 0x4200104390 = 0x4200104390: THUNK(0x416360)
   stk[39] (0x42001fe308) = 0x4200104380 -- Object 0x4200104380 = 0x4200104380: THUNK(0x416310)
   stk[38] (0x42001fe310) = 0x4200104370 -- Object 0x4200104370 = 0x4200104370: THUNK(0x4162c0)
   stk[37] (0x42001fe318) = 0x4200104360 -- Object 0x4200104360 = 0x4200104360: THUNK(0x416270)
   stk[36] (0x42001fe320) = 0x4200104350 -- Object 0x4200104350 = 0x4200104350: THUNK(0x416220)
   stk[35] (0x42001fe328) = 0x4200104340 -- Object 0x4200104340 = 0x4200104340: THUNK(0x4161d0)
   stk[34] (0x42001fe330) = 0x4200104330 -- Object 0x4200104330 = 0x4200104330: THUNK(0x416180)
   stk[33] (0x42001fe338) = 0x4200104320 -- Object 0x4200104320 = 0x4200104320: THUNK(0x416130)
   stk[32] (0x42001fe340) = 0x4200104310 -- Object 0x4200104310 = 0x4200104310: THUNK(0x4160e0)
   stk[31] (0x42001fe348) = 0x4200104300 -- Object 0x4200104300 = 0x4200104300: THUNK(0x416090)
   stk[30] (0x42001fe350) = 0x42001042f0 -- Object 0x42001042f0 = 0x42001042f0: THUNK(0x416040)
   stk[29] (0x42001fe358) = 0x42001042e0 -- Object 0x42001042e0 = 0x42001042e0: THUNK(0x415ff0)
   stk[28] (0x42001fe360) = 0x42001042d0 -- Object 0x42001042d0 = 0x42001042d0: THUNK(0x415fa0)
   stk[27] (0x42001fe368) = 0x42001042c0 -- Object 0x42001042c0 = 0x42001042c0: THUNK(0x415f50)
   stk[26] (0x42001fe370) = 0x42001042b0 -- Object 0x42001042b0 = 0x42001042b0: THUNK(0x415f00)
   stk[25] (0x42001fe378) = 0x42001042a0 -- Object 0x42001042a0 = 0x42001042a0: THUNK(0x415eb0)
   stk[24] (0x42001fe380) = 0x4200104290 -- Object 0x4200104290 = 0x4200104290: THUNK(0x415e60)
   stk[23] (0x42001fe388) = 0x4200104280 -- Object 0x4200104280 = 0x4200104280: THUNK(0x415e10)
   stk[22] (0x42001fe390) = 0x4200104270 -- Object 0x4200104270 = 0x4200104270: THUNK(0x415dc0)
   stk[21] (0x42001fe398) = 0x4200104260 -- Object 0x4200104260 = 0x4200104260: THUNK(0x415d70)
   stk[20] (0x42001fe3a0) = 0x4200104250 -- Object 0x4200104250 = 0x4200104250: THUNK(0x415d20)
   stk[19] (0x42001fe3a8) = 0x4200104240 -- Object 0x4200104240 = 0x4200104240: THUNK(0x415cd0)
   stk[18] (0x42001fe3b0) = 0x4200104230 -- Object 0x4200104230 = 0x4200104230: THUNK(0x415c80)
   stk[17] (0x42001fe3b8) = 0x4200104220 -- Object 0x4200104220 = 0x4200104220: THUNK(0x415c30)
   stk[16] (0x42001fe3c0) = 0x4200104210 -- Object 0x4200104210 = 0x4200104210: THUNK(0x415be0)
   stk[15] (0x42001fe3c8) = 0x4200104200 -- Object 0x4200104200 = 0x4200104200: THUNK(0x415b90)
   stk[14] (0x42001fe3d0) = 0x42001041f0 -- Object 0x42001041f0 = 0x42001041f0: THUNK(0x415b40)
   stk[13] (0x42001fe3d8) = 0x42001041e0 -- Object 0x42001041e0 = 0x42001041e0: THUNK(0x415af0)
   stk[12] (0x42001fe3e0) = 0x42001041d0 -- Object 0x42001041d0 = 0x42001041d0: THUNK(0x415aa0)
   stk[11] (0x42001fe3e8) = 0x42001041c0 -- Object 0x42001041c0 = 0x42001041c0: THUNK(0x415a50)
   stk[10] (0x42001fe3f0) = 0x42001041b0 -- Object 0x42001041b0 = 0x42001041b0: THUNK(0x415a00)
0x42001fe3f8: MARKED_UPDATE_FRAME(0x769a40,0x4200105658)
stg_ap_v_info
RET_SMALL (0x421740)
   stk[5] (0x42001fe418) = 0x7ea008 -- Object 0x7ea008 = 0x7ea008: THUNK(0x406108)
0x42001fe420: CATCH_FRAME(0x762438,0x80ba8a)
0x42001fe438: STOP_FRAME(0x768600)
170
"I'm a BIG_RET!"
Edited by Sven Tennie

Merge request reports