Skip to content

Commit 33fba23

Browse files
authored
Reduce public visibility (#312)
* Turns public modules to private or pub crate if possible * Removes some unused code/macros
1 parent 1ed7f0f commit 33fba23

34 files changed

+380
-255
lines changed

.github/scripts/ci-doc.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
. $(dirname "$0")/ci-common.sh
22

33
# Check cargo doc
4-
cargo doc --features $non_exclusive_features --no-deps
4+
# We generate docs including private items so it would be easier for MMTk developers (GC implementers). However,
5+
# this could be confusing to MMTk users (binding implementers), as they may find items in the doc which
6+
# are not visible to a binding. If we exclude private items, the doc would be easier for the users, but would hide
7+
# implementation details for developers.
8+
cargo doc --features $non_exclusive_features --no-deps --document-private-items
59

610
# Check tutorial code
711
tutorial_code_dir=$project_root/docs/tutorial/code/mygc_semispace

src/lib.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#![feature(asm)]
33
#![feature(const_fn)]
44
#![feature(integer_atomics)]
5+
#![feature(is_sorted)]
56
#![feature(drain_filter)]
67
#![feature(nll)]
78
#![feature(box_syntax)]
@@ -12,6 +13,8 @@
1213
#![feature(associated_type_defaults)]
1314
#![feature(specialization)]
1415
#![feature(trait_alias)]
16+
// TODO: We should fix missing docs for public items and turn this on (Issue #309).
17+
// #![deny(missing_docs)]
1518

1619
//! Memory Management ToolKit (MMTk) is a portable and high performance memory manager
1720
//! that includes various garbage collection algorithms and provides clean and efficient
@@ -50,17 +53,19 @@ extern crate num_cpus;
5053
#[macro_use]
5154
extern crate downcast_rs;
5255

53-
#[macro_use]
54-
pub mod util;
55-
mod mm;
5656
mod mmtk;
57+
pub use mmtk::MMTK;
58+
pub(crate) use mmtk::VM_MAP;
59+
60+
mod policy;
61+
62+
pub mod memory_manager;
5763
pub mod plan;
58-
pub mod policy;
5964
pub mod scheduler;
65+
pub mod util;
6066
pub mod vm;
6167

62-
pub use crate::mm::memory_manager;
63-
pub use crate::mmtk::MMTK;
6468
pub use crate::plan::{
65-
AllocationSemantics, CopyContext, Mutator, MutatorContext, Plan, TraceLocal, TransitiveClosure,
69+
AllocationSemantics, BarrierSelector, CopyContext, Mutator, MutatorContext, Plan, TraceLocal,
70+
TransitiveClosure,
6671
};

src/mm/memory_manager.rs renamed to src/memory_manager.rs

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@
1212
//! pointer. Either way, the VM binding code needs to guarantee the safety.
1313
1414
use crate::mmtk::MMTK;
15-
use crate::plan::mutator_context::{Mutator, MutatorContext};
1615
use crate::plan::AllocationSemantics;
16+
use crate::plan::{Mutator, MutatorContext};
1717
use crate::scheduler::GCWorker;
18+
use crate::scheduler::Work;
19+
use crate::scheduler::WorkBucketStage;
1820
use crate::util::alloc::allocators::AllocatorSelector;
1921
use crate::util::constants::LOG_BYTES_IN_PAGE;
2022
use crate::util::heap::layout::vm_layout_constants::HEAP_END;
@@ -49,7 +51,8 @@ pub fn gc_init<VM: VMBinding>(mmtk: &'static mut MMTK<VM>, heap_size: usize) {
4951
),
5052
}
5153
assert!(heap_size > 0, "Invalid heap size");
52-
mmtk.plan.gc_init(heap_size, &mmtk.vm_map, &mmtk.scheduler);
54+
mmtk.plan
55+
.gc_init(heap_size, &crate::VM_MAP, &mmtk.scheduler);
5356
info!("Initialized MMTk with {:?}", mmtk.options.plan);
5457
}
5558

@@ -63,7 +66,7 @@ pub fn bind_mutator<VM: VMBinding>(
6366
mmtk: &'static MMTK<VM>,
6467
tls: VMMutatorThread,
6568
) -> Box<Mutator<VM>> {
66-
crate::plan::global::create_mutator(tls, mmtk)
69+
crate::plan::create_mutator(tls, mmtk)
6770
}
6871

6972
/// Reclaim a mutator that is no longer needed.
@@ -372,3 +375,43 @@ pub fn get_finalized_object<VM: VMBinding>(mmtk: &'static MMTK<VM>) -> Option<Ob
372375
.unwrap()
373376
.get_ready_object()
374377
}
378+
379+
/// Get the number of workers. MMTk spawns worker threads for the 'threads' defined in the options.
380+
/// So the number of workers is derived from the threads option. Note the feature single_worker overwrites
381+
/// the threads option, and force one worker thread.
382+
///
383+
/// Arguments:
384+
/// * `mmtk`: A reference to an MMTk instance.
385+
pub fn num_of_workers<VM: VMBinding>(mmtk: &'static MMTK<VM>) -> usize {
386+
mmtk.scheduler.num_workers()
387+
}
388+
389+
/// Add a work packet to the given work bucket. Note that this simply adds the work packet to the given
390+
/// work bucket, and the scheduler will decide when to execute the work packet.
391+
///
392+
/// Arguments:
393+
/// * `mmtk`: A reference to an MMTk instance.
394+
/// * `bucket`: Which work bucket to add this packet to.
395+
/// * `packet`: The work packet to be added.
396+
pub fn add_work_packet<VM: VMBinding, W: Work<MMTK<VM>>>(
397+
mmtk: &'static MMTK<VM>,
398+
bucket: WorkBucketStage,
399+
packet: W,
400+
) {
401+
mmtk.scheduler.work_buckets[bucket].add(packet)
402+
}
403+
404+
/// Bulk add a number of work packets to the given work bucket. Note that this simply adds the work packets
405+
/// to the given work bucket, and the scheduler will decide when to execute the work packets.
406+
///
407+
/// Arguments:
408+
/// * `mmtk`: A reference to an MMTk instance.
409+
/// * `bucket`: Which work bucket to add these packets to.
410+
/// * `packet`: The work packets to be added.
411+
pub fn add_work_packets<VM: VMBinding>(
412+
mmtk: &'static MMTK<VM>,
413+
bucket: WorkBucketStage,
414+
packets: Vec<Box<dyn Work<MMTK<VM>>>>,
415+
) {
416+
mmtk.scheduler.work_buckets[bucket].bulk_add(packets)
417+
}

src/mm/mod.rs

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/mmtk.rs

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
///! MMTk instance.
12
use crate::plan::Plan;
23
use crate::policy::space::SFTMap;
3-
use crate::scheduler::Scheduler;
4+
use crate::scheduler::MMTkScheduler;
45
use crate::util::finalizable_processor::FinalizableProcessor;
56
use crate::util::heap::layout::heap_layout::Mmapper;
67
use crate::util::heap::layout::heap_layout::VMMap;
@@ -24,38 +25,37 @@ lazy_static! {
2425
// 2. These mmappers are possibly global across multiple MMTk instances, as they manage the
2526
// entire address space.
2627
// TODO: We should refactor this when we know more about how multiple MMTK instances work.
28+
29+
/// A global VMMap that manages the mapping of spaces to virtual memory ranges.
2730
pub static ref VM_MAP: VMMap = VMMap::new();
31+
32+
/// A global Mmapper for mmaping and protection of virtual memory.
2833
pub static ref MMAPPER: Mmapper = Mmapper::new();
34+
35+
// A global space function table that allows efficient dispatch space specific code for addresses in our heap.
2936
pub static ref SFT_MAP: SFTMap<'static> = SFTMap::new();
3037
}
3138

32-
/// An MMTk instance. MMTk allows mutiple instances to run independently, and each instance gives users a separate heap.
39+
/// An MMTk instance. MMTk allows multiple instances to run independently, and each instance gives users a separate heap.
3340
/// *Note that multi-instances is not fully supported yet*
3441
pub struct MMTK<VM: VMBinding> {
35-
pub plan: Box<dyn Plan<VM = VM>>,
36-
pub vm_map: &'static VMMap,
37-
pub mmapper: &'static Mmapper,
38-
pub sftmap: &'static SFTMap<'static>,
39-
pub reference_processors: ReferenceProcessors,
40-
pub finalizable_processor: Mutex<FinalizableProcessor>,
41-
pub options: Arc<UnsafeOptionsWrapper>,
42-
pub scheduler: Arc<Scheduler<Self>>,
42+
pub(crate) plan: Box<dyn Plan<VM = VM>>,
43+
pub(crate) reference_processors: ReferenceProcessors,
44+
pub(crate) finalizable_processor: Mutex<FinalizableProcessor>,
45+
pub(crate) options: Arc<UnsafeOptionsWrapper>,
46+
pub(crate) scheduler: Arc<MMTkScheduler<VM>>,
4347
#[cfg(feature = "sanity")]
44-
pub sanity_checker: Mutex<SanityChecker>,
48+
pub(crate) sanity_checker: Mutex<SanityChecker>,
4549
inside_harness: AtomicBool,
4650
}
4751

4852
impl<VM: VMBinding> MMTK<VM> {
4953
pub fn new() -> Self {
50-
let scheduler = Scheduler::new();
54+
let scheduler = MMTkScheduler::new();
5155
let options = Arc::new(UnsafeOptionsWrapper::new(Options::default()));
52-
let plan =
53-
crate::plan::global::create_plan(options.plan, &VM_MAP, &MMAPPER, options.clone());
56+
let plan = crate::plan::create_plan(options.plan, &VM_MAP, &MMAPPER, options.clone());
5457
MMTK {
5558
plan,
56-
vm_map: &VM_MAP,
57-
mmapper: &MMAPPER,
58-
sftmap: &SFT_MAP,
5959
reference_processors: ReferenceProcessors::new(),
6060
finalizable_processor: Mutex::new(FinalizableProcessor::new()),
6161
options,
@@ -78,6 +78,10 @@ impl<VM: VMBinding> MMTK<VM> {
7878
self.plan.base().stats.stop_all(self);
7979
self.inside_harness.store(false, Ordering::SeqCst);
8080
}
81+
82+
pub fn get_plan(&self) -> &dyn Plan<VM = VM> {
83+
self.plan.as_ref()
84+
}
8185
}
8286

8387
impl<VM: VMBinding> Default for MMTK<VM> {

src/plan/barriers.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use crate::util::side_metadata::*;
66
use crate::util::*;
77
use crate::MMTK;
88

9+
/// BarrierSelector describes which barrier to use.
910
#[derive(Copy, Clone, Debug, PartialEq)]
1011
pub enum BarrierSelector {
1112
NoBarrier,

src/plan/marksweep/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Plan: marksweep (currently using malloc as its freelist allocator)
2+
13
mod gc_work;
24
mod global;
35
pub mod mutator;

src/plan/mod.rs

Lines changed: 41 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,53 @@
22
//!
33
//! This module provides various GC plans, each of which implements a GC algorithm.
44
//! Generally a plan consists of a few parts:
5-
//! * A plan type that implements the [`Plan`](crate::plan::global::Plan) trait, which defines
5+
//! * A plan type that implements the [`Plan`](crate::plan::Plan) trait, which defines
66
//! spaces used in the plan, and their behaviors in GC and page accounting.
77
//! * A mutator definition, which describes the mapping between allocators and allocation semantics,
88
//! and the mapping between allocators and spaces. If the plan needs barrier, the barrier definition is
99
//! also included here.
10-
//! * A constant for [`PlanConstraints`](crate::plan::plan_constraints::PlanConstraints), which defines
10+
//! * A constant for [`PlanConstraints`](crate::plan::PlanConstraints), which defines
1111
//! plan-specific constants.
1212
//! * Plan-specific [`GCWork`](crate::scheduler::GCWork), which is scheduled during GC. If the plan
13-
//! implements a copying GC, a [`CopyContext`](crate::plan::global::CopyContext) also needs to be provided.
13+
//! implements a copying GC, a [`CopyContext`](crate::plan::CopyContext) also needs to be provided.
1414
//!
1515
//! For more about implementing a plan, it is recommended to read the [MMTk tutorial](/docs/tutorial/Tutorial.md).
1616
17-
pub mod barriers;
18-
pub mod controller_collector_context;
19-
pub mod global;
20-
pub mod mutator_context;
21-
pub mod plan_constraints;
22-
pub mod tracelocal;
23-
pub mod transitive_closure;
24-
pub use self::global::AllocationSemantics;
25-
pub use self::global::CopyContext;
26-
pub use self::global::Plan;
27-
pub use self::mutator_context::Mutator;
28-
pub use self::mutator_context::MutatorContext;
29-
pub use self::plan_constraints::PlanConstraints;
30-
pub use self::tracelocal::TraceLocal;
31-
pub use self::transitive_closure::TransitiveClosure;
32-
33-
pub mod gencopy;
34-
pub mod marksweep;
35-
pub mod nogc;
36-
pub mod semispace;
17+
mod barriers;
18+
pub use barriers::BarrierSelector;
19+
20+
mod controller_collector_context;
21+
22+
mod global;
23+
pub(crate) use global::create_mutator;
24+
pub(crate) use global::create_plan;
25+
pub use global::AllocationSemantics;
26+
pub use global::CopyContext;
27+
pub(crate) use global::GcStatus;
28+
pub use global::Plan;
29+
30+
mod mutator_context;
31+
pub use mutator_context::Mutator;
32+
pub use mutator_context::MutatorContext;
33+
34+
mod plan_constraints;
35+
pub use plan_constraints::PlanConstraints;
36+
37+
mod tracelocal;
38+
pub use tracelocal::TraceLocal;
39+
40+
mod transitive_closure;
41+
pub use transitive_closure::TransitiveClosure;
42+
43+
mod gencopy;
44+
mod marksweep;
45+
mod nogc;
46+
mod semispace;
47+
48+
// Expose plan constraints as public. Though a binding can get them from plan.constraints(),
49+
// it is possible for performance reasons that they want the constraints as constants.
50+
51+
pub use gencopy::GENCOPY_CONSTRAINTS;
52+
pub use marksweep::MS_CONSTRAINTS;
53+
pub use nogc::NOGC_CONSTRAINTS;
54+
pub use semispace::SS_CONSTRAINTS;

src/policy/copyspace.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use std::sync::atomic::{AtomicBool, Ordering};
1616

1717
const META_DATA_PAGES_PER_REGION: usize = CARD_META_PAGES_PER_REGION;
1818

19+
/// This type implements a simple copying space.
1920
pub struct CopySpace<VM: VMBinding> {
2021
common: CommonSpace<VM>,
2122
pr: MonotonePageResource<VM>,
@@ -153,6 +154,7 @@ impl<VM: VMBinding> CopySpace<VM> {
153154
}
154155
}
155156

157+
#[allow(dead_code)] // Only used with certain features (such as sanity)
156158
pub fn protect(&self) {
157159
if !self.common().contiguous {
158160
panic!(
@@ -167,6 +169,7 @@ impl<VM: VMBinding> CopySpace<VM> {
167169
trace!("Protect {:x} {:x}", start, start + extent);
168170
}
169171

172+
#[allow(dead_code)] // Only used with certain features (such as sanity)
170173
pub fn unprotect(&self) {
171174
if !self.common().contiguous {
172175
panic!(

src/policy/immortalspace.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ use crate::util::heap::HeapMeta;
1616
use crate::util::side_metadata::{SideMetadataContext, SideMetadataSpec};
1717
use crate::vm::VMBinding;
1818

19+
/// This type implements a simple immortal collection
20+
/// policy. Under this policy all that is required is for the
21+
/// "collector" to propagate marks in a liveness trace. It does not
22+
/// actually collect.
1923
pub struct ImmortalSpace<VM: VMBinding> {
2024
mark_state: u8,
2125
common: CommonSpace<VM>,

src/policy/largeobjectspace.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ const USE_PRECEEDING_GC_HEADER: bool = true;
2525
const PRECEEDING_GC_HEADER_WORDS: usize = 1;
2626
const PRECEEDING_GC_HEADER_BYTES: usize = PRECEEDING_GC_HEADER_WORDS << LOG_BYTES_IN_WORD;
2727

28+
/// This type implements a policy for large objects. Each instance corresponds
29+
/// to one Treadmill space.
2830
pub struct LargeObjectSpace<VM: VMBinding> {
2931
common: CommonSpace<VM>,
3032
pr: FreeListPageResource<VM>,

src/policy/lockfreeimmortalspace.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ use crate::vm::*;
1818
use std::marker::PhantomData;
1919
use std::sync::atomic::{AtomicUsize, Ordering};
2020

21+
/// This type implements a lock free version of the immortal collection
22+
/// policy. This is close to the OpenJDK's epsilon GC.
23+
/// Different from the normal ImmortalSpace, this version should only
24+
/// be used by NoGC plan, and it now uses the whole heap range.
25+
// FIXME: It is wrong that the space uses the whole heap range. It has to reserve its own
26+
// range from HeapMeta, and not clash with other spaces.
2127
pub struct LockFreeImmortalSpace<VM: VMBinding> {
2228
#[allow(unused)]
2329
name: &'static str,
@@ -122,6 +128,7 @@ impl<VM: VMBinding> Space<VM> for LockFreeImmortalSpace<VM> {
122128
}
123129

124130
impl<VM: VMBinding> LockFreeImmortalSpace<VM> {
131+
#[allow(dead_code)] // Only used with certain features.
125132
pub fn new(
126133
name: &'static str,
127134
slow_path_zeroing: bool,

src/policy/mallocspace/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
///! A marksweep space that allocates from malloc.
12
mod global;
23
pub mod metadata;
34

src/policy/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,3 @@ pub mod immortalspace;
1818
pub mod largeobjectspace;
1919
pub mod lockfreeimmortalspace;
2020
pub mod mallocspace;
21-
22-
pub const NUMBER_OF_POLICIES_REQUIRING_SIDE_METADATA: usize = 0;

src/policy/space.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ impl<'a> SFTMap<'a> {
186186
}
187187
}
188188

189+
// TODO: We should clear a SFT entry when a space releases a chunk.
190+
#[allow(dead_code)]
189191
pub fn clear(&self, chunk_idx: usize) {
190192
self.set(chunk_idx, &EMPTY_SPACE_SFT);
191193
}

0 commit comments

Comments
 (0)