Adding oat_process

- Added oat_process, a version of app_process use to launch frameworks apps
- Added liboat_runtime, a version of libandroid_runtime that uses art instead of dvm
  This is just a special makefile, frameworks/base/core/jni code is used for source
- Added support for build a boot.oat with the full BOOTCLASSPATH
  The older smaller boat.oat is now core.oat
- Added mem_map code for making sure a requested memory region is available
  Moved mem_map code to cc file to make easier to debug with smaller rebuild
- Moved oat base address to 0x6000000 as a work around to host addres conflict
- Added -Xms and -Xmx options to dex2oat to allow build specific memory options
- Fixed miranda method initialization problem found compiling full bootclasspath
- Made compiler.cc tolerant of verification errors found compiling full bootclasspath
- Bumped arena block alloc warning to avoid noise when compiling full bootclasspath
- Marked implicit GC unimplemented to fail fast
- Added --output argument to oatdump
- Made many object asserts tolerate access in IsErroneous state
  now that verifier is failing validation of some classes during compilation
- Made runtime tolerate unknown access as short term solution for oat_process
- Workaround SSA issue to restore full bootclasspath compilation
- Added test-art-target-processs to excercise oat_process with "am"
  "am" found bug where class_linker was using Method::GetClass and not ::GetDeclaringClass

Change-Id: I1a645a142b163e06bab9e72eb094ae1f1dbfbd97
diff --git a/src/oatdump.cc b/src/oatdump.cc
index 7578fb1..52cddb5 100644
--- a/src/oatdump.cc
+++ b/src/oatdump.cc
@@ -3,6 +3,8 @@
 #include <stdio.h>
 #include <stdlib.h>
 
+#include <fstream>
+#include <iostream>
 #include <string>
 #include <vector>
 
@@ -45,6 +47,10 @@
           "       the generated image to match the target file system layout.\n"
           "      Example: --strip-prefix=out/target/product/crespo\n"
           "\n");
+  fprintf(stderr,
+          "  --output=<file> may be used to send the output to a file.\n"
+          "      Example: --output=/tmp/oatdump.txt\n"
+          "\n");
   exit(EXIT_FAILURE);
 }
 
@@ -52,15 +58,32 @@
   "kJniStubArray",
 };
 
-struct OatDump {
-  const Space* dump_space;
+class OatDump {
 
-  bool InDumpSpace(const Object* object) {
-    DCHECK(dump_space != NULL);
-    const byte* o = reinterpret_cast<const byte*>(object);
-    return (o >= dump_space->GetBase() && o < dump_space->GetLimit());
+ public:
+  static void Dump(std::ostream& os, Space& image_space, const ImageHeader& image_header) {
+    os << "MAGIC:\n";
+    os << image_header.GetMagic() << "\n\n";
+
+    os << "ROOTS:\n";
+    for (int i = 0; i < ImageHeader::kImageRootsMax; i++) {
+      ImageHeader::ImageRoot image_root = static_cast<ImageHeader::ImageRoot>(i);
+      os << StringPrintf("%s: %p\n",
+                         image_roots_descriptions_[i], image_header.GetImageRoot(image_root));
+    }
+    os << "\n";
+
+    os << "OBJECTS:\n" << std::flush;
+    OatDump state(image_space, os);
+    HeapBitmap* heap_bitmap = Heap::GetLiveBits();
+    DCHECK(heap_bitmap != NULL);
+    heap_bitmap->Walk(OatDump::Callback, &state);
   }
 
+ private:
+
+  OatDump(const Space& dump_space, std::ostream& os) : dump_space_(dump_space_), os_(os) {}
+
   static void Callback(Object* obj, void* arg) {
     DCHECK(obj != NULL);
     DCHECK(arg != NULL);
@@ -106,8 +129,15 @@
         }
       }
     }
-    std::cout << summary;
+    state->os_ << summary << std::flush;
   }
+
+  bool InDumpSpace(const Object* object) {
+    const byte* o = reinterpret_cast<const byte*>(object);
+    return (o >= dump_space_.GetBase() && o < dump_space_.GetLimit());
+  }
+  const Space& dump_space_;
+  std::ostream& os_;
 };
 
 int oatdump(int argc, char** argv) {
@@ -125,6 +155,8 @@
   const char* boot_image_filename = NULL;
   std::vector<const char*> boot_dex_filenames;
   std::string strip_location_prefix;
+  std::ostream* os = &std::cout;
+  UniquePtr<std::ofstream> out;
 
   for (int i = 0; i < argc; i++) {
     const StringPiece option(argv[i]);
@@ -138,6 +170,14 @@
       boot_dex_filenames.push_back(option.substr(strlen("--boot-dex-file=")).data());
     } else if (option.starts_with("--strip-prefix=")) {
       strip_location_prefix = option.substr(strlen("--strip-prefix=")).data();
+    } else if (option.starts_with("--output=")) {
+      const char* filename = option.substr(strlen("--output=")).data();
+      out.reset(new std::ofstream(filename));
+      if (!out->good()) {
+        fprintf(stderr, "failed to open output filename %s\n", filename);
+        usage();
+      }
+      os = out.get();
     } else {
       fprintf(stderr, "unknown argument %s\n", option.data());
       usage();
@@ -202,24 +242,7 @@
     fprintf(stderr, "invalid image header %s\n", image_filename);
     return EXIT_FAILURE;
   }
-
-  printf("MAGIC:\n");
-  printf("%s\n\n", image_header.GetMagic());
-
-  printf("ROOTS:\n");
-  for (int i = 0; i < ImageHeader::kImageRootsMax; i++) {
-    ImageHeader::ImageRoot image_root = static_cast<ImageHeader::ImageRoot>(i);
-    printf("%s: %p\n", image_roots_descriptions_[i], image_header.GetImageRoot(image_root));
-  }
-  printf("\n");
-
-  printf("OBJECTS:\n");
-  OatDump state;
-  state.dump_space = image_space;
-  HeapBitmap* heap_bitmap = Heap::GetLiveBits();
-  DCHECK(heap_bitmap != NULL);
-  heap_bitmap->Walk(OatDump::Callback, &state);
-
+  OatDump::Dump(*os, *image_space, image_header);
   return EXIT_SUCCESS;
 }