Cleanup existing builder inlining tests
Change-Id: Iec56f47c65dcd4ba02409b4078811c5d5dd777c2
diff --git a/src/test/java/com/android/tools/r8/ir/optimize/classinliner/ClassInlinerBuilderWithControlFlowTest.java b/src/test/java/com/android/tools/r8/ir/optimize/classinliner/ClassInlinerBuilderWithControlFlowTest.java
new file mode 100644
index 0000000..44db913
--- /dev/null
+++ b/src/test/java/com/android/tools/r8/ir/optimize/classinliner/ClassInlinerBuilderWithControlFlowTest.java
@@ -0,0 +1,139 @@
+// Copyright (c) 2019, 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.ir.optimize.classinliner;
+
+import static com.android.tools.r8.utils.codeinspector.Matchers.isPresent;
+import static org.hamcrest.CoreMatchers.not;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertEquals;
+
+import com.android.tools.r8.TestParameters;
+import com.android.tools.r8.TestParametersCollection;
+import com.android.tools.r8.utils.StringUtils;
+import com.android.tools.r8.utils.codeinspector.ClassSubject;
+import com.android.tools.r8.utils.codeinspector.CodeInspector;
+import java.util.Collections;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+@RunWith(Parameterized.class)
+public class ClassInlinerBuilderWithControlFlowTest extends ClassInlinerTestBase {
+
+ private static final String EXPECTED =
+ StringUtils.lines(
+ "flow = >0>0>-1>1234>1236>7>3>1240>1266>6>1248>3798>8>1254>10>1264>8885>12>1273>19063>14>"
+ + "16>1288>39449>18>1301>80229>20>1315>161806>23>1335>324994>25>1353>651383>27>1372>1"
+ + "304183>29>1392>2609806>32>1418>5221092>34>1442>10443683>36>1467>20888893>38>1493>4"
+ + "1779342>40>1520>42>1551>83560313>44>1581>167122280>46>1612>334246248>48>1644>66849"
+ + "4219>50>1677>1336990197>52>54>1716>-1620985089>56>1753>1052998963>58>1791>21059998"
+ + "12>60>1830>-82965744>62>1870>-165929517>64>1911>-331857019>");
+
+ private final TestParameters parameters;
+
+ @Parameterized.Parameters(name = "{0}")
+ public static TestParametersCollection data() {
+ return getTestParameters().withAllRuntimesAndApiLevels().build();
+ }
+
+ public ClassInlinerBuilderWithControlFlowTest(TestParameters parameters) {
+ this.parameters = parameters;
+ }
+
+ @Test
+ public void testR8() throws Exception {
+ testForR8(parameters.getBackend())
+ .addInnerClasses(ClassInlinerBuilderWithControlFlowTest.class)
+ .addKeepMainRule(TestClass.class)
+ .noMinification()
+ .setMinApi(parameters.getApiLevel())
+ .compile()
+ .inspect(this::inspect)
+ .run(parameters.getRuntime(), TestClass.class)
+ .assertSuccessWithOutput(EXPECTED);
+ }
+
+ @Test
+ public void testExpectedBehavior() throws Exception {
+ testForRuntime(parameters)
+ .addInnerClasses(ClassInlinerBuilderWithControlFlowTest.class)
+ .run(parameters.getRuntime(), TestClass.class)
+ .assertSuccessWithOutput(EXPECTED);
+ }
+
+ private void inspect(CodeInspector inspector) {
+ ClassSubject clazz = inspector.clazz(TestClass.class);
+
+ assertEquals(
+ Collections.singleton(StringBuilder.class.getTypeName()), collectTypes(clazz.mainMethod()));
+
+ assertThat(inspector.clazz(ControlFlow.class), not(isPresent()));
+ }
+
+ static class TestClass {
+
+ public static void main(String[] args) {
+ ControlFlow flow = new ControlFlow(-1, 2, 7);
+ for (int k = 0; k < 25; k++) {
+ if (k % 3 == 0) {
+ flow.foo(k);
+ } else if (k % 3 == 1) {
+ flow.bar(1, 2, 3, 4);
+ }
+ }
+ System.out.println("flow = " + flow.toString());
+ }
+ }
+
+ static class ControlFlow {
+
+ int a;
+ int b;
+ int c = 1234;
+ int d;
+ String s = ">";
+
+ ControlFlow(int b, int c, int d) {
+ this.s += this.a++ + ">";
+ this.s += this.b + ">";
+ this.b = b;
+ this.s += this.b + ">";
+ this.s += this.c + ">";
+ this.c += c;
+ this.s += this.c + ">";
+ this.s += (this.d = d) + ">";
+ }
+
+ void foo(int count) {
+ for (int i = 0; i < count; i++) {
+ switch (i % 4) {
+ case 0:
+ this.s += ++this.a + ">";
+ break;
+ case 1:
+ this.c += this.b;
+ this.s += this.c + ">";
+ break;
+ case 2:
+ this.d += this.d++ + this.c++ + this.b++ + this.a++;
+ this.s += this.d + ">";
+ break;
+ }
+ }
+ }
+
+ void bar(int a, int b, int c, int d) {
+ this.a += a;
+ this.b += b;
+ this.c += c;
+ this.d += d;
+ }
+
+ @Override
+ public String toString() {
+ return s;
+ }
+ }
+}
diff --git a/src/test/java/com/android/tools/r8/ir/optimize/classinliner/ClassInlinerBuilderWithMoreControlFlowTest.java b/src/test/java/com/android/tools/r8/ir/optimize/classinliner/ClassInlinerBuilderWithMoreControlFlowTest.java
new file mode 100644
index 0000000..3778db4
--- /dev/null
+++ b/src/test/java/com/android/tools/r8/ir/optimize/classinliner/ClassInlinerBuilderWithMoreControlFlowTest.java
@@ -0,0 +1,98 @@
+// Copyright (c) 2019, 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.ir.optimize.classinliner;
+
+import static com.android.tools.r8.utils.codeinspector.Matchers.isPresent;
+import static org.hamcrest.CoreMatchers.not;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertEquals;
+
+import com.android.tools.r8.TestParameters;
+import com.android.tools.r8.TestParametersCollection;
+import com.android.tools.r8.utils.StringUtils;
+import com.android.tools.r8.utils.codeinspector.ClassSubject;
+import com.android.tools.r8.utils.codeinspector.CodeInspector;
+import java.util.Collections;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+@RunWith(Parameterized.class)
+public class ClassInlinerBuilderWithMoreControlFlowTest extends ClassInlinerTestBase {
+
+ private static final String EXPECTED = StringUtils.lines("Pos(x=0, y=10)");
+
+ private final TestParameters parameters;
+
+ @Parameterized.Parameters(name = "{0}")
+ public static TestParametersCollection data() {
+ return getTestParameters().withAllRuntimesAndApiLevels().build();
+ }
+
+ public ClassInlinerBuilderWithMoreControlFlowTest(TestParameters parameters) {
+ this.parameters = parameters;
+ }
+
+ @Test
+ public void testR8() throws Exception {
+ testForR8(parameters.getBackend())
+ .addInnerClasses(ClassInlinerBuilderWithMoreControlFlowTest.class)
+ .addKeepMainRule(TestClass.class)
+ .noMinification()
+ .setMinApi(parameters.getApiLevel())
+ .compile()
+ .inspect(this::inspect)
+ .run(parameters.getRuntime(), TestClass.class)
+ .assertSuccessWithOutput(EXPECTED);
+ }
+
+ @Test
+ public void testExpectedBehavior() throws Exception {
+ testForRuntime(parameters)
+ .addInnerClasses(ClassInlinerBuilderWithMoreControlFlowTest.class)
+ .run(parameters.getRuntime(), TestClass.class)
+ .assertSuccessWithOutput(EXPECTED);
+ }
+
+ private void inspect(CodeInspector inspector) {
+ ClassSubject clazz = inspector.clazz(TestClass.class);
+
+ assertEquals(
+ Collections.singleton(StringBuilder.class.getTypeName()), collectTypes(clazz.mainMethod()));
+
+ assertThat(inspector.clazz(Pos.class), not(isPresent()));
+ }
+
+ static class TestClass {
+
+ public static void main(String[] args) {
+ String str = "1234567890";
+ Pos pos = new Pos();
+ while (pos.y < str.length()) {
+ pos.x = pos.y;
+ pos.y = pos.x;
+
+ if (str.charAt(pos.x) != '*') {
+ if ('0' <= str.charAt(pos.y) && str.charAt(pos.y) <= '9') {
+ while (pos.y < str.length() && '0' <= str.charAt(pos.y) && str.charAt(pos.y) <= '9') {
+ pos.y++;
+ }
+ }
+ }
+ }
+ System.out.println(pos.myToString());
+ }
+ }
+
+ static class Pos {
+
+ int x = 0;
+ int y = 0;
+
+ String myToString() {
+ return "Pos(x=" + x + ", y=" + y + ")";
+ }
+ }
+}
diff --git a/src/test/java/com/android/tools/r8/ir/optimize/classinliner/ClassInlinerSimplePairBuilderTest.java b/src/test/java/com/android/tools/r8/ir/optimize/classinliner/ClassInlinerSimplePairBuilderTest.java
new file mode 100644
index 0000000..f751e25
--- /dev/null
+++ b/src/test/java/com/android/tools/r8/ir/optimize/classinliner/ClassInlinerSimplePairBuilderTest.java
@@ -0,0 +1,164 @@
+// Copyright (c) 2019, 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.ir.optimize.classinliner;
+
+import static com.android.tools.r8.utils.codeinspector.Matchers.isPresent;
+import static org.hamcrest.CoreMatchers.not;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertEquals;
+
+import com.android.tools.r8.NeverInline;
+import com.android.tools.r8.TestParameters;
+import com.android.tools.r8.TestParametersCollection;
+import com.android.tools.r8.utils.StringUtils;
+import com.android.tools.r8.utils.codeinspector.ClassSubject;
+import com.android.tools.r8.utils.codeinspector.CodeInspector;
+import com.google.common.collect.ImmutableSet;
+import java.util.Set;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+@RunWith(Parameterized.class)
+public class ClassInlinerSimplePairBuilderTest extends ClassInlinerTestBase {
+
+ private static final String EXPECTED =
+ StringUtils.lines(
+ "[before] first = null",
+ "[after] first = f1",
+ "Pair(f1, <null>)",
+ "[before] second = null",
+ "[after] second = s2",
+ "Pair(<null>, s2)",
+ "[before] first = null",
+ "[after] first = f3",
+ "[before] second = null",
+ "[after] second = s4",
+ "Pair(f3, s4)");
+
+ private final TestParameters parameters;
+
+ @Parameterized.Parameters(name = "{0}")
+ public static TestParametersCollection data() {
+ return getTestParameters().withAllRuntimesAndApiLevels().build();
+ }
+
+ public ClassInlinerSimplePairBuilderTest(TestParameters parameters) {
+ this.parameters = parameters;
+ }
+
+ @Test
+ public void testR8() throws Exception {
+ testForR8(parameters.getBackend())
+ .addInnerClasses(ClassInlinerSimplePairBuilderTest.class)
+ .addKeepMainRule(TestClass.class)
+ // TODO(b/143129517): This relies on PairBuilder::build being inlined, thus the limit of 6.
+ .addOptionsModification(options -> options.inliningInstructionLimit = 6)
+ .enableInliningAnnotations()
+ .noMinification()
+ .setMinApi(parameters.getApiLevel())
+ .compile()
+ .inspect(this::inspect)
+ .run(parameters.getRuntime(), TestClass.class)
+ .assertSuccessWithOutput(EXPECTED);
+ }
+
+ @Test
+ public void testExpectedBehavior() throws Exception {
+ testForRuntime(parameters)
+ .addInnerClasses(ClassInlinerSimplePairBuilderTest.class)
+ .run(parameters.getRuntime(), TestClass.class)
+ .assertSuccessWithOutput(EXPECTED);
+ }
+
+ private void inspect(CodeInspector inspector) {
+ ClassSubject clazz = inspector.clazz(TestClass.class);
+ if (parameters.isCfRuntime()) {
+ assertThat(inspector.clazz(PairBuilder.class), isPresent());
+
+ // const-string canonicalization is disabled in CF, which helps ClassInliner identify
+ // PairBuilder as candidate.
+ Set<String> expected =
+ ImmutableSet.of(StringBuilder.class.getTypeName(), PairBuilder.class.getTypeName());
+ assertEquals(expected, collectTypes(clazz.uniqueMethodWithName("testSimpleBuilder1")));
+ assertEquals(expected, collectTypes(clazz.uniqueMethodWithName("testSimpleBuilder2")));
+ assertEquals(expected, collectTypes(clazz.uniqueMethodWithName("testSimpleBuilder3")));
+ } else {
+ assertThat(inspector.clazz(PairBuilder.class), not(isPresent()));
+
+ Set<String> expected = ImmutableSet.of(StringBuilder.class.getTypeName());
+ assertEquals(expected, collectTypes(clazz.uniqueMethodWithName("testSimpleBuilder1")));
+ assertEquals(expected, collectTypes(clazz.uniqueMethodWithName("testSimpleBuilder2")));
+ assertEquals(expected, collectTypes(clazz.uniqueMethodWithName("testSimpleBuilder3")));
+ }
+ }
+
+ static class TestClass {
+
+ public static void main(String[] args) {
+ testSimpleBuilder1();
+ testSimpleBuilder2();
+ testSimpleBuilder3();
+ }
+
+ @NeverInline
+ static void testSimpleBuilder1() {
+ System.out.println(new PairBuilder<String, String>().setFirst("f1").build().myToString());
+ }
+
+ @NeverInline
+ static void testSimpleBuilder2() {
+ System.out.println(new PairBuilder<String, String>().setSecond("s2").build().myToString());
+ }
+
+ @NeverInline
+ static void testSimpleBuilder3() {
+ System.out.println(
+ new PairBuilder<String, String>().setFirst("f3").setSecond("s4").build().myToString());
+ }
+ }
+
+ static class Pair<F, S> {
+ final F first;
+ final S second;
+
+ Pair(F first, S second) {
+ this.first = first;
+ this.second = second;
+ }
+
+ String myToString() {
+ return "Pair("
+ + (first == null ? "<null>" : first)
+ + ", "
+ + (second == null ? "<null>" : second)
+ + ")";
+ }
+ }
+
+ static class PairBuilder<F, S> {
+
+ F first;
+ S second = null;
+
+ PairBuilder<F, S> setFirst(F first) {
+ System.out.println("[before] first = " + this.first);
+ this.first = first;
+ System.out.println("[after] first = " + this.first);
+ return this;
+ }
+
+ PairBuilder<F, S> setSecond(S second) {
+ System.out.println("[before] second = " + this.second);
+ this.second = second;
+ System.out.println("[after] second = " + this.second);
+ return this;
+ }
+
+ public Pair<F, S> build() {
+ return new Pair<>(first, second);
+ }
+ }
+}
diff --git a/src/test/java/com/android/tools/r8/ir/optimize/classinliner/ClassInlinerSimplePairBuilderWithMultipleBuildsTest.java b/src/test/java/com/android/tools/r8/ir/optimize/classinliner/ClassInlinerSimplePairBuilderWithMultipleBuildsTest.java
new file mode 100644
index 0000000..6e5dc39
--- /dev/null
+++ b/src/test/java/com/android/tools/r8/ir/optimize/classinliner/ClassInlinerSimplePairBuilderWithMultipleBuildsTest.java
@@ -0,0 +1,137 @@
+// Copyright (c) 2019, 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.ir.optimize.classinliner;
+
+import static com.android.tools.r8.utils.codeinspector.Matchers.isPresent;
+import static org.hamcrest.CoreMatchers.not;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertEquals;
+
+import com.android.tools.r8.TestParameters;
+import com.android.tools.r8.TestParametersCollection;
+import com.android.tools.r8.utils.StringUtils;
+import com.android.tools.r8.utils.codeinspector.ClassSubject;
+import com.android.tools.r8.utils.codeinspector.CodeInspector;
+import java.util.Collections;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+@RunWith(Parameterized.class)
+public class ClassInlinerSimplePairBuilderWithMultipleBuildsTest extends ClassInlinerTestBase {
+
+ private static final String EXPECTED =
+ StringUtils.lines(
+ "Pair(<null>, <null>)",
+ "[before] first = null",
+ "[after] first = f1",
+ "Pair(f1, <null>)",
+ "[before] second = null",
+ "[after] second = s2",
+ "Pair(f1, s2)");
+
+ private final TestParameters parameters;
+
+ @Parameterized.Parameters(name = "{0}")
+ public static TestParametersCollection data() {
+ return getTestParameters().withAllRuntimesAndApiLevels().build();
+ }
+
+ public ClassInlinerSimplePairBuilderWithMultipleBuildsTest(TestParameters parameters) {
+ this.parameters = parameters;
+ }
+
+ @Test
+ public void testR8() throws Exception {
+ testForR8(parameters.getBackend())
+ .addInnerClasses(ClassInlinerSimplePairBuilderWithMultipleBuildsTest.class)
+ .addKeepMainRule(TestClass.class)
+ // TODO(b/143129517): This relies on PairBuilder::build being inlined, thus the limit of 6.
+ .addOptionsModification(options -> options.inliningInstructionLimit = 6)
+ .noMinification()
+ .setMinApi(parameters.getApiLevel())
+ .compile()
+ .inspect(this::inspect)
+ .run(parameters.getRuntime(), TestClass.class)
+ .assertSuccessWithOutput(EXPECTED);
+ }
+
+ @Test
+ public void testExpectedBehavior() throws Exception {
+ testForRuntime(parameters)
+ .addInnerClasses(ClassInlinerSimplePairBuilderWithMultipleBuildsTest.class)
+ .run(parameters.getRuntime(), TestClass.class)
+ .assertSuccessWithOutput(EXPECTED);
+ }
+
+ private void inspect(CodeInspector inspector) {
+ ClassSubject clazz = inspector.clazz(TestClass.class);
+
+ // Note that Pair created instances were also inlined in the following method since
+ // we use 'System.out.println(pX.toString())', if we used 'System.out.println(pX)'
+ // as in the above method, the instance of pair would be passed to println() which
+ // would make it not eligible for inlining.
+ assertEquals(
+ Collections.singleton(StringBuilder.class.getTypeName()), collectTypes(clazz.mainMethod()));
+
+ assertThat(inspector.clazz(PairBuilder.class), not(isPresent()));
+ }
+
+ static class TestClass {
+
+ public static void main(String[] args) {
+ PairBuilder<String, String> builder = new PairBuilder<>();
+ Pair p1 = builder.build();
+ System.out.println(p1.myToString());
+ builder.setFirst("f1");
+ Pair p2 = builder.build();
+ System.out.println(p2.myToString());
+ builder.setSecond("s2");
+ Pair p3 = builder.build();
+ System.out.println(p3.myToString());
+ }
+ }
+
+ static class Pair<F, S> {
+
+ final F first;
+ final S second;
+
+ Pair(F first, S second) {
+ this.first = first;
+ this.second = second;
+ }
+
+ String myToString() {
+ return "Pair("
+ + (first == null ? "<null>" : first)
+ + ", "
+ + (second == null ? "<null>" : second)
+ + ")";
+ }
+ }
+
+ static class PairBuilder<F, S> {
+
+ F first;
+ S second = null;
+
+ void setFirst(F first) {
+ System.out.println("[before] first = " + this.first);
+ this.first = first;
+ System.out.println("[after] first = " + this.first);
+ }
+
+ void setSecond(S second) {
+ System.out.println("[before] second = " + this.second);
+ this.second = second;
+ System.out.println("[after] second = " + this.second);
+ }
+
+ public Pair<F, S> build() {
+ return new Pair<>(first, second);
+ }
+ }
+}
diff --git a/src/test/java/com/android/tools/r8/ir/optimize/classinliner/ClassInlinerTest.java b/src/test/java/com/android/tools/r8/ir/optimize/classinliner/ClassInlinerTest.java
index e088bf0..325bdd5 100644
--- a/src/test/java/com/android/tools/r8/ir/optimize/classinliner/ClassInlinerTest.java
+++ b/src/test/java/com/android/tools/r8/ir/optimize/classinliner/ClassInlinerTest.java
@@ -11,18 +11,11 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import com.android.tools.r8.NeverInline;
-import com.android.tools.r8.TestBase;
+import com.android.tools.r8.TestParameters;
+import com.android.tools.r8.TestParametersCollection;
import com.android.tools.r8.TestRunResult;
-import com.android.tools.r8.ToolHelper;
import com.android.tools.r8.ToolHelper.ProcessResult;
-import com.android.tools.r8.ir.optimize.classinliner.builders.BuildersTestClass;
-import com.android.tools.r8.ir.optimize.classinliner.builders.ControlFlow;
-import com.android.tools.r8.ir.optimize.classinliner.builders.Pair;
-import com.android.tools.r8.ir.optimize.classinliner.builders.PairBuilder;
-import com.android.tools.r8.ir.optimize.classinliner.builders.Tuple;
import com.android.tools.r8.ir.optimize.classinliner.code.C;
import com.android.tools.r8.ir.optimize.classinliner.code.CodeTestClass;
import com.android.tools.r8.ir.optimize.classinliner.invalidroot.InvalidRootsTestClass;
@@ -40,41 +33,33 @@
import com.android.tools.r8.ir.optimize.classinliner.trivial.TrivialTestClass;
import com.android.tools.r8.jasmin.JasminBuilder;
import com.android.tools.r8.jasmin.JasminBuilder.ClassBuilder;
-import com.android.tools.r8.naming.MemberNaming.MethodSignature;
import com.android.tools.r8.utils.AndroidApp;
import com.android.tools.r8.utils.InternalOptions;
import com.android.tools.r8.utils.StringUtils;
import com.android.tools.r8.utils.codeinspector.ClassSubject;
import com.android.tools.r8.utils.codeinspector.CodeInspector;
-import com.android.tools.r8.utils.codeinspector.FieldAccessInstructionSubject;
import com.android.tools.r8.utils.codeinspector.FoundClassSubject;
-import com.android.tools.r8.utils.codeinspector.InstructionSubject;
-import com.android.tools.r8.utils.codeinspector.NewInstanceInstructionSubject;
-import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
-import com.google.common.collect.Streams;
import java.util.Collections;
-import java.util.Iterator;
import java.util.Set;
import java.util.stream.Collectors;
-import java.util.stream.Stream;
import org.junit.Assume;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
@RunWith(Parameterized.class)
-public class ClassInlinerTest extends TestBase {
+public class ClassInlinerTest extends ClassInlinerTestBase {
- private final Backend backend;
+ private final TestParameters parameters;
- @Parameterized.Parameters(name = "Backend: {0}")
- public static Backend[] data() {
- return ToolHelper.getBackends();
+ @Parameterized.Parameters(name = "{0}")
+ public static TestParametersCollection data() {
+ return getTestParameters().withAllRuntimesAndApiLevels().build();
}
- public ClassInlinerTest(Backend backend) {
- this.backend = backend;
+ public ClassInlinerTest(TestParameters parameters) {
+ this.parameters = parameters;
}
@Test
@@ -96,7 +81,7 @@
};
String javaOutput = runOnJava(main);
TestRunResult result =
- testForR8(backend)
+ testForR8(parameters.getBackend())
.addProgramClasses(classes)
.enableInliningAnnotations()
.addKeepMainRule(main)
@@ -112,132 +97,56 @@
assertEquals(
Collections.singleton("java.lang.StringBuilder"),
- collectTypes(clazz, "testInner", "void"));
+ collectTypes(clazz.uniqueMethodWithName("testInner")));
assertEquals(
Collections.emptySet(),
- collectTypes(clazz, "testConstructorMapping1", "void"));
+ collectTypes(clazz.uniqueMethodWithName("testConstructorMapping1")));
assertEquals(
Collections.emptySet(),
- collectTypes(clazz, "testConstructorMapping2", "void"));
+ collectTypes(clazz.uniqueMethodWithName("testConstructorMapping2")));
assertEquals(
Collections.singleton("java.lang.StringBuilder"),
- collectTypes(clazz, "testConstructorMapping3", "void"));
+ collectTypes(clazz.uniqueMethodWithName("testConstructorMapping3")));
assertEquals(
- Collections.emptySet(),
- collectTypes(clazz, "testEmptyClass", "void"));
+ Collections.emptySet(), collectTypes(clazz.uniqueMethodWithName("testEmptyClass")));
assertEquals(
Collections.singleton(
"com.android.tools.r8.ir.optimize.classinliner.trivial.EmptyClassWithInitializer"),
- collectTypes(clazz, "testEmptyClassWithInitializer", "void"));
+ collectTypes(clazz.uniqueMethodWithName("testEmptyClassWithInitializer")));
assertEquals(
Collections.singleton(
"com.android.tools.r8.ir.optimize.classinliner.trivial.ClassWithFinal"),
- collectTypes(clazz, "testClassWithFinalizer", "void"));
+ collectTypes(clazz.uniqueMethodWithName("testClassWithFinalizer")));
assertEquals(
- Collections.emptySet(),
- collectTypes(clazz, "testCallOnIface1", "void"));
+ Collections.emptySet(), collectTypes(clazz.uniqueMethodWithName("testCallOnIface1")));
assertEquals(
- Collections.singleton(
- "com.android.tools.r8.ir.optimize.classinliner.trivial.Iface2Impl"),
- collectTypes(clazz, "testCallOnIface2", "void"));
+ Collections.singleton("com.android.tools.r8.ir.optimize.classinliner.trivial.Iface2Impl"),
+ collectTypes(clazz.uniqueMethodWithName("testCallOnIface2")));
assertEquals(
Sets.newHashSet(
"com.android.tools.r8.ir.optimize.classinliner.trivial.CycleReferenceAB",
"java.lang.StringBuilder"),
- collectTypes(clazz, "testCycles", "void"));
+ collectTypes(clazz.uniqueMethodWithName("testCycles")));
assertEquals(
- Sets.newHashSet("java.lang.StringBuilder",
+ Sets.newHashSet(
+ "java.lang.StringBuilder",
"com.android.tools.r8.ir.optimize.classinliner.trivial.CycleReferenceAB"),
- collectTypes(inspector.clazz(CycleReferenceAB.class), "foo", "void", "int"));
+ collectTypes(inspector.clazz(CycleReferenceAB.class).uniqueMethodWithName("foo")));
assertFalse(inspector.clazz(CycleReferenceBA.class).isPresent());
}
@Test
- public void testBuilders() throws Exception {
- Class<?> main = BuildersTestClass.class;
- Class<?>[] classes = {
- NeverInline.class,
- BuildersTestClass.class,
- BuildersTestClass.Pos.class,
- Tuple.class,
- Pair.class,
- PairBuilder.class,
- ControlFlow.class,
- };
- String javaOutput = runOnJava(main);
- TestRunResult result =
- testForR8(backend)
- .addProgramClasses(classes)
- .enableInliningAnnotations()
- .addKeepMainRule(main)
- .addKeepAttributes("LineNumberTable")
- .addOptionsModification(
- o -> {
- o.inliningInstructionLimit = 6;
- configure(o);
- })
- .allowAccessModification()
- .noMinification()
- .run(main)
- .assertSuccessWithOutput(javaOutput);
-
- CodeInspector inspector = result.inspector();
- ClassSubject clazz = inspector.clazz(main);
-
- for (int i = 1; i <= 3; i++) {
- Set<String> expected =
- backend == Backend.CF
- // const-string canonicalization is disabled in CF, which helps ClassInliner identify
- // PairBuilder as candidate.
- ? ImmutableSet.of(
- "java.lang.StringBuilder",
- "com.android.tools.r8.ir.optimize.classinliner.builders.PairBuilder")
- : ImmutableSet.of("java.lang.StringBuilder");
- assertEquals(expected, collectTypes(clazz, "testSimpleBuilder" + i, "void"));
- }
-
- // Note that Pair created instances were also inlined in the following method since
- // we use 'System.out.println(pX.toString())', if we used 'System.out.println(pX)'
- // as in the above method, the instance of pair would be passed to println() which
- // would make it not eligible for inlining.
- // TODO(b/143129517): This relies on PairBuilder::build being inlined, thus the limit of 6.
- assertEquals(
- Collections.singleton("java.lang.StringBuilder"),
- collectTypes(clazz, "testSimpleBuilderWithMultipleBuilds", "void"));
-
- if (backend == Backend.DEX) {
- assertFalse(inspector.clazz(PairBuilder.class).isPresent());
- }
-
- assertEquals(
- Collections.singleton("java.lang.StringBuilder"),
- collectTypes(clazz, "testBuilderConstructors", "void"));
-
- assertFalse(inspector.clazz(Tuple.class).isPresent());
-
- assertEquals(
- Collections.singleton("java.lang.StringBuilder"),
- collectTypes(clazz, "testWithControlFlow", "void"));
-
- assertFalse(inspector.clazz(ControlFlow.class).isPresent());
-
- assertEquals(Collections.emptySet(), collectTypes(clazz, "testWithMoreControlFlow", "void"));
-
- assertFalse(inspector.clazz(BuildersTestClass.Pos.class).isPresent());
- }
-
- @Test
public void testErroneousInput() throws Exception {
JasminBuilder builder = new JasminBuilder();
@@ -258,7 +167,11 @@
" return");
AndroidApp compiled =
- compileWithR8(builder.build(), getProguardConfig(mainClass.name), this::configure, backend);
+ compileWithR8(
+ builder.build(),
+ getProguardConfig(mainClass.name),
+ this::configure,
+ parameters.getBackend());
// Check that the code fails with an IncompatibleClassChangeError with Java.
ProcessResult javaResult =
@@ -267,7 +180,7 @@
// Check that the code fails with an IncompatibleClassChangeError with ART.
ProcessResult result =
- backend == Backend.DEX
+ parameters.isDexRuntime()
? runOnArtRaw(compiled, mainClass.name)
: runOnJavaRaw(compiled, mainClass.name, Collections.emptyList());
assertThat(result.stderr, containsString("IncompatibleClassChangeError"));
@@ -284,7 +197,7 @@
};
String javaOutput = runOnJava(main);
TestRunResult result =
- testForR8(backend)
+ testForR8(parameters.getBackend())
.addProgramClasses(classes)
.enableInliningAnnotations()
.addKeepMainRule(main)
@@ -298,17 +211,11 @@
CodeInspector inspector = result.inspector();
ClassSubject clazz = inspector.clazz(C.class);
- assertEquals(
- Collections.emptySet(),
- collectTypes(clazz, "method1", "int"));
+ assertEquals(Collections.emptySet(), collectTypes(clazz.uniqueMethodWithName("method1")));
- assertEquals(
- Collections.emptySet(),
- collectTypes(clazz, "method2", "int"));
+ assertEquals(Collections.emptySet(), collectTypes(clazz.uniqueMethodWithName("method2")));
- assertEquals(
- Collections.emptySet(),
- collectTypes(clazz, "method3", "int"));
+ assertEquals(Collections.emptySet(), collectTypes(clazz.uniqueMethodWithName("method3")));
assertFalse(inspector.clazz(C.L.class).isPresent());
assertFalse(inspector.clazz(C.F.class).isPresent());
@@ -326,7 +233,7 @@
};
String javaOutput = runOnJava(main);
TestRunResult result =
- testForR8(backend)
+ testForR8(parameters.getBackend())
.addProgramClasses(classes)
.enableProguardTestOptions()
.enableInliningAnnotations()
@@ -350,15 +257,15 @@
// TODO(b/143129517, 141719453): This expectation relies on the class inlining limits.
assertEquals(
Sets.newHashSet("java.lang.StringBuilder", "java.lang.RuntimeException"),
- collectTypes(clazz, "testExtraNeverReturnsNormally", "void"));
+ collectTypes(clazz.uniqueMethodWithName("testExtraNeverReturnsNormally")));
assertEquals(
Sets.newHashSet("java.lang.StringBuilder", "java.lang.RuntimeException"),
- collectTypes(clazz, "testDirectNeverReturnsNormally", "void"));
+ collectTypes(clazz.uniqueMethodWithName("testDirectNeverReturnsNormally")));
assertEquals(
Sets.newHashSet("java.lang.StringBuilder", "java.lang.RuntimeException"),
- collectTypes(clazz, "testInitNeverReturnsNormally", "void"));
+ collectTypes(clazz.uniqueMethodWithName("testInitNeverReturnsNormally")));
assertThat(inspector.clazz(InvalidRootsTestClass.NeverReturnsNormally.class), isPresent());
assertThat(
@@ -367,7 +274,7 @@
// TODO(b/143129517, b/141719453): This expectation relies on the class inlining limits.
assertEquals(
Sets.newHashSet("java.lang.StringBuilder", "java.lang.RuntimeException"),
- collectTypes(clazz, "testRootInvalidatesAfterInlining", "void"));
+ collectTypes(clazz.uniqueMethodWithName("testRootInvalidatesAfterInlining")));
assertThat(inspector.clazz(InvalidRootsTestClass.A.class), not(isPresent()));
assertThat(inspector.clazz(InvalidRootsTestClass.B.class), not(isPresent()));
@@ -375,7 +282,7 @@
@Test
public void testDesugaredLambdas() throws Exception {
- Assume.assumeFalse("No desugaring with CF backend", backend == Backend.CF);
+ Assume.assumeFalse("No desugaring with CF backend", parameters.isCfRuntime());
Class<?> main = LambdasTestClass.class;
Class<?>[] classes = {
LambdasTestClass.class,
@@ -384,7 +291,7 @@
};
String javaOutput = runOnJava(main);
TestRunResult result =
- testForR8(backend)
+ testForR8(parameters.getBackend())
.addProgramClasses(classes)
.addKeepMainRule(main)
.addKeepAttributes("LineNumberTable")
@@ -404,9 +311,8 @@
ClassSubject clazz = inspector.clazz(main);
assertEquals(
- Sets.newHashSet(
- "java.lang.StringBuilder"),
- collectTypes(clazz, "testStatelessLambda", "void"));
+ Sets.newHashSet("java.lang.StringBuilder"),
+ collectTypes(clazz.uniqueMethodWithName("testStatelessLambda")));
// TODO(b/120814598): Should only be "java.lang.StringBuilder". Lambdas are not class inlined
// because parameter usage is not available for each lambda constructor.
@@ -416,9 +322,7 @@
.map(FoundClassSubject::getFinalName)
.filter(name -> name.contains(LAMBDA_CLASS_NAME_PREFIX))
.collect(Collectors.toList()));
- assertEquals(
- expectedTypes,
- collectTypes(clazz, "testStatefulLambda", "void", "java.lang.String", "java.lang.String"));
+ assertEquals(expectedTypes, collectTypes(clazz.uniqueMethodWithName("testStatefulLambda")));
// TODO(b/120814598): Should be 0. Lambdas are not class inlined because parameter usage is not
// available for each lambda constructor.
@@ -427,36 +331,6 @@
inspector.allClasses().stream().filter(ClassSubject::isSynthesizedJavaLambdaClass).count());
}
- private Set<String> collectTypes(
- ClassSubject clazz, String methodName, String retValue, String... params) {
- return Stream.concat(
- collectNewInstanceTypesWithRetValue(clazz, methodName, retValue, params),
- collectStaticGetTypesWithRetValue(clazz, methodName, retValue, params)
- ).collect(Collectors.toSet());
- }
-
- private Stream<String> collectNewInstanceTypesWithRetValue(
- ClassSubject clazz, String methodName, String retValue, String... params) {
- assertNotNull(clazz);
- MethodSignature signature = new MethodSignature(methodName, retValue, params);
- Iterator<InstructionSubject> iterator = clazz.method(signature).iterateInstructions();
- return Streams.stream(iterator)
- .filter(InstructionSubject::isNewInstance)
- .map(is -> ((NewInstanceInstructionSubject) is).getType().toSourceString());
- }
-
- private Stream<String> collectStaticGetTypesWithRetValue(
- ClassSubject clazz, String methodName, String retValue, String... params) {
- assertNotNull(clazz);
- MethodSignature signature = new MethodSignature(methodName, retValue, params);
- Iterator<InstructionSubject> iterator = clazz.method(signature).iterateInstructions();
- return Streams.stream(iterator)
- .filter(InstructionSubject::isStaticGet)
- .map(is -> (FieldAccessInstructionSubject) is)
- .filter(fais -> fais.holder().is(fais.type()))
- .map(fais -> fais.holder().toString());
- }
-
private String getProguardConfig(String main) {
return StringUtils.joinLines(
keepMainProguardConfiguration(main),
diff --git a/src/test/java/com/android/tools/r8/ir/optimize/classinliner/ClassInlinerTestBase.java b/src/test/java/com/android/tools/r8/ir/optimize/classinliner/ClassInlinerTestBase.java
new file mode 100644
index 0000000..71e7aab
--- /dev/null
+++ b/src/test/java/com/android/tools/r8/ir/optimize/classinliner/ClassInlinerTestBase.java
@@ -0,0 +1,46 @@
+// Copyright (c) 2019, 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.ir.optimize.classinliner;
+
+import static com.android.tools.r8.utils.codeinspector.Matchers.isPresent;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertNotNull;
+
+import com.android.tools.r8.TestBase;
+import com.android.tools.r8.utils.codeinspector.FieldAccessInstructionSubject;
+import com.android.tools.r8.utils.codeinspector.InstructionSubject;
+import com.android.tools.r8.utils.codeinspector.MethodSubject;
+import com.android.tools.r8.utils.codeinspector.NewInstanceInstructionSubject;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+public abstract class ClassInlinerTestBase extends TestBase {
+
+ protected Set<String> collectTypes(MethodSubject methodSubject) {
+ assertNotNull(methodSubject);
+ assertThat(methodSubject, isPresent());
+ return Stream.concat(
+ collectNewInstanceTypesWithRetValue(methodSubject),
+ collectStaticGetTypesWithRetValue(methodSubject))
+ .collect(Collectors.toSet());
+ }
+
+ private Stream<String> collectNewInstanceTypesWithRetValue(MethodSubject methodSubject) {
+ return methodSubject
+ .streamInstructions()
+ .filter(InstructionSubject::isNewInstance)
+ .map(is -> ((NewInstanceInstructionSubject) is).getType().toSourceString());
+ }
+
+ private Stream<String> collectStaticGetTypesWithRetValue(MethodSubject methodSubject) {
+ return methodSubject
+ .streamInstructions()
+ .filter(InstructionSubject::isStaticGet)
+ .map(is -> (FieldAccessInstructionSubject) is)
+ .filter(fais -> fais.holder().is(fais.type()))
+ .map(fais -> fais.holder().toString());
+ }
+}
diff --git a/src/test/java/com/android/tools/r8/ir/optimize/classinliner/ClassInlinerTupleBuilderConstructorsTest.java b/src/test/java/com/android/tools/r8/ir/optimize/classinliner/ClassInlinerTupleBuilderConstructorsTest.java
new file mode 100644
index 0000000..1b5d955
--- /dev/null
+++ b/src/test/java/com/android/tools/r8/ir/optimize/classinliner/ClassInlinerTupleBuilderConstructorsTest.java
@@ -0,0 +1,140 @@
+// Copyright (c) 2019, 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.ir.optimize.classinliner;
+
+import static com.android.tools.r8.utils.codeinspector.Matchers.isPresent;
+import static org.hamcrest.CoreMatchers.not;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assume.assumeTrue;
+
+import com.android.tools.r8.TestParameters;
+import com.android.tools.r8.TestParametersCollection;
+import com.android.tools.r8.utils.StringUtils;
+import com.android.tools.r8.utils.codeinspector.ClassSubject;
+import com.android.tools.r8.utils.codeinspector.CodeInspector;
+import java.util.Collections;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+@RunWith(Parameterized.class)
+public class ClassInlinerTupleBuilderConstructorsTest extends ClassInlinerTestBase {
+
+ private static final String EXPECTED =
+ StringUtils.lines(
+ "Tuple1(false, 0, 0, 0, 0, 0, 0.0, 0.0, <null>)",
+ "Tuple1(true, 77, 9977, 35, 42, 987654321123456789, -12.34, 43210.98765, s)");
+
+ private final TestParameters parameters;
+
+ @Parameterized.Parameters(name = "{0}")
+ public static TestParametersCollection data() {
+ return getTestParameters().withAllRuntimesAndApiLevels().build();
+ }
+
+ public ClassInlinerTupleBuilderConstructorsTest(TestParameters parameters) {
+ this.parameters = parameters;
+ }
+
+ @Test
+ public void testR8() throws Exception {
+ testForR8(parameters.getBackend())
+ .addInnerClasses(ClassInlinerTupleBuilderConstructorsTest.class)
+ .addKeepMainRule(TestClass.class)
+ .noMinification()
+ .setMinApi(parameters.getApiLevel())
+ .compile()
+ .inspect(this::inspect)
+ .run(parameters.getRuntime(), TestClass.class)
+ .assertSuccessWithOutput(EXPECTED);
+ }
+
+ @Test
+ public void testJVM() throws Exception {
+ assumeTrue(parameters.isCfRuntime());
+ testForJvm()
+ .addTestClasspath()
+ .run(parameters.getRuntime(), TestClass.class)
+ .assertSuccessWithOutput(EXPECTED);
+ }
+
+ private void inspect(CodeInspector inspector) {
+ ClassSubject clazz = inspector.clazz(TestClass.class);
+
+ assertEquals(
+ Collections.singleton(StringBuilder.class.getTypeName()), collectTypes(clazz.mainMethod()));
+
+ assertThat(inspector.clazz(Tuple.class), not(isPresent()));
+ }
+
+ static class TestClass {
+
+ public static void main(String[] args) {
+ System.out.println(new Tuple().myToString());
+ System.out.println(
+ new Tuple(
+ true,
+ (byte) 77,
+ (short) 9977,
+ '#',
+ 42,
+ 987654321123456789L,
+ -12.34f,
+ 43210.98765,
+ "s")
+ .myToString());
+ }
+ }
+
+ static class Tuple {
+
+ boolean z;
+ byte b;
+ short s;
+ char c;
+ int i;
+ long l;
+ float f;
+ double d;
+ Object o;
+
+ Tuple() {}
+
+ Tuple(boolean z, byte b, short s, char c, int i, long l, float f, double d, Object o) {
+ this.z = z;
+ this.b = b;
+ this.s = s;
+ this.c = c;
+ this.i = i;
+ this.l = l;
+ this.f = f;
+ this.d = d;
+ this.o = o;
+ }
+
+ String myToString() {
+ return "Tuple1("
+ + z
+ + ", "
+ + b
+ + ", "
+ + s
+ + ", "
+ + ((int) c)
+ + ", "
+ + i
+ + ", "
+ + l
+ + ", "
+ + f
+ + ", "
+ + d
+ + ", "
+ + (o == null ? "<null>" : o)
+ + ")";
+ }
+ }
+}
diff --git a/src/test/java/com/android/tools/r8/ir/optimize/classinliner/builders/BuildersTestClass.java b/src/test/java/com/android/tools/r8/ir/optimize/classinliner/builders/BuildersTestClass.java
deleted file mode 100644
index 4a40fe9..0000000
--- a/src/test/java/com/android/tools/r8/ir/optimize/classinliner/builders/BuildersTestClass.java
+++ /dev/null
@@ -1,104 +0,0 @@
-// Copyright (c) 2018, 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.ir.optimize.classinliner.builders;
-
-import com.android.tools.r8.NeverInline;
-
-public class BuildersTestClass {
- private static int ID = 0;
-
- private static int nextInt() {
- return ID++;
- }
-
- private static String next() {
- return Integer.toString(nextInt());
- }
-
- public static void main(String[] args) {
- BuildersTestClass test = new BuildersTestClass();
- test.testSimpleBuilder1();
- test.testSimpleBuilderWithMultipleBuilds();
- test.testBuilderConstructors();
- test.testWithControlFlow();
- test.testWithMoreControlFlow();
- }
-
- @NeverInline
- private void testSimpleBuilder1() {
- System.out.println(
- new PairBuilder<String, String>().setFirst("f-" + next()).build().myToString());
- testSimpleBuilder2();
- testSimpleBuilder3();
- }
-
- @NeverInline
- private void testSimpleBuilder2() {
- System.out.println(
- new PairBuilder<String, String>().setSecond("s-" + next()).build().myToString());
- }
-
- @NeverInline
- private void testSimpleBuilder3() {
- System.out.println(new PairBuilder<String, String>()
- .setFirst("f-" + next()).setSecond("s-" + next()).build().myToString());
- }
-
- @NeverInline
- private void testSimpleBuilderWithMultipleBuilds() {
- PairBuilder<String, String> builder = new PairBuilder<>();
- Pair p1 = builder.build();
- System.out.println(p1.myToString());
- builder.setFirst("f-" + next());
- Pair p2 = builder.build();
- System.out.println(p2.myToString());
- builder.setSecond("s-" + next());
- Pair p3 = builder.build();
- System.out.println(p3.myToString());
- }
-
- @NeverInline
- private void testBuilderConstructors() {
- System.out.println(new Tuple().myToString());
- System.out.println(new Tuple(true, (byte) 77, (short) 9977, '#', 42,
- 987654321123456789L, -12.34f, 43210.98765, "s-" + next() + "-s").myToString());
- }
-
- @NeverInline
- private void testWithControlFlow() {
- ControlFlow flow = new ControlFlow(-1, 2, 7);
- for (int k = 0; k < 25; k++) {
- if (k % 3 == 0) {
- flow.foo(k);
- } else if (k % 3 == 1) {
- flow.bar(nextInt(), nextInt(), nextInt(), nextInt());
- }
- }
- System.out.println("flow = " + flow.toString());
- }
-
- @NeverInline
- private void testWithMoreControlFlow() {
- String str = "1234567890";
- Pos pos = new Pos();
- while (pos.y < str.length()) {
- pos.x = pos.y;
- pos.y = pos.x;
-
- if (str.charAt(pos.x) != '*') {
- if ('0' <= str.charAt(pos.y) && str.charAt(pos.y) <= '9') {
- while (pos.y < str.length() && '0' <= str.charAt(pos.y) && str.charAt(pos.y) <= '9') {
- pos.y++;
- }
- }
- }
- }
- }
-
- public static class Pos {
- public int x = 0;
- public int y = 0;
- }
-}
diff --git a/src/test/java/com/android/tools/r8/ir/optimize/classinliner/builders/ControlFlow.java b/src/test/java/com/android/tools/r8/ir/optimize/classinliner/builders/ControlFlow.java
deleted file mode 100644
index 7b95dc1..0000000
--- a/src/test/java/com/android/tools/r8/ir/optimize/classinliner/builders/ControlFlow.java
+++ /dev/null
@@ -1,54 +0,0 @@
-// Copyright (c) 2018, 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.ir.optimize.classinliner.builders;
-
-public class ControlFlow {
- int a;
- int b;
- int c = 1234;
- int d;
- String s = ">";
-
- ControlFlow(int b, int c, int d) {
- this.s += this.a++ + ">";
- this.s += this.b + ">";
- this.b = b;
- this.s += this.b + ">";
- this.s += this.c + ">";
- this.c += c;
- this.s += this.c + ">";
- this.s += (this.d = d) + ">";
- }
-
- public void foo(int count) {
- for (int i = 0; i < count; i++) {
- switch (i % 4) {
- case 0:
- this.s += ++this.a + ">";
- break;
- case 1:
- this.c += this.b;
- this.s += this.c + ">";
- break;
- case 2:
- this.d += this.d++ + this.c++ + this.b++ + this.a++;
- this.s += this.d + ">";
- break;
- }
- }
- }
-
- public void bar(int a, int b, int c, int d) {
- this.a += a;
- this.b += b;
- this.c += c;
- this.d += d;
- }
-
- @Override
- public String toString() {
- return s;
- }
-}
diff --git a/src/test/java/com/android/tools/r8/ir/optimize/classinliner/builders/Pair.java b/src/test/java/com/android/tools/r8/ir/optimize/classinliner/builders/Pair.java
deleted file mode 100644
index fcbea05..0000000
--- a/src/test/java/com/android/tools/r8/ir/optimize/classinliner/builders/Pair.java
+++ /dev/null
@@ -1,21 +0,0 @@
-// Copyright (c) 2018, 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.ir.optimize.classinliner.builders;
-
-public class Pair<F, S> {
- public final F first;
- public final S second;
-
- public Pair(F first, S second) {
- this.first = first;
- this.second = second;
- }
-
- public String myToString() {
- return "Pair(" +
- (first == null ? "<null>" : first) + ", " +
- (second == null ? "<null>" : second) + ")";
- }
-}
diff --git a/src/test/java/com/android/tools/r8/ir/optimize/classinliner/builders/PairBuilder.java b/src/test/java/com/android/tools/r8/ir/optimize/classinliner/builders/PairBuilder.java
deleted file mode 100644
index 0c80c53..0000000
--- a/src/test/java/com/android/tools/r8/ir/optimize/classinliner/builders/PairBuilder.java
+++ /dev/null
@@ -1,29 +0,0 @@
-// Copyright (c) 2018, 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.ir.optimize.classinliner.builders;
-
-public class PairBuilder<F, S> {
- public F first;
- public S second = null;
-
- public PairBuilder<F, S> setFirst(F first) {
- System.out.println("[before] first = " + this.first);
- this.first = first;
- System.out.println("[after] first = " + this.first);
- return this;
- }
-
- public PairBuilder<F, S> setSecond(S second) {
- System.out.println("[before] second = " + this.second);
- this.second = second;
- System.out.println("[after] second = " + this.second);
- return this;
- }
-
- public Pair<F, S> build() {
- return new Pair<>(first, second);
- }
-}
-
diff --git a/src/test/java/com/android/tools/r8/ir/optimize/classinliner/builders/Tuple.java b/src/test/java/com/android/tools/r8/ir/optimize/classinliner/builders/Tuple.java
deleted file mode 100644
index 1c0718b..0000000
--- a/src/test/java/com/android/tools/r8/ir/optimize/classinliner/builders/Tuple.java
+++ /dev/null
@@ -1,38 +0,0 @@
-// Copyright (c) 2018, 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.ir.optimize.classinliner.builders;
-
-public class Tuple {
- public boolean z;
- public byte b;
- public short s;
- public char c;
- public int i;
- public long l;
- public float f;
- public double d;
- public Object o;
-
- Tuple() {
- }
-
- Tuple(boolean z, byte b, short s, char c, int i, long l, float f, double d, Object o) {
- this.z = z;
- this.b = b;
- this.s = s;
- this.c = c;
- this.i = i;
- this.l = l;
- this.f = f;
- this.d = d;
- this.o = o;
- }
-
- public String myToString() {
- return "Tuple1(" + z + ", " + b + ", " + s + ", " +
- ((int) c) + ", " + i + ", " + l + ", " + f + ", " +
- d + ", " + (o == null ? "<null>" : o) + ")";
- }
-}