Moving from libdvm to libart (1 of 5)

Change-Id: I6541802c5f403a4ba4424818084b94bebe71dfca
diff --git a/src/class_linker.cc b/src/class_linker.cc
index d59323b..caf2876 100644
--- a/src/class_linker.cc
+++ b/src/class_linker.cc
@@ -556,34 +556,41 @@
 const OatFile* ClassLinker::GenerateOatFile(const std::string& filename) {
   std::string oat_filename(GetArtCacheFilenameOrDie(OatFile::DexFilenameToOatFilename(filename)));
 
+  std::string dex2oat_string("/system/bin/dex2oat");
+#ifndef NDEBUG
+  dex2oat_string += 'd';
+#endif
+  const char* dex2oat = dex2oat_string.c_str();
+
+  const char* class_path = Runtime::Current()->GetClassPath().c_str();
+
+  std::string boot_image_option_string("--boot-image=");
+  boot_image_option_string += Heap::GetSpaces()[0]->GetImageFilename();
+  const char* boot_image_option = boot_image_option_string.c_str();
+
+  std::string dex_file_option_string("--dex-file=");
+  dex_file_option_string += filename;
+  const char* dex_file_option = dex_file_option_string.c_str();
+
+  std::string oat_file_option_string("--oat=");
+  oat_file_option_string += oat_filename;
+  const char* oat_file_option = oat_file_option_string.c_str();
+
   // fork and exec dex2oat
   pid_t pid = fork();
   if (pid == 0) {
-    std::string boot_image_option("--boot-image=");
-    boot_image_option += Heap::GetSpaces()[0]->GetImageFilename();
-
-    std::string dex_file_option("--dex-file=");
-    dex_file_option += filename;
-
-    std::string oat_file_option("--oat=");
-    oat_file_option += oat_filename;
-
-    std::string dex2oat("/system/bin/dex2oat");
-#ifndef NDEBUG
-    dex2oat += 'd';
-#endif
-
-    execl(dex2oat.c_str(), dex2oat.c_str(),
+    // no allocation allowed between fork and exec
+    execl(dex2oat, dex2oat,
           "--runtime-arg", "-Xms64m",
           "--runtime-arg", "-Xmx64m",
           "--runtime-arg", "-classpath",
-          "--runtime-arg", Runtime::Current()->GetClassPath().c_str(),
-          boot_image_option.c_str(),
-          dex_file_option.c_str(),
-          oat_file_option.c_str(),
+          "--runtime-arg", class_path,
+          boot_image_option,
+          dex_file_option,
+          oat_file_option,
           NULL);
 
-    PLOG(FATAL) << "execl(dex2oatd) failed";
+    PLOG(FATAL) << "execl(" << dex2oat << ") failed";
     return NULL;
   } else {
     // wait for dex2oat to finish
@@ -594,7 +601,7 @@
       return NULL;
     }
     if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) {
-      LOG(ERROR) << "dex2oatd failed with dex-file=" << filename;
+      LOG(ERROR) << dex2oat << " failed with dex-file=" << filename;
       return NULL;
     }
   }
diff --git a/src/dex2oat.cc b/src/dex2oat.cc
index da07dbd..ab63a48 100644
--- a/src/dex2oat.cc
+++ b/src/dex2oat.cc
@@ -33,11 +33,11 @@
           "\n");
   fprintf(stderr,
           "  --oat=<file.oat>: specifies the required oat filename.\n"
-          "      Example: --oat=/data/art-cache/boot.oat\n"
+          "      Example: --oat=/system/framework/boot.oat\n"
           "\n");
   fprintf(stderr,
           "  --image=<file.art>: specifies the output image filename.\n"
-          "      Example: --image=/data/art-cache/boot.art\n"
+          "      Example: --image=/system/framework/boot.art\n"
           "\n");
   fprintf(stderr,
           "  --image-classes=<classname-file>: specifies classes to include in an image.\n"
@@ -49,8 +49,8 @@
           "\n");
   fprintf(stderr,
           "  --boot-image=<file.art>: provide the image file for the boot class path.\n"
-          "      Example: --boot-image=/data/art-cache/boot.art\n"
-          "      Default: <host-prefix>/data/art-cache/boot.art\n"
+          "      Example: --boot-image=/system/framework/boot.art\n"
+          "      Default: <host-prefix>/system/framework/boot.art\n"
           "\n");
   fprintf(stderr,
           "  --host-prefix may be used to translate host paths to target paths during\n"
diff --git a/src/oatdump.cc b/src/oatdump.cc
index 2006827..3b204c0 100644
--- a/src/oatdump.cc
+++ b/src/oatdump.cc
@@ -23,20 +23,20 @@
 static void usage() {
   fprintf(stderr,
           "Usage: oatdump [options] ...\n"
-          "    Example: oatdump --image=$ANDROID_PRODUCT_OUT/data/art-cache/boot.art --host-prefix=$ANDROID_PRODUCT_OUT\n"
-          "    Example: adb shell oatdump --image=/data/art-cache/boot.art\n"
+          "    Example: oatdump --image=$ANDROID_PRODUCT_OUT/system/framework/boot.art --host-prefix=$ANDROID_PRODUCT_OUT\n"
+          "    Example: adb shell oatdump --image=/system/framework/boot.art\n"
           "\n");
   fprintf(stderr,
           "  --oat=<file.oat>: specifies an input oat filename.\n"
-          "      Example: --image=/data/art-cache/boot.oat\n"
+          "      Example: --image=/system/framework/boot.oat\n"
           "\n");
   fprintf(stderr,
           "  --image=<file.art>: specifies an input image filename.\n"
-          "      Example: --image=/data/art-cache/boot.art\n"
+          "      Example: --image=/system/framework/boot.art\n"
           "\n");
   fprintf(stderr,
           "  --boot-image=<file.art>: provide the image file for the boot class path.\n"
-          "      Example: --boot-image=/data/art-cache/boot.art\n"
+          "      Example: --boot-image=/system/framework/boot.art\n"
           "\n");
   fprintf(stderr,
           "  --host-prefix may be used to translate host paths to target paths during\n"
diff --git a/src/runtime.cc b/src/runtime.cc
index ad86e05..cfb1b29 100644
--- a/src/runtime.cc
+++ b/src/runtime.cc
@@ -394,7 +394,7 @@
   }
 
   if (!compiler && parsed->images_.empty()) {
-    parsed->images_.push_back("/data/art-cache/boot.art");
+    parsed->images_.push_back("/system/framework/boot.art");
   }
   if (parsed->heap_growth_limit_ == 0) {
     parsed->heap_growth_limit_ = parsed->heap_maximum_size_;
diff --git a/src/runtime.h b/src/runtime.h
index b5e6954..7f5f6f6 100644
--- a/src/runtime.h
+++ b/src/runtime.h
@@ -221,7 +221,7 @@
 
   // The host prefix is used during cross compilation. It is removed
   // from the start of host paths such as:
-  //    $ANDROID_PRODUCT_OUT/data/art-cache/boot.oat
+  //    $ANDROID_PRODUCT_OUT/system/framework/boot.oat
   // to produce target paths such as
   //    /system/framework/boot.oat
   // Similarly it is prepended to target paths to arrive back at a