Skip to content

ID-based safety for small objects #17

Description

@nobugs-hare

Idea: if we have a pointer to a small object, we can avoid maintain.ing those potentially very large lists of back pointers. In particular, we can:

  • have allocator have a function max_object_boundaries_guaranteed_size()
  • on alloc, if size <= 2^18 and size <= max_object_boundaries_guaranteed_size(), it is going to be ID-based alloc, otherwise - it is going to be list-based.
    • if it is list-based - control block stays "as is"
    • if it is ID-based - we have 8 bytes of ID before the alloc, that's it
  • reserve one bit in both owning and soft ptrs to indicate it is ID-based or list-based; ID-based is used only if object_boundaries_guaranteed is returned (and if alloc size <= 2^18, see below)
  • list-based logic stays pretty much "as is", except that one bit and except for moving list-based logic into non-inlinable functions
  • for ID-based items we change layout of soft_ptrs completely; we have a pointer, plus 19 bits, and 64 bits for ID; out of 19, 1 bit goes for id-or-list-based flag, and we have 18 bits for offset-between-owning_ptr-and-real_ptr (and if allocation is over 2^18 in size, we enforce list-based model).
  • for each conversion from soft_ptr into naked_ptr (or dereference etc.) - we compare ID field within ptr and ID in the beginning of the allocated block; if they don't match - we are accessing a dead object, it is an exception.

IMPORTANT: there are drawbacks of ID-based schema; in particular - relocatable allocs are not possible. As a result, ID-based stuff MUST be OPTIONAL (global #define)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions