Skip to content

Commit ac5f13d

Browse files
committed
Register PPPs
Register potential pinning parent types (PPPs) when created or when an object becomes a PPP.
1 parent 3c0f73c commit ac5f13d

File tree

3 files changed

+85
-1
lines changed

3 files changed

+85
-1
lines changed

gc.c

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2671,6 +2671,38 @@ maybe_register_finalizable(VALUE obj) {
26712671
BUILTIN_TYPE(obj), (void*)obj, RBASIC(obj)->flags);
26722672
}
26732673
}
2674+
2675+
static inline bool
2676+
rb_mmtk_is_ppp(VALUE obj) {
2677+
RUBY_ASSERT(!rb_special_const_p(obj));
2678+
2679+
switch (RB_BUILTIN_TYPE(obj)) {
2680+
case T_DATA:
2681+
return true;
2682+
case T_IMEMO:
2683+
switch (imemo_type(obj)) {
2684+
case imemo_tmpbuf:
2685+
case imemo_ast:
2686+
case imemo_ifunc:
2687+
case imemo_memo:
2688+
case imemo_parser_strterm:
2689+
return true;
2690+
default:
2691+
return false;
2692+
}
2693+
default:
2694+
return false;
2695+
}
2696+
}
2697+
2698+
static inline void
2699+
maybe_register_ppp(VALUE obj) {
2700+
RUBY_ASSERT(!rb_special_const_p(obj));
2701+
2702+
if (rb_mmtk_is_ppp(obj)) {
2703+
mmtk_register_ppp((MMTk_ObjectReference)obj);
2704+
}
2705+
}
26742706
#endif
26752707

26762708
static inline VALUE
@@ -2689,6 +2721,7 @@ newobj_init(VALUE klass, VALUE flags, int wb_protected, rb_objspace_t *objspace,
26892721
#if USE_MMTK
26902722
if (rb_mmtk_enabled_p()) {
26912723
maybe_register_finalizable(obj);
2724+
maybe_register_ppp(obj);
26922725
}
26932726
#endif
26942727

@@ -15806,6 +15839,8 @@ rb_mmtk_mark_and_move(VALUE *field)
1580615839
}
1580715840
}
1580815841

15842+
// This function is used to visit and update all fields during tracing.
15843+
// It shall call both gc_mark_children and gc_update_object_references during copying GC.
1580915844
static inline void
1581015845
rb_mmtk_scan_object_ruby_style(MMTk_ObjectReference object)
1581115846
{
@@ -15820,6 +15855,27 @@ rb_mmtk_scan_object_ruby_style(MMTk_ObjectReference object)
1582015855

1582115856
rb_objspace_t *objspace = &rb_objspace;
1582215857
gc_mark_children(objspace, obj);
15858+
15859+
// TODO: Enable the following line later.
15860+
//gc_update_object_references(objspace, obj);
15861+
}
15862+
15863+
// This is used to determine the pinning fields of potential pinning parents (PPPs).
15864+
// It should only call gc_mark_children.
15865+
static inline void
15866+
rb_mmtk_call_gc_mark_children(MMTk_ObjectReference object)
15867+
{
15868+
rb_mmtk_assert_mmtk_worker();
15869+
15870+
VALUE obj = (VALUE)object;
15871+
15872+
// TODO: When mmtk-core can clear the VO bit (a.k.a. alloc-bit), we can remove this.
15873+
if (RB_BUILTIN_TYPE(obj) == T_NONE) {
15874+
return;
15875+
}
15876+
15877+
rb_objspace_t *objspace = &rb_objspace;
15878+
gc_mark_children(objspace, obj);
1582315879
}
1582415880

1582515881
static inline void
@@ -15838,7 +15894,7 @@ rb_mmtk_object_moved_p(VALUE value)
1583815894
{
1583915895
if (!SPECIAL_CONST_P(value)) {
1584015896
MMTk_ObjectReference object = (MMTk_ObjectReference)value;
15841-
return rb_mmtk_call_object_closure(object, false) == object;
15897+
return rb_mmtk_call_object_closure(object, false) != object;
1584215898
} else {
1584315899
return false;
1584415900
}
@@ -16127,6 +16183,7 @@ MMTk_RubyUpcalls ruby_upcalls = {
1612716183
rb_mmtk_scan_thread_roots,
1612816184
rb_mmtk_scan_thread_root,
1612916185
rb_mmtk_scan_object_ruby_style,
16186+
rb_mmtk_call_gc_mark_children,
1613016187
rb_mmtk_call_obj_free,
1613116188
rb_mmtk_update_global_weak_tables,
1613216189
};

hash.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@
4949
#include "ruby/ractor.h"
5050
#include "vm_sync.h"
5151

52+
#if USE_MMTK
53+
#include "mmtk.h" // For mmtk_register_ppp
54+
#endif
55+
5256
#ifndef HASH_DEBUG
5357
#define HASH_DEBUG 0
5458
#endif
@@ -4410,6 +4414,12 @@ rb_hash_compare_by_id(VALUE hash)
44104414
RHASH_ST_TABLE_SET(hash, identtable);
44114415
RHASH_ST_CLEAR(tmp);
44124416

4417+
#if USE_MMTK
4418+
if (rb_mmtk_enabled_p()) {
4419+
mmtk_register_ppp((MMTk_ObjectReference)hash);
4420+
}
4421+
#endif
4422+
44134423
return hash;
44144424
}
44154425

@@ -4431,6 +4441,13 @@ rb_ident_hash_new(void)
44314441
{
44324442
VALUE hash = rb_hash_new();
44334443
RHASH_ST_TABLE_SET(hash, st_init_table(&identhash));
4444+
4445+
#if USE_MMTK
4446+
if (rb_mmtk_enabled_p()) {
4447+
mmtk_register_ppp((MMTk_ObjectReference)hash);
4448+
}
4449+
#endif
4450+
44344451
return hash;
44354452
}
44364453

@@ -4439,6 +4456,13 @@ rb_ident_hash_new_with_size(st_index_t size)
44394456
{
44404457
VALUE hash = rb_hash_new();
44414458
RHASH_ST_TABLE_SET(hash, st_init_table_with_size(&identhash, size));
4459+
4460+
#if USE_MMTK
4461+
if (rb_mmtk_enabled_p()) {
4462+
mmtk_register_ppp((MMTk_ObjectReference)hash);
4463+
}
4464+
#endif
4465+
44424466
return hash;
44434467
}
44444468

mmtk.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ typedef struct MMTk_RubyUpcalls {
6767
void (*scan_thread_roots)(void);
6868
void (*scan_thread_root)(MMTk_VMMutatorThread mutator_tls, MMTk_VMWorkerThread worker_tls);
6969
void (*scan_object_ruby_style)(MMTk_ObjectReference object);
70+
void (*call_gc_mark_children)(MMTk_ObjectReference object);
7071
void (*call_obj_free)(MMTk_ObjectReference object);
7172
void (*update_global_weak_tables)(void);
7273
} MMTk_RubyUpcalls;
@@ -166,4 +167,6 @@ struct MMTk_RawVecOfObjRef mmtk_get_all_obj_free_candidates(void);
166167

167168
void mmtk_free_raw_vec_of_obj_ref(struct MMTk_RawVecOfObjRef raw_vec);
168169

170+
void mmtk_register_ppp(MMTk_ObjectReference object);
171+
169172
#endif /* MMTK_H */

0 commit comments

Comments
 (0)