Skip to content

Commit 2343768

Browse files
committed
WIP
1 parent 2e5f756 commit 2343768

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

gc.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1909,6 +1909,7 @@ obj_to_id_tbl_compact(void *data)
19091909
st_foreach(obj_to_id_tbl, obj_to_id_tbl_any_moved_p_i, (st_data_t)&any_moved_args);
19101910

19111911
if (any_moved_args.need_rebuild) {
1912+
fprintf(stderr, "-- rebyild---\n");
19121913
st_table *new_table;
19131914
DURING_GC_COULD_MALLOC_REGION_START();
19141915
{
@@ -1969,7 +1970,7 @@ class_object_id(VALUE klass)
19691970
static inline VALUE
19701971
object_id_get(VALUE obj, shape_id_t shape_id)
19711972
{
1972-
VALUE id;
1973+
VALUE id = Qundef;
19731974

19741975
switch (rb_shape_has_object_id(shape_id)) {
19751976
case SHAPE_NO_OBJ_ID:
@@ -1995,6 +1996,7 @@ object_id_get(VALUE obj, shape_id_t shape_id)
19951996
{
19961997
RUBY_ASSERT(obj_to_id_tbl);
19971998
unsigned int lock_lev = RB_GC_VM_LOCK();
1999+
fprintf(stderr, "lookup %"PRIxVALUE"\n", obj);
19982000
st_lookup(obj_to_id_tbl, obj, &id);
19992001

20002002
#if RUBY_DEBUG
@@ -2027,14 +2029,18 @@ object_id0(VALUE obj, bool shareable)
20272029
attr_index_t capacity = RSHAPE_CAPACITY(shape_id);
20282030
attr_index_t free_capacity = capacity - RSHAPE_LEN(shape_id);
20292031
if (shareable && RB_TYPE_P(obj, T_OBJECT) && capacity && !free_capacity) {
2030-
// If the object was shared and has no free capacity, we can't safely store the object_id inline.
2032+
// If the object was shared and has no free capacity, we can't safely store the object_id inline, as it
2033+
// would require to move the object content into an external buffer.
20312034
// This is only a problem for T_OBJECT, given other types have external fields and can do RCU.
20322035
shape_id_t next_shape_id = rb_shape_transition_object_id_external(obj);
20332036
if (RB_UNLIKELY(!obj_to_id_tbl)) {
20342037
obj_to_id_tbl = st_init_numtable();
20352038
obj_to_id_value = TypedData_Wrap_Struct(0, &obj_to_id_tbl_type, obj_to_id_tbl);
20362039
}
2040+
fprintf(stderr, "insert %"PRIxVALUE"\n", obj);
2041+
// This can trigger compaction, which may rebuild the table and then crash....
20372042
st_insert(obj_to_id_tbl, obj, id);
2043+
fprintf(stderr, "inserted\n");
20382044
RBASIC_SET_SHAPE_ID(obj, next_shape_id);
20392045
}
20402046
else {

test/ruby/test_object_id.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ def initialize
254254
@a = @b = @c = nil
255255
end
256256
end
257-
N = 50
257+
N = 20
258258
objs = Ractor.make_shareable(N.times.map { MyClass.new })
259259
260260
GC.stress = true

0 commit comments

Comments
 (0)