6. AMS (Automatic Mark and Sweep)

AMS is an automatically managed but non-moving pool class. It should be used instead of AMC (Automatic Mostly-Copying) for blocks that need to be automatically managed, but cannot be moved.


AMS is likely to be useful as a step in integrating a program with the MPS. It allows you to work on scanning (and investigate errors resulting from underscanning) without having to deal with objects moving as well. When you are confident that scanning is correct, you can switch to AMC (Automatic Mostly-Copying).

AMS is not currently suitable for production use. However, it could be developed into a solid mark-and-sweep pool. If you have a use case that needs this, contact us.

6.1. AMS properties

6.2. AMS interface

#include "mpscams.h"
mps_pool_class_t mps_class_ams(void)

Return the pool class for an AMS (Automatic Mark & Sweep) pool.

When creating an AMS pool, mps_pool_create_k() requires one keyword argument:

It accepts three optional keyword arguments:

  • MPS_KEY_CHAIN (type mps_chain_t) specifies the generation chain for the pool. If not specified, the pool will use the arena’s default chain.

  • MPS_KEY_GEN (type unsigned) specifies the generation in the chain into which new objects will be allocated. If you pass your own chain, then this defaults to 0, but if you didn’t (and so use the arena’s default chain), then an appropriate generation is used.

    Note that AWL does not use generational garbage collection, so blocks remain in this generation and are not promoted.

  • MPS_KEY_AMS_SUPPORT_AMBIGUOUS (type mps_bool_t, default TRUE) specifies whether references to blocks in the pool may be ambiguous.

For example:

    MPS_ARGS_ADD(args, MPS_KEY_FORMAT, fmt);
    res = mps_pool_create_k(&pool, arena, mps_class_ams(), args);
} MPS_ARGS_END(args);

When creating an allocation point on an AMS pool, mps_ap_create_k() accepts one optional keyword argument:

For example:

    MPS_ARGS_ADD(args, MPS_KEY_RANK, mps_rank_ambig());
    res = mps_ap_create_k(&ap, ams_pool, args);
} MPS_ARGS_END(args);
mps_pool_class_t mps_class_ams_debug(void)

A debugging version of the AMS pool class.

When creating a debugging AMS pool, mps_pool_create_k() accepts the following keyword arguments: MPS_KEY_FORMAT, MPS_KEY_CHAIN, MPS_KEY_GEN, and MPS_KEY_AMS_SUPPORT_AMBIGUOUS are as described above, and MPS_KEY_POOL_DEBUG_OPTIONS specifies the debugging options. See mps_pool_debug_option_s.