1
+ use crate :: jl_gc_log;
1
2
use crate :: SINGLETON ;
2
3
use crate :: {
3
4
jl_gc_get_max_memory, jl_gc_prepare_to_collect, jl_gc_update_stats, jl_get_gc_disable_counter,
4
5
jl_hrtime, jl_throw_out_of_memory_error,
5
6
} ;
6
7
use crate :: { JuliaVM , USER_TRIGGERED_GC } ;
7
- use crate :: jl_gc_log;
8
8
use log:: { debug, trace} ;
9
9
use mmtk:: util:: alloc:: AllocationError ;
10
10
use mmtk:: util:: heap:: GCTriggerPolicy ;
@@ -26,6 +26,7 @@ use std::collections::HashSet;
26
26
use std:: sync:: RwLock ;
27
27
use std:: thread:: ThreadId ;
28
28
29
+ #[ cfg( feature = "print_fragmentation" ) ]
29
30
use crate :: api:: print_fragmentation;
30
31
31
32
lazy_static ! {
@@ -212,7 +213,6 @@ pub extern "C" fn mmtk_block_thread_for_gc() {
212
213
AtomicIsize :: store ( & USER_TRIGGERED_GC , 0 , Ordering :: SeqCst ) ;
213
214
}
214
215
215
-
216
216
#[ cfg( feature = "dump_block_stats" ) ]
217
217
pub fn dump_immix_block_stats ( ) {
218
218
use mmtk:: util:: Address ;
@@ -238,7 +238,12 @@ pub fn dump_immix_block_stats() {
238
238
unsafe {
239
239
crate :: julia_scanning:: get_julia_object_type( object. to_raw_address( ) )
240
240
} ,
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
+ } ,
242
247
mmtk:: memory_manager:: is_pinned( object) ,
243
248
)
244
249
. expect ( "Unable to write to log file" ) ;
@@ -261,12 +266,13 @@ pub fn dump_immix_block_stats() {
261
266
}
262
267
263
268
#[ 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
265
271
println ! ( "Dumping heap for GC {} phase {}" , gc_count, phase) ;
272
+ use json:: JsonValue ;
273
+ use mmtk:: util:: constants:: LOG_BYTES_IN_PAGE ;
266
274
use mmtk:: util:: heap:: inspection:: * ;
267
275
use mmtk:: vm:: ObjectModel ;
268
- use mmtk:: util:: constants:: LOG_BYTES_IN_PAGE ;
269
- use json:: JsonValue ;
270
276
use std:: fs:: File ;
271
277
use std:: io:: Write ;
272
278
@@ -278,7 +284,7 @@ pub fn dump_heap(gc_count: u64, phase: u64) { // phase: 0 for pre-gc, 1 for post
278
284
json
279
285
}
280
286
281
- fn region_into_json ( space : & dyn SpaceInspector , region : & dyn RegionInspector ) -> JsonValue {
287
+ fn region_into_json ( space : & dyn SpaceInspector , region : & dyn RegionInspector ) -> JsonValue {
282
288
// println!("Dumping region: {} {}", region.region_type(), region.start());
283
289
let mut json = JsonValue :: new_object ( ) ;
284
290
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
288
294
let sub_regions = space. list_sub_regions ( region) ;
289
295
if sub_regions. is_empty ( ) {
290
296
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 ( ) ;
305
315
} 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 ( ) ;
309
321
}
310
322
311
323
json
312
324
}
313
325
314
326
// Dump high-levvel space information
315
327
{
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 ( ) ;
321
330
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 ( ) ;
324
337
}
325
338
326
339
// Dump Immix heap -- be careful we only dump one chunk at a time to avoid using too much Rust memory and get OOM
327
340
{
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 ( ) ;
333
343
334
344
file. write_all ( b"[\n " ) . unwrap ( ) ;
335
345
336
- let immix_space = SINGLETON . inspect_spaces ( ) . into_iter ( )
346
+ let immix_space = SINGLETON
347
+ . inspect_spaces ( )
348
+ . into_iter ( )
337
349
. find ( |s| s. space_name ( ) == "immix" )
338
350
. expect ( "Immix space not found" ) ;
339
351
let chunks = immix_space. list_top_regions ( ) ;
340
352
let n_chunks = chunks. len ( ) ;
341
353
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
+ } ) ;
350
365
assert ! ( i == n_chunks) ;
351
366
352
367
file. write_all ( b"]\n " ) . unwrap ( ) ;
0 commit comments