Skip to content

Commit 4d8c288

Browse files
committed
Collect live bytes per space, and report by space
1 parent 8640ab8 commit 4d8c288

File tree

15 files changed

+82
-57
lines changed

15 files changed

+82
-57
lines changed

src/global_state.rs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
use atomic_refcell::AtomicRefCell;
2+
#[cfg(feature = "count_live_bytes_in_gc")]
3+
use std::collections::HashMap;
14
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
25
use std::sync::Mutex;
36
use std::time::Instant;
47

5-
use atomic_refcell::AtomicRefCell;
6-
78
/// This stores some global states for an MMTK instance.
89
/// Some MMTK components like plans and allocators may keep an reference to the struct, and can access it.
910
// This used to be a part of the `BasePlan`. In that case, any component that accesses
@@ -47,7 +48,7 @@ pub struct GlobalState {
4748
pub(crate) malloc_bytes: AtomicUsize,
4849
/// This stores the size in bytes for all the live objects in last GC. This counter is only updated in the GC release phase.
4950
#[cfg(feature = "count_live_bytes_in_gc")]
50-
pub(crate) live_bytes_in_last_gc: AtomicUsize,
51+
pub(crate) live_bytes_in_last_gc: AtomicRefCell<HashMap<&'static str, usize>>,
5152
}
5253

5354
impl GlobalState {
@@ -183,16 +184,6 @@ impl GlobalState {
183184
pub(crate) fn decrease_malloc_bytes_by(&self, size: usize) {
184185
self.malloc_bytes.fetch_sub(size, Ordering::SeqCst);
185186
}
186-
187-
#[cfg(feature = "count_live_bytes_in_gc")]
188-
pub fn get_live_bytes_in_last_gc(&self) -> usize {
189-
self.live_bytes_in_last_gc.load(Ordering::SeqCst)
190-
}
191-
192-
#[cfg(feature = "count_live_bytes_in_gc")]
193-
pub fn set_live_bytes_in_last_gc(&self, size: usize) {
194-
self.live_bytes_in_last_gc.store(size, Ordering::SeqCst);
195-
}
196187
}
197188

198189
impl Default for GlobalState {
@@ -214,7 +205,7 @@ impl Default for GlobalState {
214205
#[cfg(feature = "malloc_counted_size")]
215206
malloc_bytes: AtomicUsize::new(0),
216207
#[cfg(feature = "count_live_bytes_in_gc")]
217-
live_bytes_in_last_gc: AtomicUsize::new(0),
208+
live_bytes_in_last_gc: AtomicRefCell::new(HashMap::new()),
218209
}
219210
}
220211
}

src/memory_manager.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ use crate::vm::slot::MemorySlice;
2626
use crate::vm::ReferenceGlue;
2727
use crate::vm::VMBinding;
2828

29+
#[cfg(feature = "count_live_bytes_in_gc")]
30+
use std::collections::HashMap;
31+
2932
/// Initialize an MMTk instance. A VM should call this method after creating an [`crate::MMTK`]
3033
/// instance but before using any of the methods provided in MMTk (except `process()` and `process_bulk()`).
3134
///
@@ -538,9 +541,8 @@ pub fn free_bytes<VM: VMBinding>(mmtk: &MMTK<VM>) -> usize {
538541
/// The value returned by this method is only updated when we finish tracing in a GC. A recommended timing
539542
/// to call this method is at the end of a GC (e.g. when the runtime is about to resume threads).
540543
#[cfg(feature = "count_live_bytes_in_gc")]
541-
pub fn live_bytes_in_last_gc<VM: VMBinding>(mmtk: &MMTK<VM>) -> usize {
542-
use std::sync::atomic::Ordering;
543-
mmtk.state.live_bytes_in_last_gc.load(Ordering::SeqCst)
544+
pub fn live_bytes_in_last_gc<VM: VMBinding>(mmtk: &MMTK<VM>) -> HashMap<&'static str, usize> {
545+
mmtk.state.live_bytes_in_last_gc.borrow().clone()
544546
}
545547

546548
/// Return the starting address of the heap. *Note that currently MMTk uses

src/policy/copyspace.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub struct CopySpace<VM: VMBinding> {
2525
}
2626

2727
impl<VM: VMBinding> SFT for CopySpace<VM> {
28-
fn name(&self) -> &str {
28+
fn name(&self) -> &'static str {
2929
self.get_name()
3030
}
3131

src/policy/immix/immixspace.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ pub struct ImmixSpaceArgs {
8686
unsafe impl<VM: VMBinding> Sync for ImmixSpace<VM> {}
8787

8888
impl<VM: VMBinding> SFT for ImmixSpace<VM> {
89-
fn name(&self) -> &str {
89+
fn name(&self) -> &'static str {
9090
self.get_name()
9191
}
9292

src/policy/immortalspace.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub struct ImmortalSpace<VM: VMBinding> {
2727
}
2828

2929
impl<VM: VMBinding> SFT for ImmortalSpace<VM> {
30-
fn name(&self) -> &str {
30+
fn name(&self) -> &'static str {
3131
self.get_name()
3232
}
3333
fn is_live(&self, _object: ObjectReference) -> bool {

src/policy/largeobjectspace.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub struct LargeObjectSpace<VM: VMBinding> {
3232
}
3333

3434
impl<VM: VMBinding> SFT for LargeObjectSpace<VM> {
35-
fn name(&self) -> &str {
35+
fn name(&self) -> &'static str {
3636
self.get_name()
3737
}
3838
fn is_live(&self, object: ObjectReference) -> bool {

src/policy/lockfreeimmortalspace.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub struct LockFreeImmortalSpace<VM: VMBinding> {
4545
}
4646

4747
impl<VM: VMBinding> SFT for LockFreeImmortalSpace<VM> {
48-
fn name(&self) -> &str {
48+
fn name(&self) -> &'static str {
4949
self.get_name()
5050
}
5151
fn is_live(&self, _object: ObjectReference) -> bool {

src/policy/markcompactspace.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub const GC_EXTRA_HEADER_WORD: usize = 1;
3333
const GC_EXTRA_HEADER_BYTES: usize = GC_EXTRA_HEADER_WORD << LOG_BYTES_IN_WORD;
3434

3535
impl<VM: VMBinding> SFT for MarkCompactSpace<VM> {
36-
fn name(&self) -> &str {
36+
fn name(&self) -> &'static str {
3737
self.get_name()
3838
}
3939

src/policy/marksweepspace/malloc_ms/global.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ pub struct MallocSpace<VM: VMBinding> {
6464
}
6565

6666
impl<VM: VMBinding> SFT for MallocSpace<VM> {
67-
fn name(&self) -> &str {
67+
fn name(&self) -> &'static str {
6868
self.get_name()
6969
}
7070

src/policy/marksweepspace/native_ms/global.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ impl AbandonedBlockLists {
157157
}
158158

159159
impl<VM: VMBinding> SFT for MarkSweepSpace<VM> {
160-
fn name(&self) -> &str {
160+
fn name(&self) -> &'static str {
161161
self.common.name
162162
}
163163

0 commit comments

Comments
 (0)