Make use of profiling information for dex2oat

If the profile file exists, the compiler driver will read it
and store the data in an internal map.  Then, when we want to work
out whether to compile a method or not, the map is consulted and if
the method shows up with a high enough percentage of use we compile it.

The profile file itself is created by installd and is writeable by the
app.  The file is in /data/dalvik-cache/profiles and is named by
the package name.

This also modifies the profiler itself to:

1. Only count runnable threads (not suspended threads) in the profile
2. Use system properties to allow tuning of the profile parameters
3. Merge profiles from multiple processes using file locking.

Bug: 12877748
Change-Id: Iab2f3a327a2860db2a80d5724277d6c626227f2b

Conflicts:
	compiler/dex/frontend.cc
	compiler/dex/mir_analysis.cc
	compiler/dex/verification_results.cc
	compiler/driver/compiler_driver.cc
	dex2oat/dex2oat.cc
	runtime/class_linker.cc
	runtime/runtime.cc
	runtime/runtime.h
diff --git a/dex2oat/dex2oat.cc b/dex2oat/dex2oat.cc
index 7c81ffb..cc78816 100644
--- a/dex2oat/dex2oat.cc
+++ b/dex2oat/dex2oat.cc
@@ -200,6 +200,8 @@
   UsageError("      such as initial heap size, maximum heap size, and verbose output.");
   UsageError("      Use a separate --runtime-arg switch for each argument.");
   UsageError("      Example: --runtime-arg -Xms256m");
+    UsageError("");
+    UsageError("  --profile-file=<filename>: specify profiler output file to use for compilation.");
   UsageError("");
   std::cerr << "See log for usage error information\n";
   exit(EXIT_FAILURE);
@@ -310,7 +312,8 @@
                                       bool dump_stats,
                                       bool dump_passes,
                                       TimingLogger& timings,
-                                      CumulativeLogger& compiler_phases_timings) {
+                                      CumulativeLogger& compiler_phases_timings,
+                                      std::string profile_file) {
     // SirtRef and ClassLoader creation needs to come after Runtime::Create
     jobject class_loader = NULL;
     Thread* self = Thread::Current();
@@ -340,7 +343,8 @@
                                                         thread_count_,
                                                         dump_stats,
                                                         dump_passes,
-                                                        &compiler_phases_timings));
+                                                        &compiler_phases_timings,
+                                                        profile_file));
 
     driver->GetCompilerBackend()->SetBitcodeFileName(*driver.get(), bitcode_filename);
 
@@ -742,6 +746,8 @@
   InstructionSet instruction_set = kNone;
 #endif
 
+  // Profile file to use
+  std::string profile_file;
 
   bool is_host = false;
   bool dump_stats = false;
@@ -896,6 +902,12 @@
       dump_passes = true;
     } else if (option == "--dump-stats") {
       dump_stats = true;
+    } else if (option.starts_with("--profile-file=")) {
+      profile_file = option.substr(strlen("--profile-file=")).data();
+      VLOG(compiler) << "dex2oat: profile file is " << profile_file;
+    } else if (option == "--no-profile-file") {
+      LOG(INFO) << "dex2oat: no profile file supplied (explictly)";
+      // No profile
     } else {
       Usage("Unknown argument %s", option.data());
     }
@@ -1204,7 +1216,8 @@
                                                                   dump_stats,
                                                                   dump_passes,
                                                                   timings,
-                                                                  compiler_phases_timings));
+                                                                  compiler_phases_timings,
+                                                                  profile_file));
 
   if (compiler.get() == NULL) {
     LOG(ERROR) << "Failed to create oat file: " << oat_location;