Change JIT code to use optimizing.

Obviously, will fall back to quick for most methods currently,
due to lack of -QUICK opcodes support.

Change-Id: I28882fbe805cd907275b6047437d9639a475964a
diff --git a/compiler/jit/jit_compiler.cc b/compiler/jit/jit_compiler.cc
index a1d8226..a122ceb 100644
--- a/compiler/jit/jit_compiler.cc
+++ b/compiler/jit/jit_compiler.cc
@@ -71,18 +71,18 @@
       CompilerOptions::kDefaultSmallMethodThreshold,
       CompilerOptions::kDefaultTinyMethodThreshold,
       CompilerOptions::kDefaultNumDexMethodsThreshold,
-      false,
+      /* include_patch_information */ false,
       CompilerOptions::kDefaultTopKProfileThreshold,
-      false,  // TODO: Think about debuggability of JIT-compiled code.
+      Runtime::Current()->IsDebuggable(),
       CompilerOptions::kDefaultGenerateDebugInfo,
-      false,
-      false,
-      false,
-      false,  // pic
-      nullptr,
+      /* implicit_null_checks */ true,
+      /* implicit_so_checks */ true,
+      /* implicit_suspend_checks */ false,
+      /* pic */ true,  // TODO: Support non-PIC in optimizing.
+      /* verbose_methods */ nullptr,
       pass_manager_options,
-      nullptr,
-      false));
+      /* init_failure_output */ nullptr,
+      /* abort_on_hard_verifier_failure */ false));
   const InstructionSet instruction_set = kRuntimeISA;
   instruction_set_features_.reset(InstructionSetFeatures::FromCppDefines());
   cumulative_logger_.reset(new CumulativeLogger("jit times"));
@@ -92,10 +92,23 @@
                                               method_inliner_map_.get(),
                                               CompilerCallbacks::CallbackMode::kCompileApp));
   compiler_driver_.reset(new CompilerDriver(
-      compiler_options_.get(), verification_results_.get(), method_inliner_map_.get(),
-      Compiler::kQuick, instruction_set, instruction_set_features_.get(), false,
-      nullptr, nullptr, nullptr, 1, false, true,
-      std::string(), cumulative_logger_.get(), -1, std::string()));
+      compiler_options_.get(),
+      verification_results_.get(),
+      method_inliner_map_.get(),
+      Compiler::kOptimizing,
+      instruction_set,
+      instruction_set_features_.get(),
+      /* image */ false,
+      /* image_classes */ nullptr,
+      /* compiled_classes */ nullptr,
+      /* compiled_methods */ nullptr,
+      /* thread_count */ 1,
+      /* dump_stats */ false,
+      /* dump_passes */ false,
+      /* dump_cfg_file_name */ "",
+      cumulative_logger_.get(),
+      /* swap_fd */ -1,
+      /* profile_file */ ""));
   // Disable dedupe so we can remove compiled methods.
   compiler_driver_->SetDedupeEnabled(false);
   compiler_driver_->SetSupportBootImageFixup(false);
@@ -195,9 +208,14 @@
   std::copy(quick_code->data(), quick_code->data() + code_size, code_ptr);
   // After we are done writing we need to update the method header.
   // Write out the method header last.
-  method_header = new(method_header)OatQuickMethodHeader(
-      code_ptr - mapping_table, code_ptr - vmap_table, code_ptr - gc_map, frame_size_in_bytes,
-      core_spill_mask, fp_spill_mask, code_size);
+  method_header = new(method_header) OatQuickMethodHeader(
+      (mapping_table == nullptr) ? 0 : code_ptr - mapping_table,
+      (vmap_table == nullptr) ? 0 : code_ptr - vmap_table,
+      (gc_map == nullptr) ? 0 : code_ptr - gc_map,
+      frame_size_in_bytes,
+      core_spill_mask,
+      fp_spill_mask,
+      code_size);
   // Return the code ptr.
   return code_ptr;
 }
@@ -216,23 +234,35 @@
   auto* const mapping_table = compiled_method->GetMappingTable();
   auto* const vmap_table = compiled_method->GetVmapTable();
   auto* const gc_map = compiled_method->GetGcMap();
-  CHECK(gc_map != nullptr) << PrettyMethod(method);
-  // Write out pre-header stuff.
-  uint8_t* const mapping_table_ptr = code_cache->AddDataArray(
-      self, mapping_table->data(), mapping_table->data() + mapping_table->size());
-  if (mapping_table_ptr == nullptr) {
-    return false;  // Out of data cache.
+  uint8_t* mapping_table_ptr = nullptr;
+  uint8_t* vmap_table_ptr = nullptr;
+  uint8_t* gc_map_ptr = nullptr;
+
+  if (mapping_table != nullptr) {
+    // Write out pre-header stuff.
+    mapping_table_ptr = code_cache->AddDataArray(
+        self, mapping_table->data(), mapping_table->data() + mapping_table->size());
+    if (mapping_table_ptr == nullptr) {
+      return false;  // Out of data cache.
+    }
   }
-  uint8_t* const vmap_table_ptr = code_cache->AddDataArray(
-      self, vmap_table->data(), vmap_table->data() + vmap_table->size());
-  if (vmap_table_ptr == nullptr) {
-    return false;  // Out of data cache.
+
+  if (vmap_table != nullptr) {
+    vmap_table_ptr = code_cache->AddDataArray(
+        self, vmap_table->data(), vmap_table->data() + vmap_table->size());
+    if (vmap_table_ptr == nullptr) {
+      return false;  // Out of data cache.
+    }
   }
-  uint8_t* const gc_map_ptr = code_cache->AddDataArray(
-      self, gc_map->data(), gc_map->data() + gc_map->size());
-  if (gc_map_ptr == nullptr) {
-    return false;  // Out of data cache.
+
+  if (gc_map != nullptr) {
+    gc_map_ptr = code_cache->AddDataArray(
+        self, gc_map->data(), gc_map->data() + gc_map->size());
+    if (gc_map_ptr == nullptr) {
+      return false;  // Out of data cache.
+    }
   }
+
   // Don't touch this until you protect / unprotect the code.
   const size_t reserve_size = sizeof(OatQuickMethodHeader) + quick_code->size() + 32;
   uint8_t* const code_reserve = code_cache->ReserveCode(self, reserve_size);
diff --git a/runtime/oat_file_assistant.cc b/runtime/oat_file_assistant.cc
index b28adf9..df0cf45 100644
--- a/runtime/oat_file_assistant.cc
+++ b/runtime/oat_file_assistant.cc
@@ -698,18 +698,13 @@
     return false;
   }
 
-  ClassLinker* linker = runtime->GetClassLinker();
-  CHECK(linker != nullptr) << "ClassLinker is not created yet";
-  const OatFile* primary_oat_file = linker->GetPrimaryOatFile();
-  const bool debuggable = primary_oat_file != nullptr && primary_oat_file->IsDebuggable();
-
   std::vector<std::string> argv;
   argv.push_back(runtime->GetCompilerExecutable());
   argv.push_back("--runtime-arg");
   argv.push_back("-classpath");
   argv.push_back("--runtime-arg");
   argv.push_back(runtime->GetClassPathString());
-  if (debuggable) {
+  if (runtime->IsDebuggable()) {
     argv.push_back("--debuggable");
   }
   runtime->AddCurrentRuntimeFeaturesAsDex2OatArguments(&argv);
diff --git a/runtime/runtime.cc b/runtime/runtime.cc
index 5067b0d..884662d 100644
--- a/runtime/runtime.cc
+++ b/runtime/runtime.cc
@@ -680,6 +680,11 @@
   return IsShuttingDownLocked();
 }
 
+bool Runtime::IsDebuggable() const {
+  const OatFile* oat_file = GetClassLinker()->GetPrimaryOatFile();
+  return oat_file != nullptr && oat_file->IsDebuggable();
+}
+
 void Runtime::StartDaemonThreads() {
   VLOG(startup) << "Runtime::StartDaemonThreads entering";
 
diff --git a/runtime/runtime.h b/runtime/runtime.h
index bcc7118..6fd1b07 100644
--- a/runtime/runtime.h
+++ b/runtime/runtime.h
@@ -552,6 +552,8 @@
     return method_ref_string_init_reg_map_;
   }
 
+  bool IsDebuggable() const;
+
  private:
   static void InitPlatformSignalHandlers();