Skip to content

Commit 9f82b63

Browse files
committed
[GR-52314] Make MissingRegistrationReportingMode a runtime option
PullRequest: graal/17086
2 parents 219b3c7 + 30218e4 commit 9f82b63

File tree

4 files changed

+14
-14
lines changed

4 files changed

+14
-14
lines changed

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -468,14 +468,14 @@ The Native Image agent does not support custom implementations of `ResourceBundl
468468

469469
This mode will be made the default behavior of Native Image in a future release. We encourage you to start transitioning your code as soon as possible.
470470
The [Native Image agent](AutomaticMetadataCollection.md) outputs JSON files that conform to both the default and strict modes of operation.
471-
The following options are useful for debugging issues during the transition to the strict mode:
472-
473-
* `-H:ThrowMissingRegistrationErrors=<package list>`: limits `MissingReflectionRegistrationError` to be thrown from a defined list of packages.
474-
This is useful when using some library code that has not been ported to the new mode yet;
475-
* `-H:MissingRegistrationReportingMode`: sets how `MissingReflectionRegistrationError` is reported:
476-
* `Throw` is the default. The error is simply thrown as a Java exception;
477-
* `Warn` outputs a small stack trace for every error encountered, which results in a report of all the places the tested code is going to throw when the strict mode is enabled;
478-
* `Exit` exits the program when encountering the error. This is useful to detect blanket `catch (Throwable t) {` blocks that would otherwise silence the error.
471+
Native Image also provides some useful options for debugging issues during the transition to the strict mode:
472+
473+
* To make sure that the reflection for your image is configured correctly you can add `-H:ThrowMissingRegistrationErrors=` to the native-image build arguments.
474+
If the resulting image fails in libraries that are not under your control, you can add a package prefix to the option to limit the errors to operations called from classes within the specified packages: `-H:ThrowMissingRegistrationErrors=<package-prefix>`.
475+
* The default behavior under `-H:ThrowMissingRegistrationErrors=` is to throw an error, which will potentially end the program execution.
476+
To get an overview of all places in your code where missing registrations occur, including a small stack trace, without committing to the strict behavior you can add `-XX:MissingRegistrationReportingMode=Warn` to the program invocation.
477+
To detect places where the application accidentally swallows a missing registration error (such as with blanket `catch (Throwable t)` blocks), you can add `-XX:MissingRegistrationReportingMode=Exit` to the program invocation.
478+
The application will then unconditionally print the error message and stack trace and exit immediately without throwing.
479479

480480
### Further Reading
481481

substratevm/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ This changelog summarizes major changes to GraalVM Native Image.
1313
* (GR-47712) Using the `--static` option without the `--libc=musl` option causes the build process to fail (and reports the appropriate error). Static linking is currently only supported with musl.
1414
* (GR-50434) Introduce a `"type"` field in reflection and JNI configuration files to support more than simple named types.
1515
* (GR-51053) Use [`vswhere`](https://github.com/microsoft/vswhere) to find Visual Studio installations more reliably and in non-standard installation locations.
16+
* (GR-52314) `-XX:MissingRegistrationReportingMode` can now be used on program invocation instead of as a build option, to avoid a rebuild when debugging missing registration errors.
1617

1718
## GraalVM for JDK 22 (Internal Version 24.0.0)
1819
* (GR-48304) Red Hat added support for the JFR event ThreadAllocationStatistics.

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,10 @@
2424
*/
2525
package com.oracle.svm.core;
2626

27-
import static com.oracle.svm.core.SubstrateOptions.ReportingMode.Warn;
28-
2927
import java.io.Serial;
3028
import java.util.Set;
3129
import java.util.concurrent.ConcurrentHashMap;
30+
import java.util.concurrent.atomic.AtomicReference;
3231

3332
import com.oracle.svm.core.util.ExitStatus;
3433

@@ -46,7 +45,7 @@ public static SubstrateOptions.ReportingMode missingRegistrationReportingMode()
4645

4746
private static final int CONTEXT_LINES = 4;
4847

49-
private static final Set<String> seenOutputs = SubstrateOptions.MissingRegistrationReportingMode.getValue() == Warn ? ConcurrentHashMap.newKeySet() : null;
48+
private static final AtomicReference<Set<String>> seenOutputs = new AtomicReference<>(null);
5049

5150
public static void report(Error exception, StackTraceElement responsibleClass) {
5251
if (responsibleClass != null && !MissingRegistrationSupport.singleton().reportMissingRegistrationErrors(responsibleClass)) {
@@ -93,13 +92,13 @@ public static void report(Error exception, StackTraceElement responsibleClass) {
9392
break;
9493
}
9594
}
96-
if (seenOutputs.isEmpty()) {
95+
if (seenOutputs.get() == null && seenOutputs.compareAndSet(null, ConcurrentHashMap.newKeySet())) {
9796
/* First output, we print an explanation message */
9897
System.out.println("Note: this run will print partial stack traces of the locations where a " + exception.getClass().toString() + " would be thrown " +
9998
"when the -H:+ThrowMissingRegistrationErrors option is set. The trace stops at the first entry of JDK code and provides " + CONTEXT_LINES + " lines of context.");
10099
}
101100
String output = sb.toString();
102-
if (seenOutputs.add(output)) {
101+
if (seenOutputs.get().add(output)) {
103102
System.out.print(output);
104103
}
105104
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1041,7 +1041,7 @@ public enum ReportingMode {
10411041
"\"Throw\" (default): Throw a MissingReflectionRegistrationError;",
10421042
"\"Exit\": Call System.exit() to avoid accidentally catching the error;",
10431043
"\"Warn\": Print a message to stdout, including a stack trace to see what caused the issue."})//
1044-
public static final HostedOptionKey<ReportingMode> MissingRegistrationReportingMode = new HostedOptionKey<>(
1044+
public static final RuntimeOptionKey<ReportingMode> MissingRegistrationReportingMode = new RuntimeOptionKey<>(
10451045
ReportingMode.Throw);
10461046

10471047
@Option(help = "Instead of warning, throw IOExceptions for link-at-build-time resources at build time")//

0 commit comments

Comments
 (0)