Package org.graalvm.nativeimage
Class ImageInfo
java.lang.Object
org.graalvm.nativeimage.ImageInfo
Utility class to retrieve information about the context in which code gets executed. The provided
string constants are part of the API and guaranteed to remain unchanged in future versions. This
allows to use
System.getProperty(String)
directly with the string literals defined here
thus eliminating the need to depend on this class.- Since:
- 19.0
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
Holds the string that is the name of the system property providing information about the context in which code is currently executing.static final String
Holds the string that will be returned by the system property forPROPERTY_IMAGE_CODE_KEY
if code is executing in the context of image building (e.g.static final String
Holds the string that will be returned by the system property forPROPERTY_IMAGE_CODE_KEY
if code is executing at image runtime.static final String
Name of the system property that holds if this image is built as a shared library or an executable.static final String
Holds the string that will be returned by the system property forPROPERTY_IMAGE_KIND_KEY
if image is an executable.static final String
Holds the string that will be returned by the system property forPROPERTY_IMAGE_KIND_KEY
if image is a shared library. -
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
Returns true if (at the time of the call) code is executing in the context of image building (e.g.static boolean
Returns true if (at the time of the call) code is executing in the context of image building or during image runtime, else false.static boolean
Returns true if (at the time of the call) code is executing at image runtime.static boolean
Returns true if the image is built as an executable.static boolean
Returns true if the image is build as a shared library.
-
Field Details
-
PROPERTY_IMAGE_CODE_KEY
Holds the string that is the name of the system property providing information about the context in which code is currently executing. If the property returns the string given byPROPERTY_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 byPROPERTY_IMAGE_CODE_VALUE_RUNTIME
the code is executing at image runtime. Otherwise the property is not set.- Since:
- 19.0
- See Also:
-
PROPERTY_IMAGE_CODE_VALUE_BUILDTIME
Holds the string that will be returned by the system property forPROPERTY_IMAGE_CODE_KEY
if 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
- See Also:
-
PROPERTY_IMAGE_CODE_VALUE_RUNTIME
Holds the string that will be returned by the system property forPROPERTY_IMAGE_CODE_KEY
if code is executing at image runtime.- Since:
- 19.0
- See Also:
-
PROPERTY_IMAGE_KIND_KEY
Name of the system property that holds if this image is built as a shared library or an executable. If the property isPROPERTY_IMAGE_KIND_VALUE_EXECUTABLE
the image is built as an executable. If the property isPROPERTY_IMAGE_KIND_VALUE_SHARED_LIBRARY
the image is built as a shared library.- Since:
- 19.0
- See Also:
-
PROPERTY_IMAGE_KIND_VALUE_SHARED_LIBRARY
Holds the string that will be returned by the system property forPROPERTY_IMAGE_KIND_KEY
if image is a shared library.- Since:
- 19.0
- See Also:
-
PROPERTY_IMAGE_KIND_VALUE_EXECUTABLE
Holds the string that will be returned by the system property forPROPERTY_IMAGE_KIND_KEY
if image is an executable.- Since:
- 19.0
- See Also:
-
-
Method Details
-
inImageCode
public static boolean inImageCode()Returns true if (at the time of the call) code is executing in the context of image building or during image runtime, else false. This method will be const-folded so that it can be used to hide parts of an application that only work when running on the JVM. For example:if (!ImageInfo.inImageCode()) { ... JVM specific code here ... }
- Since:
- 19.0
-
inImageRuntimeCode
public static boolean inImageRuntimeCode()Returns true if (at the time of the call) code is executing at image runtime. This method will be const-folded. It can be used to hide parts of an application that only work when running as native image.- Since:
- 19.0
-
inImageBuildtimeCode
public static boolean inImageBuildtimeCode()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
-
isExecutable
public static boolean isExecutable()Returns true if the image is built as an executable.- Since:
- 19.0
-