Skip to content

Commit 7db0e07

Browse files
committed
Don't preserve object_id when moving object to another Ractor
That seemed like the logical thing to do to me, but ko1 disagree.
1 parent 0350290 commit 7db0e07

File tree

5 files changed

+1
-62
lines changed

5 files changed

+1
-62
lines changed

bootstraptest/test_ractor.rb

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2101,13 +2101,3 @@ def ==(o)
21012101
:fail
21022102
end
21032103
}
2104-
2105-
# moved objects keep their object_id
2106-
assert_equal 'ok', %q{
2107-
ractor = Ractor.new { Ractor.receive }
2108-
obj = Object.new
2109-
id = obj.object_id
2110-
ractor.send(obj, move: true)
2111-
roundtripped_obj = ractor.take
2112-
roundtripped_obj.object_id == id ? :ok : :fail
2113-
}

gc.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,6 @@ typedef struct gc_function_map {
665665
// Object ID
666666
VALUE (*object_id)(void *objspace_ptr, VALUE obj);
667667
VALUE (*object_id_to_ref)(void *objspace_ptr, VALUE object_id);
668-
void (*object_id_move)(void *objspace_ptr, VALUE dest, VALUE src);
669668
// Forking
670669
void (*before_fork)(void *objspace_ptr);
671670
void (*after_fork)(void *objspace_ptr, rb_pid_t pid);
@@ -843,7 +842,6 @@ ruby_modular_gc_init(void)
843842
// Object ID
844843
load_modular_gc_func(object_id);
845844
load_modular_gc_func(object_id_to_ref);
846-
load_modular_gc_func(object_id_move);
847845
// Forking
848846
load_modular_gc_func(before_fork);
849847
load_modular_gc_func(after_fork);
@@ -927,7 +925,6 @@ ruby_modular_gc_init(void)
927925
// Object ID
928926
# define rb_gc_impl_object_id rb_gc_functions.object_id
929927
# define rb_gc_impl_object_id_to_ref rb_gc_functions.object_id_to_ref
930-
# define rb_gc_impl_object_id_move rb_gc_functions.object_id_move
931928
// Forking
932929
# define rb_gc_impl_before_fork rb_gc_functions.before_fork
933930
# define rb_gc_impl_after_fork rb_gc_functions.after_fork
@@ -2664,12 +2661,7 @@ rb_gc_mark_roots(void *objspace, const char **categoryp)
26642661
void
26652662
rb_gc_ractor_moved(VALUE dest, VALUE src)
26662663
{
2667-
void *objspace = rb_gc_get_objspace();
2668-
if (UNLIKELY(FL_TEST_RAW(src, FL_SEEN_OBJ_ID))) {
2669-
rb_gc_impl_object_id_move(objspace, dest, src);
2670-
}
2671-
2672-
rb_gc_obj_free(objspace, src);
2664+
rb_gc_obj_free(rb_gc_get_objspace(), src);
26732665
MEMZERO((void *)src, char, rb_gc_obj_slot_size(src));
26742666
RBASIC(src)->flags = T_OBJECT | FL_FREEZE; // Avoid mutations using bind_call, etc.
26752667
}

gc/default/default.c

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1614,27 +1614,6 @@ rb_gc_impl_object_id_to_ref(void *objspace_ptr, VALUE object_id)
16141614
}
16151615
}
16161616

1617-
void
1618-
rb_gc_impl_object_id_move(void *objspace_ptr, VALUE dest, VALUE src)
1619-
{
1620-
/* If the source object's object_id has been seen, we need to update
1621-
* the object to object id mapping. */
1622-
st_data_t id = 0;
1623-
rb_objspace_t *objspace = objspace_ptr;
1624-
1625-
unsigned int lev = rb_gc_vm_lock();
1626-
st_data_t key = (st_data_t)src;
1627-
if (!st_delete(objspace->obj_to_id_tbl, &key, &id)) {
1628-
rb_bug("gc_move: object ID seen, but not in mapping table: %s", rb_obj_info(src));
1629-
}
1630-
FL_UNSET_RAW(src, FL_SEEN_OBJ_ID);
1631-
1632-
st_insert(objspace->obj_to_id_tbl, (st_data_t)dest, id);
1633-
st_insert(objspace->id_to_obj_tbl, id, (st_data_t)dest);
1634-
FL_SET_RAW(dest, FL_SEEN_OBJ_ID);
1635-
rb_gc_vm_unlock(lev);
1636-
}
1637-
16381617
static void free_stack_chunks(mark_stack_t *);
16391618
static void mark_stack_free_cache(mark_stack_t *);
16401619
static void heap_page_free(rb_objspace_t *objspace, struct heap_page *page);

gc/gc_impl.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ GC_IMPL_FN void rb_gc_impl_shutdown_call_finalizer(void *objspace_ptr);
103103
// Object ID
104104
GC_IMPL_FN VALUE rb_gc_impl_object_id(void *objspace_ptr, VALUE obj);
105105
GC_IMPL_FN VALUE rb_gc_impl_object_id_to_ref(void *objspace_ptr, VALUE object_id);
106-
GC_IMPL_FN void rb_gc_impl_object_id_move(void *objspace_ptr, VALUE dest, VALUE src);
107106
// Forking
108107
GC_IMPL_FN void rb_gc_impl_before_fork(void *objspace_ptr);
109108
GC_IMPL_FN void rb_gc_impl_after_fork(void *objspace_ptr, rb_pid_t pid);

gc/mmtk/mmtk.c

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,27 +1155,6 @@ rb_gc_impl_object_id_to_ref(void *objspace_ptr, VALUE object_id)
11551155
}
11561156
}
11571157

1158-
void
1159-
rb_gc_impl_object_id_move(void *objspace_ptr, VALUE dest, VALUE src)
1160-
{
1161-
/* If the source object's object_id has been seen, we need to update
1162-
* the object to object id mapping. */
1163-
st_data_t id = 0;
1164-
struct objspace *objspace = objspace_ptr;
1165-
1166-
unsigned int lev = rb_gc_vm_lock();
1167-
st_data_t key = (st_data_t)src;
1168-
if (!st_delete(objspace->obj_to_id_tbl, &key, &id)) {
1169-
rb_bug("gc_move: object ID seen, but not in mapping table: %s", rb_obj_info(src));
1170-
}
1171-
FL_UNSET_RAW(src, FL_SEEN_OBJ_ID);
1172-
1173-
st_insert(objspace->obj_to_id_tbl, (st_data_t)dest, id);
1174-
st_insert(objspace->id_to_obj_tbl, id, (st_data_t)dest);
1175-
FL_SET_RAW(dest, FL_SEEN_OBJ_ID);
1176-
rb_gc_vm_unlock(lev);
1177-
}
1178-
11791158
// Forking
11801159

11811160
void

0 commit comments

Comments
 (0)