Prepare inliner for constructor inlining

Change-Id: I40daca6a7eaf14c7242afc76ba818327378b6828
diff --git a/src/main/java/com/android/tools/r8/ir/optimize/DefaultInliningOracle.java b/src/main/java/com/android/tools/r8/ir/optimize/DefaultInliningOracle.java
index 6f524f6..79ba9d1 100644
--- a/src/main/java/com/android/tools/r8/ir/optimize/DefaultInliningOracle.java
+++ b/src/main/java/com/android/tools/r8/ir/optimize/DefaultInliningOracle.java
@@ -478,6 +478,10 @@
       ProgramMethod singleTarget,
       InliningIRProvider inliningIRProvider,
       WhyAreYouNotInliningReporter whyAreYouNotInliningReporter) {
+    if (!inlinerOptions.isConstructorInliningEnabled()) {
+      return false;
+    }
+
     IRCode inlinee = inliningIRProvider.getInliningIR(invoke, singleTarget);
 
     // In the Java VM Specification section "4.10.2.4. Instance Initialization Methods and
@@ -517,7 +521,6 @@
     //       ...
     //     }
     //   }
-    // TODO(b/278679664): Relax requirement (3) when targeting DEX.
     Value thisValue = inlinee.entryBlock().entry().asArgument().outValue();
 
     List<InvokeDirect> initCallsOnThis = new ArrayList<>();
@@ -526,8 +529,10 @@
         InvokeDirect initCall = instruction.asInvokeDirect();
         Value receiver = initCall.getReceiver().getAliasedValue();
         if (receiver == thisValue) {
-          // The <init>() call of the constructor must be on the same class.
-          if (calleeMethodHolder != initCall.getInvokedMethod().getHolderType()) {
+          // The <init>() call of the constructor must be on the same class when targeting the JVM
+          // and Dalvik.
+          if (!options.canInitNewInstanceUsingSuperclassConstructor()
+              && calleeMethodHolder != initCall.getInvokedMethod().getHolderType()) {
             whyAreYouNotInliningReporter
                 .reportUnsafeConstructorInliningDueToIndirectConstructorCall(initCall);
             return false;
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 c8936dd..dbd49aa 100644
--- a/src/main/java/com/android/tools/r8/utils/InternalOptions.java
+++ b/src/main/java/com/android/tools/r8/utils/InternalOptions.java
@@ -1626,6 +1626,8 @@
 
   public static class InlinerOptions {
 
+    public boolean enableConstructorInlining = true;
+
     public boolean enableInlining =
         !parseSystemPropertyForDevelopmentOrDefault("com.android.tools.r8.disableinlining", false);
 
@@ -1683,6 +1685,14 @@
       return 5;
     }
 
+    public boolean isConstructorInliningEnabled() {
+      return enableConstructorInlining;
+    }
+
+    public void setEnableConstructorInlining(boolean enableConstructorInlining) {
+      this.enableConstructorInlining = enableConstructorInlining;
+    }
+
     public boolean shouldApplyInliningToInlinee(
         AppView<?> appView, ProgramMethod inlinee, int inliningDepth) {
       if (applyInliningToInlineePredicateForTesting != null) {