Skip to content

Commit

Permalink
Merge branch '2.16'
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Aug 3, 2023
2 parents 6ce3269 + 7d112ec commit 33de83f
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions src/main/java/tools/jackson/databind/util/NativeImageUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,40 @@
* @since 2.14
*/
public class NativeImageUtil {
private static final boolean RUNNING_IN_SVM;

private static final boolean RUNNING_IN_SVM = System.getProperty("org.graalvm.nativeimage.imagecode") != null;

static {
RUNNING_IN_SVM = System.getProperty("org.graalvm.nativeimage.imagecode") != null;
}

private NativeImageUtil() {
}
private NativeImageUtil() { }

/**
* Check whether we're running in substratevm native image runtime mode.
* This check cannot be a constant, because
* Check whether we're running in SubstrateVM native image and also in "runtime" mode.
* The "runtime" 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}).
* As optimization, {@code RUNNING_IN_SVM} is used to short-circuit on normal JVMs.
*
* @since 2.16
*/
public static boolean isRunningInNativeImage() {
public static boolean isInNativeImageAndIsAtRuntime() {
return RUNNING_IN_SVM && "runtime".equals(System.getProperty("org.graalvm.nativeimage.imagecode"));
}

/**
* Checks whether we're running in SubstrateVM native image <b>only by the presence</b> of
* {@code "org.graalvm.nativeimage.imagecode"} system property, regardless of its value (buildtime or runtime).
* We are irrespective of the build or runtime phase, because native-image can initialize static initializers at build time.
*<p>
* @since 2.16
*/
public static boolean isInNativeImage() {
return RUNNING_IN_SVM;
}

/**
* Check whether the given error is a substratevm UnsupportedFeatureError
*/
public static boolean isUnsupportedFeatureError(Throwable e) {
if (!isRunningInNativeImage()) {
if (!isInNativeImageAndIsAtRuntime()) {
return false;
}
if (e instanceof InvocationTargetException) {
Expand All @@ -47,7 +56,7 @@ public static boolean isUnsupportedFeatureError(Throwable e) {
* members visible in reflection).
*/
public static boolean needsReflectionConfiguration(Class<?> cl) {
if (!isRunningInNativeImage()) {
if (!isInNativeImageAndIsAtRuntime()) {
return false;
}
// records list their fields but not other members
Expand Down

0 comments on commit 33de83f

Please sign in to comment.