Fix bug making us not inline when a simple class without clinit had static fields with nothing setting them.
The conditional was reversed, so if there was fields, we would only
allow inlining if there was a field that had an allocation side effect.
This gives 50K on chrome
Bug: 122683370
Change-Id: I80ad09ffe722178b9e9dc682ab6486cd2974d6bd
diff --git a/src/main/java/com/android/tools/r8/graph/DexClass.java b/src/main/java/com/android/tools/r8/graph/DexClass.java
index d9940f3..b229074 100644
--- a/src/main/java/com/android/tools/r8/graph/DexClass.java
+++ b/src/main/java/com/android/tools/r8/graph/DexClass.java
@@ -474,7 +474,7 @@
public boolean defaultValuesForStaticFieldsMayTriggerAllocation() {
return Arrays.stream(staticFields())
- .anyMatch(field -> !field.getStaticValue().mayTriggerAllocation());
+ .anyMatch(field -> field.getStaticValue().mayTriggerAllocation());
}
public List<InnerClassAttribute> getInnerClasses() {
diff --git a/src/test/java/com/android/tools/r8/ir/optimize/inliner/InlineWithSimpleFieldNoValue.java b/src/test/java/com/android/tools/r8/ir/optimize/inliner/InlineWithSimpleFieldNoValue.java
new file mode 100644
index 0000000..eac5881
--- /dev/null
+++ b/src/test/java/com/android/tools/r8/ir/optimize/inliner/InlineWithSimpleFieldNoValue.java
@@ -0,0 +1,43 @@
+// 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.inliner;
+
+import static junit.framework.TestCase.assertTrue;
+
+import com.android.tools.r8.R8TestRunResult;
+import com.android.tools.r8.TestBase;
+import com.android.tools.r8.utils.StringUtils;
+import org.junit.Test;
+
+class TestClass {
+ public static void main(String[] args) {
+ System.out.println(InlineFrom.getValue());
+ InlineFrom.value = 43;
+ System.out.println(InlineFrom.value);
+ }
+}
+
+// Simple class, with no clinit and no static field initialization.
+// We should always inline getValue()
+// We ensure that we use value.
+class InlineFrom {
+ public static int value;
+
+ public static int getValue() {
+ return 42;
+ }
+}
+
+public class InlineWithSimpleFieldNoValue extends TestBase {
+ @Test
+ public void test() throws Exception {
+ R8TestRunResult result = testForR8(Backend.DEX)
+ .addKeepMainRule(TestClass.class)
+ .addProgramClasses(TestClass.class, InlineFrom.class)
+ .run(TestClass.class)
+ .assertSuccessWithOutput(StringUtils.lines("42", "43"));
+ assertTrue(result.inspector().clazz(InlineFrom.class).allMethods().isEmpty());
+ }
+}