Skip to content

Commit

Permalink
Remove unused table updating code
Browse files Browse the repository at this point in the history
  • Loading branch information
peterzhu2118 committed Oct 25, 2024
1 parent cfa1469 commit eb3de39
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 102 deletions.
3 changes: 0 additions & 3 deletions gc/mmtk.c
Original file line number Diff line number Diff line change
Expand Up @@ -406,9 +406,6 @@ MMTk_RubyUpcalls ruby_upcalls = {
rb_mmtk_scan_object_ruby_style,
rb_mmtk_call_gc_mark_children,
rb_mmtk_call_obj_free,
NULL,
NULL,
NULL,
rb_mmtk_vm_live_bytes,
rb_mmtk_update_global_tables,
rb_mmtk_global_tables_count,
Expand Down
3 changes: 0 additions & 3 deletions gc/mmtk.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,6 @@ typedef struct MMTk_RubyUpcalls {
void (*scan_object_ruby_style)(MMTk_ObjectReference object);
void (*call_gc_mark_children)(MMTk_ObjectReference object);
void (*call_obj_free)(MMTk_ObjectReference object);
void (*cleanup_generic_iv_tbl)(void);
void *(*get_original_givtbl)(MMTk_ObjectReference object);
void (*move_givtbl)(MMTk_ObjectReference old_objref, MMTk_ObjectReference new_objref);
size_t (*vm_live_bytes)(void);
void (*update_global_tables)(int tbl_idx);
int (*global_tables_count)(void);
Expand Down
36 changes: 1 addition & 35 deletions gc/mmtk/src/abi.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::api::RubyMutator;
use crate::{upcalls, Ruby};
use crate::Ruby;
use libc::c_int;
use mmtk::scheduler::GCWorker;
use mmtk::util::{Address, ObjectReference, VMMutatorThread, VMWorkerThread};
Expand Down Expand Up @@ -112,37 +112,6 @@ impl RubyObjectAccess {
pub fn object_size(&self) -> usize {
Self::prefix_size() + self.payload_size() + Self::suffix_size()
}

pub fn get_givtbl(&self) -> *mut libc::c_void {
if self.has_moved_givtbl() {
let moved_givtbl = crate::binding().moved_givtbl.lock().unwrap();
moved_givtbl
.get(&self.objref)
.unwrap_or_else(|| {
panic!(
"Object {} has HAS_MOVED_GIVTBL flag but not an entry in `moved_givtbl`",
self.objref
)
})
.gen_ivtbl
} else {
self.get_original_givtbl().unwrap_or_else(|| {
panic!(
"Object {} does not have HAS_MOVED_GIVTBL flag or original givtbl",
self.objref
)
})
}
}

pub fn get_original_givtbl(&self) -> Option<*mut libc::c_void> {
let addr = (upcalls().get_original_givtbl)(self.objref);
if addr.is_null() {
None
} else {
Some(addr)
}
}
}

type ObjectClosureFunction =
Expand Down Expand Up @@ -351,9 +320,6 @@ pub struct RubyUpcalls {
pub scan_object_ruby_style: extern "C" fn(object: ObjectReference),
pub call_gc_mark_children: extern "C" fn(object: ObjectReference),
pub call_obj_free: extern "C" fn(object: ObjectReference),
pub cleanup_generic_iv_tbl: extern "C" fn(),
pub get_original_givtbl: extern "C" fn(object: ObjectReference) -> *mut libc::c_void,
pub move_givtbl: extern "C" fn(old_objref: ObjectReference, new_objref: ObjectReference),
pub vm_live_bytes: extern "C" fn() -> usize,
pub update_global_tables: extern "C" fn(tbl_idx: c_int),
pub global_tables_count: extern "C" fn() -> c_int,
Expand Down
9 changes: 1 addition & 8 deletions gc/mmtk/src/binding.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use std::collections::{HashMap, HashSet};
use std::collections::HashSet;
use std::ffi::CString;
use std::sync::atomic::AtomicBool;
use std::sync::Mutex;
use std::thread::JoinHandle;

use libc::c_void;
use mmtk::util::ObjectReference;
use mmtk::MMTK;

Expand Down Expand Up @@ -49,17 +48,12 @@ impl RubyConfiguration {
}
}

pub(crate) struct MovedGIVTblEntry {
pub gen_ivtbl: *mut c_void,
}

pub struct RubyBinding {
pub mmtk: &'static MMTK<Ruby>,
pub options: RubyBindingOptions,
pub upcalls: *const abi::RubyUpcalls,
pub plan_name: Mutex<Option<CString>>,
pub weak_proc: WeakProcessor,
pub(crate) moved_givtbl: Mutex<HashMap<ObjectReference, MovedGIVTblEntry>>,
pub gc_thread_join_handles: Mutex<Vec<JoinHandle<()>>>,
pub wb_unprotected_objects: Mutex<HashSet<ObjectReference>>,

Expand All @@ -86,7 +80,6 @@ impl RubyBinding {
upcalls,
plan_name: Mutex::new(None),
weak_proc: WeakProcessor::new(),
moved_givtbl: Default::default(),
gc_thread_join_handles: Default::default(),
wb_unprotected_objects: Default::default(),

Expand Down
60 changes: 7 additions & 53 deletions gc/mmtk/src/object_model.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use std::ptr::copy_nonoverlapping;

use crate::abi::{RubyObjectAccess, MIN_OBJ_ALIGN, OBJREF_OFFSET};
use crate::abi::{RubyObjectAccess, OBJREF_OFFSET};
use crate::{abi, Ruby};
use mmtk::util::constants::BITS_IN_BYTE;
use mmtk::util::copy::{CopySemantics, GCWorkerCopyContext};
Expand Down Expand Up @@ -38,57 +36,13 @@ impl ObjectModel<Ruby> for VMObjectModel {
const NEED_VO_BITS_DURING_TRACING: bool = true;

fn copy(
from: ObjectReference,
semantics: CopySemantics,
copy_context: &mut GCWorkerCopyContext<Ruby>,
_from: ObjectReference,
_semantics: CopySemantics,
_copy_context: &mut GCWorkerCopyContext<Ruby>,
) -> ObjectReference {
let from_acc = RubyObjectAccess::from_objref(from);
let maybe_givtbl = from_acc.has_exivar_flag().then(|| {
from_acc
.get_original_givtbl()
.unwrap_or_else(|| panic!("Object {} has FL_EXIVAR but no givtbl.", from))
});
let from_start = from_acc.obj_start();
let object_size = from_acc.object_size();
let to_start = copy_context.alloc_copy(from, object_size, MIN_OBJ_ALIGN, 0, semantics);
debug_assert!(!to_start.is_zero());
let to_payload = to_start.add(OBJREF_OFFSET);
unsafe {
copy_nonoverlapping::<u8>(from_start.to_ptr(), to_start.to_mut_ptr(), object_size);
}
// unsafe: `to_payload`` cannot be zero because `alloc_copy`` never returns zero.
let to_obj = unsafe { ObjectReference::from_raw_address_unchecked(to_payload) };
copy_context.post_copy(to_obj, object_size, semantics);
log::trace!("Copied object from {} to {}", from, to_obj);

#[cfg(feature = "clear_old_copy")]
{
log::trace!(
"Clearing old copy {} ({}-{})",
from,
from_start,
from_start + object_size
);
// For debug purpose, we clear the old copy so that if the Ruby VM reads from the old
// copy again, it will likely result in an error.
unsafe { std::ptr::write_bytes::<u8>(from_start.to_mut_ptr(), 0, object_size) }
}

if let Some(givtbl) = maybe_givtbl {
{
let mut moved_givtbl = crate::binding().moved_givtbl.lock().unwrap();
moved_givtbl.insert(
to_obj,
crate::binding::MovedGIVTblEntry {
gen_ivtbl: givtbl,
},
);
}
let to_acc = RubyObjectAccess::from_objref(to_obj);
to_acc.set_has_moved_givtbl();
}

to_obj
unimplemented!(
"Copying GC not currently supported"
)
}

fn copy_to(_from: ObjectReference, _to: ObjectReference, _region: Address) -> Address {
Expand Down

0 comments on commit eb3de39

Please sign in to comment.