Register tests for profiling after the runtime has started

Ensure that the profile saver thread starts after the runtime finishes
starting. In test mode (when -Xps-profile-path is passed) we were
registering the app info to early.

Test: run-test 927-timers
Change-Id: Iede588524dda3ff60aa3e2c61ed1d906f63a6c70
diff --git a/runtime/runtime.cc b/runtime/runtime.cc
index d0aec11..2074f1e 100644
--- a/runtime/runtime.cc
+++ b/runtime/runtime.cc
@@ -844,6 +844,18 @@
                  0);
   }
 
+  // In case we have a profile path passed as a command line argument,
+  // register the current class path for profiling now. Note that we cannot do
+  // this before we create the JIT and having it here is the most convenient way.
+  // This is used when testing profiles with dalvikvm command as there is no
+  // framework to register the dex files for profiling.
+  if (jit_.get() != nullptr && jit_options_->GetSaveProfilingInfo() &&
+      !jit_options_->GetProfileSaverOptions().GetProfilePath().empty()) {
+    std::vector<std::string> dex_filenames;
+    Split(class_path_string_, ':', &dex_filenames);
+    RegisterAppInfo(dex_filenames, jit_options_->GetProfileSaverOptions().GetProfilePath());
+  }
+
   return true;
 }
 
@@ -2410,18 +2422,6 @@
     LOG(WARNING) << "Failed to create JIT " << error_msg;
     return;
   }
-
-  // In case we have a profile path passed as a command line argument,
-  // register the current class path for profiling now. Note that we cannot do
-  // this before we create the JIT and having it here is the most convenient way.
-  // This is used when testing profiles with dalvikvm command as there is no
-  // framework to register the dex files for profiling.
-  if (jit_options_->GetSaveProfilingInfo() &&
-      !jit_options_->GetProfileSaverOptions().GetProfilePath().empty()) {
-    std::vector<std::string> dex_filenames;
-    Split(class_path_string_, ':', &dex_filenames);
-    RegisterAppInfo(dex_filenames, jit_options_->GetProfileSaverOptions().GetProfilePath());
-  }
 }
 
 bool Runtime::CanRelocate() const {