Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Merged
merged 4 commits into from
May 16, 2025
Merged

Fix rb_gc_impl_copy_finalizer #13350

merged 4 commits into from
May 16, 2025

Conversation

casperisfine
Copy link
Contributor

  • 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), [])
Copy link
Contributor Author

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.

Copy link

launchable-app bot commented May 15, 2025

Tests Failed

✖️no tests failed ✔️61840 tests passed(1 flake)

@casperisfine casperisfine force-pushed the copy-finalizer-lock branch 2 times, most recently from fdf9e04 to 60f41e2 Compare May 15, 2025 14:26
@byroot byroot enabled auto-merge (rebase) May 15, 2025 14:26
@byroot byroot disabled auto-merge May 15, 2025 14:34
@@ -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();
Copy link
Member

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.

Copy link
Contributor Author

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.

@casperisfine casperisfine force-pushed the copy-finalizer-lock branch from ea38265 to b0d2a3b Compare May 16, 2025 15:03
@byroot byroot enabled auto-merge (rebase) May 16, 2025 18:05
@byroot byroot merged commit 22c0913 into ruby:master May 16, 2025
82 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants