Don't preserve object_id
when moving object to another Ractor
That seemed like the logical thing to do to me, but ko1 disagree.
This commit is contained in:
parent
0350290262
commit
7db0e07134
Notes:
git
2025-03-31 10:02:13 +00:00
@ -2101,13 +2101,3 @@ assert_equal 'ok', %q{
|
||||
:fail
|
||||
end
|
||||
}
|
||||
|
||||
# moved objects keep their object_id
|
||||
assert_equal 'ok', %q{
|
||||
ractor = Ractor.new { Ractor.receive }
|
||||
obj = Object.new
|
||||
id = obj.object_id
|
||||
ractor.send(obj, move: true)
|
||||
roundtripped_obj = ractor.take
|
||||
roundtripped_obj.object_id == id ? :ok : :fail
|
||||
}
|
||||
|
10
gc.c
10
gc.c
@ -665,7 +665,6 @@ typedef struct gc_function_map {
|
||||
// Object ID
|
||||
VALUE (*object_id)(void *objspace_ptr, VALUE obj);
|
||||
VALUE (*object_id_to_ref)(void *objspace_ptr, VALUE object_id);
|
||||
void (*object_id_move)(void *objspace_ptr, VALUE dest, VALUE src);
|
||||
// Forking
|
||||
void (*before_fork)(void *objspace_ptr);
|
||||
void (*after_fork)(void *objspace_ptr, rb_pid_t pid);
|
||||
@ -843,7 +842,6 @@ ruby_modular_gc_init(void)
|
||||
// Object ID
|
||||
load_modular_gc_func(object_id);
|
||||
load_modular_gc_func(object_id_to_ref);
|
||||
load_modular_gc_func(object_id_move);
|
||||
// Forking
|
||||
load_modular_gc_func(before_fork);
|
||||
load_modular_gc_func(after_fork);
|
||||
@ -927,7 +925,6 @@ ruby_modular_gc_init(void)
|
||||
// Object ID
|
||||
# define rb_gc_impl_object_id rb_gc_functions.object_id
|
||||
# define rb_gc_impl_object_id_to_ref rb_gc_functions.object_id_to_ref
|
||||
# define rb_gc_impl_object_id_move rb_gc_functions.object_id_move
|
||||
// Forking
|
||||
# define rb_gc_impl_before_fork rb_gc_functions.before_fork
|
||||
# define rb_gc_impl_after_fork rb_gc_functions.after_fork
|
||||
@ -2664,12 +2661,7 @@ rb_gc_mark_roots(void *objspace, const char **categoryp)
|
||||
void
|
||||
rb_gc_ractor_moved(VALUE dest, VALUE src)
|
||||
{
|
||||
void *objspace = rb_gc_get_objspace();
|
||||
if (UNLIKELY(FL_TEST_RAW(src, FL_SEEN_OBJ_ID))) {
|
||||
rb_gc_impl_object_id_move(objspace, dest, src);
|
||||
}
|
||||
|
||||
rb_gc_obj_free(objspace, src);
|
||||
rb_gc_obj_free(rb_gc_get_objspace(), src);
|
||||
MEMZERO((void *)src, char, rb_gc_obj_slot_size(src));
|
||||
RBASIC(src)->flags = T_OBJECT | FL_FREEZE; // Avoid mutations using bind_call, etc.
|
||||
}
|
||||
|
@ -1614,27 +1614,6 @@ rb_gc_impl_object_id_to_ref(void *objspace_ptr, VALUE object_id)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
rb_gc_impl_object_id_move(void *objspace_ptr, VALUE dest, VALUE src)
|
||||
{
|
||||
/* If the source object's object_id has been seen, we need to update
|
||||
* the object to object id mapping. */
|
||||
st_data_t id = 0;
|
||||
rb_objspace_t *objspace = objspace_ptr;
|
||||
|
||||
unsigned int lev = rb_gc_vm_lock();
|
||||
st_data_t key = (st_data_t)src;
|
||||
if (!st_delete(objspace->obj_to_id_tbl, &key, &id)) {
|
||||
rb_bug("gc_move: object ID seen, but not in mapping table: %s", rb_obj_info(src));
|
||||
}
|
||||
FL_UNSET_RAW(src, FL_SEEN_OBJ_ID);
|
||||
|
||||
st_insert(objspace->obj_to_id_tbl, (st_data_t)dest, id);
|
||||
st_insert(objspace->id_to_obj_tbl, id, (st_data_t)dest);
|
||||
FL_SET_RAW(dest, FL_SEEN_OBJ_ID);
|
||||
rb_gc_vm_unlock(lev);
|
||||
}
|
||||
|
||||
static void free_stack_chunks(mark_stack_t *);
|
||||
static void mark_stack_free_cache(mark_stack_t *);
|
||||
static void heap_page_free(rb_objspace_t *objspace, struct heap_page *page);
|
||||
|
@ -103,7 +103,6 @@ GC_IMPL_FN void rb_gc_impl_shutdown_call_finalizer(void *objspace_ptr);
|
||||
// Object ID
|
||||
GC_IMPL_FN VALUE rb_gc_impl_object_id(void *objspace_ptr, VALUE obj);
|
||||
GC_IMPL_FN VALUE rb_gc_impl_object_id_to_ref(void *objspace_ptr, VALUE object_id);
|
||||
GC_IMPL_FN void rb_gc_impl_object_id_move(void *objspace_ptr, VALUE dest, VALUE src);
|
||||
// Forking
|
||||
GC_IMPL_FN void rb_gc_impl_before_fork(void *objspace_ptr);
|
||||
GC_IMPL_FN void rb_gc_impl_after_fork(void *objspace_ptr, rb_pid_t pid);
|
||||
|
@ -1155,27 +1155,6 @@ rb_gc_impl_object_id_to_ref(void *objspace_ptr, VALUE object_id)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
rb_gc_impl_object_id_move(void *objspace_ptr, VALUE dest, VALUE src)
|
||||
{
|
||||
/* If the source object's object_id has been seen, we need to update
|
||||
* the object to object id mapping. */
|
||||
st_data_t id = 0;
|
||||
struct objspace *objspace = objspace_ptr;
|
||||
|
||||
unsigned int lev = rb_gc_vm_lock();
|
||||
st_data_t key = (st_data_t)src;
|
||||
if (!st_delete(objspace->obj_to_id_tbl, &key, &id)) {
|
||||
rb_bug("gc_move: object ID seen, but not in mapping table: %s", rb_obj_info(src));
|
||||
}
|
||||
FL_UNSET_RAW(src, FL_SEEN_OBJ_ID);
|
||||
|
||||
st_insert(objspace->obj_to_id_tbl, (st_data_t)dest, id);
|
||||
st_insert(objspace->id_to_obj_tbl, id, (st_data_t)dest);
|
||||
FL_SET_RAW(dest, FL_SEEN_OBJ_ID);
|
||||
rb_gc_vm_unlock(lev);
|
||||
}
|
||||
|
||||
// Forking
|
||||
|
||||
void
|
||||
|
Loading…
x
Reference in New Issue
Block a user