runtime: migrate to an internal memory allocator - #167
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Jule Runtime: Migration to Internal Memory Allocator
This PR replaces the Jule runtime's reliance on the standard C++
newanddeleteoperators with a custom memory allocator based on the rpmalloc allocation algorithm.The allocator has been implemented directly in Pure Jule and integrated into the Jule runtime. It has no external dependencies and is now used by both the runtime and the API for their internal memory allocations.
Motivation
The Jule runtime previously relied on the standard C++
newanddeleteoperators for memory allocation. While this provided a simple and familiar allocation mechanism, it limited the runtime's ability to optimize memory management for its own concurrency and execution model.The main motivations for introducing a custom allocator are:
A dedicated allocator allows the runtime to manage allocations according to its own requirements rather than relying entirely on the behavior of the standard C++ allocator.
The new allocator is based on the rpmalloc allocation algorithm and has been reimplemented directly in Pure Jule.
Rather than introducing rpmalloc as an external dependency, its algorithm has been adapted and integrated into the runtime itself. This keeps the runtime self-contained while allowing the allocator to be specifically integrated with Jule's execution model.
rpmalloc was chosen as the foundation for several reasons:
This makes rpmalloc a good foundation for an allocator that can evolve alongside Jule's runtime architecture.
Runtime and API Changes
The Jule runtime and API now use the custom allocator for their internal allocations.
The allocator is also exposed through the following C++ API:
Both functions operate on raw memory. They do not construct or destroy C++ objects.
Object lifetime management remains the responsibility of the compiler and API where appropriate. When an allocation represents an object requiring initialization or destruction, the corresponding constructor and destructor calls are emitted or performed separately.
This separation keeps the allocator focused purely on memory management while preserving the existing object-lifetime semantics.
Standard Allocators Remain Unchanged
The new allocator does not override the standard C and C++ allocation functions by default.
In particular, it does not replace:
mallocfreenewdeleteThe custom allocator is therefore isolated to allocations explicitly performed through the Jule runtime and API. Existing C++ code using the standard allocation mechanisms continues to use the standard allocators unless explicitly changed.