Skip to content

[GR-77163] Safely publish object type id cache.#14006

Merged
graalvmbot merged 1 commit into
masterfrom
chw/GR-77163/multi_type_state
Jul 17, 2026
Merged

[GR-77163] Safely publish object type id cache.#14006
graalvmbot merged 1 commit into
masterfrom
chw/GR-77163/multi_type_state

Conversation

@graalvmbot

Copy link
Copy Markdown
Collaborator

failing: Multi type state with single type.

It happened in bytecode-sensitive subtraction. That code builds result object arrays using a cached int[] of object type IDs from ContextSensitiveMultiTypeState.getObjectTypeIds(). The cache was lazily initialized and stored in a plain field. In parallel analysis, another worker thread could observe the array reference without a proper publication edge, so it was not guaranteed to see the filled array contents.

If stale/default type IDs were read, subtraction could keep/remove the wrong objects, then try to construct a MultiTypeState even though the resulting bitset had only one type, triggering the assertion.

Implemented change
I changed ContextSensitiveMultiTypeState.objectTypeIds to volatile.

That makes the lazy cache safely published: the thread that fills the array writes all elements first, then publishes the reference through a volatile write. Other threads reading the non-null volatile reference are guaranteed to see the initialized contents. No synchronization is needed because duplicate initialization is harmless and the array is not mutated after publication.

backport
This needs to be backported to 25.0.

@oracle-contributor-agreement oracle-contributor-agreement Bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label Jul 17, 2026
@graalvmbot
graalvmbot merged commit 5aec5e7 into master Jul 17, 2026
3 checks passed
@graalvmbot
graalvmbot deleted the chw/GR-77163/multi_type_state branch July 17, 2026 15:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

OCA Verified All contributors have signed the Oracle Contributor Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants