[MLton] Crash in GC

"Chris Cannam" <[email protected]> Wed, 02 Nov 2022 14:46:16 +0000
Newsgroups gmane.comp.lang.ml.mlton.devel
Message-ID <[email protected]>
Hello!

I have a pure SML program (no FFI) which compiles and runs when compiled with the default MLton options, but crashes with a segfault when compiled with certain GC flags.

For example,

$ mlton program.sml
$ ./program

runs to completion, while

$ mlton -runtime 'copy-generational-ratio 10.0' program.sml
$ ./program

runs for a second or so and then crashes. The crash is a segfault in (according to gdb) forwardObjptr within performGC.

I tried emitting C and compiling that with -g linked against libmlton-dbg.a, and in this mode I get an assertion failure::

gc/invariant.c:13: assertIsObjptrInFromSpaceOrImmutableMutableOrRootStaticHeap: Assertion `isObjptrInFromSpace (s, *opp) || isObjptrInImmutableMutableOrRootStaticHeap (s, *opp)' failed.

The failure is within the invariant check made at the end of performGC just before leaveGC is called, and is within the "checking old generation" part of invariantForGC.

The same behaviour happens with the Arch Linux package of 20210117 and with a clean build from the current MLton repo, and it doesn't appear to matter which codegen I use.

Any tips or ideas for how to debug this? Besides that it seems a bug, I am afraid that a failure in GC with unusual options now has the potential to become a failure with default options in the future under different memory pressure or allocation patterns.

I can provide a test program off-list if that would help anyone get to grips with it, but although it's just a single SML file, it is quite large - the result of concatenating about 38k lines from other files - and I haven't identified a nice small test case.


Chris