diff --git a/rts/Threads.c b/rts/Threads.c index 434e1298c27f82a5bd98383802d0e2d285df52c2..203a24879489b419049423f393129fe0f60fd75b 100644 --- a/rts/Threads.c +++ b/rts/Threads.c @@ -602,7 +602,15 @@ threadStackOverflow (Capability *cap, StgTSO *tso) "allocating new stack chunk of size %d bytes", chunk_size * sizeof(W_)); + // Charge the current thread for allocating stack. Stack usage is + // non-deterministic, because the chunk boundaries might vary from + // run to run, but accounting for this is better than not + // accounting for it, since a deep recursion will otherwise not be + // subject to allocation limits. + cap->r.rCurrentTSO = tso; new_stack = (StgStack*) allocate(cap, chunk_size); + cap->r.rCurrentTSO = NULL; + SET_HDR(new_stack, &stg_STACK_info, old_stack->header.prof.ccs); TICK_ALLOC_STACK(chunk_size);