Skip to content

Fix write barriers in rb_hash_add_new_element #13659

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jhawthorn
Copy link
Member

The write barriers must be run after the st_update callback returns, as the objects are not on the object until then and there may be allocation when there is a new object inserted.

This is hard to reproduce, and I haven't seen an actual crash due to it, but it is detected by wbcheck

RUBY_GC_LIBRARY=wbcheck WBCHECK_VERIFY_AFTER_WB=1 ./miniruby -e '("a".."zz").uniq.to_a'
WBCHECK ERROR: Missed write barrier detected!
  Parent object: 0x720db01f99c0 (wb_protected: true)
    rb_obj_info_dump: 0x0000720db01f99c0 T_HASH/[S] 18
  Reference counts - snapshot: 32, writebarrier: 2, current: 36, missed: 2
  Missing reference to: 0x716db02e3450
    rb_obj_info_dump: 0x0000716db02e3450 T_STRING/String  len: 1, capa: 15 "q"
  Missing reference to: 0x716db02e3450
    rb_obj_info_dump: 0x0000716db02e3450 T_STRING/String  len: 1, capa: 15 "q"

A part of why this is hard to reproduce and it's unlikely to crash is that the insertion only rarely allocates.

The write barriers must be run after the st_update callback returns,
as the objects are not on the object until then and there may be
allocation when there is a new object inserted.

This is hard to reproduce, and I haven't seen an actual crash due to it,
but it is detected by wbcheck

    RUBY_GC_LIBRARY=wbcheck WBCHECK_VERIFY_AFTER_WB=1 ./miniruby -e '("a".."zz").uniq.to_a'
    WBCHECK ERROR: Missed write barrier detected!
      Parent object: 0x720db01f99c0 (wb_protected: true)
        rb_obj_info_dump: 0x0000720db01f99c0 T_HASH/[S] 18
      Reference counts - snapshot: 32, writebarrier: 2, current: 36, missed: 2
      Missing reference to: 0x716db02e3450
        rb_obj_info_dump: 0x0000716db02e3450 T_STRING/String  len: 1, capa: 15 "q"
      Missing reference to: 0x716db02e3450
        rb_obj_info_dump: 0x0000716db02e3450 T_STRING/String  len: 1, capa: 15 "q"

A part of why this is hard to reproduce and it's unlikely to crash is
that the insertion only rarely allocates.

Co-authored-by: Luke Gruber <[email protected]>
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.

1 participant