Fix logic to find dex2oat.

On device, we now have dex2oat64/dex2oat32 with no symlinks, so be
explicit on the bitness when trying to find the executable.

Bug: 153380900
Test: run-gtests.sh, testrunner.py, run-libcore-tests, run-libjdwp-tests
Change-Id: I796eedc84d75aaa2a525d3ed2cbcbe157e5220fb
diff --git a/oatdump/oatdump_test.cc b/oatdump/oatdump_test.cc
index ccd2272..0c98cc1 100644
--- a/oatdump/oatdump_test.cc
+++ b/oatdump/oatdump_test.cc
@@ -97,7 +97,8 @@
       "_export.dex";
   const std::string dexdump = GetExecutableFilePath("dexdump",
                                                     /*is_debug=*/false,
-                                                    /*is_static=*/false);
+                                                    /*is_static=*/false,
+                                                    /*bitness=*/false);
   std::string output;
   auto post_fork_fn = []() { return true; };
   ForkAndExecResult res = ForkAndExec({dexdump, "-d", dex_location}, post_fork_fn, &output);
diff --git a/oatdump/oatdump_test.h b/oatdump/oatdump_test.h
index f47c4d2..6f4616e 100644
--- a/oatdump/oatdump_test.h
+++ b/oatdump/oatdump_test.h
@@ -71,7 +71,7 @@
   };
 
   // Returns path to the oatdump/dex2oat/dexdump binary.
-  std::string GetExecutableFilePath(const char* name, bool is_debug, bool is_static) {
+  std::string GetExecutableFilePath(const char* name, bool is_debug, bool is_static, bool bitness) {
     std::string path = GetArtBinDir() + '/' + name;
     if (is_debug) {
       path += 'd';
@@ -79,11 +79,14 @@
     if (is_static) {
       path += 's';
     }
+    if (bitness) {
+      path += Is64BitInstructionSet(kRuntimeISA) ? "64" : "32";
+    }
     return path;
   }
 
-  std::string GetExecutableFilePath(Flavor flavor, const char* name) {
-    return GetExecutableFilePath(name, kIsDebugBuild, flavor == kStatic);
+  std::string GetExecutableFilePath(Flavor flavor, const char* name, bool bitness) {
+    return GetExecutableFilePath(name, kIsDebugBuild, flavor == kStatic, bitness);
   }
 
   enum Mode {
@@ -124,7 +127,8 @@
 
   ::testing::AssertionResult GenerateAppOdexFile(Flavor flavor,
                                                  const std::vector<std::string>& args) {
-    std::string dex2oat_path = GetExecutableFilePath(flavor, "dex2oat");
+    std::string dex2oat_path =
+        GetExecutableFilePath(flavor, "dex2oat", /* bitness= */ kIsTargetBuild);
     std::vector<std::string> exec_argv = {
         dex2oat_path,
         "--runtime-arg",
@@ -167,7 +171,7 @@
                                   const std::vector<std::string>& args,
                                   Display display,
                                   bool expect_failure = false) {
-    std::string file_path = GetExecutableFilePath(flavor, "oatdump");
+    std::string file_path = GetExecutableFilePath(flavor, "oatdump", /* bitness= */ false);
 
     if (!OS::FileExists(file_path.c_str())) {
       return ::testing::AssertionFailure() << file_path << " should be a valid file path";
diff --git a/runtime/runtime.cc b/runtime/runtime.cc
index d7682bb..8fbc178 100644
--- a/runtime/runtime.cc
+++ b/runtime/runtime.cc
@@ -818,6 +818,9 @@
   if (kIsDebugBuild) {
     compiler_executable += 'd';
   }
+  if (kIsTargetBuild) {
+    compiler_executable += Is64BitInstructionSet(kRuntimeISA) ? "64" : "32";
+  }
   return compiler_executable;
 }
 
diff --git a/test/etc/run-test-jar b/test/etc/run-test-jar
index fc74f05..2c65ea2 100755
--- a/test/etc/run-test-jar
+++ b/test/etc/run-test-jar
@@ -30,8 +30,8 @@
 DEBUGGER_AGENT=""
 WRAP_DEBUGGER_AGENT="n"
 DEV_MODE="n"
-DEX2OAT_NDEBUG_BINARY="dex2oat"
-DEX2OAT_DEBUG_BINARY="dex2oatd"
+DEX2OAT_NDEBUG_BINARY="dex2oat32"
+DEX2OAT_DEBUG_BINARY="dex2oatd32"
 EXPERIMENTAL=""
 FALSE_BIN="false"
 FLAGS=""
@@ -266,6 +266,11 @@
         ANDROID_ART_ROOT="${ANDROID_HOST_OUT}/com.android.art"
         ANDROID_I18N_ROOT="${ANDROID_HOST_OUT}/com.android.i18n"
         ANDROID_TZDATA_ROOT="${ANDROID_HOST_OUT}/com.android.tzdata"
+        # On host, we default to using the symlink, as the PREFER_32BIT
+        # configuration is the only configuration building a 32bit version of
+        # dex2oat.
+        DEX2OAT_DEBUG_BINARY="dex2oatd"
+        DEX2OAT_NDEBUG_BINARY="dex2oat"
         shift
     elif [ "x$1" = "x--bionic" ]; then
         BIONIC="y"
@@ -427,6 +432,8 @@
         TEST_DIRECTORY="nativetest64"
         ARCHITECTURES_PATTERN="${ARCHITECTURES_64}"
         GET_DEVICE_ISA_BITNESS_FLAG="--64"
+        DEX2OAT_NDEBUG_BINARY="dex2oat64"
+        DEX2OAT_DEBUG_BINARY="dex2oatd64"
         shift
     elif [ "x$1" = "x--experimental" ]; then
         if [ "$#" -lt 2 ]; then
diff --git a/tools/art b/tools/art
index ea379a8..19fbb8c 100644
--- a/tools/art
+++ b/tools/art
@@ -302,6 +302,7 @@
 ######################################
 ART_BINARY=dalvikvm
 DEX2OAT_BINARY=dex2oat
+DEX2OAT_SUFFIX="32"
 DELETE_ANDROID_DATA="no"
 LAUNCH_WRAPPER=
 LIBART=libart.so
@@ -324,15 +325,17 @@
     ;;
   --32)
     ART_BINARY=dalvikvm32
+    DEX2OAT_SUFFIX=32
     ;;
   --64)
     ART_BINARY=dalvikvm64
+    DEX2OAT_SUFFIX=64
     ;;
   -d)
     ;& # Fallthrough
   --debug)
     LIBART="libartd.so"
-    DEX2OAT_BINARY=dex2oatd
+    DEX2OAT_BINARY="dex2oatd"
     # Expect that debug mode wants all checks.
     EXTRA_OPTIONS+=(-XX:SlowDebug=true)
     ;;
@@ -478,7 +481,7 @@
   exit 1
 fi
 
-DEX2OAT_BINARY_PATH=$ANDROID_ROOT/bin/$DEX2OAT_BINARY
+DEX2OAT_BINARY_PATH=$ANDROID_ROOT/bin/$DEX2OAT_BINARY$DEX2OAT_SUFFIX
 
 if [ ! -x "$DEX2OAT_BINARY_PATH" ]; then
   echo "Warning: Android Compiler not found: $DEX2OAT_BINARY_PATH"