Limitchecks...

Stephen Weeks MLton@research.nj.nec.com
Thu, 24 Feb 2000 12:25:55 -0800 (PST)


> I'm trying to compare my user gc with MLtons C native version. This is a bit
> hard, as to get an apples to apples comparison I need to make sure each
> program invokes the GC the same number of times. The obvious hack is to make
> sure my user GC and MLton's GC just get invoked at every nth limitcheck, but
> for that to happend I've got make sure I've got a limit check exactly where 
> MLton has one. 
> 
> so what's MLton's policy for placing limitchecks? Can I make it "dumb" and
> have it insert one at every function/label entry?

The policy is governed by backend/{limit-check, allocate-registers,
machine}.  
* limit-check.fun decides at what Cps.Jumps limit checks might need
  to be inserted. The current policy is to 
    - force a limit check at every loop header (for signals)
    - maybe check at the beginning of handlers and conts
* allocate-registers.fun translates the information produced by
  limit-check.fun to the format expected by machine and also inserts a 
  stack limit check at the beginning of every Cps.Func.  A stack limit 
  check includes a heap limit check as well.
* machine.fun computes how many bytes to check for and inserts checks.
  It inserts a limitCheck if either limit-check.fun said Yes, or
  limit-check.fun said Maybe and there are bytes allocated before the
  next check, or if allocate-registers.fun said to insert a stack
  limit check.

I don't think you really want one at every function/label entry, but
if you do, you can just change LimitCheck.limitCheck to return 
"fn _ => Yes".  Who knows, this may even tickle some interesting bugs!