Skip to content

Commit f963f26

Browse files
committed
Add features to control dump frag tats
1 parent fc86e67 commit f963f26

File tree

3 files changed

+61
-47
lines changed

3 files changed

+61
-47
lines changed

Makefile

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ endif
1919
endif
2020

2121
PROJECT_DIRS := JULIA_PATH=$(JULIA_PATH) MMTK_JULIA_DIR=$(MMTK_JULIA_DIR)
22-
MMTK_VARS := MMTK_PLAN=$(MMTK_PLAN) MMTK_MOVING=$(MMTK_MOVING) MMTK_ALWAYS_MOVING=$(MMTK_ALWAYS_MOVING) MMTK_MAX_MOVING=$(MMTK_MAX_MOVING)
22+
MMTK_VARS := MMTK_PLAN=$(MMTK_PLAN) MMTK_MOVING=$(MMTK_MOVING) MMTK_ALWAYS_MOVING=$(MMTK_ALWAYS_MOVING) MMTK_MAX_MOVING=$(MMTK_MAX_MOVING) MMTK_DUMP_FRAGMENTATION=$(MMTK_DUMP_FRAGMENTATION) MMTK_DUMP_BLOCK_STATS=$(MMTK_DUMP_BLOCK_STATS) MMTK_DUMP_HEAP=$(MMTK_DUMP_HEAP)
2323

2424
ifeq (${MMTK_PLAN},Immix)
2525
CARGO_FEATURES = immix
@@ -41,6 +41,18 @@ ifeq ($(MMTK_MAX_MOVING), 1)
4141
CARGO_FEATURES := $(CARGO_FEATURES),immix_max_moving
4242
endif
4343

44+
ifeq ($(MMTK_DUMP_FRAGMENTATION), 1)
45+
CARGO_FEATURES := $(CARGO_FEATURES),print_fragmentation
46+
endif
47+
48+
ifeq ($(MMTK_DUMP_BLOCK_STATS), 1)
49+
CARGO_FEATURES := $(CARGO_FEATURES),dump_block_stats
50+
endif
51+
52+
ifeq ($(MMTK_DUMP_HEAP), 1)
53+
CARGO_FEATURES := $(CARGO_FEATURES),heap_dump
54+
endif
55+
4456
# Build the mmtk-julia project
4557
# Note that we might need to clone julia if it doesn't exist
4658
# since we need to run bindgen as part of building mmtk-julia

mmtk/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ json = "0.12.4"
4242

4343
[features]
4444
# We must build with default features
45-
default = ["mmtk/vm_space", "julia_copy_stack", "mmtk/object_pinning", "mmtk/is_mmtk_object", "mmtk/vo_bit_access", "address_based_hashing"]#, "dump_memory_stats"]
45+
default = ["mmtk/vm_space", "julia_copy_stack", "mmtk/object_pinning", "mmtk/is_mmtk_object", "mmtk/vo_bit_access", "address_based_hashing", "heap_dump"]#, "dump_memory_stats"]
4646

4747
# Default features
4848
julia_copy_stack = []
@@ -66,4 +66,7 @@ immix_max_moving = ["mmtk/immix_stress_defrag", "mmtk/immix_defrag_every_block"]
6666
dump_memory_stats = ["mmtk/dump_memory_stats"]
6767

6868
address_based_hashing = []
69+
6970
heap_dump = []
71+
dump_block_stats = []
72+
print_fragmentation = []

mmtk/src/collection.rs

Lines changed: 44 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,13 @@ impl Collection<JuliaVM> for VMCollection {
101101

102102
#[cfg(feature = "heap_dump")]
103103
dump_heap(GC_COUNT.load(Ordering::SeqCst), 1);
104-
// dump_immix_block_stats();
105104
GC_COUNT.fetch_add(1, Ordering::SeqCst);
106105

106+
#[cfg(feature = "dump_block_stats")]
107+
dump_immix_block_stats();
108+
#[cfg(feature = "print_fragmentation")]
109+
print_fragmentation();
110+
107111
AtomicBool::store(&BLOCK_FOR_GC, false, Ordering::SeqCst);
108112
AtomicBool::store(&WORLD_HAS_STOPPED, false, Ordering::SeqCst);
109113

@@ -204,57 +208,52 @@ pub extern "C" fn mmtk_block_thread_for_gc() {
204208
AtomicIsize::store(&USER_TRIGGERED_GC, 0, Ordering::SeqCst);
205209
}
206210

207-
// This will dump the block stats for the last GC (it overwrites the file each time)
208-
// Setting it to true will make the runs much slower!!!
209-
const DUMP_BLOCK_STATS_FOR_HISTOGRAM: bool = false;
210211

212+
#[cfg(feature = "dump_block_stats")]
211213
pub fn dump_immix_block_stats() {
212214
use mmtk::util::Address;
213215
use mmtk::util::ObjectReference;
214216
use std::fs::OpenOptions;
215217
use std::io::Write;
216218

217-
if DUMP_BLOCK_STATS_FOR_HISTOGRAM {
218-
let mut file = OpenOptions::new()
219-
.create(true)
220-
.write(true)
221-
.truncate(true)
222-
.open("/home/eduardo/output-block-stats.log") // ← Replace with your desired file path
223-
.expect("Unable to open log file");
224-
225-
SINGLETON.enumerate_objects(
226-
|space_name: &str, block_start: Address, block_size: usize, object: ObjectReference| {
227-
if space_name == "immix" {
228-
writeln!(
229-
file,
230-
"Block: {}, object: {} ({}), size: {}, pinned: {}",
231-
block_start,
232-
object,
233-
unsafe {
234-
crate::julia_scanning::get_julia_object_type(object.to_raw_address())
235-
},
236-
unsafe { crate::object_model::get_so_object_size(object, crate::object_model::get_hash_size(object)) },
237-
mmtk::memory_manager::is_pinned(object),
238-
)
239-
.expect("Unable to write to log file");
240-
} else if space_name == "nonmoving" {
241-
writeln!(
242-
file,
243-
"Nonmoving: {}, object: {} ({}), size: {}, reachable: {}",
244-
block_start,
245-
object,
246-
unsafe {
247-
crate::julia_scanning::get_julia_object_type(object.to_raw_address())
248-
},
249-
unsafe { crate::object_model::get_so_object_size(object, 0) },
250-
object.is_reachable(),
251-
)
252-
.expect("Unable to write to log file");
253-
}
254-
},
255-
);
256-
print_fragmentation();
257-
}
219+
let mut file = OpenOptions::new()
220+
.create(true)
221+
.write(true)
222+
.truncate(true)
223+
.open("output-block-stats.log") // ← Replace with your desired file path
224+
.expect("Unable to open log file");
225+
226+
SINGLETON.enumerate_objects(
227+
|space_name: &str, block_start: Address, block_size: usize, object: ObjectReference| {
228+
if space_name == "immix" {
229+
writeln!(
230+
file,
231+
"Block: {}, object: {} ({}), size: {}, pinned: {}",
232+
block_start,
233+
object,
234+
unsafe {
235+
crate::julia_scanning::get_julia_object_type(object.to_raw_address())
236+
},
237+
unsafe { crate::object_model::get_so_object_size(object, crate::object_model::get_hash_size(object)) },
238+
mmtk::memory_manager::is_pinned(object),
239+
)
240+
.expect("Unable to write to log file");
241+
} else if space_name == "nonmoving" {
242+
writeln!(
243+
file,
244+
"Nonmoving: {}, object: {} ({}), size: {}, reachable: {}",
245+
block_start,
246+
object,
247+
unsafe {
248+
crate::julia_scanning::get_julia_object_type(object.to_raw_address())
249+
},
250+
unsafe { crate::object_model::get_so_object_size(object, 0) },
251+
object.is_reachable(),
252+
)
253+
.expect("Unable to write to log file");
254+
}
255+
},
256+
);
258257
}
259258

260259
#[cfg(feature = "heap_dump")]

0 commit comments

Comments
 (0)