From 8fe7df1a36e2894bb7e4ea7d78e50a39e8f57bf9 Mon Sep 17 00:00:00 2001 From: Loic Ottet Date: Tue, 24 Sep 2024 14:18:28 +0200 Subject: [PATCH] Make missing registration warn mode stack trace length customizable --- substratevm/CHANGELOG.md | 1 + .../src/com/oracle/svm/core/MissingRegistrationUtils.java | 7 +++---- .../src/com/oracle/svm/core/SubstrateOptions.java | 3 +++ 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/substratevm/CHANGELOG.md b/substratevm/CHANGELOG.md index 2e6c38525543..26a49359177a 100644 --- a/substratevm/CHANGELOG.md +++ b/substratevm/CHANGELOG.md @@ -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. diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/MissingRegistrationUtils.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/MissingRegistrationUtils.java index a6a4977952c2..e6d574509d2d 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/MissingRegistrationUtils.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/MissingRegistrationUtils.java @@ -43,8 +43,6 @@ public static SubstrateOptions.ReportingMode missingRegistrationReportingMode() return SubstrateOptions.MissingRegistrationReportingMode.getValue(); } - private static final int CONTEXT_LINES = 4; - private static final AtomicReference> seenOutputs = new AtomicReference<>(null); public static void report(Error exception, StackTraceElement responsibleClass) { @@ -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)) { diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateOptions.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateOptions.java index 1ca7cbc4f6f1..ce0885c9a1f6 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateOptions.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateOptions.java @@ -1249,6 +1249,9 @@ public enum ReportingMode { public static final RuntimeOptionKey MissingRegistrationReportingMode = new RuntimeOptionKey<>( ReportingMode.Throw); + @Option(help = "Number of context lines printed for each missing registration error in Warn mode")// + public static final RuntimeOptionKey MissingRegistrationWarnContextLines = new RuntimeOptionKey<>(8); + @Option(help = "Instead of warning, throw IOExceptions for link-at-build-time resources at build time")// public static final HostedOptionKey ThrowLinkAtBuildTimeIOExceptions = new HostedOptionKey<>(false);