Record `LinkableUsage` instead of `Linkable` in `LoaderState`

Retaining a ByteCode Linkable after it has been loaded retains its UnlinkedBCO, keeping it alive for the remainder of the program. This starts accumulating a lot of UnlinkedBCO and memory over time. However, the Linkable is merely used to later record its usage in mkObjectUsage, which is used for recompilation checking.

However, this is incorrect, as the interface file and bytecode objects could be in different states, e.g. the interface changes, but the bytecode library hasn't changed so we don't need to recompile and vice versa.

By computing a Fingerprint for the ModuleByteCode, and recording it in the LinkableUsage, we know precisely whether the ByteCode object on disk is outdated.

Thus, parts of this commit just makes sure that we efficiently compute a Fingerprint for ModuleByteCode and store it in the on-disk representation of ModuleByteCode.

We change the LoaderState to retain LinkableUsage, which is smaller representation of a Linkable. This allows us to free the unneeded fields of Linkable after linking them.

We declare the following memory invariants that this commit implements:

  • No LinkablePart should be retained from LoaderState.
  • Linkables should be unloaded after they have been loaded.

These invariants are unfortunately tricky to automatically uphold, so we are simply documenting our assumptions for now.

Closes #27018 (closed)

Closes #26500 (closed)

Edited by Hannes Siebenhandl

Merge request reports

Loading