Skip to content

Initialize classes with simple side-effect-free class initializers before static analysis #2342

@christianwimmer

Description

@christianwimmer

In the native image generator, classes that have side-effect free class initializers should be initialized as early as possible so that the static analysis already sees them as initialized and can constant fold.

Before static analysis, we are restricted to intraprocedural analysis. But method inlining helps: we can inline statically bound methods to grow the analysis scope. If after such inlining the class initializer is side-effect free, i.e., does not read or write any static field outside of its class, then initialization can be done eagerly.

An important use case are enums: All "non-crazy" enums can be initialized by this analysis.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions