Add benchmark for legacy desugared library configuration.
Bug: 221381680
Change-Id: I258dec2122e15c617a64761f07b8b81208bfd2f4
diff --git a/.gitignore b/.gitignore
index c97f9a0..7ad6f32 100644
--- a/.gitignore
+++ b/.gitignore
@@ -127,6 +127,8 @@
third_party/openjdk/desugar_jdk_libs.tar.gz
third_party/openjdk/desugar_jdk_libs_11
third_party/openjdk/desugar_jdk_libs_11.tar.gz
+third_party/openjdk/desugar_jdk_libs_legacy
+third_party/openjdk/desugar_jdk_libs_legacy.tar.gz
third_party/openjdk/desugar_jdk_libs_releases/1.0.9
third_party/openjdk/desugar_jdk_libs_releases/1.0.9.tar.gz
third_party/openjdk/desugar_jdk_libs_releases/1.0.10
diff --git a/src/test/java/com/android/tools/r8/ToolHelper.java b/src/test/java/com/android/tools/r8/ToolHelper.java
index 112e1b9..dc4d111 100644
--- a/src/test/java/com/android/tools/r8/ToolHelper.java
+++ b/src/test/java/com/android/tools/r8/ToolHelper.java
@@ -1372,16 +1372,16 @@
BenchmarkResults benchmarkResults)
throws CompilationFailedException {
AndroidAppConsumers compatSink = new AndroidAppConsumers(builder);
+ long start = 0;
+ if (benchmarkResults != null) {
+ start = System.nanoTime();
+ }
D8Command command = builder.build();
InternalOptions options = command.getInternalOptions();
if (optionsConsumer != null) {
ExceptionUtils.withD8CompilationHandler(
options.reporter, () -> optionsConsumer.accept(options));
}
- long start = 0;
- if (benchmarkResults != null) {
- start = System.nanoTime();
- }
D8.runForTesting(command.getInputApp(), options);
if (benchmarkResults != null) {
long end = System.nanoTime();
diff --git a/src/test/java/com/android/tools/r8/benchmarks/BenchmarkCollection.java b/src/test/java/com/android/tools/r8/benchmarks/BenchmarkCollection.java
index da0c335..c741f27 100644
--- a/src/test/java/com/android/tools/r8/benchmarks/BenchmarkCollection.java
+++ b/src/test/java/com/android/tools/r8/benchmarks/BenchmarkCollection.java
@@ -5,6 +5,7 @@
import static java.util.Collections.emptyList;
+import com.android.tools.r8.benchmarks.desugaredlib.LegacyDesugaredLibraryBenchmark;
import com.android.tools.r8.benchmarks.helloworld.HelloWorldBenchmark;
import java.io.IOException;
import java.util.ArrayList;
@@ -43,6 +44,7 @@
BenchmarkCollection collection = new BenchmarkCollection();
// Every benchmark that should be active on golem must be setup in this method.
HelloWorldBenchmark.configs().forEach(collection::addBenchmark);
+ LegacyDesugaredLibraryBenchmark.configs().forEach(collection::addBenchmark);
return collection;
}
diff --git a/src/test/java/com/android/tools/r8/benchmarks/BenchmarkDependency.java b/src/test/java/com/android/tools/r8/benchmarks/BenchmarkDependency.java
index 2bdd4ba..f59ebb6 100644
--- a/src/test/java/com/android/tools/r8/benchmarks/BenchmarkDependency.java
+++ b/src/test/java/com/android/tools/r8/benchmarks/BenchmarkDependency.java
@@ -12,6 +12,10 @@
return new BenchmarkDependency("openjdk-rt-1.8", Paths.get("third_party", "openjdk"));
}
+ public static BenchmarkDependency getAndroidJar30() {
+ return new BenchmarkDependency("lib-v30", Paths.get("third_party", "android_jar"));
+ }
+
// Directory name of the dependency.
private final String directoryName;
diff --git a/src/test/java/com/android/tools/r8/benchmarks/desugaredlib/LegacyDesugaredLibraryBenchmark.java b/src/test/java/com/android/tools/r8/benchmarks/desugaredlib/LegacyDesugaredLibraryBenchmark.java
new file mode 100644
index 0000000..e6d1d00
--- /dev/null
+++ b/src/test/java/com/android/tools/r8/benchmarks/desugaredlib/LegacyDesugaredLibraryBenchmark.java
@@ -0,0 +1,79 @@
+// Copyright (c) 2022, 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.benchmarks.desugaredlib;
+
+import com.android.tools.r8.StringResource;
+import com.android.tools.r8.TestParameters;
+import com.android.tools.r8.benchmarks.BenchmarkBase;
+import com.android.tools.r8.benchmarks.BenchmarkConfig;
+import com.android.tools.r8.benchmarks.BenchmarkDependency;
+import com.android.tools.r8.benchmarks.BenchmarkEnvironment;
+import com.android.tools.r8.benchmarks.BenchmarkTarget;
+import com.android.tools.r8.utils.AndroidApiLevel;
+import com.google.common.collect.ImmutableList;
+import java.nio.file.Paths;
+import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+@RunWith(Parameterized.class)
+public class LegacyDesugaredLibraryBenchmark extends BenchmarkBase {
+
+ private static final BenchmarkDependency androidJar = BenchmarkDependency.getAndroidJar30();
+ private static final BenchmarkDependency legacyConf =
+ new BenchmarkDependency("desugar_jdk_libs_legacy", Paths.get("third_party", "openjdk"));
+
+ public LegacyDesugaredLibraryBenchmark(BenchmarkConfig config, TestParameters parameters) {
+ super(config, parameters);
+ }
+
+ @Parameters(name = "{0}")
+ public static List<Object[]> data() {
+ return parametersFromConfigs(configs());
+ }
+
+ public static List<BenchmarkConfig> configs() {
+ return ImmutableList.of(
+ BenchmarkConfig.builder()
+ .setName("LegacyDesugaredLibraryConf")
+ .setTarget(BenchmarkTarget.D8)
+ .setFromRevision(12150)
+ .setMethod(LegacyDesugaredLibraryBenchmark::run)
+ .addDependency(androidJar)
+ .addDependency(legacyConf)
+ .measureRunTime()
+ .build());
+ }
+
+ public static void run(BenchmarkEnvironment environment) throws Exception {
+ runner(environment.getConfig())
+ .setWarmupIterations(1)
+ .setBenchmarkIterations(10)
+ .reportResultSum()
+ .run(
+ results ->
+ testForD8(environment.getTemp(), Backend.DEX)
+ .setMinApi(AndroidApiLevel.B)
+ .addLibraryFiles(androidJar.getRoot(environment).resolve("android.jar"))
+ .apply(
+ b ->
+ b.getBuilder()
+ .addDesugaredLibraryConfiguration(
+ StringResource.fromFile(
+ legacyConf
+ .getRoot(environment)
+ .resolve("desugar_jdk_libs.json"))))
+ .benchmarkCompile(results));
+ }
+
+ static class TestClass {
+
+ public static void main(String[] args) {
+ System.out.println(Stream.of("Hello", "world!").collect(Collectors.joining(" ")));
+ }
+ }
+}
diff --git a/third_party/openjdk/desugar_jdk_libs_legacy.tar.gz.sha1 b/third_party/openjdk/desugar_jdk_libs_legacy.tar.gz.sha1
new file mode 100644
index 0000000..bcf1956
--- /dev/null
+++ b/third_party/openjdk/desugar_jdk_libs_legacy.tar.gz.sha1
@@ -0,0 +1 @@
+5e0a4ead7e29d87c31f0facb2e7971caff7ac443
\ No newline at end of file