Revert "Introduce a threading module"
This reverts commit 084418bc60fd7480b18e17a9a96e7625d57d5861.
Reason for revert: breaks the build
Change-Id: Iabb79257ee38aebe3d8e9ebc991dae3add7fc2d8
diff --git a/d8_r8/main/build.gradle.kts b/d8_r8/main/build.gradle.kts
index c03fcb8..3aeb083 100644
--- a/d8_r8/main/build.gradle.kts
+++ b/d8_r8/main/build.gradle.kts
@@ -26,7 +26,6 @@
java {
sourceSets.main.configure {
java.srcDir(getRoot().resolveAll("src", "main", "java"))
- resources.srcDirs(getRoot().resolveAll("src", "main", "resources"))
resources.srcDirs(getRoot().resolveAll("third_party", "api_database", "api_database"))
}
sourceCompatibility = JvmCompatibility.sourceCompatibility
@@ -200,7 +199,6 @@
dependsOn(resourceShrinkerJarTask)
dependsOn(gradle.includedBuild("shared").task(":downloadDeps"))
from(sourceSets.main.get().output)
- exclude("com/android/tools/r8/threading/providers/**")
from(keepAnnoJarTask.outputs.files.map(::zipTree))
from(resourceShrinkerJarTask.outputs.files.map(::zipTree))
from(getRoot().resolve("LICENSE"))
@@ -214,27 +212,9 @@
archiveFileName.set("r8-full-exclude-deps.jar")
}
- val threadingModuleBlockingJar by registering(Zip::class) {
- from(sourceSets.main.get().output)
- include("com/android/tools/r8/threading/providers/blocking/**")
- destinationDirectory.set(getRoot().resolveAll("build", "libs"))
- archiveFileName.set("threading-module-blocking.jar")
- }
-
- val threadingModuleSingleThreadedJar by registering(Zip::class) {
- from(sourceSets.main.get().output)
- include("com/android/tools/r8/threading/providers/singlethreaded/**")
- destinationDirectory.set(getRoot().resolveAll("build", "libs"))
- archiveFileName.set("threading-module-singlethreaded.jar")
- }
-
val depsJar by registering(Zip::class) {
dependsOn(gradle.includedBuild("shared").task(":downloadDeps"))
dependsOn(resourceShrinkerDepsTask)
- dependsOn(threadingModuleBlockingJar)
- dependsOn(threadingModuleSingleThreadedJar)
- from(threadingModuleBlockingJar.get().outputs.getFiles().map(::zipTree))
- from(threadingModuleSingleThreadedJar.get().outputs.getFiles().map(::zipTree))
from(mainJarDependencies().map(::zipTree))
from(resourceShrinkerDepsTask.outputs.files.map(::zipTree))
from(consolidatedLicense)
diff --git a/d8_r8/test_modules/tests_java_8/build.gradle.kts b/d8_r8/test_modules/tests_java_8/build.gradle.kts
index 8b0bc68..cb1f81e 100644
--- a/d8_r8/test_modules/tests_java_8/build.gradle.kts
+++ b/d8_r8/test_modules/tests_java_8/build.gradle.kts
@@ -137,13 +137,11 @@
systemProperty(
"R8_RUNTIME_PATH",
mainCompileTask.outputs.files.getAsPath().split(File.pathSeparator)[0] +
- File.pathSeparator + mainDepsJarTask.outputs.files.singleFile +
- File.pathSeparator + getRoot().resolveAll("src", "main", "resources"))
+ File.pathSeparator + mainDepsJarTask.outputs.files.singleFile)
systemProperty(
"RETRACE_RUNTIME_PATH",
mainCompileTask.outputs.files.getAsPath().split(File.pathSeparator)[0] +
- File.pathSeparator + mainDepsJarTask.outputs.files.singleFile +
- File.pathSeparator + getRoot().resolveAll("src", "main", "resources"))
+ File.pathSeparator + mainDepsJarTask.outputs.files.singleFile)
systemProperty("R8_DEPS", mainDepsJarTask.outputs.files.singleFile)
systemProperty("com.android.tools.r8.artprofilerewritingcompletenesscheck", "true")
}
diff --git a/src/main/java/com/android/tools/r8/dex/ApplicationReader.java b/src/main/java/com/android/tools/r8/dex/ApplicationReader.java
index 74a107a..6ccf2e6 100644
--- a/src/main/java/com/android/tools/r8/dex/ApplicationReader.java
+++ b/src/main/java/com/android/tools/r8/dex/ApplicationReader.java
@@ -36,7 +36,6 @@
import com.android.tools.r8.naming.ClassNameMapper;
import com.android.tools.r8.origin.Origin;
import com.android.tools.r8.shaking.MainDexInfo;
-import com.android.tools.r8.threading.TaskCollection;
import com.android.tools.r8.utils.AndroidApiLevel;
import com.android.tools.r8.utils.AndroidApp;
import com.android.tools.r8.utils.ClassProvider;
@@ -48,6 +47,7 @@
import com.android.tools.r8.utils.LibraryClassCollection;
import com.android.tools.r8.utils.MainDexListParser;
import com.android.tools.r8.utils.StringDiagnostic;
+import com.android.tools.r8.utils.ThreadUtils;
import com.android.tools.r8.utils.Timing;
import it.unimi.dsi.fastutil.ints.IntArrayList;
import it.unimi.dsi.fastutil.ints.IntList;
@@ -61,6 +61,7 @@
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
import java.util.stream.Collectors;
public class ApplicationReader {
@@ -128,8 +129,8 @@
timing.begin("DexApplication.read");
final LazyLoadedDexApplication.Builder builder = DexApplication.builder(options, timing);
- TaskCollection<?> tasks = new TaskCollection<>(options, executorService);
try {
+ List<Future<?>> futures = new ArrayList<>();
// Still preload some of the classes, primarily for two reasons:
// (a) class lazy loading is not supported for DEX files
// now and current implementation of parallel DEX file
@@ -137,10 +138,10 @@
// (b) some of the class file resources don't provide information
// about class descriptor.
// TODO: try and preload less classes.
- readProguardMap(proguardMap, builder, tasks);
- ClassReader classReader = new ClassReader(tasks);
+ readProguardMap(proguardMap, builder, executorService, futures);
+ ClassReader classReader = new ClassReader(executorService, futures);
classReader.readSources();
- tasks.await();
+ ThreadUtils.awaitFutures(futures);
flags = classReader.getDexApplicationReadFlags();
builder.setFlags(flags);
classReader.initializeLazyClassCollection(builder);
@@ -267,30 +268,34 @@
}
private void readProguardMap(
- StringResource map, DexApplication.Builder<?> builder, TaskCollection<?> tasks)
- throws ExecutionException {
+ StringResource map,
+ DexApplication.Builder<?> builder,
+ ExecutorService executorService,
+ List<Future<?>> futures) {
// Read the Proguard mapping file in parallel with DexCode and DexProgramClass items.
if (map == null) {
return;
}
- tasks.submit(
- () -> {
- try {
- builder.setProguardMap(
- ClassNameMapper.mapperFromString(
- map.getString(),
- options.reporter,
- options.mappingComposeOptions().allowEmptyMappedRanges,
- options.testing.enableExperimentalMapFileVersion,
- true));
- } catch (IOException | ResourceException e) {
- throw new CompilationError("Failure to read proguard map file", e, map.getOrigin());
- }
- });
+ futures.add(
+ executorService.submit(
+ () -> {
+ try {
+ builder.setProguardMap(
+ ClassNameMapper.mapperFromString(
+ map.getString(),
+ options.reporter,
+ options.mappingComposeOptions().allowEmptyMappedRanges,
+ options.testing.enableExperimentalMapFileVersion,
+ true));
+ } catch (IOException | ResourceException e) {
+ throw new CompilationError("Failure to read proguard map file", e, map.getOrigin());
+ }
+ }));
}
private final class ClassReader {
- private final TaskCollection<?> tasks;
+ private final ExecutorService executorService;
+ private final List<Future<?>> futures;
// We use concurrent queues to collect classes
// since the classes can be collected concurrently.
@@ -310,8 +315,9 @@
private boolean hasReadProgramResourceFromCf = false;
private boolean hasReadProgramResourceFromDex = false;
- ClassReader(TaskCollection<?> tasks) {
- this.tasks = tasks;
+ ClassReader(ExecutorService executorService, List<Future<?>> futures) {
+ this.executorService = executorService;
+ this.futures = futures;
}
public DexApplicationReadFlags getDexApplicationReadFlags() {
@@ -322,7 +328,7 @@
}
private void readDexSources(List<ProgramResource> dexSources, Queue<DexProgramClass> classes)
- throws IOException, ResourceException, ExecutionException {
+ throws IOException, ResourceException {
if (dexSources.isEmpty()) {
return;
}
@@ -361,11 +367,13 @@
ApplicationReaderMap applicationReaderMap = ApplicationReaderMap.getInstance(options);
if (!options.testing.dexContainerExperiment) {
for (DexParser<DexProgramClass> dexParser : dexParsers) {
- tasks.submit(
- () -> {
- dexParser.addClassDefsTo(
- classes::add, applicationReaderMap); // Depends on Methods, Code items etc.
- });
+ futures.add(
+ executorService.submit(
+ () -> {
+ dexParser.addClassDefsTo(
+ classes::add,
+ applicationReaderMap); // Depends on Methods, Code items etc.
+ }));
}
} else {
// All Dex parsers use the same DEX reader, so don't process in parallel.
@@ -422,8 +430,7 @@
}
private void readClassSources(
- List<ProgramResource> classSources, Queue<DexProgramClass> classes)
- throws ExecutionException {
+ List<ProgramResource> classSources, Queue<DexProgramClass> classes) {
if (classSources.isEmpty()) {
return;
}
@@ -440,11 +447,18 @@
PROGRAM);
// Read classes in parallel.
for (ProgramResource input : classSources) {
- tasks.submit(() -> reader.read(input));
+ futures.add(
+ executorService.submit(
+ () -> {
+ reader.read(input);
+ // No other way to have a void callable, but we want the IOException from read
+ // to be wrapped into an ExecutionException.
+ return null;
+ }));
}
}
- void readSources() throws IOException, ResourceException, ExecutionException {
+ void readSources() throws IOException, ResourceException {
Collection<ProgramResource> resources = inputApp.computeAllProgramResources();
List<ProgramResource> dexResources = new ArrayList<>(resources.size());
List<ProgramResource> cfResources = new ArrayList<>(resources.size());
diff --git a/src/main/java/com/android/tools/r8/threading/TaskCollection.java b/src/main/java/com/android/tools/r8/threading/TaskCollection.java
deleted file mode 100644
index 4fcaaaf..0000000
--- a/src/main/java/com/android/tools/r8/threading/TaskCollection.java
+++ /dev/null
@@ -1,43 +0,0 @@
-// Copyright (c) 2023, the R8 project authors. Please see the AUTHORS file
-// for details. All rights reserved. Use of this source code is governed by a
-// BSD-style license that can be found in the LICENSE file.
-
-package com.android.tools.r8.threading;
-
-import com.android.tools.r8.utils.InternalOptions;
-import com.android.tools.r8.utils.ThrowingAction;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.concurrent.Callable;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Future;
-
-public class TaskCollection<T> {
-
- private final ThreadingModule threadingModule;
- private final ExecutorService executorService;
-
- private final List<Future<T>> futures = new ArrayList<>();
-
- public TaskCollection(InternalOptions options, ExecutorService executorService) {
- this.threadingModule = options.getThreadingModule();
- this.executorService = executorService;
- }
-
- public <E extends Exception> void submit(ThrowingAction<E> task) throws ExecutionException {
- submit(
- () -> {
- task.execute();
- return null;
- });
- }
-
- public void submit(Callable<T> task) throws ExecutionException {
- futures.add(threadingModule.submit(task, executorService));
- }
-
- public void await() throws ExecutionException {
- threadingModule.awaitFutures(futures);
- }
-}
diff --git a/src/main/java/com/android/tools/r8/threading/ThreadingModule.java b/src/main/java/com/android/tools/r8/threading/ThreadingModule.java
deleted file mode 100644
index f6bfbc5..0000000
--- a/src/main/java/com/android/tools/r8/threading/ThreadingModule.java
+++ /dev/null
@@ -1,34 +0,0 @@
-// Copyright (c) 2023, the R8 project authors. Please see the AUTHORS file
-// for details. All rights reserved. Use of this source code is governed by a
-// BSD-style license that can be found in the LICENSE file.
-
-package com.android.tools.r8.threading;
-
-import com.android.tools.r8.errors.Unreachable;
-import java.util.Iterator;
-import java.util.List;
-import java.util.ServiceLoader;
-import java.util.concurrent.Callable;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Future;
-
-public interface ThreadingModule {
- <T> Future<T> submit(Callable<T> task, ExecutorService executorService) throws ExecutionException;
-
- <T> void awaitFutures(List<Future<T>> futures) throws ExecutionException;
-
- class Loader {
-
- public static ThreadingModuleProvider load() {
- ServiceLoader<ThreadingModuleProvider> providers =
- ServiceLoader.load(ThreadingModuleProvider.class);
- // Don't use `Optional findFirst()` here as it hits a desugared-library issue.
- Iterator<ThreadingModuleProvider> iterator = providers.iterator();
- if (iterator.hasNext()) {
- return iterator.next();
- }
- throw new Unreachable("Failure to service-load a provider for the threading module");
- }
- }
-}
diff --git a/src/main/java/com/android/tools/r8/threading/ThreadingModuleProvider.java b/src/main/java/com/android/tools/r8/threading/ThreadingModuleProvider.java
deleted file mode 100644
index fccc55b..0000000
--- a/src/main/java/com/android/tools/r8/threading/ThreadingModuleProvider.java
+++ /dev/null
@@ -1,10 +0,0 @@
-// Copyright (c) 2023, the R8 project authors. Please see the AUTHORS file
-// for details. All rights reserved. Use of this source code is governed by a
-// BSD-style license that can be found in the LICENSE file.
-
-package com.android.tools.r8.threading;
-
-public interface ThreadingModuleProvider {
-
- ThreadingModule create();
-}
diff --git a/src/main/java/com/android/tools/r8/threading/providers/blocking/ThreadingModuleBlocking.java b/src/main/java/com/android/tools/r8/threading/providers/blocking/ThreadingModuleBlocking.java
deleted file mode 100644
index 326c946..0000000
--- a/src/main/java/com/android/tools/r8/threading/providers/blocking/ThreadingModuleBlocking.java
+++ /dev/null
@@ -1,44 +0,0 @@
-// Copyright (c) 2023, the R8 project authors. Please see the AUTHORS file
-// for details. All rights reserved. Use of this source code is governed by a
-// BSD-style license that can be found in the LICENSE file.
-
-package com.android.tools.r8.threading.providers.blocking;
-
-import com.android.tools.r8.threading.ThreadingModule;
-import java.util.Iterator;
-import java.util.List;
-import java.util.concurrent.Callable;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Future;
-
-public class ThreadingModuleBlocking implements ThreadingModule {
-
- @Override
- public <T> Future<T> submit(Callable<T> task, ExecutorService executorService) {
- return executorService.submit(task);
- }
-
- @Override
- public <T> void awaitFutures(List<Future<T>> futures) throws ExecutionException {
- Iterator<? extends Future<?>> it = futures.iterator();
- try {
- while (it.hasNext()) {
- it.next().get();
- }
- } catch (InterruptedException e) {
- throw new RuntimeException("Interrupted while waiting for future.", e);
- } finally {
- // In case we get interrupted or one of the threads throws an exception, still wait for all
- // further work to make sure synchronization guarantees are met. Calling cancel unfortunately
- // does not guarantee that the task at hand actually terminates before cancel returns.
- while (it.hasNext()) {
- try {
- it.next().get();
- } catch (Throwable t) {
- // Ignore any new Exception.
- }
- }
- }
- }
-}
diff --git a/src/main/java/com/android/tools/r8/threading/providers/blocking/ThreadingModuleBlockingProvider.java b/src/main/java/com/android/tools/r8/threading/providers/blocking/ThreadingModuleBlockingProvider.java
deleted file mode 100644
index 0c390ee..0000000
--- a/src/main/java/com/android/tools/r8/threading/providers/blocking/ThreadingModuleBlockingProvider.java
+++ /dev/null
@@ -1,16 +0,0 @@
-// Copyright (c) 2023, the R8 project authors. Please see the AUTHORS file
-// for details. All rights reserved. Use of this source code is governed by a
-// BSD-style license that can be found in the LICENSE file.
-
-package com.android.tools.r8.threading.providers.blocking;
-
-import com.android.tools.r8.threading.ThreadingModule;
-import com.android.tools.r8.threading.ThreadingModuleProvider;
-
-public class ThreadingModuleBlockingProvider implements ThreadingModuleProvider {
-
- @Override
- public ThreadingModule create() {
- return new ThreadingModuleBlocking();
- }
-}
diff --git a/src/main/java/com/android/tools/r8/threading/providers/singlethreaded/ThreadingModuleSingleThreadedProvider.java b/src/main/java/com/android/tools/r8/threading/providers/singlethreaded/ThreadingModuleSingleThreadedProvider.java
deleted file mode 100644
index 6174077..0000000
--- a/src/main/java/com/android/tools/r8/threading/providers/singlethreaded/ThreadingModuleSingleThreadedProvider.java
+++ /dev/null
@@ -1,50 +0,0 @@
-// Copyright (c) 2023, the R8 project authors. Please see the AUTHORS file
-// for details. All rights reserved. Use of this source code is governed by a
-// BSD-style license that can be found in the LICENSE file.
-
-package com.android.tools.r8.threading.providers.singlethreaded;
-
-import com.android.tools.r8.threading.ThreadingModule;
-import com.android.tools.r8.threading.ThreadingModuleProvider;
-import com.google.common.util.concurrent.Futures;
-import java.util.List;
-import java.util.concurrent.Callable;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Future;
-
-public class ThreadingModuleSingleThreadedProvider implements ThreadingModuleProvider {
-
- @Override
- public ThreadingModule create() {
- return new ThreadingModuleSingleThreaded();
- }
-
- public static class ThreadingModuleSingleThreaded implements ThreadingModule {
-
- @Override
- public <T> Future<T> submit(Callable<T> task, ExecutorService executorService)
- throws ExecutionException {
- try {
- T value = task.call();
- return Futures.immediateFuture(value);
- } catch (Exception e) {
- throw new ExecutionException(e);
- }
- }
-
- @Override
- public <T> void awaitFutures(List<Future<T>> futures) throws ExecutionException {
- assert allDone(futures);
- }
-
- private <T> boolean allDone(List<Future<T>> futures) {
- for (Future<?> future : futures) {
- if (!future.isDone()) {
- return false;
- }
- }
- return true;
- }
- }
-}
diff --git a/src/main/java/com/android/tools/r8/utils/InternalOptions.java b/src/main/java/com/android/tools/r8/utils/InternalOptions.java
index 1fe0c94..51593eb 100644
--- a/src/main/java/com/android/tools/r8/utils/InternalOptions.java
+++ b/src/main/java/com/android/tools/r8/utils/InternalOptions.java
@@ -102,7 +102,6 @@
import com.android.tools.r8.shaking.GlobalKeepInfoConfiguration;
import com.android.tools.r8.shaking.ProguardConfiguration;
import com.android.tools.r8.shaking.ProguardConfigurationRule;
-import com.android.tools.r8.threading.ThreadingModule;
import com.android.tools.r8.utils.IROrdering.IdentityIROrdering;
import com.android.tools.r8.utils.IROrdering.NondeterministicIROrdering;
import com.android.tools.r8.utils.collections.ProgramMethodSet;
@@ -238,8 +237,6 @@
public List<Consumer<InspectorImpl>> outputInspections = Collections.emptyList();
- private ThreadingModule lazyThreadingModule = null;
-
// Constructor for testing and/or other utilities.
public InternalOptions() {
reporter = new Reporter();
@@ -288,13 +285,6 @@
}
}
- public ThreadingModule getThreadingModule() {
- if (lazyThreadingModule == null) {
- lazyThreadingModule = ThreadingModule.Loader.load().create();
- }
- return lazyThreadingModule;
- }
-
private void keepDebugRelatedInformation() {
assert !proguardConfiguration.isObfuscating();
getProguardConfiguration().getKeepAttributes().sourceFile = true;
@@ -312,6 +302,11 @@
protoShrinking.enableEnumLiteProtoShrinking = true;
}
+ public InternalOptions withModifications(Consumer<InternalOptions> consumer) {
+ consumer.accept(this);
+ return this;
+ }
+
void disableAllOptimizations() {
disableGlobalOptimizations();
enableNameReflectionOptimization = false;
diff --git a/src/main/resources/META-INF/services/com.android.tools.r8.threading.ThreadingModuleProvider b/src/main/resources/META-INF/services/com.android.tools.r8.threading.ThreadingModuleProvider
deleted file mode 100644
index f54c274..0000000
--- a/src/main/resources/META-INF/services/com.android.tools.r8.threading.ThreadingModuleProvider
+++ /dev/null
@@ -1,2 +0,0 @@
-com.android.tools.r8.threading.providers.blocking.ThreadingModuleBlockingProvider
-com.android.tools.r8.threading.providers.singlethreaded.ThreadingModuleSingleThreadedProvider
diff --git a/src/test/bootstrap/com/android/tools/r8/bootstrap/SanityCheck.java b/src/test/bootstrap/com/android/tools/r8/bootstrap/SanityCheck.java
index a30a06f..d44f4c7 100644
--- a/src/test/bootstrap/com/android/tools/r8/bootstrap/SanityCheck.java
+++ b/src/test/bootstrap/com/android/tools/r8/bootstrap/SanityCheck.java
@@ -12,8 +12,6 @@
import static org.junit.Assume.assumeTrue;
import com.android.tools.r8.TestBase;
-import com.android.tools.r8.TestParameters;
-import com.android.tools.r8.TestParametersCollection;
import com.android.tools.r8.ToolHelper;
import com.android.tools.r8.naming.ClassNameMapper;
import com.android.tools.r8.utils.ZipUtils;
@@ -29,30 +27,16 @@
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-import org.junit.runners.Parameterized.Parameters;
-@RunWith(Parameterized.class)
public class SanityCheck extends TestBase {
private static final String SRV_PREFIX = "META-INF/services/";
private static final String METADATA_EXTENSION =
"com.android.tools.r8.jetbrains.kotlinx.metadata.internal.extensions.MetadataExtensions";
private static final String EXT_IN_SRV = SRV_PREFIX + METADATA_EXTENSION;
- private static final String THREADING_MODULE_SERVICE_FILE =
- "META-INF/services/com.android.tools.r8.threading.ThreadingModuleProvider";
- @Parameters
- public static TestParametersCollection data() {
- return TestParameters.builder().withNoneRuntime().build();
- }
-
- public SanityCheck(TestParameters parameters) {
- parameters.assertNoneRuntime();
- }
-
- private void checkJarContent(Path jar, boolean allowDirectories, Predicate<String> entryTester)
+ private void checkJarContent(
+ Path jar, boolean allowDirectories, Predicate<String> entryTester)
throws Exception {
ZipFile zipFile;
try {
@@ -76,8 +60,6 @@
// Allow.
} else if (name.equals("LICENSE")) {
licenseSeen = true;
- } else if (name.equals(THREADING_MODULE_SERVICE_FILE)) {
- // Allow.
} else if (entryTester.test(name)) {
// Allow.
} else if (apiDatabaseFiles.contains(name)) {