Skip to content

Commit 6979770

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. If shared libraries were using this flag, the same functionality can be restored by using `-H:+InstallJavaExitHandlersForSharedLibrary`.
1 parent e176dc4 commit 6979770

File tree

11 files changed

+28
-44
lines changed

11 files changed

+28
-44
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
@@ -1482,7 +1482,6 @@ def run_stage_instrument_run(self):
14821482
mx.abort(
14831483
f"Profile file {self.config.profile_path} does not exist "
14841484
f"even though the instrument run terminated successfully with exit code 0. "
1485-
f"Try adding the '--install-exit-handlers' build option if it is not present."
14861485
)
14871486
print(f"Profile file {self.config.profile_path} sha1 is {mx.sha1OfFile(self.config.profile_path)}")
14881487
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
@@ -1417,7 +1417,6 @@ def contents(self):
14171417

14181418
if isinstance(image_config, mx_sdk.LauncherConfig) or (isinstance(image_config, mx_sdk.LanguageLibraryConfig) and image_config.launchers):
14191419
build_args += [
1420-
'--install-exit-handlers',
14211420
'--enable-monitoring=jvmstat,heapdump,jfr,threaddump',
14221421
] + svm_experimental_options([
14231422
'-H:+DumpRuntimeCompilationOnSignal',

sdk/mx.sdk/mx_sdk_vm_ng.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -380,19 +380,17 @@ def get_build_args(self):
380380
build_args += [
381381
'-R:+EnableSignalHandling',
382382
'-R:+InstallSegfaultHandler',
383-
'--install-exit-handlers',
384-
]
383+
] + mx_sdk_vm_impl.svm_experimental_options(['-H:+InstallExitHandlers'])
385384

386385
# Monitoring flags
387386
if get_bootstrap_graalvm_version() >= mx.VersionSpec("24.0"):
388387
build_args += ['--enable-monitoring=jvmstat,heapdump,jfr,threaddump']
389388
else:
390389
build_args += ['--enable-monitoring=jvmstat,heapdump,jfr']
391-
build_args += ['-H:+UnlockExperimentalVMOptions', '-H:+DumpThreadStacksOnSignal', '-H:-UnlockExperimentalVMOptions']
392-
build_args += [
393-
'-H:+UnlockExperimentalVMOptions', '-H:+DumpRuntimeCompilationOnSignal', '-H:-UnlockExperimentalVMOptions',
394-
'-R:-UsePerfData', # See GR-25329, reduces startup instructions significantly
395-
]
390+
build_args += mx_sdk_vm_impl.svm_experimental_options(['-H:+DumpThreadStacksOnSignal', '-H:+DumpRuntimeCompilationOnSignal'])
391+
build_args += [
392+
'-R:-UsePerfData', # See GR-25329, reduces startup instructions significantly
393+
]
396394

397395
return build_args
398396

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
@@ -23,6 +23,7 @@ This changelog summarizes major changes to GraalVM Native Image.
2323
* (GR-53985) Add experimental option `ClassForNameRespectsClassLoader` that makes `Class.forName(...)` respect the class loader hierarchy.
2424
* (GR-59869) Implemented initial optimization of Java Vector API (JEP 338) operations in native images. See the compiler changelog for more details.
2525
* (GR-63268) Reflection and JNI queries do not require metadata entries to throw the expected JDK exception when querying a class that doesn't exist under `--exact-reachability-metadata` if the query cannot possibly be a valid class name
26+
* (GR-64787) Enable `--install-exit-handlers` by default for executables and deprecate the option. If shared libraries were using this flag, the same functionality can be restored by using `-H:+InstallJavaExitHandlersForSharedLibrary`.
2627

2728
## GraalVM for JDK 24 (Internal Version 24.2.0)
2829
* (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
@@ -368,11 +368,6 @@ def extra_run_arg(self, benchmark, args, image_run_args):
368368
# Added by BaristaNativeImageCommand
369369
return []
370370

371-
def extra_image_build_argument(self, benchmark, args):
372-
return [
373-
"--install-exit-handlers"
374-
] + super().extra_image_build_argument(benchmark, args)
375-
376371
def run(self, benchmarks, bmSuiteArgs) -> mx_benchmark.DataPoints:
377372
self.context = mx_sdk_benchmark.BaristaBenchmarkSuite.RuntimeContext(self, None, benchmarks[0], bmSuiteArgs)
378373
return self.intercept_run(super(), benchmarks, bmSuiteArgs)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
public class SubstrateExitHandlerFeature implements InternalFeature {
3535
@Override
3636
public void beforeAnalysis(BeforeAnalysisAccess access) {
37-
if (SubstrateOptions.needsExitHandlers()) {
37+
if (SubstrateOptions.InstallExitHandlers.getValue()) {
3838
RuntimeSupport.getRuntimeSupport().addStartupHook(new SubstrateExitHandlerStartupHook());
3939
}
4040
}
@@ -43,7 +43,7 @@ public void beforeAnalysis(BeforeAnalysisAccess access) {
4343
final class SubstrateExitHandlerStartupHook implements RuntimeSupport.Hook {
4444
@Override
4545
public void execute(boolean isFirstIsolate) {
46-
if (isFirstIsolate) {
46+
if (SubstrateOptions.EnableSignalHandling.getValue() && isFirstIsolate) {
4747
Target_java_lang_Terminator.setup();
4848
}
4949
}

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

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,6 +1070,23 @@ private static void validateStripDebugInfo(HostedOptionKey<Boolean> optionKey) {
10701070
@Option(help = "Emit debuginfo debug.svm.imagebuild.* sections with detailed image-build options.")//
10711071
public static final HostedOptionKey<Boolean> UseImagebuildDebugSections = new HostedOptionKey<>(true);
10721072

1073+
@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.")//
1074+
@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)//
1075+
protected static final HostedOptionKey<Boolean> InstallExitHandlers = new HostedOptionKey<>(null) {
1076+
@Override
1077+
public Boolean getValueOrDefault(UnmodifiableEconomicMap<OptionKey<?>, Object> values) {
1078+
if (values.containsKey(this)) {
1079+
return (Boolean) values.get(this);
1080+
}
1081+
return ImageInfo.isExecutable();
1082+
}
1083+
1084+
@Override
1085+
public Boolean getValue(OptionValues values) {
1086+
return getValueOrDefault(values.getMap());
1087+
}
1088+
};
1089+
10731090
@Fold
10741091
public static boolean supportCompileInIsolates() {
10751092
UserError.guarantee(!ConcealedOptions.SupportCompileInIsolates.getValue() || SpawnIsolates.getValue(),
@@ -1141,11 +1158,6 @@ protected void onValueUpdate(EconomicMap<OptionKey<?>, Object> values, Integer o
11411158
@Option(help = "The largest page size of machines that can run the image. The default of 0 automatically selects a typically suitable value.")//
11421159
protected static final HostedOptionKey<Integer> PageSize = new HostedOptionKey<>(0);
11431160

1144-
/** Use {@link SubstrateOptions#needsExitHandlers()} instead. */
1145-
@APIOption(name = "install-exit-handlers")//
1146-
@Option(help = "Provide java.lang.Terminator exit handlers", type = User)//
1147-
protected static final HostedOptionKey<Boolean> InstallExitHandlers = new HostedOptionKey<>(false);
1148-
11491161
@Option(help = "Physical memory size (in bytes). By default, the value is queried from the OS/container during VM startup.", type = OptionType.Expert)//
11501162
public static final RuntimeOptionKey<Long> MaxRAM = new RuntimeOptionKey<>(0L, IsolateCreationOnly);
11511163

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

1173-
@Fold
1174-
public static boolean needsExitHandlers() {
1175-
return ConcealedOptions.InstallExitHandlers.getValue() || VMInspectionOptions.hasJfrSupport() || VMInspectionOptions.hasNativeMemoryTrackingSupport();
1176-
}
1177-
11781185
@Option(help = "Overwrites the available number of processors provided by the OS. Any value <= 0 means using the processor count from the OS.")//
11791186
public static final RuntimeOptionKey<Integer> ActiveProcessorCount = new RuntimeOptionKey<>(-1, IsolateCreationOnly, RelevantForCompilationIsolates);
11801187

0 commit comments

Comments
 (0)