Skip to content

[GR-45250][GR-45734] Reachability proofs for reflective operations #11079

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

graalvmbot
Copy link
Collaborator

@graalvmbot graalvmbot commented Apr 24, 2025

Additions from this PR

The current implementation of the analysis for constant reflection (and other dynamic access) invocations is optimization dependent, leading to the possibility of different image run-time behavior when compiled with different optimization options (specifically related to InlineBeforeAnalysis).

This PR introduced a bytecode-level analysis for such invocations, thus avoiding any graph optimizations.

Two new hosted options are introduced:

  • -H:StrictDynamicAccessInference=Disable|Warn|Enforce
    • Disable: Disable the strict mode and fall back to the optimization dependent analysis for inferrable dynamic calls
    • Warn: Fold both the calls inferred with the strict mode analysis and the optimization dependent analysis, but print a warning for non-strict call folding
    • Enforce: Fold only the calls inferred by the strict analysis mode
  • -H:DynamicAccessInferenceLog=<location>
    • Outputs a .json log of inferred invocations which would otherwise require a reachability registration to the specified location

Review guide

The PR is roughly split into the following components:

  • A generic bytecode data-flow analyzer in the com.oracle.svm.hosted.dataflow package. The main classes here are:
    • com.oracle.svm.hosted.dataflow.ForwardDataFlowAnalyzer - a generic data flow analyzer;
    • com.oracle.svm.hosted.dataflow.AbstractInterpreter - an abstract bytecode interpreter built on top of ForwardDataFlowAnalyzer by propagating abstract bytecode execution frames through the data-flow.
  • A constant expression analysis utilizing AbstractInterpreter. It is implemented in the com.oracle.svm.hosted.dynamicaccessinference package.

The entry point of the analysis is in the com.oracle.svm.hosted.dynamicaccessinference.StrictDynamicAccessInferenceFeature class. The main steps are:

  • Create a com.oracle.svm.hosted.dynamicaccessinference.ConstantExpressionRegistry and register it as an image singleton. The registry maps method and BCI pairs into the abstract state before the execution of the corresponding instruction. That abstract state holds the information on constant expressions.
  • Register a com.oracle.svm.hosted.dynamicaccessinference.StrictDynamicAccessInferenceSupport singleton which analyzes every method sent to AnalysisBytecodeParser and ClassInitializerBytecodeParser using a com.oracle.svm.hosted.dynamicaccessinference.ConstantExpressionAnalyzer. The results are stored in the constant expression registry.
  • Use the collected analysis results in invocation plugins which target methods such as Class.forName(String). The full list of targeted methods can be found in the feature class.

Additionally, all logging of inferred calls is handled by the com.oracle.svm.hosted.dynamicaccessinference.DynamicAccessInferenceLoggingFeature feature.

One important implementation detail to note is that ConstantExpressionAnalyzer unwraps analysis methods in order to avoid lookups through the analysis universe, and thus potential unsupported feature exceptions.

The decision if this functionality is added to --future-defaults can be made after the review and integration tests are complete.

@oracle-contributor-agreement oracle-contributor-agreement bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label Apr 24, 2025
@graalvmbot graalvmbot force-pushed the alekstef/GR-45250-GR-45734-bytecode-level-reflection-analysis branch 3 times, most recently from 51bf4e1 to 50a8e02 Compare May 13, 2025 12:33
@graalvmbot graalvmbot force-pushed the alekstef/GR-45250-GR-45734-bytecode-level-reflection-analysis branch 14 times, most recently from db34a29 to 5a4d449 Compare May 22, 2025 10:53
@graalvmbot graalvmbot force-pushed the alekstef/GR-45250-GR-45734-bytecode-level-reflection-analysis branch 12 times, most recently from 4d9ed1b to 385e93e Compare May 27, 2025 13:33
@graalvmbot graalvmbot force-pushed the alekstef/GR-45250-GR-45734-bytecode-level-reflection-analysis branch from 385e93e to b5cd103 Compare May 27, 2025 13:53
@graalvmbot graalvmbot changed the title [WIP][GR-45250][GR-45734] Reachability proofs for reflective operations [GR-45250][GR-45734] Reachability proofs for reflective operations May 27, 2025
@graalvmbot graalvmbot force-pushed the alekstef/GR-45250-GR-45734-bytecode-level-reflection-analysis branch from b5cd103 to bc5bec8 Compare May 27, 2025 15:03
@graalvmbot graalvmbot force-pushed the alekstef/GR-45250-GR-45734-bytecode-level-reflection-analysis branch 3 times, most recently from 85054c9 to 3650c1d Compare May 29, 2025 12:20
@graalvmbot graalvmbot force-pushed the alekstef/GR-45250-GR-45734-bytecode-level-reflection-analysis branch 4 times, most recently from 17ffed5 to a5128b5 Compare June 2, 2025 10:47
@graalvmbot graalvmbot force-pushed the alekstef/GR-45250-GR-45734-bytecode-level-reflection-analysis branch from a5128b5 to d820f11 Compare June 2, 2025 12:30
@graalvmbot graalvmbot force-pushed the alekstef/GR-45250-GR-45734-bytecode-level-reflection-analysis branch from b22165b to e236ee3 Compare June 3, 2025 12:58
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