Skip to content

Conversation

graalvmbot
Copy link
Collaborator

The folding of @Stable fields before analysis is a recurrent source of non-determinism, because if such a field can be folded depends on if it was already initialized, which is often done in parallel with the folding, thus creating race conditions. To ensure deterministic analysis results, this PR delays the folding of @Stable fields until the analysis is finished. Note that these fields still get folded after analysis, so the impact on the quality of generated code should be minimal.

This PR also introduces a configurable set of @Stable fields that can still be folded before analysis. It currently includes the folllowing fields:

  • java.lang.Module.enableNativeAccess, which is registered unconditionally for every image, because it has a significant impact on the number of reachable methods in small images.
  • sun.mics.Unsafe.memoryAccessWarned, which is registered for Truffle, because its folding is necessary to remove the code printing warnings on the first unsafe access.
  • A set of fields related to VarHandles, see the changes in VarHandleFeature for details.

Trying to fold a registered @Stable field which still has a default value results in a build failure, because if the initialization occurs later, the folding might again result in a non-deterministic behavior. In future, we may extend this list further with other fields that are guaranteed to be initialized before any method that accessed them is parsed, as in such cases the analysis results should still be deterministic.

@oracle-contributor-agreement oracle-contributor-agreement bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label Sep 11, 2025
@graalvmbot graalvmbot merged commit ee80875 into master Sep 11, 2025
13 checks passed
@graalvmbot graalvmbot deleted the d-kozak/GR-68726/do-not-fold-stable-fields-in-analysis branch September 11, 2025 10:58
@christianwimmer
Copy link

This is the best thing ever, why did we not have that idea years ago...

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.

3 participants