diff --git a/java/com/google/turbine/deps/Transitive.java b/java/com/google/turbine/deps/Transitive.java index f224fde4..a2752b92 100644 --- a/java/com/google/turbine/deps/Transitive.java +++ b/java/com/google/turbine/deps/Transitive.java @@ -16,6 +16,7 @@ package com.google.turbine.deps; + import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.turbine.binder.Binder.BindingResult; @@ -32,6 +33,7 @@ import com.google.turbine.bytecode.ClassReader; import com.google.turbine.bytecode.ClassWriter; import com.google.turbine.model.TurbineFlag; +import com.google.turbine.parallel.TurbineExecutor; import java.util.LinkedHashSet; import java.util.Map; import java.util.Set; @@ -45,10 +47,10 @@ public final class Transitive { public static ImmutableMap collectDeps( - ClassPath bootClassPath, BindingResult bound) { - ImmutableMap.Builder transitive = ImmutableMap.builder(); + TurbineExecutor executor, ClassPath bootClassPath, BindingResult bound) { Set closure = superClosure(bound); Dependencies.addPackageInfos(closure, bound); + ImmutableList.Builder toTrim = ImmutableList.builder(); for (ClassSymbol sym : closure) { BytecodeBoundClass info = bound.classPathEnv().get(sym); if (info == null) { @@ -59,12 +61,25 @@ public static ImmutableMap collectDeps( // don't export symbols loaded from the bootclasspath continue; } - transitive.put( - sym.binaryName(), ClassWriter.writeClass(trimClass(info.classFile(), info.jarFile()))); + toTrim.add(info); + } + ImmutableMap.Builder transitive = ImmutableMap.builder(); + for (TrimmedClass trimmed : executor.map(toTrim.build(), Transitive::trim)) { + transitive.put(trimmed.binaryName(), trimmed.bytes()); } return transitive.buildOrThrow(); } + // The array is only carried from the task back to the caller, never compared or hashed. + @SuppressWarnings("ArrayRecordComponent") + private record TrimmedClass(String binaryName, byte[] bytes) {} + + private static TrimmedClass trim(BytecodeBoundClass info) { + return new TrimmedClass( + info.sym().binaryName(), + ClassWriter.writeClass(trimClass(info.classFile(), info.jarFile()))); + } + public static ImmutableMap trimOutput(ImmutableMap lowered) { ImmutableMap.Builder trimmed = ImmutableMap.builder(); for (Map.Entry sym : lowered.entrySet()) { diff --git a/java/com/google/turbine/main/Main.java b/java/com/google/turbine/main/Main.java index 97dd6bf7..4bd63676 100644 --- a/java/com/google/turbine/main/Main.java +++ b/java/com/google/turbine/main/Main.java @@ -235,12 +235,13 @@ private static Result compile(TurbineOptions options, TurbineExecutor executor) ImmutableMap transitive = options.headerCompilationOutput().isPresent() ? ImmutableMap.of() - : Transitive.collectDeps(bootclasspath, bound); + : Transitive.collectDeps(executor, bootclasspath, bound); writeOutput(options, bound.generatedClasses(), lowered.bytes(), transitive); } if (options.headerCompilationOutput().isPresent()) { ImmutableMap trimmed = Transitive.trimOutput(lowered.bytes()); - ImmutableMap transitive = Transitive.collectDeps(bootclasspath, bound); + ImmutableMap transitive = + Transitive.collectDeps(executor, bootclasspath, bound); writeHeaderCompilationOutput(options, trimmed, transitive); } if (options.outputManifest().isPresent()) {