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

Implement the GC in Rust #1750

Merged
merged 21 commits into from
Sep 3, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Tweak pub modifiers
osa1 committed Sep 3, 2020
commit bd13ac9571587b9f76b11bc06a525f149bec4e4e
4 changes: 2 additions & 2 deletions rts/motoko-rts/src/alloc.rs
Original file line number Diff line number Diff line change
@@ -7,12 +7,12 @@ use crate::rts_trap_with;
use crate::types::{skew, Bytes, SkewedPtr, Words};

#[no_mangle]
pub unsafe extern "C" fn alloc_bytes(n: Bytes<u32>) -> SkewedPtr {
unsafe extern "C" fn alloc_bytes(n: Bytes<u32>) -> SkewedPtr {
alloc_words(n.to_words())
}

#[no_mangle]
pub unsafe extern "C" fn alloc_words(n: Words<u32>) -> SkewedPtr {
unsafe extern "C" fn alloc_words(n: Words<u32>) -> SkewedPtr {
let bytes = n.to_bytes();
// Update ALLOCATED
gc::ALLOCATED += Bytes(bytes.0 as u64);
13 changes: 6 additions & 7 deletions rts/motoko-rts/src/gc.rs
Original file line number Diff line number Diff line change
@@ -10,14 +10,14 @@ extern "C" {
pub(crate) fn set_hp(hp: usize);

/// Get __heap_base
pub(crate) fn get_heap_base() -> usize;
fn get_heap_base() -> usize;

/// Skewed pointer to a skewed pointer to an array. See closure-table.c for details.
pub(crate) fn closure_table_loc() -> SkewedPtr;
fn closure_table_loc() -> SkewedPtr;

/// Get pointer to the static memory with an array to the static roots. Provided by the
/// generated code.
pub(crate) fn get_static_roots() -> SkewedPtr;
fn get_static_roots() -> SkewedPtr;
}

/// Maximum live data retained in a GC.
@@ -53,8 +53,7 @@ unsafe extern "C" fn get_total_allocations() -> Bytes<u64> {
}

/// Returns object size in words
pub(crate) unsafe fn object_size(obj: usize) -> Words<u32> {

unsafe fn object_size(obj: usize) -> Words<u32> {
// NB. Constants below are header sizes of objects and should be in sync with sizes of structs
// in types.rs. TODO: Some ideas to make sure they're in sync:
//
@@ -112,7 +111,7 @@ pub(crate) unsafe fn object_size(obj: usize) -> Words<u32> {
}
}

pub(crate) fn is_tagged_scalar(p: SkewedPtr) -> bool {
fn is_tagged_scalar(p: SkewedPtr) -> bool {
p.0 & 0b1 == 0
}

@@ -349,7 +348,7 @@ unsafe fn evac_static_roots(

/// The entry point. Called by the generated code.
#[no_mangle]
pub unsafe extern "C" fn collect() {
unsafe extern "C" fn collect() {
let begin_from_space = get_heap_base();
let end_from_space = get_hp();
let begin_to_space = end_from_space;