From f768ec8f46bd40aa1d1040787a8d12ad480f41c7 Mon Sep 17 00:00:00 2001 From: Fabio Niephaus Date: Wed, 1 Nov 2023 17:13:14 +0100 Subject: [PATCH 1/4] Avoid `ConcurrentModificationException` in `ProgressReporter`. --- .../oracle/svm/hosted/ProgressReporter.java | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ProgressReporter.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ProgressReporter.java index d36baa66971a..1b62f7048d9f 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ProgressReporter.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ProgressReporter.java @@ -48,14 +48,9 @@ import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.Consumer; import java.util.stream.Collectors; -import jdk.graal.compiler.options.OptionKey; -import jdk.graal.compiler.options.OptionStability; -import jdk.graal.compiler.options.OptionValues; -import jdk.graal.compiler.serviceprovider.GraalServices; import org.graalvm.nativeimage.ImageSingletons; import org.graalvm.nativeimage.hosted.Feature; import org.graalvm.nativeimage.impl.ImageSingletonsSupport; @@ -97,6 +92,11 @@ import com.oracle.svm.hosted.util.VMErrorReporter; import com.oracle.svm.util.ImageBuildStatistics; +import jdk.graal.compiler.options.OptionKey; +import jdk.graal.compiler.options.OptionStability; +import jdk.graal.compiler.options.OptionValues; +import jdk.graal.compiler.serviceprovider.GraalServices; + public class ProgressReporter { private static final boolean IS_CI = SubstrateUtil.isRunningInCI(); private static final int CHARACTERS_PER_LINE; @@ -1079,7 +1079,13 @@ final int getCurrentTextLength() { } final void printLineParts() { - lineParts.forEach(ProgressReporter.this::print); + /* + * This uses a copy of the array to avoid any ConcurrentModificationExceptions in case + * progress is still being printed. + */ + for (String part : lineParts.toArray(new String[0])) { + print(part); + } } void flushln() { @@ -1102,7 +1108,7 @@ abstract class StagePrinter> extends LinePrinter { private BuildStage activeBuildStage = null; private ScheduledFuture periodicPrintingTask; - private AtomicBoolean isCancelled = new AtomicBoolean(); + private boolean isCancelled; T start(BuildStage stage) { assert activeBuildStage == null; @@ -1118,14 +1124,14 @@ T start(BuildStage stage) { } private void startPeriodicProgress() { - isCancelled.set(false); + isCancelled = false; periodicPrintingTask = executor.scheduleAtFixedRate(new Runnable() { int countdown; int numPrints; @Override public void run() { - if (isCancelled.get()) { + if (isCancelled) { return; } if (--countdown < 0) { @@ -1155,7 +1161,7 @@ final void end(Timer timer) { void end(double totalTime) { if (activeBuildStage.hasPeriodicProgress) { - isCancelled.set(true); + isCancelled = true; periodicPrintingTask.cancel(false); } if (activeBuildStage.hasProgressBar) { From 8494137f7402253903ab5cf9626a5454fef2fd21 Mon Sep 17 00:00:00 2001 From: Fabio Niephaus Date: Wed, 1 Nov 2023 17:15:05 +0100 Subject: [PATCH 2/4] Fail early when using `--static` on macOS/Windows. --- .../src/com/oracle/svm/core/SubstrateOptions.java | 7 ++++++- .../com/oracle/svm/hosted/image/CCLinkerInvocation.java | 4 ++-- 2 files changed, 8 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 f06cf70dc159..5a83b207fda5 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 @@ -57,6 +57,7 @@ import com.oracle.svm.core.option.RuntimeOptionKey; import com.oracle.svm.core.option.SubstrateOptionsParser; import com.oracle.svm.core.thread.VMOperationControl; +import com.oracle.svm.core.util.InterruptImageBuilding; import com.oracle.svm.core.util.UserError; import com.oracle.svm.util.LogUtils; import com.oracle.svm.util.ModuleSupport; @@ -112,7 +113,11 @@ public static boolean parseOnce() { @APIOption(name = "static")// @Option(help = "Build statically linked executable (requires static libc and zlib)")// - public static final HostedOptionKey StaticExecutable = new HostedOptionKey<>(false); + public static final HostedOptionKey StaticExecutable = new HostedOptionKey<>(false, key -> { + if (!Platform.includedIn(Platform.LINUX.class)) { + throw new InterruptImageBuilding("Building static executable images is currently only supported on Linux. Remove the '--static' option or build on a Linux machine."); + } + }); @APIOption(name = "libc")// @Option(help = "Selects the libc implementation to use. Available implementations: glibc, musl, bionic")// diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/CCLinkerInvocation.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/CCLinkerInvocation.java index 4b1990d800da..a82937e46912 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/CCLinkerInvocation.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/CCLinkerInvocation.java @@ -45,7 +45,6 @@ import com.oracle.objectfile.macho.MachOSymtab; import com.oracle.svm.core.BuildDirectoryProvider; import com.oracle.svm.core.LinkerInvocation; -import com.oracle.svm.core.OS; import com.oracle.svm.core.SubstrateOptions; import com.oracle.svm.core.c.libc.BionicLibC; import com.oracle.svm.core.c.libc.LibCBase; @@ -451,7 +450,8 @@ String getSymbolName(ObjectFile.Symbol symbol) { protected void setOutputKind(List cmd) { switch (imageKind) { case STATIC_EXECUTABLE: - throw UserError.abort("%s does not support building static executable images.", OS.getCurrent().name()); + // checked in the definition of --static + throw VMError.shouldNotReachHereUnexpectedInput(imageKind); case SHARED_LIBRARY: cmd.add("-shared"); if (Platform.includedIn(Platform.DARWIN.class)) { From f0dac0968b5bd5cb69817096da4f37374ef27b0c Mon Sep 17 00:00:00 2001 From: Fabio Niephaus Date: Wed, 1 Nov 2023 17:15:16 +0100 Subject: [PATCH 3/4] Improve an error message. --- .../src/com/oracle/svm/hosted/image/CCLinkerInvocation.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/CCLinkerInvocation.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/CCLinkerInvocation.java index a82937e46912..4972c17a268b 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/CCLinkerInvocation.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/CCLinkerInvocation.java @@ -584,7 +584,7 @@ static LinkerInvocation getLinkerInvocation(AbstractImage.NativeImageKind imageK } Path outputFile = outputDirectory.resolve(imageName + imageKind.getFilenameSuffix()); - UserError.guarantee(!Files.isDirectory(outputFile), "Cannot write image to %s. Path exists as directory. (Use -H:Name=)", outputFile); + UserError.guarantee(!Files.isDirectory(outputFile), "Cannot write image to %s. Path exists as directory (use '-o /path/to/image').", outputFile); inv.setOutputFile(outputFile); inv.setTempDirectory(tempDirectory); From 4d70a332ebce5a807adda0c1d00969f0fbbb9c8d Mon Sep 17 00:00:00 2001 From: Fabio Niephaus Date: Wed, 1 Nov 2023 17:40:07 +0100 Subject: [PATCH 4/4] Minor cleanups and refactorings. --- .../src/com/oracle/svm/core/util/VMError.java | 4 -- .../com/oracle/svm/driver/NativeImage.java | 66 ++++--------------- .../driver/WindowsBuildEnvironmentUtil.java | 4 +- .../oracle/svm/hosted/ProgressReporter.java | 34 ++++------ .../svm/hosted/ProgressReporterFeature.java | 5 +- .../hosted/ProgressReporterJsonHelper.java | 18 ++--- .../com/oracle/svm/hosted/util/CPUType.java | 2 +- .../svm/hosted/util/CPUTypeAArch64.java | 4 +- .../oracle/svm/hosted/util/CPUTypeAMD64.java | 4 +- 9 files changed, 42 insertions(+), 99 deletions(-) diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/util/VMError.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/util/VMError.java index 2243322cf2ea..19e70d46583f 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/util/VMError.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/util/VMError.java @@ -210,10 +210,6 @@ public static RuntimeException unsupportedFeature(String msg) { throw new HostedError("UNSUPPORTED FEATURE: " + msg); } - public static boolean hostedError(Throwable t) { - return t instanceof HostedError; - } - /** * Processes {@code args} to convert selected values to strings. *
    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 c0727935043d..58dd81ee9a53 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 @@ -333,7 +333,6 @@ protected BuildConfiguration(List args) { this(null, null, args); } - @SuppressWarnings("deprecation") BuildConfiguration(Path rootDir, Path workDir, List args) { try { modulePathBuild = (boolean) isModulePathBuild.invoke(null); @@ -635,16 +634,6 @@ public List getBuildArgs() { public boolean buildFallbackImage() { return false; } - - /** - * ResourcesJar packs resources files needed for some jdk services such as xml - * serialization. - * - * @return the path to the resources.jar file - */ - public Optional getResourcesJar() { - return Optional.of(rootDir.resolve(Paths.get("lib", "resources.jar"))); - } } class DriverMetaInfProcessor implements NativeImageMetaInfResourceProcessor { @@ -669,7 +658,6 @@ public boolean processMetaInfResource(Path classpathEntry, Path resourceRoot, Pa throw showError("Failed to process ForceOnModulePath attribute: Module descriptor for the module " + forceOnModulePath + " could not be resolved with class-path entry: " + classpathEntry + ".", e); } - ignoreClasspathEntry = true; addImageModulePath(classpathEntry, true, false); addAddedModules(forceOnModulePath); ignoreClasspathEntry = true; @@ -683,7 +671,7 @@ public boolean processMetaInfResource(Path classpathEntry, Path resourceRoot, Pa */ String originSuffix = isNativeImagePropertiesFile ? "" : OptionOrigin.isAPISuffix; - NativeImageArgsProcessor args = NativeImage.this.new NativeImageArgsProcessor(resourcePath.toUri().toString() + originSuffix); + NativeImageArgsProcessor args = NativeImage.this.new NativeImageArgsProcessor(resourcePath.toUri() + originSuffix); Path componentDirectory = resourceRoot.relativize(resourcePath).getParent(); Function resolver = str -> { int nameCount = componentDirectory.getNameCount(); @@ -743,17 +731,13 @@ private ArrayList createFallbackBuildArgs() { List runtimeJavaArgs = imageBuilderArgs.stream() .filter(s -> s.startsWith(oRRuntimeJavaArg)) - .collect(Collectors.toList()); - for (String runtimeJavaArg : runtimeJavaArgs) { - buildArgs.add(runtimeJavaArg); - } + .toList(); + buildArgs.addAll(runtimeJavaArgs); List fallbackExecutorJavaArgs = imageBuilderArgs.stream() .filter(s -> s.startsWith(oHFallbackExecutorJavaArg)) - .collect(Collectors.toList()); - for (String fallbackExecutorJavaArg : fallbackExecutorJavaArgs) { - buildArgs.add(fallbackExecutorJavaArg); - } + .toList(); + buildArgs.addAll(fallbackExecutorJavaArgs); buildArgs.add(oHEnabled(SubstrateOptions.UnlockExperimentalVMOptions)); buildArgs.add(oHEnabled(SubstrateOptions.BuildOutputSilent)); @@ -810,11 +794,6 @@ private FallbackBuildConfiguration(NativeImage original) { fallbackBuildArgs = original.createFallbackBuildArgs(); } - @Override - public List getImageClasspath() { - return Collections.emptyList(); - } - @Override public List getBuildArgs() { return fallbackBuildArgs; @@ -932,10 +911,9 @@ private void completeOptionArgs() { consolidateListArgs(imageBuilderJavaArgs, "-Dpolyglot.image-build-time.PreinitializeContexts=", ",", Function.identity()); } - protected static boolean replaceArg(Collection args, String argPrefix, String argSuffix) { - boolean elementsRemoved = args.removeIf(arg -> arg.startsWith(argPrefix)); + protected static void replaceArg(Collection args, String argPrefix, String argSuffix) { + args.removeIf(arg -> arg.startsWith(argPrefix)); args.add(argPrefix + argSuffix); - return elementsRemoved; } private static LinkedHashSet collectListArgs(Collection args, String argPrefix, String delimiter) { @@ -1340,14 +1318,7 @@ private static List getHostedOptionArgumentValues(List ar return values; } - private static final class ArgumentEntry { - private final int index; - private final String value; - - private ArgumentEntry(int index, String value) { - this.index = index; - this.value = value; - } + private record ArgumentEntry(int index, String value) { } private static Boolean getHostedOptionFinalBooleanArgumentValue(List args, OptionKey option) { @@ -1414,8 +1385,6 @@ private static String getAgentOptions(List options, String option } private String targetPlatform = null; - private String targetOS = null; - private String targetArch = null; private void addTargetArguments() { /* @@ -1434,8 +1403,8 @@ private void addTargetArguments() { throw NativeImage.showError("--target argument must be in format -"); } - targetOS = parts[0]; - targetArch = parts[1]; + String targetOS = parts[0]; + String targetArch = parts[1]; if (customJavaArgs.stream().anyMatch(arg -> arg.startsWith("-D" + Platform.PLATFORM_PROPERTY_NAME + "="))) { LogUtils.warning("Usage of -D" + Platform.PLATFORM_PROPERTY_NAME + " might conflict with --target parameter."); @@ -1512,8 +1481,7 @@ protected Path createImageBuilderArgumentFile(List imageBuilderArguments protected int buildImage(List javaArgs, LinkedHashSet cp, LinkedHashSet mp, ArrayList imageArgs, LinkedHashSet imagecp, LinkedHashSet imagemp) { - List arguments = new ArrayList<>(); - arguments.addAll(javaArgs); + List arguments = new ArrayList<>(javaArgs); if (!cp.isEmpty()) { arguments.addAll(Arrays.asList("-cp", cp.stream().map(Path::toString).collect(Collectors.joining(File.pathSeparator)))); @@ -2028,8 +1996,6 @@ void addImageClasspath(Path classpath) { addImageClasspathEntry(imageClasspath, classpath, true); } - LinkedHashSet builderModuleNames = null; - void addImageModulePath(Path modulePathEntry) { addImageModulePath(modulePathEntry, true, true); } @@ -2246,7 +2212,6 @@ void performANSIReset() { @SuppressWarnings("serial") public static final class NativeImageError extends Error { - final int exitCode; private NativeImageError(String message) { @@ -2472,13 +2437,6 @@ protected void deleteAllFiles(Path toDelete) { } } - private static final class ExcludeConfig { - final Pattern jarPattern; - final Pattern resourcePattern; - - private ExcludeConfig(Pattern jarPattern, Pattern resourcePattern) { - this.jarPattern = jarPattern; - this.resourcePattern = resourcePattern; - } + private record ExcludeConfig(Pattern jarPattern, Pattern resourcePattern) { } } diff --git a/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/WindowsBuildEnvironmentUtil.java b/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/WindowsBuildEnvironmentUtil.java index 2f27ea661f7d..97f569d02d95 100644 --- a/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/WindowsBuildEnvironmentUtil.java +++ b/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/WindowsBuildEnvironmentUtil.java @@ -100,13 +100,13 @@ static void propagateEnv(Map environment) { OUTPUT_SEPARATOR, vcVarsAllLocation, OUTPUT_SEPARATOR); Process p = Runtime.getRuntime().exec(new String[]{"cmd.exe", "/c", commandSequence}); try (BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()))) { - String line = null; + String line; while ((line = reader.readLine()) != null) { if (line.startsWith(OUTPUT_SEPARATOR)) { numSeenOutputSeparators++; } else if (numSeenOutputSeparators == 0) { // collect environment variables from 1st `set` invocation - processLineWithKeyValue(line, (key, value) -> originalEnv.put(key, value)); + processLineWithKeyValue(line, originalEnv::put); } else if (numSeenOutputSeparators == 2) { // iterate through updated environment variables from 2nd `set` invocation processLineWithKeyValue(line, (key, value) -> { diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ProgressReporter.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ProgressReporter.java index 1b62f7048d9f..1c2bb3df82e1 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ProgressReporter.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ProgressReporter.java @@ -51,6 +51,7 @@ import java.util.function.Consumer; import java.util.stream.Collectors; +import com.oracle.graal.pointsto.meta.AnalysisType; import org.graalvm.nativeimage.ImageSingletons; import org.graalvm.nativeimage.hosted.Feature; import org.graalvm.nativeimage.impl.ImageSingletonsSupport; @@ -260,7 +261,7 @@ private void printFeatures(List features) { int numFeatures = features.size(); if (numFeatures > 0) { l().a(" ").a(numFeatures).a(" ").doclink("user-specific feature(s)", "#glossary-user-specific-features").a(":").println(); - features.sort((a, b) -> a.getClass().getName().compareTo(b.getClass().getName())); + features.sort(Comparator.comparing(a -> a.getClass().getName())); for (Feature feature : features) { printFeature(l(), feature); } @@ -343,7 +344,7 @@ private void printExperimentalOptions(ImageClassLoader classLoader) { origins = origin.toString(); String valueString; if (hok.getDescriptor().getOptionValueType() == Boolean.class) { - valueString = Boolean.valueOf(value.toString()) ? "+" : "-"; + valueString = Boolean.parseBoolean(value.toString()) ? "+" : "-"; optionPrefix += valueString; } else { valueString = value.toString(); @@ -436,7 +437,7 @@ public void closeAction() { private void printAnalysisStatistics(AnalysisUniverse universe, Collection libraries) { String actualFormat = "%,9d "; String totalFormat = " (%4.1f%% of %,8d total)"; - long reachableTypes = universe.getTypes().stream().filter(t -> t.isReachable()).count(); + long reachableTypes = universe.getTypes().stream().filter(AnalysisType::isReachable).count(); long totalTypes = universe.getTypes().size(); recordJsonMetric(AnalysisResults.TYPES_TOTAL, totalTypes); recordJsonMetric(AnalysisResults.DEPRECATED_CLASS_TOTAL, totalTypes); @@ -445,14 +446,14 @@ private void printAnalysisStatistics(AnalysisUniverse universe, Collection fields = universe.getFields(); - long reachableFields = fields.stream().filter(f -> f.isAccessed()).count(); + long reachableFields = fields.stream().filter(AnalysisField::isAccessed).count(); int totalFields = fields.size(); recordJsonMetric(AnalysisResults.FIELD_TOTAL, totalFields); recordJsonMetric(AnalysisResults.FIELD_REACHABLE, reachableFields); l().a(actualFormat, reachableFields).doclink("reachable fields", "#glossary-reachability").a(" ") .a(totalFormat, Utils.toPercentage(reachableFields, totalFields), totalFields).println(); Collection methods = universe.getMethods(); - long reachableMethods = methods.stream().filter(m -> m.isReachable()).count(); + long reachableMethods = methods.stream().filter(AnalysisMethod::isReachable).count(); int totalMethods = methods.size(); recordJsonMetric(AnalysisResults.METHOD_TOTAL, totalMethods); recordJsonMetric(AnalysisResults.METHOD_REACHABLE, reachableMethods); @@ -617,7 +618,7 @@ private void printBreakdowns() { int numCodeItems = codeBreakdown.size(); int numHeapItems = heapBreakdown.getSortedBreakdownEntries().size(); - long totalCodeBytes = codeBreakdown.values().stream().collect(Collectors.summingLong(Long::longValue)); + long totalCodeBytes = codeBreakdown.values().stream().mapToLong(Long::longValue).sum(); p.l().a(String.format("%9s for %s more packages", ByteFormattingUtil.bytesToHuman(totalCodeBytes - printedCodeBytes), numCodeItems - printedCodeItems)) .jumpToMiddle() @@ -648,7 +649,7 @@ public void printEpilog(Optional optionalImageName, Optional featureHandler = optionalGenerator.isEmpty() ? Optional.empty() : Optional.ofNullable(optionalGenerator.get().featureHandler); + Optional featureHandler = optionalGenerator.map(nativeImageGenerator -> nativeImageGenerator.featureHandler); ReportUtils.report("GraalVM Native Image Error Report", errorReportPath, p -> VMErrorReporter.generateErrorReport(p, buildOutputLog, classLoader, featureHandler, optionalError.get()), false); if (ImageSingletonsSupport.isInstalled()) { @@ -738,9 +739,7 @@ private void printArtifacts(Map> artifacts) { pathToTypes.computeIfAbsent(path, p -> new ArrayList<>()).add(artifactType.name().toLowerCase()); } }); - pathToTypes.forEach((path, typeNames) -> { - l().a(" ").link(path).dim().a(" (").a(String.join(", ", typeNames)).a(")").reset().println(); - }); + pathToTypes.forEach((path, typeNames) -> l().a(" ").link(path).dim().a(" (").a(String.join(", ", typeNames)).a(")").reset().println()); } private Path reportBuildOutput(Path jsonOutputFile) { @@ -862,7 +861,7 @@ private static String truncateClassOrPackageName(String classOrPackageName) { sb.append(rest); } else { int remainingSpaceDivBy2 = (maxLength - sbLength) / 2; - sb.append(rest.substring(0, remainingSpaceDivBy2 - 1) + "~" + rest.substring(restLength - remainingSpaceDivBy2, restLength)); + sb.append(rest, 0, remainingSpaceDivBy2 - 1).append("~").append(rest, restLength - remainingSpaceDivBy2, restLength); } break; } @@ -968,11 +967,6 @@ public final T blueBold() { return getThis(); } - public final T magentaBold() { - colorStrategy.magentaBold(this); - return getThis(); - } - public final T red() { colorStrategy.red(this); return getThis(); @@ -1110,7 +1104,7 @@ abstract class StagePrinter> extends LinePrinter { private ScheduledFuture periodicPrintingTask; private boolean isCancelled; - T start(BuildStage stage) { + void start(BuildStage stage) { assert activeBuildStage == null; activeBuildStage = stage; appendStageStart(); @@ -1120,7 +1114,6 @@ T start(BuildStage stage) { if (activeBuildStage.hasPeriodicProgress) { startPeriodicProgress(); } - return getThis(); } private void startPeriodicProgress() { @@ -1225,10 +1218,9 @@ public CharacterwiseStagePrinter a(String value) { } @Override - CharacterwiseStagePrinter start(BuildStage stage) { + void start(BuildStage stage) { super.start(stage); builderIO.progressReporter = ProgressReporter.this; - return getThis(); } @Override @@ -1352,7 +1344,7 @@ default void reset() { } } - final class ColorlessStrategy implements ColorStrategy { + static final class ColorlessStrategy implements ColorStrategy { } final class ColorfulStrategy implements ColorStrategy { diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ProgressReporterFeature.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ProgressReporterFeature.java index 56bcd223ace1..925305d97d40 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ProgressReporterFeature.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ProgressReporterFeature.java @@ -124,13 +124,10 @@ private static boolean recommendTraceAgentForAWT() { } public record UserRecommendation(String id, String description, Supplier isApplicable) { - public UserRecommendation(String id, String description, Supplier isApplicable) { + public UserRecommendation { assert id.toUpperCase().equals(id) && id.length() < 5 : "id must be uppercase and have fewer than 5 chars"; int maxLength = 74; assert description.length() < maxLength : "description must have fewer than " + maxLength + " chars to fit in terminal. Length: " + description.length(); - this.id = id; - this.description = description; - this.isApplicable = isApplicable; } } } diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ProgressReporterJsonHelper.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ProgressReporterJsonHelper.java index 48af0374e7da..b3883522ed6d 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ProgressReporterJsonHelper.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ProgressReporterJsonHelper.java @@ -108,9 +108,9 @@ enum ImageDetailKey implements JsonMetric { RUNTIME_COMPILED_METHODS_COUNT("runtime_compiled_methods", null, "count"), GRAPH_ENCODING_SIZE("runtime_compiled_methods", null, "graph_encoding_bytes"); - private String bucket; - private String jsonKey; - private String subBucket; + private final String bucket; + private final String jsonKey; + private final String subBucket; ImageDetailKey(String bucket, String subBucket, String key) { this.bucket = bucket; @@ -135,8 +135,8 @@ enum ResourceUsageKey implements JsonMetric { MEMORY_TOTAL("memory", "system_total"), TOTAL_SECS(null, "total_secs"); - private String bucket; - private String jsonKey; + private final String bucket; + private final String jsonKey; ResourceUsageKey(String bucket, String key) { this.bucket = bucket; @@ -170,8 +170,8 @@ public enum AnalysisResults implements JsonMetric { DEPRECATED_CLASS_JNI("classes", "jni"), DEPRECATED_CLASS_REFLECT("classes", "reflection"); - private String key; - private String bucket; + private final String key; + private final String bucket; AnalysisResults(String bucket, String key) { this.key = key; @@ -209,8 +209,8 @@ public enum GeneralInfo implements JsonMetric { GC("garbage_collector", null), CC("c_compiler", null); - private String key; - private String bucket; + private final String key; + private final String bucket; GeneralInfo(String key, String bucket) { this.key = key; diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/util/CPUType.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/util/CPUType.java index 9901a92390f6..149ee01b8990 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/util/CPUType.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/util/CPUType.java @@ -53,7 +53,7 @@ static void printList() { } private static void print(String name, CPUType[] values) { - Arrays.sort(values, Comparator.comparing(v -> v.getName())); + Arrays.sort(values, Comparator.comparing(CPUType::getName)); System.out.printf("On %s, the following machine types are available:%n%n", name); for (CPUType m : values) { String specificFeatures = m.getSpecificFeaturesString(); diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/util/CPUTypeAArch64.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/util/CPUTypeAArch64.java index 9a8db1933beb..a32ab66e440f 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/util/CPUTypeAArch64.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/util/CPUTypeAArch64.java @@ -87,7 +87,7 @@ private static CPUFeature[] getNativeOrEmpty() { name = cpuTypeName; parent = cpuTypeParentOrNull; specificFeatures = features.length > 0 ? EnumSet.copyOf(List.of(features)) : EnumSet.noneOf(CPUFeature.class); - assert parent == null || parent.getFeatures().stream().noneMatch(f -> specificFeatures.contains(f)) : "duplicate features detected but not allowed"; + assert parent == null || parent.getFeatures().stream().noneMatch(specificFeatures::contains) : "duplicate features detected but not allowed"; } @Override @@ -102,7 +102,7 @@ public CPUTypeAArch64 getParent() { @Override public String getSpecificFeaturesString() { - return specificFeatures.stream().map(f -> f.name()).collect(Collectors.joining(" + ")); + return specificFeatures.stream().map(Enum::name).collect(Collectors.joining(" + ")); } public EnumSet getFeatures() { diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/util/CPUTypeAMD64.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/util/CPUTypeAMD64.java index 00fea87390ca..0dd5f1f9efc1 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/util/CPUTypeAMD64.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/util/CPUTypeAMD64.java @@ -124,7 +124,7 @@ private static CPUFeature[] getNativeOrEmpty() { name = cpuTypeName; parent = cpuTypeParent; specificFeatures = features.length > 0 ? EnumSet.copyOf(List.of(features)) : EnumSet.noneOf(CPUFeature.class); - assert parent == null || parent.getFeatures().stream().noneMatch(f -> specificFeatures.contains(f)) : "duplicate features detected but not allowed"; + assert parent == null || parent.getFeatures().stream().noneMatch(specificFeatures::contains) : "duplicate features detected but not allowed"; } @Override @@ -139,7 +139,7 @@ public CPUTypeAMD64 getParent() { @Override public String getSpecificFeaturesString() { - return specificFeatures.stream().map(f -> f.name()).collect(Collectors.joining(" + ")); + return specificFeatures.stream().map(Enum::name).collect(Collectors.joining(" + ")); } public EnumSet getFeatures() {