-
Notifications
You must be signed in to change notification settings - Fork 115
Implement the GC in Rust #1750
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
Merged
Merged
Implement the GC in Rust #1750
Changes from 11 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
f245b75
Implement the GC in Rust
osa1 ce9828a
Apply suggestions from code review
osa1 eb33aac
Fix build error after applying suggestions
osa1 5adcd4e
Move heap-related functions to Heap module in compile.ml
osa1 c99c3fe
Remove unused globals in code gen
osa1 b413d98
Remove unused function add_global64
osa1 755a096
Panic if we see an indirection in scavenge
osa1 ee53aa0
Pass mut ref to end_to_space and update it directly
osa1 e59f35b
Remove memset after GC for now -- consumes too much gas
osa1 3da969c
Use memcpy from libc
osa1 2b2a8f7
Encapsulate offset(1) code
osa1 3d3a9be
Implement some helper methods for Word and Bytes types
osa1 bd13ac9
Tweak pub modifiers
osa1 59890cc
Remove magic values in object_size, refactor Bytes/Words a little bit…
osa1 53f24e5
Use size_of in Object size as well
osa1 567475e
Remove hard-coded blob header size
osa1 1f8b54a
Update Object.hash_ptr comments
osa1 a8f1c90
Move heap pointer global to the RTS
osa1 52060df
Update comments re: scavenging static roots
osa1 8d02c33
Rename indirection -> forwarding pointer
osa1 01758d0
Merge branch 'master' into osa1/rust_gc
mergify[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,5 +3,4 @@ stage = 0 | |
|
||
[dependencies.compiler_builtins] | ||
stage = 1 | ||
features = [ "mem" ] | ||
version = "0.1.32" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
//! Implements allocation routines used by the generated code and the GC. | ||
|
||
use core::arch::wasm32; | ||
|
||
use crate::gc; | ||
use crate::rts_trap_with; | ||
use crate::types::{bytes_to_words, skew, words_to_bytes, Bytes, SkewedPtr, Words}; | ||
|
||
#[no_mangle] | ||
pub unsafe extern "C" fn alloc_bytes(n: Bytes<u32>) -> SkewedPtr { | ||
alloc_words(bytes_to_words(n)) | ||
} | ||
|
||
#[no_mangle] | ||
pub unsafe extern "C" fn alloc_words(n: Words<u32>) -> SkewedPtr { | ||
let bytes = words_to_bytes(n); | ||
// Update ALLOCATED | ||
gc::ALLOCATED.0 += bytes.0 as u64; | ||
|
||
// Update heap pointer | ||
let old_hp = gc::get_hp(); | ||
let new_hp = old_hp + bytes.0 as usize; | ||
gc::set_hp(new_hp); | ||
osa1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// Grow memory if needed | ||
grow_memory(new_hp); | ||
|
||
skew(old_hp) | ||
} | ||
|
||
/// Page allocation. Ensures that the memory up to the given pointer is allocated. | ||
pub(crate) unsafe fn grow_memory(ptr: usize) { | ||
let total_pages_needed = ((ptr / 65536) + 1) as i32; | ||
let current_pages = wasm32::memory_size(0) as i32; | ||
let new_pages_needed = total_pages_needed - current_pages; | ||
if new_pages_needed > 0 { | ||
if wasm32::memory_grow(0, new_pages_needed as usize) == core::usize::MAX { | ||
rts_trap_with("Cannot grow memory\0".as_ptr()); | ||
} | ||
} | ||
} |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.