Skip to content

Read HashTable field offsets from HashTable, not EqHashTable - #312

Merged
hg-ms merged 1 commit into
mainfrom
fix/hashtable-field-offsets
Aug 3, 2026
Merged

Read HashTable field offsets from HashTable, not EqHashTable#312
hg-ms merged 1 commit into
mainfrom
fix/hashtable-field-offsets

Conversation

@hg-ms

@hg-ms hg-ms commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

XCollectionsInternals computed the size, keys and values offsets from EqHashTable and applied them to HashTable instances. EqHashTable has an additional field, so its layout is shifted and the offsets do not address the intended fields.

Every restored HashTable was therefore written at wrong offsets by BinaryHandlerHashTable.updateState. With standard object headers the writes still landed inside the larger instance and silently corrupted a neighbouring field. With compact object headers the instance is smaller and the offset points past its end, so the write hits the following object's mark word, which then carries the klass pointer: the next garbage collection decodes a corrupt klass and the JVM dies.

XCollectionsInternals computed the size, keys and values offsets from
EqHashTable and applied them to HashTable instances. EqHashTable has an
additional field, so its layout is shifted and the offsets do not address
the intended fields.

Every restored HashTable was therefore written at wrong offsets by
BinaryHandlerHashTable.updateState. With standard object headers the
writes still landed inside the larger instance and silently corrupted a
neighbouring field. With compact object headers the instance is smaller
and the offset points past its end, so the write hits the following
object's mark word, which then carries the klass pointer: the next
garbage collection decodes a corrupt klass and the JVM dies.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a critical binary persistence corruption bug by ensuring HashTable field offsets are computed from HashTable itself (not EqHashTable), preventing incorrect XMemory writes during restore that could corrupt adjacent fields or crash the JVM (notably with compact object headers).

Changes:

  • Compute OFFSET_HashTable_{size,keys,values} from HashTable.class instead of EqHashTable.class.
  • Replace the wildcard collections import with explicit imports for the types referenced in XCollectionsInternals.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@hg-ms
hg-ms requested review from fh-ms and zdenek-jonas August 3, 2026 09:01
@hg-ms
hg-ms merged commit c6bfb1d into main Aug 3, 2026
20 checks passed
@hg-ms
hg-ms deleted the fix/hashtable-field-offsets branch August 3, 2026 10:08
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