Changes between Version 16 and Version 17 of Commentary/ResourceLimits


Ignore:
Timestamp:
Sep 2, 2013 4:52:17 AM (2 years ago)
Author:
ezyang
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Commentary/ResourceLimits

    v16 v17  
    5656}}}
    5757
    58 Changes to:
     58Changes to (XXX):
    5959
    6060{{{
     
    7070         goto cmv;
    7171}}}
     72
     73Here is an interesting bugger:
     74
     75{{{
     76 sat_s15K_info()
     77         { label: sat_s15K_info
     78           rep:HeapRep static { Thunk }
     79           type: [73,79]
     80           desc: [60,109,97,105,110,58,77,97,105,110,46,115,97,116,95,115,49,53,75,62]
     81         }
     82     c17Q:
     83         if (%MO_UU_Conv_W32_W64(I32[era]) > 0) goto c17R;
     84         goto c17S;
     85     c17R:
     86         I64[R1 + 16] = I64[R1 + 16] & 1152921503533105152 | %MO_UU_Conv_W32_W64(I32[era]) | 1152921504606846976;
     87         goto c17S;
     88     c17S:
     89         if (Sp - 80 < SpLim) goto c17U;
     90         Hp = Hp + 64;
     91         if (Hp > HpLim) goto c17W;
     92         I64[I64[R1 + 8] + 72] = I64[I64[R1 + 8] + 72] + %MO_UU_Conv_W64_W64(4 - 2);
     93         I64[Hp - 56] = stg_CAF_BLACKHOLE_info;
     94         I64[Hp - 48] = I64[R1 + 8];
     95         I64[Hp - 40] = (%MO_UU_Conv_W32_W64(I32[era]) << 30) | 0;
     96         I64[Hp - 32] = CurrentTSO;
     97         (_c17X::I64,) = foreign "ccall"
     98           newCAF((BaseReg, PtrHint), (R1, PtrHint), (Hp - 56, PtrHint));
     99         if (_c17X::I64 == 0) goto c17Y;
     100         goto c17Z;
     101     c17U: jump stg_gc_enter_1; // [R1]
     102     c17W:
     103         HpAlloc = 64;
     104         goto c17U;
     105     c17Y: jump I64[R1]; // [R1]
     106     c17Z:
     107         I64[Sp - 32] = stg_bh_upd_frame_info;
     108         I64[Sp - 8] = Hp - 56;
     109         I64[Sp - 24] = CCCS;
     110         CCCS = I64[R1 + 8];
     111         I64[CCCS + 72] = I64[CCCS + 72] + %MO_UU_Conv_W64_W64(4 - 2);
     112         I64[Hp - 24] = GHC.Integer.Type.S#_con_info;
     113         I64[Hp - 16] = CCCS;
     114         I64[Hp - 8] = (%MO_UU_Conv_W32_W64(I32[era]) << 30) | 0;
     115         I64[Hp + 0] = 2;
     116         I64[Sp - 40] = CCCS;
     117         I64[Sp - 56] = Hp - 23;
     118         I64[Sp - 64] = stg_ap_p_info;
     119         I64[Sp - 72] = CCCS;
     120         I64[Sp - 80] = stg_restore_cccs_info;
     121         R2 = Foreign.C.Types.$fNumCInt_closure;
     122         I64[Sp - 48] = s15P_info;
     123         Sp = Sp - 80;
     124         jump GHC.Num.fromInteger_info; // [R2]
     125 }]
     126}}}
     127
     128Notice the heap check serves for the later branch too. On the other hand, the CCCS coincides with the later change. This seems to be the general pattern. So we might be able to handle this CAF by special-casing CAFs.
    72129
    73130=== Thunk code ===
     
    114171{{{
    115172         if (Sp - 32 < SpLim) goto clg;
    116          // XXX Update nursery
     173         _crc = Bdescr(Hp);
     174         // XXX ugh this is really expensive
     175         // XXX is it worth avoiding the rigamorole when it's the same? maybe.
     176         // closeNursery
     177         I64[CurrentNursery + 8] = Hp + 8;
     178         // change the nursery
     179         CurrentNursery = Bdescr(R1)->rc[CurrentCap]
     180         // openNursery
     181         Hp = I64[CurrentNursery + 8] - 8;
     182         HpLim = I64[CurrentNursery] + (%MO_SS_Conv_W32_W64(I32[CurrentNursery + 48]) * 4096 - 1);
     183         // XXX end expensive bit
    117184         Hp = Hp + 40; // or whatever this adjusts to
    118185         if (Hp > HpLim) goto cli;
     
    120187         I64[Sp - 32] = stg_upd_frame_info;
    121188         I64[Sp - 8] = R1;
    122          I64[Sp - 24] = CurrentResourceContainer; // so we can restore it on return, NOT the same as nursery
    123          // XXX Update CurrentResourceContainer
     189         I64[Sp - 24] = _crc; // so we can restore it on return, NOT the same as current nursery
    124190         // (load free variables)
    125191         ...
     
    129195         goto clg;
    130196}}}
     197
     198=== Foreign calls ===
     199
     200{{{
     201// savethreadState
     202//   mkStore (cmmOffset dflags (CmmLoad (cmmOffset dflags stgCurrentTSO (tso_stackobj dflags)) (bWord dflags)) (stack_SP dflags)) stgSp
     203         I64[I64[CurrentTSO + 40] + 32] = Sp;
     204//   closeNursery dflags
     205         I64[CurrentNursery + 8] = Hp + 8;
     206//   mkStore (cmmOffset dflags stgCurrentTSO (tso_CCCS dflags)) curCCS
     207         I64[CurrentTSO + 120] = CCCS;
     208// caller_save
     209         // (empty)
     210// mkMiddle (callSuspendThread dflags id intrbl)
     211         (_c17B::I64, PtrHint) = foreign "ccall"
     212           suspendThread((BaseReg, PtrHint), (0,));
     213// mkUnsafeCall tgt res args
     214         (_c17l::I64, `signed') = foreign "ccall"
     215           cos((_c17e::I64, `signed'));
     216// mkMiddle (callResumeThread new_base id)
     217         (_c17D::I64, PtrHint) = foreign "ccall"
     218           resumeThread((_c17B::I64, PtrHint));
     219// mkAssign (CmmGlobal BaseReg) (CmmReg (CmmLocal new_base))
     220         BaseReg = _c17D::I64;
     221// caller_load
     222         // empty
     223// loadThreadState
     224//   tso = CurrentTSO
     225         _c17F::I64 = CurrentTSO;
     226//   stack = tso->stackobj
     227         _c17H::I64 = I64[_c17F::I64 + 40];
     228//   Sp = stack->sp
     229         Sp = I64[_c17H::I64 + 32];
     230//   SpLim = stack->stack + RESERVED_STACK_WORDS
     231         SpLim = _c17H::I64 + 208;
     232//   HpAlloc = 0
     233         HpAlloc = 0;
     234//   openNursery dflags
     235         Hp = I64[CurrentNursery + 8] - 8;
     236         HpLim = I64[CurrentNursery] + (%MO_SS_Conv_W32_W64(I32[CurrentNursery + 48]) * 4096 - 1);
     237//   storeCurCCSm (CmmLoad (cmmOffset dflags (CmmReg (CmmLocal tso)) (tso_CCCS dflags)) (ccsType dflags))
     238         CCCS = I64[_c17F::I64 + 120];
     239}}}
     240
     241Changes to:
     242
     243{{{
     244         I64[I64[CurrentTSO + 40] + 32] = Sp;
     245         I64[CurrentNursery + 8] = Hp + 8;
     246         // assume CurrentResourceContainer and nursery are consistent
     247         (_c17B::I64, PtrHint) = foreign "ccall" suspendThread((BaseReg, PtrHint), (0,));
     248         (_c17l::I64, `signed') = foreign "ccall" cos((_c17e::I64, `signed'));
     249         (_c17D::I64, PtrHint) = foreign "ccall" resumeThread((_c17B::I64, PtrHint));
     250         BaseReg = _c17D::I64;
     251         _c17F::I64 = CurrentTSO;
     252         _c17H::I64 = I64[_c17F::I64 + 40];
     253         Sp = I64[_c17H::I64 + 32];
     254         SpLim = _c17H::I64 + 208;
     255         HpAlloc = 0;
     256         Hp = I64[CurrentNursery + 8] - 8;
     257         HpLim = I64[CurrentNursery] + (%MO_SS_Conv_W32_W64(I32[CurrentNursery + 48]) * 4096 - 1);
     258         // (once again, using implicit Hp)
     259         R1 = _c17l::I64;
     260}}}
     261
    131262
    132263