Skip to content

Commit

Permalink
Remove the statically linked C code (#87)
Browse files Browse the repository at this point in the history
This PR removes `runtime_gc_x86.c`. Closes
#59.
  • Loading branch information
qinsoon authored Aug 4, 2023
1 parent 636f60a commit 72c87fd
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 128 deletions.
34 changes: 0 additions & 34 deletions mmtk/build.rs

This file was deleted.

56 changes: 0 additions & 56 deletions mmtk/runtime/runtime_gc_x64.c

This file was deleted.

7 changes: 3 additions & 4 deletions mmtk/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ use crate::BLOCK_FOR_GC;
use crate::JULIA_HEADER_SIZE;
use crate::SINGLETON;
use crate::UPCALLS;
use crate::{
set_julia_obj_header_size_and_buffer_tag, BUILDER, DISABLED_GC, MUTATORS, USER_TRIGGERED_GC,
};
use crate::{BUILDER, DISABLED_GC, MUTATORS, USER_TRIGGERED_GC};
use crate::{ROOT_EDGES, ROOT_NODES};

use libc::c_char;
Expand All @@ -35,7 +33,8 @@ pub extern "C" fn mmtk_gc_init(
) {
unsafe {
UPCALLS = calls;
set_julia_obj_header_size_and_buffer_tag(header_size, buffer_tag);
crate::JULIA_HEADER_SIZE = header_size;
crate::JULIA_BUFF_TAG = buffer_tag;
};

// Assert to make sure our ABI is correct
Expand Down
29 changes: 13 additions & 16 deletions mmtk/src/collection.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{spawn_collector_thread, UPCALLS};
use crate::{JuliaVM, USER_TRIGGERED_GC};
use crate::{SINGLETON, UPCALLS};
use log::{info, trace};
use mmtk::util::alloc::AllocationError;
use mmtk::util::opaque_pointer::*;
Expand All @@ -10,9 +10,6 @@ use std::sync::atomic::{AtomicBool, AtomicU64, Ordering};

use crate::{BLOCK_FOR_GC, STW_COND, WORLD_HAS_STOPPED};

const GC_THREAD_KIND_CONTROLLER: libc::c_int = 0;
const GC_THREAD_KIND_WORKER: libc::c_int = 1;

static GC_START: AtomicU64 = AtomicU64::new(0);

pub struct VMCollection {}
Expand Down Expand Up @@ -111,19 +108,19 @@ impl Collection<JuliaVM> for VMCollection {
}

fn spawn_gc_thread(tls: VMThread, ctx: GCThreadContext<JuliaVM>) {
let (ctx_ptr, kind) = match ctx {
GCThreadContext::Controller(c) => (
Box::into_raw(c) as *mut libc::c_void,
GC_THREAD_KIND_CONTROLLER,
),
GCThreadContext::Worker(w) => {
(Box::into_raw(w) as *mut libc::c_void, GC_THREAD_KIND_WORKER)
// Just drop the join handle. The thread will run until the process quits.
let _ = std::thread::spawn(move || {
use mmtk::util::opaque_pointer::*;
let worker_tls = VMWorkerThread(tls);
match ctx {
GCThreadContext::Controller(mut c) => {
mmtk::memory_manager::start_control_collector(&SINGLETON, worker_tls, &mut c)
}
GCThreadContext::Worker(mut w) => {
mmtk::memory_manager::start_worker(&SINGLETON, worker_tls, &mut w)
}
}
};

unsafe {
spawn_collector_thread(tls, ctx_ptr as usize as _, kind);
}
});
}

fn schedule_finalization(_tls: VMWorkerThread) {}
Expand Down
20 changes: 2 additions & 18 deletions mmtk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@ extern crate mmtk;
#[macro_use]
extern crate lazy_static;

use mmtk::scheduler::*;
use mmtk::util::opaque_pointer::*;
use mmtk::util::Address;
use mmtk::util::ObjectReference;
use mmtk::vm::VMBinding;
use mmtk::MMTKBuilder;
use mmtk::Mutator;
use mmtk::MMTK;

use std::collections::HashMap;
Expand Down Expand Up @@ -67,11 +65,8 @@ lazy_static! {
};
}

#[link(kind = "static", name = "runtime_gc_c")]
extern "C" {
pub static JULIA_HEADER_SIZE: usize;
pub static JULIA_BUFF_TAG: usize;
}
pub static mut JULIA_HEADER_SIZE: usize = 0;
pub static mut JULIA_BUFF_TAG: usize = 0;

#[no_mangle]
pub static BLOCK_FOR_GC: AtomicBool = AtomicBool::new(false);
Expand Down Expand Up @@ -100,17 +95,6 @@ lazy_static! {
pub static ref MUTATORS: RwLock<HashMap<Address, Address>> = RwLock::new(HashMap::new());
}

#[link(name = "runtime_gc_c")]
#[allow(improper_ctypes)]
extern "C" {
pub fn spawn_collector_thread(tls: VMThread, ctx: *mut GCWorker<JuliaVM>, kind: i32);
pub fn set_julia_obj_header_size_and_buffer_tag(size: usize, tag: usize);
pub fn reset_mutator_count();
pub fn get_next_julia_mutator() -> usize;
pub fn get_mutator_ref(mutator: *mut Mutator<JuliaVM>) -> ObjectReference;
pub fn get_mutator_from_ref(mutator: ObjectReference) -> *mut Mutator<JuliaVM>;
}

type ProcessEdgeFn = *const extern "C" fn(closure: Address, slot: Address);

#[repr(C)]
Expand Down

0 comments on commit 72c87fd

Please sign in to comment.