Skip to content

Commit 97bace5

Browse files
udesouLuis Eduardo de Souza Amorim
andauthored
Applying cargo fmt and refactoring scanning code further (#254)
Running `cargo fmt`, fixing some warnings and rewriting a few other pieces of code in the object scanning function following from #253. Co-authored-by: Luis Eduardo de Souza Amorim <eduardo@boar.moma>
1 parent 1934317 commit 97bace5

File tree

4 files changed

+116
-87
lines changed

4 files changed

+116
-87
lines changed

mmtk/src/collection.rs

Lines changed: 60 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
use crate::jl_gc_log;
12
use crate::SINGLETON;
23
use crate::{
34
jl_gc_get_max_memory, jl_gc_prepare_to_collect, jl_gc_update_stats, jl_get_gc_disable_counter,
45
jl_hrtime, jl_throw_out_of_memory_error,
56
};
67
use crate::{JuliaVM, USER_TRIGGERED_GC};
7-
use crate::jl_gc_log;
88
use log::{debug, trace};
99
use mmtk::util::alloc::AllocationError;
1010
use mmtk::util::heap::GCTriggerPolicy;
@@ -26,6 +26,7 @@ use std::collections::HashSet;
2626
use std::sync::RwLock;
2727
use std::thread::ThreadId;
2828

29+
#[cfg(feature = "print_fragmentation")]
2930
use crate::api::print_fragmentation;
3031

3132
lazy_static! {
@@ -212,7 +213,6 @@ pub extern "C" fn mmtk_block_thread_for_gc() {
212213
AtomicIsize::store(&USER_TRIGGERED_GC, 0, Ordering::SeqCst);
213214
}
214215

215-
216216
#[cfg(feature = "dump_block_stats")]
217217
pub fn dump_immix_block_stats() {
218218
use mmtk::util::Address;
@@ -238,7 +238,12 @@ pub fn dump_immix_block_stats() {
238238
unsafe {
239239
crate::julia_scanning::get_julia_object_type(object.to_raw_address())
240240
},
241-
unsafe { crate::object_model::get_so_object_size(object, crate::object_model::get_hash_size(object)) },
241+
unsafe {
242+
crate::object_model::get_so_object_size(
243+
object,
244+
crate::object_model::get_hash_size(object),
245+
)
246+
},
242247
mmtk::memory_manager::is_pinned(object),
243248
)
244249
.expect("Unable to write to log file");
@@ -261,12 +266,13 @@ pub fn dump_immix_block_stats() {
261266
}
262267

263268
#[cfg(feature = "heap_dump")]
264-
pub fn dump_heap(gc_count: u64, phase: u64) { // phase: 0 for pre-gc, 1 for post-gc
269+
pub fn dump_heap(gc_count: u64, phase: u64) {
270+
// phase: 0 for pre-gc, 1 for post-gc
265271
println!("Dumping heap for GC {} phase {}", gc_count, phase);
272+
use json::JsonValue;
273+
use mmtk::util::constants::LOG_BYTES_IN_PAGE;
266274
use mmtk::util::heap::inspection::*;
267275
use mmtk::vm::ObjectModel;
268-
use mmtk::util::constants::LOG_BYTES_IN_PAGE;
269-
use json::JsonValue;
270276
use std::fs::File;
271277
use std::io::Write;
272278

@@ -278,7 +284,7 @@ pub fn dump_heap(gc_count: u64, phase: u64) { // phase: 0 for pre-gc, 1 for post
278284
json
279285
}
280286

281-
fn region_into_json(space: &dyn SpaceInspector, region: &dyn RegionInspector) -> JsonValue{
287+
fn region_into_json(space: &dyn SpaceInspector, region: &dyn RegionInspector) -> JsonValue {
282288
// println!("Dumping region: {} {}", region.region_type(), region.start());
283289
let mut json = JsonValue::new_object();
284290
json["type"] = JsonValue::String(region.region_type().to_string());
@@ -288,65 +294,74 @@ pub fn dump_heap(gc_count: u64, phase: u64) { // phase: 0 for pre-gc, 1 for post
288294
let sub_regions = space.list_sub_regions(region);
289295
if sub_regions.is_empty() {
290296
let objects = region.list_objects();
291-
json["objects"] = objects.into_iter().map(|object| {
292-
let mut obj_json = JsonValue::new_object();
293-
obj_json["address"] = JsonValue::String(format!("{}", object));
294-
obj_json["type"] = JsonValue::String(unsafe {
295-
crate::julia_scanning::get_julia_object_type(object.to_raw_address())
296-
});
297-
obj_json["size"] = JsonValue::Number(
298-
unsafe { crate::object_model::VMObjectModel::get_current_size(object) }.into(),
299-
);
300-
obj_json["pinned"] = JsonValue::Boolean(
301-
mmtk::memory_manager::is_pinned(object),
302-
);
303-
obj_json
304-
}).collect::<Vec<_>>().into();
297+
json["objects"] = objects
298+
.into_iter()
299+
.map(|object| {
300+
let mut obj_json = JsonValue::new_object();
301+
obj_json["address"] = JsonValue::String(format!("{}", object));
302+
obj_json["type"] = JsonValue::String(unsafe {
303+
crate::julia_scanning::get_julia_object_type(object.to_raw_address())
304+
});
305+
obj_json["size"] = JsonValue::Number(
306+
unsafe { crate::object_model::VMObjectModel::get_current_size(object) }
307+
.into(),
308+
);
309+
obj_json["pinned"] =
310+
JsonValue::Boolean(mmtk::memory_manager::is_pinned(object));
311+
obj_json
312+
})
313+
.collect::<Vec<_>>()
314+
.into();
305315
} else {
306-
json["regions"] = sub_regions.into_iter().map(|sub_region| {
307-
region_into_json(space, &*sub_region)
308-
}).collect::<Vec<_>>().into();
316+
json["regions"] = sub_regions
317+
.into_iter()
318+
.map(|sub_region| region_into_json(space, &*sub_region))
319+
.collect::<Vec<_>>()
320+
.into();
309321
}
310322

311323
json
312324
}
313325

314326
// Dump high-levvel space information
315327
{
316-
let mut file = File::create(format!(
317-
"spaces_gc_{}_phase_{}.json",
318-
gc_count,
319-
phase
320-
)).unwrap();
328+
let mut file =
329+
File::create(format!("spaces_gc_{}_phase_{}.json", gc_count, phase)).unwrap();
321330
let mut json = JsonValue::new_array();
322-
SINGLETON.inspect_spaces().iter().for_each(|space| json.push(space_into_json(*space)).unwrap());
323-
file.write_all(json::stringify_pretty(json, 2).as_bytes()).unwrap();
331+
SINGLETON
332+
.inspect_spaces()
333+
.iter()
334+
.for_each(|space| json.push(space_into_json(*space)).unwrap());
335+
file.write_all(json::stringify_pretty(json, 2).as_bytes())
336+
.unwrap();
324337
}
325338

326339
// Dump Immix heap -- be careful we only dump one chunk at a time to avoid using too much Rust memory and get OOM
327340
{
328-
let mut file = File::create(format!(
329-
"immix_heap_gc_{}_phase_{}.json",
330-
gc_count,
331-
phase
332-
)).unwrap();
341+
let mut file =
342+
File::create(format!("immix_heap_gc_{}_phase_{}.json", gc_count, phase)).unwrap();
333343

334344
file.write_all(b"[\n").unwrap();
335345

336-
let immix_space = SINGLETON.inspect_spaces().into_iter()
346+
let immix_space = SINGLETON
347+
.inspect_spaces()
348+
.into_iter()
337349
.find(|s| s.space_name() == "immix")
338350
.expect("Immix space not found");
339351
let chunks = immix_space.list_top_regions();
340352
let n_chunks = chunks.len();
341353
let mut i = 0;
342-
chunks.into_iter().for_each(|chunk: Box<dyn RegionInspector>| {
343-
let json = region_into_json(immix_space, &*chunk);
344-
file.write_all(json::stringify_pretty(json, 2).as_bytes()).unwrap();
345-
if i != n_chunks - 1 {
346-
file.write_all(b",\n").unwrap();
347-
}
348-
i += 1;
349-
});
354+
chunks
355+
.into_iter()
356+
.for_each(|chunk: Box<dyn RegionInspector>| {
357+
let json = region_into_json(immix_space, &*chunk);
358+
file.write_all(json::stringify_pretty(json, 2).as_bytes())
359+
.unwrap();
360+
if i != n_chunks - 1 {
361+
file.write_all(b",\n").unwrap();
362+
}
363+
i += 1;
364+
});
350365
assert!(i == n_chunks);
351366

352367
file.write_all(b"]\n").unwrap();

mmtk/src/conservative.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use crate::julia_types::*;
21
use crate::jl_log_pinning_event;
2+
use crate::julia_types::*;
33
use mmtk::memory_manager;
44
use mmtk::util::constants::BYTES_IN_ADDRESS;
55
use mmtk::util::{Address, ObjectReference};

mmtk/src/julia_scanning.rs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -358,32 +358,20 @@ pub unsafe fn scan_julia_object<SV: SlotVisitor<JuliaVMSlot>>(obj: Address, clos
358358
objary_begin = objary_begin.shift::<Address>(elsize as isize);
359359
}
360360
} else if (*layout).fielddesc_type_custom() == 0 {
361-
let obj8_begin = mmtk_jl_dt_layout_ptrs(layout);
361+
let mut obj8_begin = mmtk_jl_dt_layout_ptrs(layout);
362362
let obj8_end = obj8_begin.shift::<u8>(npointers as isize);
363-
let mut elem_begin = obj8_begin;
364-
let elem_end = obj8_end;
365363

366364
while objary_begin < objary_end {
367-
while elem_begin < elem_end {
368-
let elem_begin_loaded = elem_begin.load::<u8>();
369-
let slot = objary_begin.shift::<Address>(elem_begin_loaded as isize);
370-
process_slot(closure, slot);
371-
elem_begin = elem_begin.shift::<u8>(1);
372-
}
373-
elem_begin = obj8_begin;
365+
scan_julia_obj_n::<u8>(objary_begin, obj8_begin, obj8_end, closure);
366+
obj8_begin = mmtk_jl_dt_layout_ptrs(layout);
374367
objary_begin = objary_begin.shift::<Address>(elsize as isize);
375368
}
376369
} else if (*layout).fielddesc_type_custom() == 1 {
377370
let mut obj16_begin = mmtk_jl_dt_layout_ptrs(layout);
378371
let obj16_end = obj16_begin.shift::<u16>(npointers as isize);
379372

380373
while objary_begin < objary_end {
381-
while obj16_begin < obj16_end {
382-
let elem_begin_loaded = obj16_begin.load::<u16>();
383-
let slot = objary_begin.shift::<Address>(elem_begin_loaded as isize);
384-
process_slot(closure, slot);
385-
obj16_begin = obj16_begin.shift::<u16>(1);
386-
}
374+
scan_julia_obj_n::<u16>(objary_begin, obj16_begin, obj16_end, closure);
387375
obj16_begin = mmtk_jl_dt_layout_ptrs(layout);
388376
objary_begin = objary_begin.shift::<Address>(elsize as isize);
389377
}

0 commit comments

Comments
 (0)