Pass instruction-set from runtime through to spawned dex2oat.

Change-Id: I1727af7beb9f710c29124d4d6bc9175e4856f3cc
diff --git a/runtime/runtime.cc b/runtime/runtime.cc
index a830018..b0a6584 100644
--- a/runtime/runtime.cc
+++ b/runtime/runtime.cc
@@ -79,6 +79,8 @@
 namespace art {
 
 static constexpr bool kEnableJavaStackTraceHandler = true;
+const char* Runtime::kDefaultInstructionSetFeatures =
+    STRINGIFY(ART_DEFAULT_INSTRUCTION_SET_FEATURES);
 Runtime* Runtime::instance_ = NULL;
 
 Runtime::Runtime()
@@ -1216,6 +1218,59 @@
   fault_message_ = message;
 }
 
+void Runtime::AddCurrentRuntimeFeaturesAsDex2OatArguments(std::vector<std::string>* argv)
+    const {
+  argv->push_back("--runtime-arg");
+  std::string checkstr = "-implicit-checks";
+
+  int nchecks = 0;
+  char checksep = ':';
+
+  if (!ExplicitNullChecks()) {
+    checkstr += checksep;
+    checksep = ',';
+    checkstr += "null";
+    ++nchecks;
+  }
+  if (!ExplicitSuspendChecks()) {
+    checkstr += checksep;
+    checksep = ',';
+    checkstr += "suspend";
+    ++nchecks;
+  }
+
+  if (!ExplicitStackOverflowChecks()) {
+    checkstr += checksep;
+    checksep = ',';
+    checkstr += "stack";
+    ++nchecks;
+  }
+
+  if (nchecks == 0) {
+    checkstr += ":none";
+  }
+  argv->push_back(checkstr);
+
+  // Make the dex2oat instruction set match that of the launching runtime. If we have multiple
+  // architecture support, dex2oat may be compiled as a different instruction-set than that
+  // currently being executed.
+#if defined(__arm__)
+  argv->push_back("--instruction-set=arm");
+#elif defined(__aarch64__)
+  argv->push_back("--instruction-set=arm64");
+#elif defined(__i386__)
+  argv->push_back("--instruction-set=x86");
+#elif defined(__x86_64__)
+  argv->push_back("--instruction-set=x86_64");
+#elif defined(__mips__)
+  argv->push_back("--instruction-set=mips");
+#endif
+
+  std::string features("--instruction-set-features=");
+  features += GetDefaultInstructionSetFeatures();
+  argv->push_back(features);
+}
+
 void Runtime::UpdateProfilerState(int state) {
   LOG(DEBUG) << "Profiler state updated to " << state;
 }