Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Garbage Collection for range maps #803

Merged
merged 6 commits into from
Jul 18, 2023
Merged

Garbage Collection for range maps #803

merged 6 commits into from
Jul 18, 2023

Conversation

mariaKt
Copy link
Contributor

@mariaKt mariaKt commented Jul 14, 2023

This PR implements garbage collection for range maps.

The current implementation of the range map's underlying data structure, the red-black tree, is using shared pointers to the internal nodes and leafs of the tree (i.e., the pointer to the root and pointers to left and right children are shared_ptr). This means that we do not need to manage those internal nodes and leaf structures as part of the llvm backend's garbage collection. However, the contents of the map (i.e., the key and value KItems) should be migrated during garbage collection when we migrate an object that contains a range map as a child. We do that by traversing said range map at the time of migration of the parent object, and migrating every such key or value KItem while updating the pointer to it on the corresponding internal node of leaf structure.

We include a KORE test that is based on extending IMP with keywords for certain range map operations. The inputs are currently small IMP programs with a few different interleavings of update and remove operations. We will use the C semantics (whose memory cell, currently a map, will be replaced by a range map) and its test suite for more extensive testing after we complete that implementation.

Note: This approach may lead to memory fragmentation/leaks for large programs. Data pointed to by memory managed by the C++ runtime (shared pointers) may not be deleted/deallocated, but instead be overwritten after the llvm garbage collection is completed. This means that reference counting will not be updated for these shared objects, thus they may never be returned to the system.
If we observe this to be an issue, we can address it in a future PR by changing the implementation of the red-black tree to not rely on shared pointers but instead use memory managed by the llvm backend (kore-alloc) for the internal nodes and leafs as well, and migrate these additionally during garbage collection.

@mariaKt mariaKt marked this pull request as ready for review July 14, 2023 22:46
Copy link
Contributor

@Baltoli Baltoli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One minor comment; tests + code look great otherwise. Nice work @mariaKt!

runtime/collect/migrate_collection.cpp Show resolved Hide resolved
Copy link
Collaborator

@dwightguth dwightguth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pretty simple. I like it! As you say, if there are issues with performance regarding the shared pointers we can create a followup PR to deal with those.

@rv-jenkins rv-jenkins merged commit e3ed1bf into master Jul 18, 2023
6 checks passed
@rv-jenkins rv-jenkins deleted the rangemap-gc branch July 18, 2023 17:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants