Revert "Revert "Revert "Revert "Add implicit null and stack checks for x86""""

This reverts commit 0025a86411145eb7cd4971f9234fc21c7b4aced1.

Bug: 16256184
Change-Id: Ie0760a0c293aa3b62e2885398a8c512b7a946a73
diff --git a/runtime/runtime.cc b/runtime/runtime.cc
index 0ddd2ae..aca2607 100644
--- a/runtime/runtime.cc
+++ b/runtime/runtime.cc
@@ -141,7 +141,10 @@
       suspend_handler_(nullptr),
       stack_overflow_handler_(nullptr),
       verify_(false),
-      target_sdk_version_(0) {
+      target_sdk_version_(0),
+      implicit_null_checks_(false),
+      implicit_so_checks_(false),
+      implicit_suspend_checks_(false) {
   for (int i = 0; i < Runtime::kLastCalleeSaveType; i++) {
     callee_save_methods_[i] = nullptr;
   }
@@ -581,41 +584,6 @@
     GetInstrumentation()->ForceInterpretOnly();
   }
 
-  bool implicit_checks_supported = false;
-  switch (kRuntimeISA) {
-    case kArm:
-    case kThumb2:
-      implicit_checks_supported = true;
-      break;
-    default:
-      break;
-  }
-
-  if (!options->interpreter_only_ && implicit_checks_supported &&
-      (options->explicit_checks_ != (ParsedOptions::kExplicitSuspendCheck |
-          ParsedOptions::kExplicitNullCheck |
-          ParsedOptions::kExplicitStackOverflowCheck) || kEnableJavaStackTraceHandler)) {
-    fault_manager.Init();
-
-    // These need to be in a specific order.  The null point check handler must be
-    // after the suspend check and stack overflow check handlers.
-    if ((options->explicit_checks_ & ParsedOptions::kExplicitSuspendCheck) == 0) {
-      suspend_handler_ = new SuspensionHandler(&fault_manager);
-    }
-
-    if ((options->explicit_checks_ & ParsedOptions::kExplicitStackOverflowCheck) == 0) {
-      stack_overflow_handler_ = new StackOverflowHandler(&fault_manager);
-    }
-
-    if ((options->explicit_checks_ & ParsedOptions::kExplicitNullCheck) == 0) {
-      null_pointer_handler_ = new NullPointerHandler(&fault_manager);
-    }
-
-    if (kEnableJavaStackTraceHandler) {
-      new JavaStackTraceHandler(&fault_manager);
-    }
-  }
-
   heap_ = new gc::Heap(options->heap_initial_size_,
                        options->heap_growth_limit_,
                        options->heap_min_free_,
@@ -648,6 +616,42 @@
   BlockSignals();
   InitPlatformSignalHandlers();
 
+  // Change the implicit checks flags based on runtime architecture.
+  switch (kRuntimeISA) {
+    case kArm:
+    case kThumb2:
+    case kX86:
+      implicit_null_checks_ = true;
+      implicit_so_checks_ = true;
+      break;
+    default:
+      // Keep the defaults.
+      break;
+  }
+
+  if (!options->interpreter_only_ &&
+    (implicit_null_checks_ || implicit_so_checks_ || implicit_suspend_checks_)) {
+    fault_manager.Init();
+
+    // These need to be in a specific order.  The null point check handler must be
+    // after the suspend check and stack overflow check handlers.
+    if (implicit_suspend_checks_) {
+      suspend_handler_ = new SuspensionHandler(&fault_manager);
+    }
+
+    if (implicit_so_checks_) {
+      stack_overflow_handler_ = new StackOverflowHandler(&fault_manager);
+    }
+
+    if (implicit_null_checks_) {
+      null_pointer_handler_ = new NullPointerHandler(&fault_manager);
+    }
+
+    if (kEnableJavaStackTraceHandler) {
+      new JavaStackTraceHandler(&fault_manager);
+    }
+  }
+
   java_vm_ = new JavaVMExt(this, options.get());
 
   Thread::Startup();
@@ -1222,37 +1226,6 @@
     argv->push_back("--compiler-filter=interpret-only");
   }
 
-  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.