Compile less stuff

Don't compile class initializers, compile programs with fewer than
commmand-line specified number of methods, mildly refactor SLOW_MODE,
rename into LIGHT_MODE.

Also, walks the image for uncompiled methods and fixes up with pointers to the
interpreter entry point.

(Removed hot method list and light method limit as these are experimental.)

Change-Id: I2ae33d8add84ab9f4d76f9d910cae422c81a7832
diff --git a/src/dex2oat.cc b/src/dex2oat.cc
index ecba628..97212ce 100644
--- a/src/dex2oat.cc
+++ b/src/dex2oat.cc
@@ -137,6 +137,8 @@
   UsageError("      Use a separate --runtime-arg switch for each argument.");
   UsageError("      Example: --runtime-arg -Xms256m");
   UsageError("");
+  UsageError("  --light-mode: compile only if generating image file");
+  UsageError("");
   std::cerr << "See log for usage error information\n";
   exit(EXIT_FAILURE);
 }
@@ -144,14 +146,15 @@
 class Dex2Oat {
  public:
   static bool Create(Dex2Oat** p_dex2oat, Runtime::Options& options, CompilerBackend compiler_backend,
-                     InstructionSet instruction_set, size_t thread_count, bool support_debugging)
+                     InstructionSet instruction_set, size_t thread_count, bool support_debugging,
+                     bool light_mode)
       SHARED_TRYLOCK_FUNCTION(true, Locks::mutator_lock_) {
     if (!CreateRuntime(options, instruction_set)) {
       *p_dex2oat = NULL;
       return false;
     }
     *p_dex2oat = new Dex2Oat(Runtime::Current(), compiler_backend, instruction_set, thread_count,
-                             support_debugging);
+                             support_debugging, light_mode);
     return true;
   }
 
@@ -160,6 +163,7 @@
     LOG(INFO) << "dex2oat took " << PrettyDuration(NanoTime() - start_ns_) << " (threads: " << thread_count_ << ")";
   }
 
+
   // Make a list of descriptors for classes to include in the image
   const std::set<std::string>* GetImageClassDescriptors(const char* image_classes_filename)
       SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
@@ -261,6 +265,7 @@
                                                         image,
                                                         thread_count_,
                                                         support_debugging_,
+                                                        light_mode_,
                                                         image_classes,
                                                         dump_stats,
                                                         dump_timings));
@@ -339,14 +344,23 @@
     return true;
   }
 
+  void SetLightMode(bool light_mode) {
+    light_mode_ = light_mode;
+  }
+
+  bool GetLightMode() {
+    return light_mode_;
+  }
+
  private:
   explicit Dex2Oat(Runtime* runtime, CompilerBackend compiler_backend, InstructionSet instruction_set,
-                   size_t thread_count, bool support_debugging)
+                   size_t thread_count, bool support_debugging, bool light_mode)
       : compiler_backend_(compiler_backend),
         instruction_set_(instruction_set),
         runtime_(runtime),
         thread_count_(thread_count),
         support_debugging_(support_debugging),
+        light_mode_(light_mode),
         start_ns_(NanoTime()) {
   }
 
@@ -484,6 +498,7 @@
   Runtime* runtime_;
   size_t thread_count_;
   bool support_debugging_;
+  bool light_mode_;
   uint64_t start_ns_;
 
   DISALLOW_IMPLICIT_CONSTRUCTORS(Dex2Oat);
@@ -671,6 +686,7 @@
   std::vector<const char*> runtime_args;
   int thread_count = sysconf(_SC_NPROCESSORS_CONF);
   bool support_debugging = false;
+  bool light_mode = false;
 #if defined(ART_USE_PORTABLE_COMPILER)
   CompilerBackend compiler_backend = kPortable;
 #else
@@ -690,6 +706,10 @@
   bool dump_timings = kIsDebugBuild;
   bool watch_dog_enabled = !kIsTargetBuild;
 
+#if ART_LIGHT_MODE
+  light_mode = true;
+#endif // ART_LIGHT_MODE
+
   for (int i = 0; i < argc; i++) {
     const StringPiece option(argv[i]);
     bool log_options = false;
@@ -718,6 +738,8 @@
       }
     } else if (option == "-g") {
       support_debugging = true;
+    } else if (option == "--light-mode") {
+      light_mode = true;
     } else if (option == "--watch-dog") {
       watch_dog_enabled = true;
     } else if (option == "--no-watch-dog") {
@@ -923,7 +945,7 @@
   }
 
   Dex2Oat* p_dex2oat;
-  if (!Dex2Oat::Create(&p_dex2oat, options, compiler_backend, instruction_set, thread_count, support_debugging)) {
+  if (!Dex2Oat::Create(&p_dex2oat, options, compiler_backend, instruction_set, thread_count, support_debugging, light_mode)) {
     LOG(ERROR) << "Failed to create dex2oat";
     return EXIT_FAILURE;
   }
@@ -970,6 +992,7 @@
     }
   }
 
+
   UniquePtr<const CompilerDriver> compiler(dex2oat->CreateOatFile(boot_image_option,
                                                                   host_prefix.get(),
                                                                   android_root,