[ruby-core:125466] [Ruby Bug#22064] GC compaction breaks compare-by-identity sets
Issue #22064 has been reported by peterzhu2118 (Peter Zhu). ---------------------------------------- Bug #22064: GC compaction breaks compare-by-identity sets https://bugs.ruby-lang.org/issues/22064 * Author: peterzhu2118 (Peter Zhu) * Status: Open * Backport: 3.3: DONTNEED, 3.4: DONTNEED, 4.0: REQUIRED ---------------------------------------- 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: ```ruby 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. -- https://bugs.ruby-lang.org/
Issue #22064 has been updated by k0kubun (Takashi Kokubun). Backport changed from 3.3: DONTNEED, 3.4: DONTNEED, 4.0: REQUIRED to 3.3: DONTNEED, 3.4: DONTNEED, 4.0: DONE ruby_4_0 commit:1f3a2c5db2a45180980cdc6d2f283c077c8b3644. ---------------------------------------- Bug #22064: GC compaction breaks compare-by-identity sets https://bugs.ruby-lang.org/issues/22064#change-117392 * Author: peterzhu2118 (Peter Zhu) * Status: Closed * Backport: 3.3: DONTNEED, 3.4: DONTNEED, 4.0: DONE ---------------------------------------- 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: ```ruby 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. -- https://bugs.ruby-lang.org/
participants (2)
-
k0kubun (Takashi Kokubun) -
peterzhu2118 (Peter Zhu)