Ticket #1466 (new bug)

Opened 6 years ago

Last modified 5 months ago

Stack check for AP_STACK

Reported by: simonmar Owned by: simonmar
Priority: normal Milestone: 7.6.2
Component: Compiler Version: 6.6.1
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Difficulty: Moderate (less than a day)
Test Case: concprog001 Blocked By: #4258
Blocking: Related Tickets:

Description

This is a bug I uncovered in the interpreter, that I think is also present in the compiler.

When compiling code for a function or thunk, we aggregate the stack usage from case continuations up to the top of the function/thunk and perform a single stack check. This normally works fine: we know the maximum amount of stack that will be required in the evaluation of this function/thunk, and we check for it up front.

However, this goes wrong if the evaluation is suspended by an asynchronous exception: the stack is broken into chunks and stored in AP_STACK objects, which may later be resumed. On resumption, we might not have enough stack any more: the code might now be running on another stack entirely, even.

Our proposed solution is as follows:

  • Continuations that require more than a certain amount of stack (say 4k) do their own stack checks.
  • an AP_STACK object records the amount of stack available at the time it was suspended, if the amount is <4k. On resumption of an AP_STACK, we ensure that at least this amount of stack is available. (there's a spare half-word field in AP_STACK that we can use for this).

The 4k limit is important: it puts a bound on the amount of stack growth due to evaluating an AP_STACK. Essentially the 4k limit is large enough that it almost never happens.

Change History

  Changed 6 years ago by simonmar

Partly done:

Tue Sep 11 14:02:28 BST 2007  Simon Marlow <simonmar@microsoft.com>
  * FIX #1466 (partly), which was causing concprog001(ghci) to fail
  An AP_STACK now ensures that there is at least AP_STACK_SPLIM words of
  stack headroom available after unpacking the payload.  Continuations
  that require more than AP_STACK_SPLIM words of stack must do their own
  stack checks instead of aggregating their stack usage into the parent
  frame.  I have made this change for the interpreter, but not for
  compiled code yet - we should do this in the glorious rewrite of the
  code generator.

  Changed 6 years ago by simonmar

  • milestone changed from 6.8 branch to 6.10 branch

Do this as part of the new back end

  Changed 5 years ago by simonmar

  • architecture changed from Unknown to Unknown/Multiple

  Changed 5 years ago by simonmar

  • os changed from Unknown to Unknown/Multiple

  Changed 4 years ago by igloo

  • milestone changed from 6.10 branch to 6.12.1

  Changed 4 years ago by simonmar

  • component changed from Runtime System to Compiler
  • milestone changed from 6.12.1 to 6.14.1

Bumping to 6.14.1 as this is work to do in the new codegen.

  Changed 4 years ago by simonmar

  • difficulty changed from Moderate (1 day) to Moderate (less than a day)

  Changed 3 years ago by igloo

  • milestone changed from 7.0.1 to 7.0.2

  Changed 2 years ago by igloo

  • milestone changed from 7.0.2 to 7.2.1

  Changed 22 months ago by igloo

  • blockedby 4258 added

  Changed 22 months ago by igloo

  • failure set to None/Unknown
  • milestone changed from 7.2.1 to 7.6.1

  Changed 9 months ago by igloo

  • milestone changed from 7.6.1 to 7.6.2

follow-up: ↓ 14   Changed 5 months ago by morabbin

Bump; does this work in the new codegen as indicated above?

in reply to: ↑ 13   Changed 5 months ago by simonmar

Replying to morabbin:

Bump; does this work in the new codegen as indicated above?

No, not done yet.

Note: See TracTickets for help on using tickets.