Project

General

Profile

Actions

Bug #22064

closed

GC compaction breaks compare-by-identity sets

Bug #22064: GC compaction breaks compare-by-identity sets

Added by peterzhu2118 (Peter Zhu) 11 days ago. Updated about 12 hours ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:125466]

Description

GitHub PR: https://github.com/ruby/ruby/pull/16923

Compare-by-identity sets use the address for hashing, so we must pin it so the object does not move in GC compaction. Objects in a compare-by-identity set is not currently pinned, causing the set to be broken if the object is moved.

For example:

set = Set.new.compare_by_identity

o = Object.new
set.add(o)

puts set.include?(o)

GC.verify_compaction_references(expand_heap: true, toward: :empty)

puts set.include?(o)

It should output true twice, but it outputs true and false.

Updated by peterzhu2118 (Peter Zhu) 10 days ago Actions #1

  • Status changed from Open to Closed

Applied in changeset git|baec5bbfffb38083b4180240a0319d20c9afc2a7.


Fix GC compaction for compare-by-identity sets

[Bug #22064]

Compare-by-identity sets use the address for hashing, so we must pin it
so the object does not move in GC compaction. Objects in a compare-by-identity
set is not currently pinned, causing the set to be broken if the object
is moved.

For example:

set = Set.new.compare_by_identity

o = Object.new
set.add(o)

puts set.include?(o)

GC.verify_compaction_references(expand_heap: true, toward: :empty)

puts set.include?(o)

It should output true twice, but it outputs true and false.

Updated by k0kubun (Takashi Kokubun) about 12 hours ago Actions #2 [ruby-core:125561]

  • Backport changed from 3.3: DONTNEED, 3.4: DONTNEED, 4.0: REQUIRED to 3.3: DONTNEED, 3.4: DONTNEED, 4.0: DONE
Actions

Also available in: PDF Atom