Skip to content

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 (default): Disable the strict mode and fall back to the optimization dependent inference for dynamic invocations
    • Warn: Use optimization dependent inference for dynamic invocations, but print a warning for invocations inferred outside of the strict mode
    • Enforce: Infer only dynamic invocations proven to be constant in the strict inference mode
  • -H:+ReportDynamicAccessInference
    • Generates a .json report of inferred dynamic access invocations

Review guide

The PR is roughly split into the following components:

  • A generic bytecode data-flow analyzer in the com.oracle.svm.hosted.dynamicaccessinference.dataflow package. The main classes here are:
    • com.oracle.svm.hosted.dynamicaccessinference.dataflow.ForwardDataFlowAnalyzer - a generic data flow analyzer;
    • com.oracle.svm.hosted.dynamicaccessinference.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 frame state before the execution of the corresponding instruction. That abstract state holds the information on constant expressions.
  • Analyze every method sent to AnalysisBytecodeParser 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).

Additionally, report generation for inferred calls is handled by the com.oracle.svm.hosted.dynamicaccessinference.DynamicAccessInferenceReportFeature 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.

@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 10 times, most recently from b22165b to e236ee3 Compare June 3, 2025 12:58
@graalvmbot graalvmbot force-pushed the alekstef/GR-45250-GR-45734-bytecode-level-reflection-analysis branch from e236ee3 to d3b758d Compare June 5, 2025 06:07
@graalvmbot graalvmbot changed the title [GR-45250][GR-45734] Reachability proofs for reflective operations [GR-45250] [GR-45734] Reachability proofs for reflective operations Jun 5, 2025
@graalvmbot graalvmbot force-pushed the alekstef/GR-45250-GR-45734-bytecode-level-reflection-analysis branch 3 times, most recently from 6499016 to e6f31c8 Compare June 9, 2025 08:23
@graalvmbot graalvmbot force-pushed the alekstef/GR-45250-GR-45734-bytecode-level-reflection-analysis branch from 831bce9 to 9a5faec Compare June 25, 2025 12:04
@graalvmbot graalvmbot changed the title [GR-45250] [GR-45734] Reachability proofs for reflective operations [GR-45250] [GR-45734] Strict Dynamic Access Inference Jun 25, 2025
@graalvmbot graalvmbot force-pushed the alekstef/GR-45250-GR-45734-bytecode-level-reflection-analysis branch from 9a5faec to 573c1d3 Compare July 9, 2025 08:41
@graalvmbot graalvmbot force-pushed the alekstef/GR-45250-GR-45734-bytecode-level-reflection-analysis branch 2 times, most recently from ddda60b to 9764aa6 Compare August 9, 2025 14:06
@graalvmbot graalvmbot force-pushed the alekstef/GR-45250-GR-45734-bytecode-level-reflection-analysis branch from 51c03ff to 0d3a0bf Compare August 21, 2025 08:01
…is for resolving dynamic access invocations.
@graalvmbot graalvmbot force-pushed the alekstef/GR-45250-GR-45734-bytecode-level-reflection-analysis branch from 0d3a0bf to 63e4d07 Compare September 3, 2025 13:28
@graalvmbot graalvmbot merged commit a931870 into master Sep 9, 2025
13 checks passed
@graalvmbot graalvmbot deleted the alekstef/GR-45250-GR-45734-bytecode-level-reflection-analysis branch September 9, 2025 15:57
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