Skip to content

Commit

Permalink
[GR-58383] Make missing registration warn mode stack trace length cus…
Browse files Browse the repository at this point in the history
…tomizable

PullRequest: graal/18880
  • Loading branch information
loicottet committed Oct 7, 2024
2 parents 6da8560 + 8fe7df1 commit 7d5509a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
1 change: 1 addition & 0 deletions substratevm/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ At runtime, premain runtime options are set along with main class' arguments in
* (GR-49517) Add support for emitting Windows x64 unwind info. This enables stack walking in native tooling such as debuggers and profilers.
* (GR-57384) Preserve the origin of a resource included in a native image. The information is included in the report produced by -H:+GenerateEmbeddedResourcesFile.
* (GR-58000) Support for `GetStringUTFLengthAsLong` added in JNI_VERSION_24 ([JDK-8328877](https://bugs.openjdk.org/browse/JDK-8328877))
* (GR-58383) The length of the printed stack trace when using `-XX:MissingRegistrationReportingMode=Warn` can now be set with `-XX:MissingRegistrationWarnContextLines=` and its default length is now 8.

## GraalVM for JDK 23 (Internal Version 24.1.0)
* (GR-51520) The old class initialization strategy, which was deprecated in GraalVM for JDK 22, is removed. The option `StrictImageHeap` no longer has any effect.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ public static SubstrateOptions.ReportingMode missingRegistrationReportingMode()
return SubstrateOptions.MissingRegistrationReportingMode.getValue();
}

private static final int CONTEXT_LINES = 4;

private static final AtomicReference<Set<String>> seenOutputs = new AtomicReference<>(null);

public static void report(Error exception, StackTraceElement responsibleClass) {
Expand Down Expand Up @@ -88,14 +86,15 @@ public static void report(Error exception, StackTraceElement responsibleClass) {
printLine(sb, stackTraceElement);
printed++;
}
if (printed >= CONTEXT_LINES) {
if (printed >= SubstrateOptions.MissingRegistrationWarnContextLines.getValue()) {
break;
}
}
if (seenOutputs.get() == null && seenOutputs.compareAndSet(null, ConcurrentHashMap.newKeySet())) {
/* First output, we print an explanation message */
System.out.println("Note: this run will print partial stack traces of the locations where a " + exception.getClass().toString() + " would be thrown " +
"when the -H:+ThrowMissingRegistrationErrors option is set. The trace stops at the first entry of JDK code and provides " + CONTEXT_LINES + " lines of context.");
"when the -H:+ThrowMissingRegistrationErrors option is set. The trace stops at the first entry of JDK code and provides " +
SubstrateOptions.MissingRegistrationWarnContextLines.getValue() + " lines of context.");
}
String output = sb.toString();
if (seenOutputs.get().add(output)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1249,6 +1249,9 @@ public enum ReportingMode {
public static final RuntimeOptionKey<ReportingMode> MissingRegistrationReportingMode = new RuntimeOptionKey<>(
ReportingMode.Throw);

@Option(help = "Number of context lines printed for each missing registration error in Warn mode")//
public static final RuntimeOptionKey<Integer> MissingRegistrationWarnContextLines = new RuntimeOptionKey<>(8);

@Option(help = "Instead of warning, throw IOExceptions for link-at-build-time resources at build time")//
public static final HostedOptionKey<Boolean> ThrowLinkAtBuildTimeIOExceptions = new HostedOptionKey<>(false);

Expand Down

0 comments on commit 7d5509a

Please sign in to comment.