-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Fix rb_gc_impl_copy_finalizer
#13350
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
casperisfine
commented
May 15, 2025
- Add missing VM_LOCK
- Generate a new object_id when copying finalizers
- Dup the finalizer entry so adding a finalizer on a cloned object doesn't impact the source object.
assert_in_out_err(["-e", <<-END], "", %w(:ok :ok :ok :ok), []) | ||
assert_in_out_err(["-e", <<-END], "", %w(:ok :ok :ok), []) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My understanding is that this assertion was incorrect.
- We define 1 finalizer on the source object
- Clone the source object, so 1+1 => 2
- Add another finalizer on the copied object, so 2 + 1 => 3.
This comment has been minimized.
This comment has been minimized.
fdf9e04
to
60f41e2
Compare
Fix a regression introduced by: ruby#13155
60f41e2
to
63aaf67
Compare
gc/default/default.c
Outdated
@@ -2832,16 +2835,22 @@ run_final(rb_objspace_t *objspace, VALUE zombie) | |||
if (FL_TEST_RAW(zombie, FL_FINALIZE)) { | |||
FL_UNSET(zombie, FL_FINALIZE); | |||
st_data_t table; | |||
unsigned int lev = rb_gc_vm_lock(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should do the locking in finalize_list
instead. We lock the VM in finalize_list
to add the slot back to the freelist, so we're just doing locking and unlocking twice for every zombie object instead of once total, which would be bad for performance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, I just had to move the lock up by one line.
The finalizer table can't be read nor modified without the VM lock.
ea38265
to
b0d2a3b
Compare