[GR-68726] Delay the folding of most @Stable fields until the analysis is finished #12146
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.VarHandles
, see the changes inVarHandleFeature
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.