[GR-58968] [GR-57818] [GR-57554] [GR-57561] [GR-57555] Extend the registrations done by TruffleFeature.beforeAnalysis #9989
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.
Overview
This PR extends the registrations that are performed by
TruffleFeature.beforeAnalysisto make sure that even small test images or non-standard usages of Truffle still end up having the core Truffle classes reachable and included in the image.Reasoning behing the new registrations
Overall, the goal is to make a few key Truffle classes always reachable. The way we currently do it is via various registrations in
TruffleFeature.beforeAnalysis.TruffleSupport.singleton().createOptimizedCallTarget root method
This method calls a constructor of a subclass of
OptimizedCallTarget.TruffleFeaturealready marked that class as in the heap, but without making the analysis see the constructor, its fields remain withemptytypestate. As soon as there is a null check or a type check somewhere, WP SCCP will see that the predicates of both branches areemptyand therefore all the rest of the flows in those method remain disabled. This is problematic especially because the fieldsrootNodeandengineare acesssed often before anything else is done, so this effectively makes the analysis of most of methods onOptimizedCallTargetto stop very early and conclude that the rest is unreachable (including methods that could be transitively reachable from the methods onOptimizedRootNode) .Marking TruffleSupport.singleton().getClass() as in the heap
Since
createOptimizedCallTargetis not static, to analysis has to see a potential receiver object on which the given method can be called.Conclusion
These two registrations are enough to fix the issues we care about and and morever, the code elements in question are already made reachable by the original analysis for any 'real' Truffle image anyways, so nothing new should be included by this change.