Add Art version 8.1.0 (Android O MR1)

Bug: 119935815
Change-Id: Iee69f8731867e1bb986792b49f0f5da735309c70
diff --git a/.gitignore b/.gitignore
index 51e0c02..cb3eaab 100644
--- a/.gitignore
+++ b/.gitignore
@@ -17,6 +17,8 @@
 tools/*/art-6.0.1.tar.gz
 tools/*/art-7.0.0
 tools/*/art-7.0.0.tar.gz
+tools/*/art-8.1.0
+tools/*/art-8.1.0.tar.gz
 tools/*/dalvik
 tools/*/dalvik.tar.gz
 tools/*/dalvik-4.0.4
diff --git a/build.gradle b/build.gradle
index 59e6b9e..5ec2f08 100644
--- a/build.gradle
+++ b/build.gradle
@@ -296,6 +296,7 @@
                 "linux/art-5.1.1",
                 "linux/art-6.0.1",
                 "linux/art-7.0.0",
+                "linux/art-8.1.0",
                 "linux/dalvik",
                 "linux/dalvik-4.0.4",
                 "${osString}/dx",
diff --git a/src/test/java/com/android/tools/r8/R8RunArtTestsTest.java b/src/test/java/com/android/tools/r8/R8RunArtTestsTest.java
index 3618a5e..07b3c77 100644
--- a/src/test/java/com/android/tools/r8/R8RunArtTestsTest.java
+++ b/src/test/java/com/android/tools/r8/R8RunArtTestsTest.java
@@ -96,7 +96,8 @@
       DexVm.Version.V4_4_4,
       DexVm.Version.V5_1_1,
       DexVm.Version.V6_0_1,
-      DexVm.Version.V7_0_0);
+      DexVm.Version.V7_0_0,
+      DexVm.Version.V8_1_0);
 
   // Input jar for jctf tests.
   private static final String JCTF_COMMON_JAR = "build/libs/jctfCommon.jar";
@@ -439,7 +440,6 @@
       "149-suspend-all-stress",
       "154-gc-loop",
       "155-java-set-resolved-type",
-      "156-register-dex-file-multi-loader",
       "157-void-class",
       "158-app-image-class-table",
       "466-get-live-vreg",
@@ -454,93 +454,127 @@
       "629-vdex-speed",
       "1337-gc-coverage",
 
-      // Addition of checks for super-class-initialization cause this to abort on non-ToT art.
-      "008-exceptions",
-
-      // Fails due to non-matching Exception messages.
-      "201-built-in-except-detail-messages",
-
       // Fails on non-R8/D8 run
       "031-class-attributes"
   );
 
-  private static Map<DexVm.Version, List<String>> expectedToFailRunWithArtVersion = ImmutableMap.of(
-      DexVm.Version.V7_0_0, ImmutableList.of(
-          // Generally fails on non-R8/D8 running.
-          "412-new-array",
-          "610-arraycopy",
-          "625-checker-licm-regressions"
-      ),
-      DexVm.Version.V6_0_1, ImmutableList.of(
-          // Generally fails on non-R8/D8 running.
-          "004-checker-UnsafeTest18",
-          "005-annotations",
-          "008-exceptions",
-          "082-inline-execute",
-          "099-vmdebug",
-          "412-new-array",
-          "530-checker-lse2",
-          "550-new-instance-clinit",
-          "580-checker-round",
-          "594-invoke-super",
-          "625-checker-licm-regressions",
-          "626-const-class-linking"
-      ),
-      DexVm.Version.V5_1_1, ImmutableList.of(
-          // Generally fails on non R8/D8 running.
-          "004-checker-UnsafeTest18",
-          "004-NativeAllocations",
-          "005-annotations",
-          "008-exceptions",
-          "082-inline-execute",
-          "099-vmdebug",
-          "143-string-value",
-          "530-checker-lse2",
-          "536-checker-intrinsic-optimization",
-          "552-invoke-non-existent-super",
-          "580-checker-round",
-          "580-checker-string-fact-intrinsics",
-          "594-invoke-super",
-          "605-new-string-from-bytes",
-          "626-const-class-linking"
-      ),
-      DexVm.Version.V4_4_4, ImmutableList.of(
-          // Generally fails on non R8/D8 running.
-          "004-checker-UnsafeTest18",
-          "004-NativeAllocations",
-          "005-annotations",
-          "008-exceptions",
-          "082-inline-execute",
-          "099-vmdebug",
-          "143-string-value",
-          "530-checker-lse2",
-          "536-checker-intrinsic-optimization",
-          "552-invoke-non-existent-super",
-          "580-checker-round",
-          "580-checker-string-fact-intrinsics",
-          "594-invoke-super",
-          "605-new-string-from-bytes",
-          "626-const-class-linking"
-      ),
-      DexVm.Version.V4_0_4, ImmutableList.of(
-          // Generally fails on non R8/D8 running.
-          "004-checker-UnsafeTest18",
-          "004-NativeAllocations",
-          "005-annotations",
-          "008-exceptions",
-          "082-inline-execute",
-          "099-vmdebug",
-          "143-string-value",
-          "530-checker-lse2",
-          "536-checker-intrinsic-optimization",
-          "552-invoke-non-existent-super",
-          "580-checker-round",
-          "580-checker-string-fact-intrinsics",
-          "594-invoke-super",
-          "605-new-string-from-bytes",
-          "626-const-class-linking"
-      )
-  );
+  private static Map<DexVm.Version, List<String>> expectedToFailRunWithArtVersion;
+
+  static {
+    ImmutableMap.Builder<DexVm.Version, List<String>> builder = ImmutableMap.builder();
+    builder
+        .put(DexVm.Version.V8_1_0, ImmutableList.of(
+            // TODO(119938529): Triage.
+            "709-checker-varhandles",
+            "454-get-vreg",
+            "457-regs"
+        ))
+        .put(DexVm.Version.V7_0_0, ImmutableList.of(
+            // Addition of checks for super-class-initialization cause this to abort on non-ToT art.
+            "008-exceptions",
+
+            // Fails due to non-matching Exception messages.
+            "201-built-in-except-detail-messages",
+
+            // Generally fails on non-R8/D8 running.
+            "412-new-array",
+            "610-arraycopy",
+            "625-checker-licm-regressions"))
+        .put(DexVm.Version.V6_0_1, ImmutableList.of(
+            // Addition of checks for super-class-initialization cause this to abort on non-ToT art.
+            "008-exceptions",
+
+            // Fails due to non-matching Exception messages.
+            "201-built-in-except-detail-messages",
+
+            // Generally fails on non-R8/D8 running.
+            "004-checker-UnsafeTest18",
+            "005-annotations",
+            "008-exceptions",
+            "082-inline-execute",
+            "099-vmdebug",
+            "156-register-dex-file-multi-loader",
+            "412-new-array",
+            "530-checker-lse2",
+            "550-new-instance-clinit",
+            "580-checker-round",
+            "594-invoke-super",
+            "625-checker-licm-regressions",
+            "626-const-class-linking"))
+        .put(DexVm.Version.V5_1_1, ImmutableList.of(
+            // Addition of checks for super-class-initialization cause this to abort on non-ToT art.
+            "008-exceptions",
+
+            // Fails due to non-matching Exception messages.
+            "201-built-in-except-detail-messages",
+
+            // Generally fails on non R8/D8 running.
+            "004-checker-UnsafeTest18",
+            "004-NativeAllocations",
+            "005-annotations",
+            "008-exceptions",
+            "082-inline-execute",
+            "099-vmdebug",
+            "143-string-value",
+            "156-register-dex-file-multi-loader",
+            "530-checker-lse2",
+            "536-checker-intrinsic-optimization",
+            "552-invoke-non-existent-super",
+            "580-checker-round",
+            "580-checker-string-fact-intrinsics",
+            "594-invoke-super",
+            "605-new-string-from-bytes",
+            "626-const-class-linking"))
+        .put(DexVm.Version.V4_4_4, ImmutableList.of(
+            // Addition of checks for super-class-initialization cause this to abort on non-ToT art.
+            "008-exceptions",
+
+            // Fails due to non-matching Exception messages.
+            "201-built-in-except-detail-messages",
+
+            // Generally fails on non R8/D8 running.
+            "004-checker-UnsafeTest18",
+            "004-NativeAllocations",
+            "005-annotations",
+            "008-exceptions",
+            "082-inline-execute",
+            "099-vmdebug",
+            "143-string-value",
+            "156-register-dex-file-multi-loader",
+            "530-checker-lse2",
+            "536-checker-intrinsic-optimization",
+            "552-invoke-non-existent-super",
+            "580-checker-round",
+            "580-checker-string-fact-intrinsics",
+            "594-invoke-super",
+            "605-new-string-from-bytes",
+            "626-const-class-linking"))
+        .put(DexVm.Version.V4_0_4, ImmutableList.of(
+            // Addition of checks for super-class-initialization cause this to abort on non-ToT art.
+            "008-exceptions",
+
+            // Fails due to non-matching Exception messages.
+            "201-built-in-except-detail-messages",
+
+            // Generally fails on non R8/D8 running.
+            "004-checker-UnsafeTest18",
+            "004-NativeAllocations",
+            "005-annotations",
+            "008-exceptions",
+            "082-inline-execute",
+            "099-vmdebug",
+            "143-string-value",
+            "156-register-dex-file-multi-loader",
+            "530-checker-lse2",
+            "536-checker-intrinsic-optimization",
+            "552-invoke-non-existent-super",
+            "580-checker-round",
+            "580-checker-string-fact-intrinsics",
+            "594-invoke-super",
+            "605-new-string-from-bytes",
+            "626-const-class-linking"));
+    expectedToFailRunWithArtVersion = builder.build();
+  }
 
   // Tests where the R8/D8 output runs in Art but the original does not.
   private static Multimap<String, TestCondition> failingRunWithArtOriginalOnly =
@@ -616,7 +650,11 @@
               TestCondition.match(
                   TestCondition.D8_COMPILER,
                   TestCondition
-                      .runtimes(DexVm.Version.V7_0_0, DexVm.Version.V6_0_1, DexVm.Version.V5_1_1)))
+                      .runtimes(
+                          DexVm.Version.V8_1_0,
+                          DexVm.Version.V7_0_0,
+                          DexVm.Version.V6_0_1,
+                          DexVm.Version.V5_1_1)))
           // lib64 libarttest.so: wrong ELF class ELFCLASS64.
           .put("543-env-long-ref",
               TestCondition.match(TestCondition.runtimesUpTo(DexVm.Version.V4_4_4)))
diff --git a/src/test/java/com/android/tools/r8/R8RunExamplesAndroidPTest.java b/src/test/java/com/android/tools/r8/R8RunExamplesAndroidPTest.java
index f4665a9..7d1a088 100644
--- a/src/test/java/com/android/tools/r8/R8RunExamplesAndroidPTest.java
+++ b/src/test/java/com/android/tools/r8/R8RunExamplesAndroidPTest.java
@@ -39,6 +39,10 @@
               ImmutableList.of(
                   "invokecustom-with-shrinking"
               ))
+          .put(DexVm.Version.V8_1_0,
+              ImmutableList.of(
+                  "invokecustom-with-shrinking"
+              ))
           .put(DexVm.Version.DEFAULT,
               ImmutableList.of(
               ))
diff --git a/src/test/java/com/android/tools/r8/RunExamplesAndroidPTest.java b/src/test/java/com/android/tools/r8/RunExamplesAndroidPTest.java
index 177fe89..e0981c4 100644
--- a/src/test/java/com/android/tools/r8/RunExamplesAndroidPTest.java
+++ b/src/test/java/com/android/tools/r8/RunExamplesAndroidPTest.java
@@ -186,6 +186,7 @@
           .put(DexVm.Version.V6_0_1, ImmutableList.of("invokecustom"))
           // Dex version not supported
           .put(DexVm.Version.V7_0_0, ImmutableList.of("invokecustom"))
+          .put(DexVm.Version.V8_1_0, ImmutableList.of("invokecustom"))
           .put(DexVm.Version.DEFAULT, ImmutableList.of())
           .build();
 
diff --git a/src/test/java/com/android/tools/r8/RunExamplesJava9Test.java b/src/test/java/com/android/tools/r8/RunExamplesJava9Test.java
index 99ac1f7..8a284ac 100644
--- a/src/test/java/com/android/tools/r8/RunExamplesJava9Test.java
+++ b/src/test/java/com/android/tools/r8/RunExamplesJava9Test.java
@@ -201,6 +201,10 @@
             // Dex version not supported
             "varhandle"
         ))
+        .put(DexVm.Version.V8_1_0, ImmutableList.of(
+            // Dex version not supported
+            "varhandle"
+        ))
         .put(DexVm.Version.DEFAULT, ImmutableList.of(
             // TODO(mikaelpeltier): Update runtime when the support will be ready
             "varhandle"
diff --git a/src/test/java/com/android/tools/r8/TestCondition.java b/src/test/java/com/android/tools/r8/TestCondition.java
index 865ca12..439b9e9 100644
--- a/src/test/java/com/android/tools/r8/TestCondition.java
+++ b/src/test/java/com/android/tools/r8/TestCondition.java
@@ -22,6 +22,7 @@
     ART_V5_1_1,
     ART_V6_0_1,
     ART_V7_0_0,
+    ART_V8_1_0,
     ART_DEFAULT,
     JAVA;
 
@@ -40,6 +41,8 @@
           return ART_V6_0_1;
         case V7_0_0:
           return ART_V7_0_0;
+        case V8_1_0:
+          return ART_V8_1_0;
         case DEFAULT:
           return ART_DEFAULT;
         default:
diff --git a/src/test/java/com/android/tools/r8/ToolHelper.java b/src/test/java/com/android/tools/r8/ToolHelper.java
index f968b8c..d4639a1 100644
--- a/src/test/java/com/android/tools/r8/ToolHelper.java
+++ b/src/test/java/com/android/tools/r8/ToolHelper.java
@@ -124,6 +124,8 @@
     ART_6_0_1_HOST(Version.V6_0_1, Kind.HOST),
     ART_7_0_0_TARGET(Version.V7_0_0, Kind.TARGET),
     ART_7_0_0_HOST(Version.V7_0_0, Kind.HOST),
+    ART_8_1_0_TARGET(Version.V8_1_0, Kind.TARGET),
+    ART_8_1_0_HOST(Version.V8_1_0, Kind.HOST),
     ART_DEFAULT(Version.DEFAULT, Kind.HOST);
 
     private static final ImmutableMap<String, DexVm> SHORT_NAME_MAP =
@@ -137,6 +139,7 @@
       V5_1_1("5.1.1"),
       V6_0_1("6.0.1"),
       V7_0_0("7.0.0"),
+      V8_1_0("8.1.0"),
       DEFAULT("default");
 
       Version(String shortName) {
@@ -413,6 +416,7 @@
   private static final Map<DexVm, String> ART_DIRS =
       ImmutableMap.<DexVm, String>builder()
           .put(DexVm.ART_DEFAULT, "art")
+          .put(DexVm.ART_8_1_0_HOST, "art-8.1.0")
           .put(DexVm.ART_7_0_0_HOST, "art-7.0.0")
           .put(DexVm.ART_6_0_1_HOST, "art-6.0.1")
           .put(DexVm.ART_5_1_1_HOST, "art-5.1.1")
@@ -421,6 +425,7 @@
   private static final Map<DexVm, String> ART_BINARY_VERSIONS =
       ImmutableMap.<DexVm, String>builder()
           .put(DexVm.ART_DEFAULT, "bin/art")
+          .put(DexVm.ART_8_1_0_HOST, "bin/art")
           .put(DexVm.ART_7_0_0_HOST, "bin/art")
           .put(DexVm.ART_6_0_1_HOST, "bin/art")
           .put(DexVm.ART_5_1_1_HOST, "bin/art")
@@ -430,6 +435,7 @@
   private static final Map<DexVm, String> ART_BINARY_VERSIONS_X64 =
       ImmutableMap.of(
           DexVm.ART_DEFAULT, "bin/art",
+          DexVm.ART_8_1_0_HOST, "bin/art",
           DexVm.ART_7_0_0_HOST, "bin/art",
           DexVm.ART_6_0_1_HOST, "bin/art");
 
@@ -451,6 +457,7 @@
     ImmutableMap.Builder<DexVm, List<String>> builder = ImmutableMap.builder();
     builder
         .put(DexVm.ART_DEFAULT, ART_BOOT_LIBS)
+        .put(DexVm.ART_8_1_0_HOST, ART_BOOT_LIBS)
         .put(DexVm.ART_7_0_0_HOST, ART_BOOT_LIBS)
         .put(DexVm.ART_6_0_1_HOST, ART_BOOT_LIBS)
         .put(DexVm.ART_5_1_1_HOST, ART_BOOT_LIBS)
@@ -459,6 +466,21 @@
     BOOT_LIBS = builder.build();
   }
 
+  private static final Map<DexVm, String> PRODUCT;
+
+  static {
+    ImmutableMap.Builder<DexVm, String> builder = ImmutableMap.builder();
+    builder
+        .put(DexVm.ART_DEFAULT, "angler")
+        .put(DexVm.ART_8_1_0_HOST, "marlin")
+        .put(DexVm.ART_7_0_0_HOST, "angler")
+        .put(DexVm.ART_6_0_1_HOST, "angler")
+        .put(DexVm.ART_5_1_1_HOST, "<missing>")
+        .put(DexVm.ART_4_4_4_HOST, "<missing>")
+        .put(DexVm.ART_4_0_4_HOST, "<missing>");
+    PRODUCT = builder.build();
+  }
+
   private static final Path DX = getDxExecutablePath();
 
   private static Path getDexVmPath(DexVm vm) {
@@ -478,12 +500,12 @@
     return getDexVmPath(vm).resolve("bin").resolve("dex2oat");
   }
 
-  private static Path getAnglerPath(DexVm vm) {
-    return getDexVmPath(vm).resolve("product").resolve("angler");
+  private static Path getProductPath(DexVm vm) {
+    return getDexVmPath(vm).resolve("product").resolve(PRODUCT.get(vm));
   }
 
-  private static Path getAnglerBootImagePath(DexVm vm) {
-    return getAnglerPath(vm).resolve("system").resolve("framework").resolve("boot.art");
+  private static Path getProductBootImagePath(DexVm vm) {
+    return getProductPath(vm).resolve("system").resolve("framework").resolve("boot.art");
   }
 
   public static byte[] getClassAsBytes(Class clazz) throws IOException {
@@ -695,6 +717,8 @@
     switch (dexVm.version) {
       case DEFAULT:
         return AndroidApiLevel.O;
+      case V8_1_0:
+        return AndroidApiLevel.O;
       case V7_0_0:
         return AndroidApiLevel.N;
       case V6_0_1:
@@ -1431,10 +1455,10 @@
     assert ByteStreams.toByteArray(Files.newInputStream(file)).length > 0;
     List<String> command = new ArrayList<>();
     command.add(getDex2OatPath(vm).toString());
-    command.add("--android-root=" + getAnglerPath(vm));
+    command.add("--android-root=" + getProductPath(vm));
     command.add("--runtime-arg");
     command.add("-Xnorelocate");
-    command.add("--boot-image=" + getAnglerBootImagePath(vm));
+    command.add("--boot-image=" + getProductBootImagePath(vm));
     command.add("--dex-file=" + file.toAbsolutePath());
     command.add("--oat-file=" + outFile.toAbsolutePath());
     command.add("--instruction-set=arm64");
diff --git a/src/test/java/com/android/tools/r8/jasmin/MemberResolutionTest.java b/src/test/java/com/android/tools/r8/jasmin/MemberResolutionTest.java
index 97eb99e..4dba00d 100644
--- a/src/test/java/com/android/tools/r8/jasmin/MemberResolutionTest.java
+++ b/src/test/java/com/android/tools/r8/jasmin/MemberResolutionTest.java
@@ -11,6 +11,7 @@
 import com.android.tools.r8.ToolHelper.ProcessResult;
 import com.android.tools.r8.VmTestRunner;
 import com.android.tools.r8.VmTestRunner.IgnoreForRangeOfVmVersions;
+import com.android.tools.r8.VmTestRunner.IgnoreForVmVersions;
 import com.android.tools.r8.jasmin.JasminBuilder.ClassBuilder;
 import com.android.tools.r8.jasmin.JasminBuilder.ClassFileVersion;
 import com.android.tools.r8.utils.ThrowingBiFunction;
@@ -468,6 +469,8 @@
   }
 
   @Test
+  // TODO(119938529): Triage.
+  @IgnoreForVmVersions(Version.V8_1_0)
   public void testRebindVirtualCallToStatic() throws Exception {
     // Library classes.
     JasminBuilder libraryBuilder = new JasminBuilder();
@@ -501,6 +504,8 @@
   }
 
   @Test
+  // TODO(119938529): Triage.
+  @IgnoreForVmVersions(Version.V8_1_0)
   public void testRebindVirtualCallToPackagePrivateStatic() throws Exception {
     // Library classes.
     JasminBuilder libraryBuilder = new JasminBuilder();
@@ -536,6 +541,8 @@
   }
 
   @Test
+  // TODO(119938529): Triage.
+  @IgnoreForVmVersions(Version.V8_1_0)
   public void testRebindVirtualCallToStaticInPackagePrivateClass() throws Exception {
     // Library classes.
     JasminBuilder libraryBuilder = new JasminBuilder();
diff --git a/src/test/java/com/android/tools/r8/regress/b78493232/Regress78493232_WithPhi.java b/src/test/java/com/android/tools/r8/regress/b78493232/Regress78493232_WithPhi.java
index 99f8c55..6ee7392 100644
--- a/src/test/java/com/android/tools/r8/regress/b78493232/Regress78493232_WithPhi.java
+++ b/src/test/java/com/android/tools/r8/regress/b78493232/Regress78493232_WithPhi.java
@@ -51,6 +51,7 @@
         case V4_0_4:
         case V4_4_4:
         case V7_0_0:
+        case V8_1_0:
         case DEFAULT:
           assertNotEquals(-1, d8Result.stderr.indexOf("java.lang.VerifyError"));
           assertNotEquals(-1, r8Result.stderr.indexOf("java.lang.VerifyError"));
diff --git a/tools/linux/README.art-versions b/tools/linux/README.art-versions
index ceb30a7..1512a64 100644
--- a/tools/linux/README.art-versions
+++ b/tools/linux/README.art-versions
@@ -42,6 +42,28 @@
   <continue with repo sync as above>
 
 
+art-8.1.0 (Android O MR1)
+-------------------------
+Build from branch android-8.1.0_r51.
+
+export BRANCH=android-8.1.0_r51
+mkdir ${BRANCH}
+cd ${BRANCH}
+repo init -u https://android.googlesource.com/platform/manifest -b ${BRANCH}
+repo sync -cq -j24
+source build/envsetup.sh
+lunch aosp_marlin-userdebug
+m -j24
+m -j24 build-art
+m -j24 test-art-host
+
+Collected into tools/linux/art-8.1.0.
+
+  scripts/update-host-art.sh \
+    --android-checkout /usr/local/ssd/android/${BRANCH} \
+    --art-dir art-8.1.0 \
+    --android-product marlin
+
 art-7.0.0
 ---------
 Build from branch android-7.0.0_r21 with the following patch:
diff --git a/tools/linux/art-8.1.0.tar.gz.sha1 b/tools/linux/art-8.1.0.tar.gz.sha1
new file mode 100644
index 0000000..91aea2f
--- /dev/null
+++ b/tools/linux/art-8.1.0.tar.gz.sha1
@@ -0,0 +1 @@
+0394edc4e2dbe9e5b04a81efede7578ecf20b853
\ No newline at end of file
diff --git a/tools/run-jdwp-tests.py b/tools/run-jdwp-tests.py
index 45f79e6..db69197 100755
--- a/tools/run-jdwp-tests.py
+++ b/tools/run-jdwp-tests.py
@@ -15,6 +15,7 @@
 
 VERSIONS = [
   'default',
+  '8.1.0',
   '7.0.0',
   '6.0.1',
   '5.1.1',
diff --git a/tools/test.py b/tools/test.py
index f1543f1..31b2134 100755
--- a/tools/test.py
+++ b/tools/test.py
@@ -18,7 +18,7 @@
 import upload_to_x20
 
 
-ALL_ART_VMS = ["default", "7.0.0", "6.0.1", "5.1.1", "4.4.4", "4.0.4"]
+ALL_ART_VMS = ["default", "8.1.0", "7.0.0", "6.0.1", "5.1.1", "4.4.4", "4.0.4"]
 BUCKET = 'r8-test-results'
 
 def ParseOptions():