Add a mapping between ABIs and instruction sets.

Bridges the android ABI lists (TARGET_CPU_ABI, TARGET_CPU_ABI2
from the BoardConfig and android.os.Build.CPU_ABI) and the
runtime concept of an instruction set used for compilation
(the --instruction-set to dex2oat and so on).

(cherry picked from commit 6174cff204aa36e622e9bd93569b4a1eb2ed222c)

Change-Id: Id2eaa60f0546d6c88770f8981adac2a896ed7d49
diff --git a/libart/src/main/java/dalvik/system/VMRuntime.java b/libart/src/main/java/dalvik/system/VMRuntime.java
index 042bcd1..ae65950 100644
--- a/libart/src/main/java/dalvik/system/VMRuntime.java
+++ b/libart/src/main/java/dalvik/system/VMRuntime.java
@@ -16,6 +16,9 @@
 
 package dalvik.system;
 
+import java.util.HashMap;
+import java.util.Map;
+
 /**
  * Provides an interface to VM-global, Dalvik-specific features.
  * An application cannot create its own Runtime instance, and must obtain
@@ -30,6 +33,17 @@
      */
     private static final VMRuntime THE_ONE = new VMRuntime();
 
+    private static final Map<String, String> ABI_TO_INSTRUCTION_SET_MAP
+            = new HashMap<String, String>();
+    static {
+        ABI_TO_INSTRUCTION_SET_MAP.put("armeabi", "arm");
+        ABI_TO_INSTRUCTION_SET_MAP.put("armeabi-v7a", "arm");
+        ABI_TO_INSTRUCTION_SET_MAP.put("mips", "mips");
+        ABI_TO_INSTRUCTION_SET_MAP.put("x86", "x86");
+        ABI_TO_INSTRUCTION_SET_MAP.put("x86_64", "x86_64");
+        ABI_TO_INSTRUCTION_SET_MAP.put("arm64-v8a", "arm64");
+    }
+
     private int targetSdkVersion;
 
     /**
@@ -280,4 +294,20 @@
      * Register application info
      */
     public static native void registerAppInfo(String appDir, String processName, String pkgname);
+
+    /**
+     * Returns the runtime instruction set corresponding to a given ABI. Multiple
+     * compatible ABIs might map to the same instruction set. For example
+     * {@code armeabi-v7a} and {@code armeabi} might map to the instruction set {@code arm}.
+     *
+     * This influences the compilation of the applications classes.
+     */
+    public static String getInstructionSet(String abi) {
+        final String instructionSet = ABI_TO_INSTRUCTION_SET_MAP.get(abi);
+        if (instructionSet == null) {
+            throw new IllegalArgumentException("Unsupported ABI: " + abi);
+        }
+
+        return instructionSet;
+    }
 }
diff --git a/libdvm/src/main/java/dalvik/system/VMRuntime.java b/libdvm/src/main/java/dalvik/system/VMRuntime.java
index 3e4c160..d532210 100644
--- a/libdvm/src/main/java/dalvik/system/VMRuntime.java
+++ b/libdvm/src/main/java/dalvik/system/VMRuntime.java
@@ -16,6 +16,9 @@
 
 package dalvik.system;
 
+import java.util.HashMap;
+import java.util.Map;
+
 /**
  * Provides an interface to VM-global, Dalvik-specific features.
  * An application cannot create its own Runtime instance, and must obtain
@@ -30,6 +33,15 @@
      */
     private static final VMRuntime THE_ONE = new VMRuntime();
 
+    private static final Map<String, String> ABI_TO_INSTRUCTION_SET_MAP
+            = new HashMap<String, String>();
+    static {
+        ABI_TO_INSTRUCTION_SET_MAP.put("armeabi", "arm");
+        ABI_TO_INSTRUCTION_SET_MAP.put("armeabi-v7a", "arm");
+        ABI_TO_INSTRUCTION_SET_MAP.put("mips", "mips");
+        ABI_TO_INSTRUCTION_SET_MAP.put("x86", "x86");
+    }
+
     private int targetSdkVersion;
 
     /**
@@ -323,4 +335,20 @@
     public static void registerAppInfo(String appDir, String processName, String pkgname) {
         // Nothing to do in dalvik.
     }
+
+    /**
+     * Returns the runtime instruction set corresponding to a given ABI. Multiple
+     * compatible ABIs might map to the same instruction set. For example
+     * {@code armeabi-v7a} and {@code armeabi} might map to the instruction set {@code arm}.
+     *
+     * This influences the compilation of the applications classes.
+     */
+    public static String getInstructionSet(String abi) {
+        final String instructionSet = ABI_TO_INSTRUCTION_SET_MAP.get(abi);
+        if (instructionSet == null) {
+            throw new IllegalArgumentException("Unsupported ABI: " + abi);
+        }
+
+        return instructionSet;
+    }
 }