MPS issue job003439

TitleMPS is too hard to use
Assigned userGareth Rees
DescriptionMPS is very hard for a beginner to use. Prior to the writing of the Guide [11] it was basically impossible to do it right: see for example, GDR's experience of trying to integrate the MPS with Lua [1] [2] [3] [4] [5] [6] [7] [8] [9] [10]. It's possible that the Guide makes things better, but its length and complexity are probably still off-putting.
AnalysisBy comparison, integrating the Boehm collector with a project is as simple as this:

1. If you need multi-threaded support, define GC_THREADS.
2. Include "gc.h".
3. Call GC_INIT() when the program starts.
4. Call GC_enable_incremental() when the program starts if you want incremental collection turning on.
5. Replace all calls to malloc() and realloc() with calls to GC_MALLOC() and GC_REALLOC() respectively. Easily done with a macro.
6. Remove all calls to free(). Ditto.
7. Call GC_REGISTER_FINALIZER() on objects that need to be finalized.

It would be very nice if the MPS offered an interface of similar simplicity. As RB says [12], this would have several benefits:

- make the MPS more appealing and easier to integrate
- allow side-by-side comparison with Boehm GC
- possibly solve some platform support issues (e.g. Mac OS X multi-threaded)

We'd need to do the following:

1. Our equivalent of GC_INIT() would create a virtual memory arena, and create an AMS pool with an object format that scans every word in the object as an ambiguous reference. (It needs to be an AMS pool because we won't be moving objects, and because we need to be able to scan ambiguous references.)
2. Our equivalent of GC_MALLOC() would allocate from the AMS pool. It would need to store the size of the allocated block alongside the block. (Perhaps using format auto_header.) Somehow we'd have to arrange that there was an allocation point for every thread that calls GC_MALLOC(). (Maybe we could create these allocation points on the fly when we discover that a new thread is trying to allocate.)
3. Automatically find roots. Find all running threads and register their stacks. Find global variables and register them as ambiguous roots. (Look at Boehm to see how it does it.)

But even before we consider trying the above, there are some simple improvements we could make:

4. Include all the pool and arena class headers in mps.h, so that you don't have to remember to include a bunch of headers.
How foundinspection
Evidence[1] <>
[2] <>
[3] <>
[4] <>
[5] <>
[6] <>
[7] <>
[8] <>
[9] <>
[10] <>
[11] <>
[12] <>
Observed in1.110.0
Created byGareth Rees
Created on2013-03-12 14:16:46
Last modified byGareth Rees
Last modified on2016-09-13 10:37:20
History2013-03-12 GDR Created based on [12].