Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
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
86 changes: 47 additions & 39 deletions mmtk/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion mmtk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ memoffset = "0.9.0"
# - change branch
# - change repo name
# But other changes including adding/removing whitespaces in commented lines may break the CI.
mmtk = { git = "https://github.com/mmtk/mmtk-core.git", rev = "e79e94e744660c486d5471f252ff05c4248bcea9" }
mmtk = { git = "https://github.com/wks/mmtk-core.git", rev = "6aa75cd72247d12b9568dc321c46feca6572a512" }
# Uncomment the following to build locally
# mmtk = { path = "../repos/mmtk-core" }

Expand Down
10 changes: 3 additions & 7 deletions mmtk/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use mmtk::memory_manager;
use mmtk::plan::BarrierSelector;
use mmtk::scheduler::GCWorker;
use mmtk::util::alloc::AllocatorSelector;
use mmtk::util::apiutils::NullableObjectReference;
use mmtk::util::opaque_pointer::*;
use mmtk::util::{Address, ObjectReference};
use mmtk::AllocationSemantics;
Expand Down Expand Up @@ -492,13 +493,8 @@ pub extern "C" fn add_finalizer(object: ObjectReference) {
}

#[no_mangle]
pub extern "C" fn get_finalized_object() -> ObjectReference {
with_singleton!(|singleton| {
match memory_manager::get_finalized_object(singleton) {
Some(obj) => obj,
None => ObjectReference::NULL,
}
})
pub extern "C" fn get_finalized_object() -> NullableObjectReference {
with_singleton!(|singleton| memory_manager::get_finalized_object(singleton).into())
}

thread_local! {
Expand Down
48 changes: 34 additions & 14 deletions mmtk/src/edges.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,37 +127,57 @@ impl<const COMPRESSED: bool> OpenJDKEdge<COMPRESSED> {

/// encode an object pointer to its u32 compressed form
fn compress(o: ObjectReference) -> u32 {
if o.is_null() {
0u32
} else {
((o.to_raw_address() - BASE.load(Ordering::Relaxed)) >> SHIFT.load(Ordering::Relaxed))
as u32
}
((o.to_raw_address() - BASE.load(Ordering::Relaxed)) >> SHIFT.load(Ordering::Relaxed))
as u32
}

/// decode an object pointer from its u32 compressed form
fn decompress(v: u32) -> ObjectReference {
fn decompress(v: u32) -> Option<ObjectReference> {
if v == 0 {
ObjectReference::NULL
None
} else {
// Note on `unsafe`: `v` must be positive here, so the result must be positive.
let objref = unsafe {
ObjectReference::from_raw_address_unchecked(
BASE.load(Ordering::Relaxed) + ((v as usize) << SHIFT.load(Ordering::Relaxed)),
)
};
Some(objref)
}
}

/// Store a null reference in the slot.
pub fn store_null(&self) {
if cfg!(any(target_arch = "x86", target_arch = "x86_64")) {
if COMPRESSED {
if self.is_compressed() {
self.x86_write_unaligned::<u32, true>(0)
} else {
self.x86_write_unaligned::<Address, true>(Address::ZERO)
}
} else {
self.x86_write_unaligned::<Address, false>(Address::ZERO)
}
} else {
ObjectReference::from_raw_address(
BASE.load(Ordering::Relaxed) + ((v as usize) << SHIFT.load(Ordering::Relaxed)),
)
debug_assert!(!COMPRESSED);
unsafe { self.addr.store(0) }
}
}
}

impl<const COMPRESSED: bool> Edge for OpenJDKEdge<COMPRESSED> {
fn load(&self) -> ObjectReference {
fn load(&self) -> Option<ObjectReference> {
if cfg!(any(target_arch = "x86", target_arch = "x86_64")) {
if COMPRESSED {
if self.is_compressed() {
Self::decompress(self.x86_read_unaligned::<u32, true>())
} else {
self.x86_read_unaligned::<ObjectReference, true>()
let addr = self.x86_read_unaligned::<Address, true>();
ObjectReference::from_raw_address(addr)
}
} else {
self.x86_read_unaligned::<ObjectReference, false>()
let addr = self.x86_read_unaligned::<Address, false>();
ObjectReference::from_raw_address(addr)
}
} else {
debug_assert!(!COMPRESSED);
Expand Down
10 changes: 7 additions & 3 deletions mmtk/src/object_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ impl<const COMPRESSED: bool> ObjectModel<OpenJDK<COMPRESSED>> for VMObjectModel<
) -> ObjectReference {
let bytes = unsafe { Oop::from(from).size::<COMPRESSED>() };
let dst = copy_context.alloc_copy(from, bytes, ::std::mem::size_of::<usize>(), 0, copy);
debug_assert!(!dst.is_zero());
// Copy
let src = from.to_raw_address();
unsafe { std::ptr::copy_nonoverlapping::<u8>(src.to_ptr(), dst.to_mut_ptr(), bytes) }
let to_obj = ObjectReference::from_raw_address(dst);
// Note on onsafe: `alloc_copy` never returns 0.
let to_obj = unsafe { ObjectReference::from_raw_address_unchecked(dst) };
copy_context.post_copy(to_obj, bytes, copy);
to_obj
}
Expand All @@ -56,7 +58,8 @@ impl<const COMPRESSED: bool> ObjectModel<OpenJDK<COMPRESSED>> for VMObjectModel<
}

fn get_reference_when_copied_to(_from: ObjectReference, to: Address) -> ObjectReference {
ObjectReference::from_raw_address(to)
debug_assert!(!to.is_zero());
unsafe { ObjectReference::from_raw_address_unchecked(to) }
}

fn get_current_size(object: ObjectReference) -> usize {
Expand Down Expand Up @@ -93,7 +96,8 @@ impl<const COMPRESSED: bool> ObjectModel<OpenJDK<COMPRESSED>> for VMObjectModel<
}

fn address_to_ref(address: Address) -> ObjectReference {
ObjectReference::from_raw_address(address)
debug_assert!(!address.is_zero());
unsafe { ObjectReference::from_raw_address_unchecked(address) }
}

fn dump_object(object: ObjectReference) {
Expand Down
6 changes: 5 additions & 1 deletion mmtk/src/reference_glue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ impl<const COMPRESSED: bool> ReferenceGlue<OpenJDK<COMPRESSED>> for VMReferenceG
let oop = Oop::from(reff);
InstanceRefKlass::referent_address::<COMPRESSED>(oop).store(referent);
}
fn get_referent(object: ObjectReference) -> ObjectReference {
fn get_referent(object: ObjectReference) -> Option<ObjectReference> {
let oop = Oop::from(object);
InstanceRefKlass::referent_address::<COMPRESSED>(oop).load()
}
Expand All @@ -24,4 +24,8 @@ impl<const COMPRESSED: bool> ReferenceGlue<OpenJDK<COMPRESSED>> for VMReferenceG
((*UPCALLS).enqueue_references)(references.as_ptr(), references.len());
}
}
fn clear_referent(new_reference: ObjectReference) {
let oop = Oop::from(new_reference);
InstanceRefKlass::referent_address::<COMPRESSED>(oop).store_null();
}
}