Skip to content

[GR-64787] Enable --install-exit-handlers by default. #11149

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
1 change: 0 additions & 1 deletion docs/reference-manual/native-image/BuildOptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ Run `native-image --help` for help on build options.
* `--gc=<value>`: select a Native Image garbage collector implementation. Allowed options for `<value>` are: `G1` for G1 garbage collector (not available in GraalVM Community Edition); `epsilon` for Epsilon garbage collector; `serial` for Serial garbage collector (default).
* `--initialize-at-build-time`: a comma-separated list of packages and classes (and implicitly all of their superclasses) that are initialized during generation of a native executable. An empty string designates all packages.
* `--initialize-at-run-time`: a comma-separated list of packages and classes (and implicitly all of their subclasses) that must be initialized at run time and not during generation. An empty string is currently not supported.
* `--install-exit-handlers`: provide `java.lang.Terminator` exit handlers
* `--libc`: select the `libc` implementation to use. Available implementations are `glibc`, `musl`, `bionic`.
* `--link-at-build-time`: require types to be fully defined at native executable build time. If used without arguments, all classes in scope of the option are required to be fully defined.
* `--link-at-build-time-paths`: require all types in given class or module path entries to be fully defined at native executable build time
Expand Down
9 changes: 0 additions & 9 deletions docs/reference-manual/native-image/Compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,6 @@ Native Image implements some Java features differently to the Java VM.

`java.lang.System#setSecurityManager(SecurityManager)` invoked with a non-null argument throws a `java.lang.SecurityException` if `-Djava.security.manager` is set to anything but `disallow` at program startup.

### Signal Handlers

Registering a signal handler requires a new thread to start that handles the signal and invokes shutdown hooks.
By default, no signal handlers are registered when building a native image, unless they are registered explicitly by the user.
For example, it is not recommended to register the default signal handlers when building a shared library, but it is desirable to include signal handlers when building a native executable for containerized environments, such as Docker containers.

To register the default signal handlers, pass the `--install-exit-handlers` option to the `native-image` builder.
This option gives you the same signal handlers as a Java VM.

### Class Initializers

By default, classes are initialized at run time.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,19 @@ Otherwise, the `System.getProperty("java.home")` call will return a `null` value
Try enabling all URL protocols on-demand at build time: `--enable-url-protocols=<protocols>`.
To enable the HTTPS support only, pass `--enable-https`.

### 4. Enable Signal Handling

If your application is using signal handling or the `java.lang.Terminator` exit handlers, provide the option `--install-exit-handlers` option at build time.

### 5. Include All Charsets and Locales
### 4. Include All Charsets and Locales

Other handy options are `-H:+AddAllCharsets` to add charsets support, and `-H:+IncludeAllLocales` to pre-initialize support for locale-sensitive behavior in the `java.util` and `java.text` packages.
Pass those options at build time.
This might increase the size of the resulting binary.

### 6. Add Missing Security Providers
### 5. Add Missing Security Providers

If your application is using Security Providers, try to pre-initialize security providers by passing the option `-H:AdditionalSecurityProviders=<list-of-providers>` at build time.
Here is a list of all JDK security providers to choose from:
`sun.security.provider.Sun,sun.security.rsa.SunRsaSign,sun.security.ec.SunEC,sun.security.ssl.SunJSSE,com.sun.crypto.provider.SunJCE,sun.security.jgss.SunProvider,com.sun.security.sasl.Provider,org.jcp.xml.dsig.internal.dom.XMLDSigRI,sun.security.smartcardio.SunPCSC,sun.security.provider.certpath.ldap.JdkLDAP,com.sun.security.sasl.gsskerb.JdkSASL`.

### 7. File a Native Image Run-Time Issue
### 6. File a Native Image Run-Time Issue

Only if you tried all the above suggestions, file a [Native Image Run-Time Issue Report](https://github.com/oracle/graal/issues/new?assignees=&labels=native-image%2Cbug%2Crun-time&projects=&template=1_1_native_image_run_time_bug_report.yml&title=%5BNative+Image%5D+) at GitHub, filling out the necessary information.

Expand Down
1 change: 0 additions & 1 deletion sdk/mx.sdk/mx_sdk_benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -1482,7 +1482,6 @@ def run_stage_instrument_run(self):
mx.abort(
f"Profile file {self.config.profile_path} does not exist "
f"even though the instrument run terminated successfully with exit code 0. "
f"Try adding the '--install-exit-handlers' build option if it is not present."
)
print(f"Profile file {self.config.profile_path} sha1 is {mx.sha1OfFile(self.config.profile_path)}")
self._ensureSamplesAreInProfile(self.config.profile_path)
Expand Down
1 change: 0 additions & 1 deletion sdk/mx.sdk/mx_sdk_vm_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -1421,7 +1421,6 @@ def contents(self):

if isinstance(image_config, mx_sdk.LauncherConfig) or (isinstance(image_config, mx_sdk.LanguageLibraryConfig) and image_config.launchers):
build_args += [
'--install-exit-handlers',
'--enable-monitoring=jvmstat,heapdump,jfr,threaddump',
] + svm_experimental_options([
'-H:+DumpRuntimeCompilationOnSignal',
Expand Down
2 changes: 1 addition & 1 deletion sdk/mx.sdk/mx_sdk_vm_ng.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ def get_build_args(self):
build_args += [
'-R:+EnableSignalHandling',
'-R:+InstallSegfaultHandler',
'--install-exit-handlers',
'-H:+UnlockExperimentalVMOptions', '-H:+InstallExitHandlers', '-H:-UnlockExperimentalVMOptions',
]

# Monitoring flags
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
Args = --enable-url-protocols=http,https \
--install-exit-handlers \
--initialize-at-build-time=org.graalvm.maven.downloader.OptionProperties \
--initialize-at-run-time=org.graalvm.maven.downloader.Main,org.graalvm.maven.downloader.MVNDownloader,org.graalvm.maven.downloader.Main$Arguments,org.graalvm.maven.downloader.MVNDownloader$DeleteDownloadDir
1 change: 1 addition & 0 deletions substratevm/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ This changelog summarizes major changes to GraalVM Native Image.
* (GR-60209) New syntax for configuration of the [Foreign Function & Memory API](https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/ForeignInterface.md)
* (GR-64584) Experimental option `-H:+RelativeCodePointers` to significantly reduce relocation entries in position-independent executables and shared libraries.
* (GR-60238) JNI registration is now included as part of the `"reflection"` section of _reachability-metadata.json_ using the `"jniAccessible"` attribute. Registrations performed through the `"jni"` section of _reachability-metadata.json_ and through _jni-config.json_ will still be accepted and parsed correctly.
* (GR-64787) Enable `--install-exit-handlers` by default for executables deprecate the option. To restore the previous functionality needs to be restored one can use `-H:-InstallExitHandlers`. To enable in shared libraries use `-H:-InstallExitHandlers`.

## GraalVM for JDK 24 (Internal Version 24.2.0)
* (GR-59717) Added `DuringSetupAccess.registerObjectReachabilityHandler` to allow registering a callback that is executed when an object of a specified type is marked as reachable during heap scanning.
Expand Down
5 changes: 0 additions & 5 deletions substratevm/mx.substratevm/mx_substratevm_benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,11 +368,6 @@ def extra_run_arg(self, benchmark, args, image_run_args):
# Added by BaristaNativeImageCommand
return []

def extra_image_build_argument(self, benchmark, args):
return [
"--install-exit-handlers"
] + super().extra_image_build_argument(benchmark, args)

def run(self, benchmarks, bmSuiteArgs) -> mx_benchmark.DataPoints:
self.context = mx_sdk_benchmark.BaristaBenchmarkSuite.RuntimeContext(self, None, benchmarks[0], bmSuiteArgs)
return self.intercept_run(super(), benchmarks, bmSuiteArgs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
public class SubstrateExitHandlerFeature implements InternalFeature {
@Override
public void beforeAnalysis(BeforeAnalysisAccess access) {
if (SubstrateOptions.needsExitHandlers()) {
if (SubstrateOptions.InstallExitHandlers.getValue()) {
RuntimeSupport.getRuntimeSupport().addStartupHook(new SubstrateExitHandlerStartupHook());
}
}
Expand All @@ -43,7 +43,7 @@ public void beforeAnalysis(BeforeAnalysisAccess access) {
final class SubstrateExitHandlerStartupHook implements RuntimeSupport.Hook {
@Override
public void execute(boolean isFirstIsolate) {
if (isFirstIsolate) {
if (SubstrateOptions.EnableSignalHandling.getValue() && isFirstIsolate) {
Target_java_lang_Terminator.setup();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1070,6 +1070,23 @@ private static void validateStripDebugInfo(HostedOptionKey<Boolean> optionKey) {
@Option(help = "Emit debuginfo debug.svm.imagebuild.* sections with detailed image-build options.")//
public static final HostedOptionKey<Boolean> UseImagebuildDebugSections = new HostedOptionKey<>(true);

@APIOption(name = "install-exit-handlers", deprecated = "--install-exit-handlers is enabled by default for executables and it can likely be removed. To use this option for the shared libraries, please use -H:+InstallExitHandlers.")//
@Option(help = "Provide java.lang.Terminator exit handlers. Default value is true for executables and false for shared libraries because this option installs signal handlers.", type = Expert, stability = OptionStability.EXPERIMENTAL)//
protected static final HostedOptionKey<Boolean> InstallExitHandlers = new HostedOptionKey<>(null) {
@Override
public Boolean getValueOrDefault(UnmodifiableEconomicMap<OptionKey<?>, Object> values) {
if (values.containsKey(this)) {
return (Boolean) values.get(this);
}
return ImageInfo.isExecutable();
}

@Override
public Boolean getValue(OptionValues values) {
return getValueOrDefault(values.getMap());
}
};

@Fold
public static boolean supportCompileInIsolates() {
UserError.guarantee(!ConcealedOptions.SupportCompileInIsolates.getValue() || SpawnIsolates.getValue(),
Expand Down Expand Up @@ -1141,11 +1158,6 @@ protected void onValueUpdate(EconomicMap<OptionKey<?>, Object> values, Integer o
@Option(help = "The largest page size of machines that can run the image. The default of 0 automatically selects a typically suitable value.")//
protected static final HostedOptionKey<Integer> PageSize = new HostedOptionKey<>(0);

/** Use {@link SubstrateOptions#needsExitHandlers()} instead. */
@APIOption(name = "install-exit-handlers")//
@Option(help = "Provide java.lang.Terminator exit handlers", type = User)//
protected static final HostedOptionKey<Boolean> InstallExitHandlers = new HostedOptionKey<>(false);

@Option(help = "Physical memory size (in bytes). By default, the value is queried from the OS/container during VM startup.", type = OptionType.Expert)//
public static final RuntimeOptionKey<Long> MaxRAM = new RuntimeOptionKey<>(0L, IsolateCreationOnly);

Expand All @@ -1170,11 +1182,6 @@ protected void onValueUpdate(EconomicMap<OptionKey<?>, Object> values, Integer o
});
}

@Fold
public static boolean needsExitHandlers() {
return ConcealedOptions.InstallExitHandlers.getValue() || VMInspectionOptions.hasJfrSupport() || VMInspectionOptions.hasNativeMemoryTrackingSupport();
}

@Option(help = "Overwrites the available number of processors provided by the OS. Any value <= 0 means using the processor count from the OS.")//
public static final RuntimeOptionKey<Integer> ActiveProcessorCount = new RuntimeOptionKey<>(-1, IsolateCreationOnly, RelevantForCompilationIsolates);

Expand Down
Loading