-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
[GR-41674] Class instanceOf and isAssignableFrom checks do need to make the checked type reachable. #5224
Conversation
@tomas-langer This PR passes all of our tests except for Helidon MP, where it leads to a strange exception at image run time:
Why the failing code /~https://github.com/jbosstm/narayana/blob/master/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/common/CoreEnvironmentBean.java#L232 is running at image run time with this PR, but not without this PR, is very interesting: Without this PR, the lazy initialization of
So it is a side effect of This PR no longer marks types used only in an I see a couple of problems in Helidon here:
All of that can be fixed in a future version of Helidon. But how can we merge this PR without breaking all Helidon MP usages that are out there right now? |
There is the case when building a native image for a JavaFX application pulls additional AWT classes. The simple code which reproduces the behavior is:
Building the native image with option
shows that class_initialization_dependencies_*.dot file contains links:
Does it mean that the native image includes classes like ComponentEvent and AWTEvent? |
2725d25
to
c6d1650
Compare
…ked type reachable
c6d1650
to
0f0a1c6
Compare
@AlexanderScherbatiy good find, and thanks for the reproducer. When constant folding the I'm working on a fix. |
#5065 reported an unnecessary imprecision of the static analysis: Just using a type in an
instanceof
ofClass.isAssignableFrom
type check makes the type reachable - which implicitly makes the class initializer of the that type reachable too. So the JDK code in /~https://github.com/openjdk/jdk/blob/844a95b907aaf6ef67d7e4b1ed0998945a6152d2/src/java.desktop/share/classes/java/beans/Introspector.java#L1128 makes the class initializer ofjava.awt.Component
reachable, which then pulls in further AWT classes.The fact that
instanceof
makes the checked type reachable has historic reasons: it was necessary when we parsed bytecode again after static analysis for AOT compilation. The fix is easy for that case:MethodTypeFlowBuilder
just does not make the type reachable forInstanceOfNode
.Handling
Class.isAssignableFrom
is a bit trickier, since it involves type constants that are embedded in the graph. So we need to recognize the graph structure and ignore theConstantNode
if the only usages areClassIsAssignableFromNode
.Making fewer types reachable is generally desirable, but can have also surprising side effects. See the Helidon compatibility problem mentioned separately in a comment.