MPS issue job004025

TitleDuplicate code between pool classes
Assigned userRichard Brooksby
DescriptionThere has long been similar code in the AWL, AMS, and LO pool classes for implementing mark-and-sweep garbage collection. Compare, for example, loSegWalk with AMSWalk and awlSegWalk.

branch/2016-04-14/no-condemn-suspend deliberately changed this code to make the similarities even more obvious, but avoided large-scale changes to structure that would actually share it. Work is required specifically to implement sharing.
Analysis1. Move some pool methods to segment subclasses instead. Methods like "whiten", "scan", "fix", and "reclaim" are pool methods because historically the pool was the only class-like place in the MPS. These should be methods on GC segments instead.
Fixed by branch/2017-03-04/seg-methods [2] and branch/2018-07-09/seg-alloc [3].

2. Lift the LO segment class into its own module implementing mark-and-sweep (and rename it).

3. Drop amsseg->grains and awlseg->grains, since they are both just PoolSizeGrains(pool, SegSize(seg)).

4. Port the firstFree optimization from AMS to MarkSweep.

5. Port the free-space-padding opimization from AMC to MarkSweep.

6. Lift the AMS segment class to a specialisation of the LO segment class with scanning.

7. Specialise the AMS segment class to add weak-link scanning for the AWL pool.

8. Investigate sharing between the AMC class (which implements another form of mark-and-sweep for ambiguous references) and these segment classes. Possibly it could inherit from the AWL segment class and specialise with object motion.

There is a concern with step 3 in that AMS implements some tricky optimizations in order to maintain only two bit-tables (nonwhite, nongrey) instead of three (alloc, marked, scanned) when ambiguous references need not be supported. Are these optimizations really effective? The optimizations can only be used when we can be sure that there are no ambiguous references into the pool. But the MPS does not support exact collection: the reserve/commit protocol requires an ambiguous reference [1]. So maybe we are paying a cost in complexity for no actual benefit. See job000535, job000548, job000549, job000550, job001549, job003782, job003841 for bugs related to these optimizations.

Note that AMS is substantially faster than AWL and LO, and the reason for this needs to be understood and the speedup ported to the other pools. My guess is that it’s the firstFree logic that leads to the speedup and not the complicated bit-table logic, but this needs confirming.
How foundinspection
Created byRichard Brooksby
Created on2016-04-29 09:07:51
Last modified byGareth Rees
Last modified on2020-08-30 17:56:19
History2016-04-29 RB Created.


Change Effect Date User Description
194690 open 2018-07-19 06:25:51 Gareth Rees Merge branch/2018-07-09/seg-alloc into the master sources.
194268 open 2018-06-28 13:57:07 Gareth Rees Merge branch/2017-03-04/seg-methods.