Skip to content

Commit eeab102

Browse files
committed
Enable --install-exit-handlers by default
Enable `--install-exit-handlers` by default and deprecate the option: Image size increase is negligable (10 types with 53 mehtods), and there is only 2.5% extra starup instructions (68498) for "Hello, World!" on Linux.
1 parent 293a883 commit eeab102

File tree

11 files changed

+25
-37
lines changed

11 files changed

+25
-37
lines changed

docs/reference-manual/native-image/BuildOptions.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ Run `native-image --help` for help on build options.
5959
* `--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).
6060
* `--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.
6161
* `--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.
62-
* `--install-exit-handlers`: provide `java.lang.Terminator` exit handlers
6362
* `--libc`: select the `libc` implementation to use. Available implementations are `glibc`, `musl`, `bionic`.
6463
* `--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.
6564
* `--link-at-build-time-paths`: require all types in given class or module path entries to be fully defined at native executable build time

docs/reference-manual/native-image/Compatibility.md

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,6 @@ Native Image implements some Java features differently to the Java VM.
5151

5252
`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.
5353

54-
### Signal Handlers
55-
56-
Registering a signal handler requires a new thread to start that handles the signal and invokes shutdown hooks.
57-
By default, no signal handlers are registered when building a native image, unless they are registered explicitly by the user.
58-
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.
59-
60-
To register the default signal handlers, pass the `--install-exit-handlers` option to the `native-image` builder.
61-
This option gives you the same signal handlers as a Java VM.
62-
6354
### Class Initializers
6455

6556
By default, classes are initialized at run time.

docs/reference-manual/native-image/guides/troubleshoot-run-time-errors.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,23 +47,19 @@ Otherwise, the `System.getProperty("java.home")` call will return a `null` value
4747
Try enabling all URL protocols on-demand at build time: `--enable-url-protocols=<protocols>`.
4848
To enable the HTTPS support only, pass `--enable-https`.
4949

50-
### 4. Enable Signal Handling
51-
52-
If your application is using signal handling or the `java.lang.Terminator` exit handlers, provide the option `--install-exit-handlers` option at build time.
53-
54-
### 5. Include All Charsets and Locales
50+
### 4. Include All Charsets and Locales
5551

5652
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.
5753
Pass those options at build time.
5854
This might increase the size of the resulting binary.
5955

60-
### 6. Add Missing Security Providers
56+
### 5. Add Missing Security Providers
6157

6258
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.
6359
Here is a list of all JDK security providers to choose from:
6460
`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`.
6561

66-
### 7. File a Native Image Run-Time Issue
62+
### 6. File a Native Image Run-Time Issue
6763

6864
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.
6965

sdk/mx.sdk/mx_sdk_benchmark.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1468,7 +1468,6 @@ def run_stage_instrument_run(self):
14681468
mx.abort(
14691469
f"Profile file {self.config.profile_path} does not exist "
14701470
f"even though the instrument run terminated successfully with exit code 0. "
1471-
f"Try adding the '--install-exit-handlers' build option if it is not present."
14721471
)
14731472
print(f"Profile file {self.config.profile_path} sha1 is {mx.sha1OfFile(self.config.profile_path)}")
14741473
self._ensureSamplesAreInProfile(self.config.profile_path)

sdk/mx.sdk/mx_sdk_vm_impl.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1423,7 +1423,6 @@ def contents(self):
14231423

14241424
if isinstance(image_config, mx_sdk.LauncherConfig) or (isinstance(image_config, mx_sdk.LanguageLibraryConfig) and image_config.launchers):
14251425
build_args += [
1426-
'--install-exit-handlers',
14271426
'--enable-monitoring=jvmstat,heapdump,jfr,threaddump',
14281427
] + svm_experimental_options([
14291428
'-H:+DumpRuntimeCompilationOnSignal',

sdk/mx.sdk/mx_sdk_vm_ng.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ def get_build_args(self):
353353
build_args += [
354354
'-R:+EnableSignalHandling',
355355
'-R:+InstallSegfaultHandler',
356-
'--install-exit-handlers',
356+
'-H:+InstallJavaExitHandlersForSharedLibrary',
357357
]
358358

359359
# Monitoring flags
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
Args = --enable-url-protocols=http,https \
2-
--install-exit-handlers \
32
--initialize-at-build-time=org.graalvm.maven.downloader.OptionProperties \
43
--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

substratevm/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ This changelog summarizes major changes to GraalVM Native Image.
1616
1. `run-time-initialized-jdk` shifts away from build-time initialization of the JDK, instead initializing most of it at run time. This transition is gradual, with individual components of the JDK becoming run-time initialized in each release. This process should complete with JDK 29 when this option should not be needed anymore. Unless you store classes from the JDK in the image heap, this option should not affect you. In case this option breaks your build, follow the suggestions in the error messages.
1717
* (GR-63494) Recurring callback support is no longer enabled by default. If this feature is needed, please specify `-H:+SupportRecurringCallback` at image build-time.
1818
* (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)
19+
* (GR-64787) Enable `--install-exit-handlers` by default and deprecate the option: Image size increase is negligible (10 new types and 53 new methods), and there is only 2.5% extra startup instructions (68498) for "Hello, World!" on Linux.
1920

2021
## GraalVM for JDK 24 (Internal Version 24.2.0)
2122
* (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.

substratevm/mx.substratevm/mx_substratevm_benchmark.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -352,11 +352,6 @@ def extra_run_arg(self, benchmark, args, image_run_args):
352352
# Added by BaristaNativeImageCommand
353353
return []
354354

355-
def extra_image_build_argument(self, benchmark, args):
356-
return [
357-
"--install-exit-handlers"
358-
] + super().extra_image_build_argument(benchmark, args)
359-
360355
def run(self, benchmarks, bmSuiteArgs) -> mx_benchmark.DataPoints:
361356
self.context = mx_sdk_benchmark.BaristaBenchmarkSuite.RuntimeContext(self, None, benchmarks[0], bmSuiteArgs)
362357
return self.intercept_run(super(), benchmarks, bmSuiteArgs)

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateExitHandlerFeature.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
*/
2525
package com.oracle.svm.core;
2626

27+
import org.graalvm.nativeimage.ImageInfo;
28+
2729
import com.oracle.svm.core.annotate.Alias;
2830
import com.oracle.svm.core.annotate.TargetClass;
2931
import com.oracle.svm.core.feature.AutomaticallyRegisteredFeature;
@@ -34,7 +36,7 @@
3436
public class SubstrateExitHandlerFeature implements InternalFeature {
3537
@Override
3638
public void beforeAnalysis(BeforeAnalysisAccess access) {
37-
if (SubstrateOptions.needsExitHandlers()) {
39+
if (!ImageInfo.isSharedLibrary() || SubstrateOptions.DeprecatedOptions.InstallExitHandlers.getValue() || SubstrateOptions.InstallJavaExitHandlersForSharedLibrary.getValue()) {
3840
RuntimeSupport.getRuntimeSupport().addStartupHook(new SubstrateExitHandlerStartupHook());
3941
}
4042
}
@@ -43,6 +45,9 @@ public void beforeAnalysis(BeforeAnalysisAccess access) {
4345
final class SubstrateExitHandlerStartupHook implements RuntimeSupport.Hook {
4446
@Override
4547
public void execute(boolean isFirstIsolate) {
48+
if (!SubstrateOptions.EnableSignalHandling.getValue()) {
49+
throw new UnsupportedOperationException("java.lang.Terminator can only be set when -XX:+EnableSignalHandling is set");
50+
}
4651
if (isFirstIsolate) {
4752
Target_java_lang_Terminator.setup();
4853
}

0 commit comments

Comments
 (0)