Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
Expand Down Expand Up @@ -60,7 +60,7 @@ private ImageInfo() {
* {@link #PROPERTY_IMAGE_CODE_VALUE_BUILDTIME} the code is executing in the context of image
* building (e.g. in a static initializer of a class that will be contained in the image). If
* the property returns the string given by {@link #PROPERTY_IMAGE_CODE_VALUE_RUNTIME} the code
* is executing at image runtime. Otherwise the property is not set.
* is executing at image runtime. Otherwise, the property is not set.
*
* @since 19.0
*/
Expand Down Expand Up @@ -118,6 +118,7 @@ private ImageInfo() {
* @since 19.0
*/
public static boolean inImageCode() {
// A plugin in SubstrateGraphBuilderPlugins constant-folds this method to return true.
return inImageBuildtimeCode() || inImageRuntimeCode();
}

Expand All @@ -129,17 +130,21 @@ public static boolean inImageCode() {
* @since 19.0
*/
public static boolean inImageRuntimeCode() {
return PROPERTY_IMAGE_CODE_VALUE_RUNTIME.equals(System.getProperty(PROPERTY_IMAGE_CODE_KEY));
// A plugin in SubstrateGraphBuilderPlugins constant-folds this method to return true.
return false;
}

private static final boolean BUILDTIME = PROPERTY_IMAGE_CODE_VALUE_BUILDTIME.equals(System.getProperty(PROPERTY_IMAGE_CODE_KEY));

/**
* Returns true if (at the time of the call) code is executing in the context of image building
* (e.g. in a static initializer of class that will be contained in the image).
*
* @since 19.0
*/
public static boolean inImageBuildtimeCode() {
return PROPERTY_IMAGE_CODE_VALUE_BUILDTIME.equals(System.getProperty(PROPERTY_IMAGE_CODE_KEY));
// A plugin in SubstrateGraphBuilderPlugins constant-folds this method to return false.
return BUILDTIME;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.graalvm.nativeimage.ImageInfo;
import org.graalvm.nativeimage.Platform;
import org.graalvm.nativeimage.ProcessProperties;

Expand Down Expand Up @@ -998,6 +999,8 @@ private void prepareImageBuildArgs() {
addImageBuilderJavaArgs("-Dcom.oracle.graalvm.isaot=true");
addImageBuilderJavaArgs("-Djava.system.class.loader=" + CUSTOM_SYSTEM_CLASS_LOADER);

addImageBuilderJavaArgs("-D" + ImageInfo.PROPERTY_IMAGE_CODE_KEY + "=" + ImageInfo.PROPERTY_IMAGE_CODE_VALUE_BUILDTIME);

/*
* The presence of CDS and custom system class loaders disables the use of archived
* non-system class and triggers a warning.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ public void run(Map<Method, CEntryPointData> entryPoints,
}

protected static void setSystemPropertiesForImageEarly() {
System.setProperty(ImageInfo.PROPERTY_IMAGE_CODE_KEY, ImageInfo.PROPERTY_IMAGE_CODE_VALUE_BUILDTIME);
VMError.guarantee(ImageInfo.inImageBuildtimeCode(), "Expected ImageInfo.inImageBuildtimeCode() to return true");
}

private static void setSystemPropertiesForImageLate(NativeImageKind imageKind) {
Expand All @@ -554,7 +554,6 @@ private static void setSystemPropertiesForImageLate(NativeImageKind imageKind) {
}

public static void clearSystemPropertiesForImage() {
System.clearProperty(ImageInfo.PROPERTY_IMAGE_CODE_KEY);
System.clearProperty(ImageInfo.PROPERTY_IMAGE_KIND_KEY);
}

Expand Down
Loading