Skip to content

Edge trait #160

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 2 commits into from
Aug 29, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 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 @@ -29,7 +29,7 @@ once_cell = "1.10.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 = "d8bcf90991224cfe06153689b14c3e1eea0e025e" }
mmtk = { git = "https://github.com/mmtk/mmtk-core.git", rev = "76131c493be38e421f5fb157f9900f850584554f" }
# Uncomment the following to build locally
# mmtk = { path = "../repos/mmtk-core" }

Expand Down
14 changes: 7 additions & 7 deletions mmtk/src/gc_work.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
use std::sync::atomic::Ordering;

use super::{OpenJDK, UPCALLS};
use super::{OpenJDK, OpenJDKEdge, UPCALLS};
use mmtk::scheduler::*;
use mmtk::vm::RootsWorkFactory;
use mmtk::MMTK;
use scanning::to_edges_closure;

macro_rules! scan_roots_work {
($struct_name: ident, $func_name: ident) => {
pub struct $struct_name<F: RootsWorkFactory> {
pub struct $struct_name<F: RootsWorkFactory<OpenJDKEdge>> {
factory: F,
}

impl<F: RootsWorkFactory> $struct_name<F> {
impl<F: RootsWorkFactory<OpenJDKEdge>> $struct_name<F> {
pub fn new(factory: F) -> Self {
Self { factory }
}
}

impl<F: RootsWorkFactory> GCWork<OpenJDK> for $struct_name<F> {
impl<F: RootsWorkFactory<OpenJDKEdge>> GCWork<OpenJDK> for $struct_name<F> {
fn do_work(&mut self, _worker: &mut GCWorker<OpenJDK>, _mmtk: &'static MMTK<OpenJDK>) {
unsafe {
((*UPCALLS).$func_name)(to_edges_closure(&mut self.factory));
Expand All @@ -43,17 +43,17 @@ scan_roots_work!(
scan_roots_work!(ScanWeakProcessorRoots, scan_weak_processor_roots);
scan_roots_work!(ScanVMThreadRoots, scan_vm_thread_roots);

pub struct ScanCodeCacheRoots<F: RootsWorkFactory> {
pub struct ScanCodeCacheRoots<F: RootsWorkFactory<OpenJDKEdge>> {
factory: F,
}

impl<F: RootsWorkFactory> ScanCodeCacheRoots<F> {
impl<F: RootsWorkFactory<OpenJDKEdge>> ScanCodeCacheRoots<F> {
pub fn new(factory: F) -> Self {
Self { factory }
}
}

impl<F: RootsWorkFactory> GCWork<OpenJDK> for ScanCodeCacheRoots<F> {
impl<F: RootsWorkFactory<OpenJDKEdge>> GCWork<OpenJDK> for ScanCodeCacheRoots<F> {
fn do_work(&mut self, _worker: &mut GCWorker<OpenJDK>, _mmtk: &'static MMTK<OpenJDK>) {
// Collect all the cached roots
let mut edges = Vec::with_capacity(crate::CODE_CACHE_ROOTS_SIZE.load(Ordering::Relaxed));
Expand Down
9 changes: 9 additions & 0 deletions mmtk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,21 @@ pub static GLOBAL_ALLOC_BIT_ADDRESS: uintptr_t =
#[derive(Default)]
pub struct OpenJDK;

/// The type of edges in OpenJDK.
///
/// TODO: We currently make it an alias to Address to make the change minimal.
/// If we support CompressedOOPs, we should define an enum type to support both
/// compressed and uncompressed OOPs.
pub type OpenJDKEdge = Address;

impl VMBinding for OpenJDK {
type VMObjectModel = object_model::VMObjectModel;
type VMScanning = scanning::VMScanning;
type VMCollection = collection::VMCollection;
type VMActivePlan = active_plan::VMActivePlan;
type VMReferenceGlue = reference_glue::VMReferenceGlue;

type VMEdge = OpenJDKEdge;
}

use std::sync::atomic::AtomicBool;
Expand Down
30 changes: 17 additions & 13 deletions mmtk/src/object_scanning.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
use super::abi::*;
use super::UPCALLS;
use super::{OpenJDKEdge, UPCALLS};
use mmtk::util::constants::*;
use mmtk::util::opaque_pointer::*;
use mmtk::util::{Address, ObjectReference};
use mmtk::vm::EdgeVisitor;
use std::{mem, slice};

trait OopIterate: Sized {
fn oop_iterate(&self, oop: Oop, closure: &mut impl EdgeVisitor);
fn oop_iterate(&self, oop: Oop, closure: &mut impl EdgeVisitor<OpenJDKEdge>);
}

impl OopIterate for OopMapBlock {
#[inline]
fn oop_iterate(&self, oop: Oop, closure: &mut impl EdgeVisitor) {
fn oop_iterate(&self, oop: Oop, closure: &mut impl EdgeVisitor<OpenJDKEdge>) {
let start = oop.get_field_address(self.offset);
for i in 0..self.count as usize {
let edge = start + (i << LOG_BYTES_IN_ADDRESS);
Expand All @@ -23,7 +23,7 @@ impl OopIterate for OopMapBlock {

impl OopIterate for InstanceKlass {
#[inline]
fn oop_iterate(&self, oop: Oop, closure: &mut impl EdgeVisitor) {
fn oop_iterate(&self, oop: Oop, closure: &mut impl EdgeVisitor<OpenJDKEdge>) {
let oop_maps = self.nonstatic_oop_maps();
for map in oop_maps {
map.oop_iterate(oop, closure)
Expand All @@ -33,7 +33,7 @@ impl OopIterate for InstanceKlass {

impl OopIterate for InstanceMirrorKlass {
#[inline]
fn oop_iterate(&self, oop: Oop, closure: &mut impl EdgeVisitor) {
fn oop_iterate(&self, oop: Oop, closure: &mut impl EdgeVisitor<OpenJDKEdge>) {
self.instance_klass.oop_iterate(oop, closure);
// if (Devirtualizer::do_metadata(closure)) {
// Klass* klass = java_lang_Class::as_Klass(obj);
Expand Down Expand Up @@ -74,7 +74,7 @@ impl OopIterate for InstanceMirrorKlass {

impl OopIterate for InstanceClassLoaderKlass {
#[inline]
fn oop_iterate(&self, oop: Oop, closure: &mut impl EdgeVisitor) {
fn oop_iterate(&self, oop: Oop, closure: &mut impl EdgeVisitor<OpenJDKEdge>) {
self.instance_klass.oop_iterate(oop, closure);
// if (Devirtualizer::do_metadata(closure)) {
// ClassLoaderData* cld = java_lang_ClassLoader::loader_data(obj);
Expand All @@ -88,7 +88,7 @@ impl OopIterate for InstanceClassLoaderKlass {

impl OopIterate for ObjArrayKlass {
#[inline]
fn oop_iterate(&self, oop: Oop, closure: &mut impl EdgeVisitor) {
fn oop_iterate(&self, oop: Oop, closure: &mut impl EdgeVisitor<OpenJDKEdge>) {
let array = unsafe { oop.as_array_oop() };
for oop in unsafe { array.data::<Oop>(BasicType::T_OBJECT) } {
closure.visit_edge(Address::from_ref(oop as &Oop));
Expand All @@ -98,15 +98,15 @@ impl OopIterate for ObjArrayKlass {

impl OopIterate for TypeArrayKlass {
#[inline]
fn oop_iterate(&self, _oop: Oop, _closure: &mut impl EdgeVisitor) {
fn oop_iterate(&self, _oop: Oop, _closure: &mut impl EdgeVisitor<OpenJDKEdge>) {
// Performance tweak: We skip processing the klass pointer since all
// TypeArrayKlasses are guaranteed processed via the null class loader.
}
}

impl OopIterate for InstanceRefKlass {
#[inline]
fn oop_iterate(&self, oop: Oop, closure: &mut impl EdgeVisitor) {
fn oop_iterate(&self, oop: Oop, closure: &mut impl EdgeVisitor<OpenJDKEdge>) {
use crate::abi::*;
use crate::api::{add_phantom_candidate, add_soft_candidate, add_weak_candidate};
self.instance_klass.oop_iterate(oop, closure);
Expand Down Expand Up @@ -139,7 +139,7 @@ impl InstanceRefKlass {
!*SINGLETON.get_options().no_reference_types
}
#[inline]
fn process_ref_as_strong(oop: Oop, closure: &mut impl EdgeVisitor) {
fn process_ref_as_strong(oop: Oop, closure: &mut impl EdgeVisitor<OpenJDKEdge>) {
let referent_addr = Self::referent_address(oop);
closure.visit_edge(referent_addr);
let discovered_addr = Self::discovered_address(oop);
Expand All @@ -148,14 +148,14 @@ impl InstanceRefKlass {
}

#[allow(unused)]
fn oop_iterate_slow(oop: Oop, closure: &mut impl EdgeVisitor, tls: OpaquePointer) {
fn oop_iterate_slow(oop: Oop, closure: &mut impl EdgeVisitor<OpenJDKEdge>, tls: OpaquePointer) {
unsafe {
((*UPCALLS).scan_object)(closure as *mut _ as _, mem::transmute(oop), tls);
}
}

#[inline]
fn oop_iterate(oop: Oop, closure: &mut impl EdgeVisitor) {
fn oop_iterate(oop: Oop, closure: &mut impl EdgeVisitor<OpenJDKEdge>) {
let klass_id = oop.klass.id;
debug_assert!(
klass_id as i32 >= 0 && (klass_id as i32) < 6,
Expand Down Expand Up @@ -192,7 +192,11 @@ fn oop_iterate(oop: Oop, closure: &mut impl EdgeVisitor) {
}

#[inline]
pub fn scan_object(object: ObjectReference, closure: &mut impl EdgeVisitor, _tls: VMWorkerThread) {
pub fn scan_object(
object: ObjectReference,
closure: &mut impl EdgeVisitor<OpenJDKEdge>,
_tls: VMWorkerThread,
) {
// println!("*****scan_object(0x{:x}) -> \n 0x{:x}, 0x{:x} \n",
// object,
// unsafe { *(object.value() as *const usize) },
Expand Down
14 changes: 7 additions & 7 deletions mmtk/src/scanning.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::gc_work::*;
use super::{NewBuffer, SINGLETON, UPCALLS};
use super::{NewBuffer, OpenJDKEdge, SINGLETON, UPCALLS};
use crate::{EdgesClosure, OpenJDK};
use mmtk::memory_manager;
use mmtk::scheduler::WorkBucketStage;
Expand All @@ -13,7 +13,7 @@ pub struct VMScanning {}

const WORK_PACKET_CAPACITY: usize = 4096;

extern "C" fn report_edges_and_renew_buffer<F: RootsWorkFactory>(
extern "C" fn report_edges_and_renew_buffer<F: RootsWorkFactory<OpenJDKEdge>>(
ptr: *mut Address,
length: usize,
capacity: usize,
Expand All @@ -34,7 +34,7 @@ extern "C" fn report_edges_and_renew_buffer<F: RootsWorkFactory>(
NewBuffer { ptr, capacity }
}

pub(crate) fn to_edges_closure<F: RootsWorkFactory>(factory: &mut F) -> EdgesClosure {
pub(crate) fn to_edges_closure<F: RootsWorkFactory<OpenJDKEdge>>(factory: &mut F) -> EdgesClosure {
EdgesClosure {
func: report_edges_and_renew_buffer::<F> as *const _,
data: factory as *mut F as *mut libc::c_void,
Expand All @@ -45,7 +45,7 @@ impl Scanning<OpenJDK> for VMScanning {
const SCAN_MUTATORS_IN_SAFEPOINT: bool = false;
const SINGLE_THREAD_MUTATOR_SCANNING: bool = false;

fn scan_object<EV: EdgeVisitor>(
fn scan_object<EV: EdgeVisitor<OpenJDKEdge>>(
tls: VMWorkerThread,
object: ObjectReference,
edge_visitor: &mut EV,
Expand All @@ -58,7 +58,7 @@ impl Scanning<OpenJDK> for VMScanning {
// TODO
}

fn scan_thread_roots(_tls: VMWorkerThread, mut factory: impl RootsWorkFactory) {
fn scan_thread_roots(_tls: VMWorkerThread, mut factory: impl RootsWorkFactory<OpenJDKEdge>) {
unsafe {
((*UPCALLS).scan_all_thread_roots)(to_edges_closure(&mut factory));
}
Expand All @@ -67,15 +67,15 @@ impl Scanning<OpenJDK> for VMScanning {
fn scan_thread_root(
_tls: VMWorkerThread,
mutator: &'static mut Mutator<OpenJDK>,
mut factory: impl RootsWorkFactory,
mut factory: impl RootsWorkFactory<OpenJDKEdge>,
) {
let tls = mutator.get_tls();
unsafe {
((*UPCALLS).scan_thread_roots)(to_edges_closure(&mut factory), tls);
}
}

fn scan_vm_specific_roots(_tls: VMWorkerThread, factory: impl RootsWorkFactory) {
fn scan_vm_specific_roots(_tls: VMWorkerThread, factory: impl RootsWorkFactory<OpenJDKEdge>) {
memory_manager::add_work_packets(
&SINGLETON,
WorkBucketStage::Prepare,
Expand Down