From e67dc745763281d0cb562fa7e9d239f5d715d9ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20W=C3=B6gerer?= Date: Tue, 14 Mar 2023 12:25:20 +0100 Subject: [PATCH 1/4] Fix SubstrateOptions.reportsPath for absolute paths --- .../src/com/oracle/svm/core/SubstrateOptions.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) 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 2f4195a73340..38d4af098250 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 @@ -816,14 +816,18 @@ public static final String getHeapDumpPath(String defaultFilename) { public static final RuntimeOptionKey FlightRecorderLogging = new RuntimeOptionKey<>("all=warning", Immutable); public static String reportsPath() { - return Paths.get(Paths.get(Path.getValue()).toString(), ImageSingletons.lookup(ReportingSupport.class).reportsPath).toAbsolutePath().toString(); + Path reportsPath = ImageSingletons.lookup(ReportingSupport.class).reportsPath; + if (reportsPath.isAbsolute()) { + return reportsPath.toString(); + } + return Paths.get(Path.getValue()).resolve(reportsPath).toString(); } public static class ReportingSupport { - String reportsPath; + Path reportsPath; public ReportingSupport(Path reportingPath) { - this.reportsPath = reportingPath.toString(); + this.reportsPath = reportingPath; } } From 9e0de1e582e9c8080470dd32c330427cd750268c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20W=C3=B6gerer?= Date: Tue, 14 Mar 2023 12:26:44 +0100 Subject: [PATCH 2/4] Ensure command line arguments diagnostics respects bundle support --- .../svm/driver/DefaultOptionHandler.java | 2 +- .../com/oracle/svm/driver/NativeImage.java | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/DefaultOptionHandler.java b/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/DefaultOptionHandler.java index 88a4e044893b..876ec0053ee8 100644 --- a/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/DefaultOptionHandler.java +++ b/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/DefaultOptionHandler.java @@ -122,7 +122,7 @@ public boolean consume(ArgumentQueue args) { return true; case "--diagnostics-mode": args.poll(); - nativeImage.setDiagnostics(true); + nativeImage.enableDiagnostics(); nativeImage.addPlainImageBuilderArg("-H:+DiagnosticsMode"); nativeImage.addPlainImageBuilderArg("-H:DiagnosticsDir=" + nativeImage.diagnosticsDir); System.out.println("# Diagnostics mode enabled: image-build reports are saved to " + nativeImage.diagnosticsDir); diff --git a/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/NativeImage.java b/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/NativeImage.java index 1a75f627ddf1..ad683c641ce1 100644 --- a/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/NativeImage.java +++ b/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/NativeImage.java @@ -280,7 +280,7 @@ private static String oR(OptionKey option) { private int verbose = Boolean.valueOf(System.getenv("VERBOSE_GRAALVM_LAUNCHERS")) ? 1 : 0; private boolean diagnostics = false; - String diagnosticsDir; + Path diagnosticsDir; private boolean jarOptionMode = false; private boolean moduleOptionMode = false; private boolean dryRun = false; @@ -1497,7 +1497,8 @@ protected int buildImage(List javaArgs, LinkedHashSet cp, LinkedHa final String commandLine = SubstrateUtil.getShellCommandString(completeCommandList, true); if (isDiagnostics()) { // write to the diagnostics dir - ReportUtils.report("command line arguments", diagnosticsDir, "command-line", "txt", printWriter -> printWriter.write(commandLine)); + Path finalDiagnosticsDir = useBundle() ? bundleSupport.substituteAuxiliaryPath(diagnosticsDir, BundleMember.Role.Output) : diagnosticsDir.toAbsolutePath(); + ReportUtils.report("command line arguments", finalDiagnosticsDir.toString(), "command-line", "txt", printWriter -> printWriter.write(commandLine)); } else { showVerboseMessage(isVerbose(), "Executing ["); showVerboseMessage(isVerbose(), commandLine); @@ -1887,13 +1888,15 @@ void addVerbose() { verbose += 1; } - void setDiagnostics(boolean val) { - diagnostics = val; - diagnosticsDir = Paths.get("reports", ReportUtils.timeStampedFileName("diagnostics", "")).toString(); - if (val) { - addVerbose(); - addVerbose(); + void enableDiagnostics() { + if (diagnostics) { + /* Already enabled */ + return; } + diagnostics = true; + diagnosticsDir = Paths.get("reports", ReportUtils.timeStampedFileName("diagnostics", "")); + addVerbose(); + addVerbose(); } void setJarOptionMode(boolean val) { From a13a9f35a4e4642ef0afb718df2b713bca193f87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20W=C3=B6gerer?= Date: Tue, 14 Mar 2023 12:28:55 +0100 Subject: [PATCH 3/4] Write class initialization configuration diagnostics into same path as other diagnostics --- .../classinitialization/ClassInitializationSupport.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/classinitialization/ClassInitializationSupport.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/classinitialization/ClassInitializationSupport.java index 406be2ad4968..0f01988973bd 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/classinitialization/ClassInitializationSupport.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/classinitialization/ClassInitializationSupport.java @@ -26,7 +26,6 @@ import static com.oracle.svm.core.SubstrateOptions.TraceObjectInstantiation; -import java.nio.file.Paths; import java.util.Comparator; import java.util.List; import java.util.Map; @@ -103,8 +102,7 @@ public void setConfigurationSealed(boolean sealed) { if (configurationSealed && ClassInitializationOptions.PrintClassInitialization.getValue()) { List allConfigs = classInitializationConfiguration.allConfigs(); allConfigs.sort(Comparator.comparing(ClassOrPackageConfig::getName)); - String path = Paths.get(Paths.get(SubstrateOptions.Path.getValue()).toString(), "reports").toAbsolutePath().toString(); - ReportUtils.report("class initialization configuration", path, "class_initialization_configuration", "csv", writer -> { + ReportUtils.report("class initialization configuration", SubstrateOptions.reportsPath(), "class_initialization_configuration", "csv", writer -> { writer.println("Class or Package Name, Initialization Kind, Reasons"); for (ClassOrPackageConfig config : allConfigs) { writer.append(config.getName()).append(", ").append(config.getKind().toString()).append(", ") From c54f51e85e04b98abc6e3cafaa6f1df786690f97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20W=C3=B6gerer?= Date: Tue, 14 Mar 2023 12:30:14 +0100 Subject: [PATCH 4/4] Use `useBundle()` instead of `bundleSupport != null` --- .../com/oracle/svm/driver/DefaultOptionHandler.java | 4 ++-- .../src/com/oracle/svm/driver/NativeImage.java | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/DefaultOptionHandler.java b/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/DefaultOptionHandler.java index 876ec0053ee8..047000bce02f 100644 --- a/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/DefaultOptionHandler.java +++ b/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/DefaultOptionHandler.java @@ -217,7 +217,7 @@ public boolean consume(ArgumentQueue args) { args.poll(); headArg = headArg.substring(1); Path origArgFile = Paths.get(headArg); - Path argFile = nativeImage.bundleSupport != null ? nativeImage.bundleSupport.substituteAuxiliaryPath(origArgFile, BundleMember.Role.Input) : origArgFile; + Path argFile = nativeImage.useBundle() ? nativeImage.bundleSupport.substituteAuxiliaryPath(origArgFile, BundleMember.Role.Input) : origArgFile; NativeImage.NativeImageArgsProcessor processor = nativeImage.new NativeImageArgsProcessor(OptionOrigin.argFilePrefix + argFile); readArgFile(argFile).forEach(processor); List leftoverArgs = processor.apply(false); @@ -458,7 +458,7 @@ private void handleJarFileArg(Path jarFilePath) { String origin = "manifest from " + jarFilePath.toUri(); nativeImage.addPlainImageBuilderArg(NativeImage.injectHostedOptionOrigin(nativeImage.oHName + jarFileNameBase, origin)); } - Path finalFilePath = nativeImage.bundleSupport != null ? nativeImage.bundleSupport.substituteClassPath(jarFilePath) : jarFilePath; + Path finalFilePath = nativeImage.useBundle() ? nativeImage.bundleSupport.substituteClassPath(jarFilePath) : jarFilePath; if (!NativeImage.processJarManifestMainAttributes(finalFilePath, nativeImage::handleMainClassAttribute)) { NativeImage.showError("No manifest in " + finalFilePath); } diff --git a/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/NativeImage.java b/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/NativeImage.java index ad683c641ce1..ff41637ef98a 100644 --- a/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/NativeImage.java +++ b/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/NativeImage.java @@ -776,7 +776,7 @@ protected NativeImage(BuildConfiguration config) { void addMacroOptionRoot(Path configDir) { Path origRootDir = canonicalize(configDir); - Path rootDir = bundleSupport != null ? bundleSupport.substituteClassPath(origRootDir) : origRootDir; + Path rootDir = useBundle() ? bundleSupport.substituteClassPath(origRootDir) : origRootDir; optionRegistry.addMacroOptionRoot(rootDir); } @@ -1671,7 +1671,7 @@ Path canonicalize(Path path) { } Path canonicalize(Path path, boolean strict) { - if (bundleSupport != null) { + if (useBundle()) { Path prev = bundleSupport.restoreCanonicalization(path); if (prev != null) { return prev; @@ -1679,14 +1679,14 @@ Path canonicalize(Path path, boolean strict) { } Path absolutePath = path.isAbsolute() ? path : config.getWorkingDirectory().resolve(path); if (!strict) { - return bundleSupport != null ? bundleSupport.recordCanonicalization(path, absolutePath) : absolutePath; + return useBundle() ? bundleSupport.recordCanonicalization(path, absolutePath) : absolutePath; } try { Path realPath = absolutePath.toRealPath(); if (!Files.isReadable(realPath)) { showError("Path entry " + path + " is not readable"); } - return bundleSupport != null ? bundleSupport.recordCanonicalization(path, realPath) : realPath; + return useBundle() ? bundleSupport.recordCanonicalization(path, realPath) : realPath; } catch (IOException e) { throw showError("Invalid Path entry " + path, e); } @@ -1806,7 +1806,7 @@ void addImageModulePath(Path modulePathEntry, boolean strict) { return; } - Path mpEntryFinal = bundleSupport != null ? bundleSupport.substituteModulePath(mpEntry) : mpEntry; + Path mpEntryFinal = useBundle() ? bundleSupport.substituteModulePath(mpEntry) : mpEntry; imageModulePath.add(mpEntryFinal); processClasspathNativeImageMetaInf(mpEntryFinal); } @@ -1870,7 +1870,7 @@ private void addImageClasspathEntry(LinkedHashSet destination, Path classp return; } - Path classpathEntryFinal = bundleSupport != null ? bundleSupport.substituteClassPath(classpathEntry) : classpathEntry; + Path classpathEntryFinal = useBundle() ? bundleSupport.substituteClassPath(classpathEntry) : classpathEntry; if (!imageClasspath.contains(classpathEntryFinal) && !customImageClasspath.contains(classpathEntryFinal)) { destination.add(classpathEntryFinal); if (ClasspathUtils.isJar(classpathEntryFinal)) {