-
Notifications
You must be signed in to change notification settings - Fork 323
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
Initialize Builtins at Native Image build time #3821
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am pleasantly surprised that one can Method.invoke
without specifying that in the reflect-config.json
!
engine/runtime/src/main/java/org/enso/interpreter/runtime/builtin/Builtins.java
Outdated
Show resolved
Hide resolved
engine/runtime/src/main/java/org/enso/interpreter/runtime/builtin/Builtins.java
Show resolved
Hide resolved
...e/runner-native/src/main/resources/META-INF/native-image/org/enso/runner/reflect-config.json
Show resolved
Hide resolved
c57f25a
to
2550cfc
Compare
This currently breaks because tests call Builtins multiple times and some state is modified during initialization. Resetting the state of types and scope would be recommended but it opens its own can of worms that I don't want to do. On the other hand, we could statically just initialize the class and then create new instances in Builtins constructor. Unfortunately calls are then not inlined, we get |
Yeap, that was it. As soon as I moved |
2550cfc
to
a464a8f
Compare
Moved loading of Builtin Types and Methods to a static initializer. That way the information is available at Native Image build time and one does not have to update a corresponding entry in `reflect-config` which would be a real pain when we start using it in anger.
Turns out one cannot re-use builtins that are initialized in the static context because some state is not reset between tests. Trying to enforce that will also open a can of worms so we decided against that. However, while trying to instantiate builtins in the constructor we would no longer inling constructor calls, resulting in `NoSuchMethodException` once the native image was generated. This turned out to be a limitation related to oracle/graal#2500 so that we cannot make calls like `clazz.getContructor().newInstance()`. `clazz.getConstructor()` in the static initializer and creating new instances in Builtins constructor was however OK for the inliner and it was able to procede with constant folding.
84fe5a1
to
4def05d
Compare
Pull Request Description
Moved loading of Builtin Types and Methods to a static initializer. That way the information is available at Native Image build time and one does not have to update a corresponding entry in
reflect-config
which would be a real pain when we start using it in anger.Fixes https://www.pivotaltracker.com/story/show/183374932
Important notice
For the inliner to do its job, we have to limit call chains. Therefore rather than making
clazz.getConstructor().newInstance()
calls we should doclazz.getConstructor()
. The latter will get constant folded and won't crash when running NI, the former won't.