-
Notifications
You must be signed in to change notification settings - Fork 77
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
Follow up wrt #191 by using NativeImageUtil.isRunningInNativeImage()
in databind
#217
Follow up wrt #191 by using NativeImageUtil.isRunningInNativeImage()
in databind
#217
Conversation
@stevenschlansker Could you please take a look? Just to make sure :) |
* | ||
* @since 2.16 | ||
*/ | ||
private static final boolean RUNNING_IN_SVM = NativeImageUtil.isRunningInNativeImage(); |
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.
Not sure this can be done, since method Javadoc states:
* This check cannot be a constant, because
* the static initializer may run early during build time
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 see. I missed the JavaDoc. Maybe we can instead inline the check inside ‘setupModule()’?
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.
Yes, I think inlining would make sense: it will only be called once anyway.
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.
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.
For other modules to use NativeImageUtil.isRunningInNativeImage()
, what I would expect is
public class NativeImageUtil {
private static final boolean RUNNING_IN_SVM = isRunningInNativeImage();
/**
* Check whether we're running in substratevm native image runtime mode.
* This check cannot be a constant, because
* the static initializer may run early during build time
*<p>
* NOTE: {@code public} since 2.16 (before that, {@code private}).
*/
public static boolean isRunningInNativeImage() {
return System.getProperty("org.graalvm.nativeimage.imagecode") != null && "runtime".equals(System.getProperty("org.graalvm.nativeimage.imagecode"));
}
// ...rest omitted
.... as such so that actual check is done at call time. 🤔 Sorry if I misunderstood the whole mechanism though.
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.
as discussed in #216, isRunningInNativeImage()
should not be used here. There needs to be a new getter for RUNNING_IN_SVM
that can be used instead.
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.
maybe isRunningInNativeImage()
should be renamed also. i did not think enough about the name when i wrote it, since it wasn't public api. now that it is, a better name would be appropriate.
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.
maybe isRunningInNativeImage() should be renamed also. i did not think enough about the name when i wrote it, since it wasn't public api. now that it is, a better name would be appropriate.
+1. Method names are also subject to change.
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.
So I....
- Made a PR in Update
NativeImageUtil
method name and expose new getter jackson-databind#4063. - Adopted new getter early (CI will temporarily fail)
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.
Since the method was non-public before 2.16, it's fine to change the name I think.
@@ -51,7 +50,8 @@ public AfterburnerModule() { } | |||
@Override | |||
public void setupModule(SetupContext context) | |||
{ | |||
if (RUNNING_IN_SVM) | |||
// [modules-base#191] Since 2.16, Native image detection | |||
if (NativeImageUtil.isInSVM()) |
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 think you missed updating this line with the new name.
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.
Right, thank you! @stevenschlansker 🙏🏽🙏🏽
Motivation
Seems like the
TODO:
was written before exposingNativeImageUtil.isRunningInNativeImage()
indatabind
by FasterXML/jackson-databind#4060