Skip to content

Commit d926f40

Browse files
peterzhu2118matzbot
authored andcommitted
[ruby/mmtk] Add moving_gc_count to GC.stat
Outputs the number of GC cycles that are moving. ruby/mmtk@fef8f04186
1 parent 78f11bd commit d926f40

4 files changed

Lines changed: 13 additions & 6 deletions

File tree

gc/mmtk/mmtk.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ struct objspace {
2121
bool gc_stress;
2222

2323
size_t gc_count;
24+
size_t moving_gc_count;
2425
size_t total_gc_time;
2526
size_t total_allocated_objects;
2627

@@ -132,7 +133,7 @@ rb_mmtk_stop_the_world(void)
132133
}
133134

134135
static void
135-
rb_mmtk_resume_mutators(void)
136+
rb_mmtk_resume_mutators(bool current_gc_may_move)
136137
{
137138
struct objspace *objspace = rb_gc_get_objspace();
138139

@@ -143,6 +144,7 @@ rb_mmtk_resume_mutators(void)
143144

144145
objspace->world_stopped = false;
145146
objspace->gc_count++;
147+
if (current_gc_may_move) objspace->moving_gc_count++;
146148
pthread_cond_broadcast(&objspace->cond_world_started);
147149

148150
if ((err = pthread_mutex_unlock(&objspace->mutex)) != 0) {
@@ -492,7 +494,7 @@ rb_mmtk_gc_thread_bug(const char *msg, ...)
492494
rb_gc_print_backtrace();
493495
fprintf(stderr, "\n");
494496

495-
rb_mmtk_resume_mutators();
497+
rb_mmtk_resume_mutators(false);
496498

497499
sleep(5);
498500

@@ -1459,6 +1461,7 @@ rb_gc_impl_latest_gc_info(void *objspace_ptr, VALUE hash_or_key)
14591461

14601462
enum gc_stat_sym {
14611463
gc_stat_sym_count,
1464+
gc_stat_sym_moving_gc_count,
14621465
gc_stat_sym_time,
14631466
gc_stat_sym_total_allocated_objects,
14641467
gc_stat_sym_total_bytes,
@@ -1478,6 +1481,7 @@ setup_gc_stat_symbols(void)
14781481
if (gc_stat_symbols[0] == 0) {
14791482
#define S(s) gc_stat_symbols[gc_stat_sym_##s] = ID2SYM(rb_intern_const(#s))
14801483
S(count);
1484+
S(moving_gc_count);
14811485
S(time);
14821486
S(total_allocated_objects);
14831487
S(total_bytes);
@@ -1514,6 +1518,7 @@ rb_gc_impl_stat(void *objspace_ptr, VALUE hash_or_sym)
15141518
rb_hash_aset(hash, gc_stat_symbols[gc_stat_sym_##name], SIZET2NUM(attr));
15151519

15161520
SET(count, objspace->gc_count);
1521+
SET(moving_gc_count, objspace->moving_gc_count);
15171522
SET(time, objspace->total_gc_time / (1000 * 1000));
15181523
SET(total_allocated_objects, objspace->total_allocated_objects);
15191524
SET(total_bytes, mmtk_total_bytes());

gc/mmtk/mmtk.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ typedef struct MMTk_RubyUpcalls {
6060
void (*init_gc_worker_thread)(struct MMTk_GCThreadTLS *gc_worker_tls);
6161
bool (*is_mutator)(void);
6262
void (*stop_the_world)(void);
63-
void (*resume_mutators)(void);
63+
void (*resume_mutators)(bool gc_may_move);
6464
void (*block_for_gc)(MMTk_VMMutatorThread tls);
6565
void (*before_updating_jit_code)(void);
6666
void (*after_updating_jit_code)(void);

gc/mmtk/src/abi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ pub struct RubyUpcalls {
301301
pub init_gc_worker_thread: extern "C" fn(gc_worker_tls: *mut GCThreadTLS),
302302
pub is_mutator: extern "C" fn() -> bool,
303303
pub stop_the_world: extern "C" fn(),
304-
pub resume_mutators: extern "C" fn(),
304+
pub resume_mutators: extern "C" fn(gc_may_move: bool),
305305
pub block_for_gc: extern "C" fn(tls: VMMutatorThread),
306306
pub before_updating_jit_code: extern "C" fn(),
307307
pub after_updating_jit_code: extern "C" fn(),

gc/mmtk/src/collection.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,13 @@ impl Collection<Ruby> for VMCollection {
4848
}
4949

5050
fn resume_mutators(_tls: VMWorkerThread) {
51-
if CURRENT_GC_MAY_MOVE.load(Ordering::Relaxed) {
51+
let current_gc_may_move = CURRENT_GC_MAY_MOVE.load(Ordering::Relaxed);
52+
53+
if current_gc_may_move {
5254
(upcalls().after_updating_jit_code)();
5355
}
5456

55-
(upcalls().resume_mutators)();
57+
(upcalls().resume_mutators)(current_gc_may_move);
5658
}
5759

5860
fn block_for_gc(tls: VMMutatorThread) {

0 commit comments

Comments
 (0)