Share boot image methods memory in JIT zygote.

Once the zygote is done compiling, copy the ArtMethods to
shared memory that will be in-place remapped. This is
a memory optimization that enables memory sharing between
zygote and early forked processes.

Currently relies on undefined behavior of the kernel, but will
follow-up with a CL that uses file sealing that will address this.

Saves around 2MB of memory for processes forked before zygote is
done compiling - there are around a dozen of processes.

Bug: 119800099
Test: boots, PostLaunchMemoryUsage
Change-Id: Ia1bdbd1abd27f28b087d9f33aca4cd901d55082f
diff --git a/runtime/jit/jit_code_cache.h b/runtime/jit/jit_code_cache.h
index 154700f..ea7614b 100644
--- a/runtime/jit/jit_code_cache.h
+++ b/runtime/jit/jit_code_cache.h
@@ -88,7 +88,7 @@
 // This map is writable only by the zygote, and readable by all children.
 class ZygoteMap {
  public:
-  explicit ZygoteMap(JitMemoryRegion* region) : map_(), region_(region) {}
+  explicit ZygoteMap(JitMemoryRegion* region) : map_(), region_(region), done_(nullptr) {}
 
   // Initialize the data structure so it can hold `number_of_methods` mappings.
   // Note that the map is fixed size and never grows.
@@ -106,6 +106,14 @@
     return GetCodeFor(method) != nullptr;
   }
 
+  void SetCompilationDone() {
+    region_->WriteData(done_, true);
+  }
+
+  bool IsCompilationDone() const {
+    return *done_;
+  }
+
  private:
   struct Entry {
     ArtMethod* method;
@@ -121,6 +129,8 @@
   // The region in which the map is allocated.
   JitMemoryRegion* const region_;
 
+  const bool* done_;
+
   DISALLOW_COPY_AND_ASSIGN(ZygoteMap);
 };