Add OatFileManager

Takes over a large amount of functionality from the class linker.

Changed OatFile to loading the same OatFile multiple times. This is
required for unloading OatFiles and moving dex caches to BSS since
these require a different OatFile for each dex cache and class
loader.

Bug: 22720414

Change-Id: I0321096723a294dc72949f21e66da82727b512fc
diff --git a/runtime/runtime.h b/runtime/runtime.h
index 6154c34..abccb44 100644
--- a/runtime/runtime.h
+++ b/runtime/runtime.h
@@ -82,6 +82,7 @@
 class MonitorList;
 class MonitorPool;
 class NullPointerHandler;
+class OatFileManager;
 class SignalCatcher;
 class StackOverflowHandler;
 class SuspensionHandler;
@@ -573,6 +574,11 @@
   // Create a normal LinearAlloc or low 4gb version if we are 64 bit AOT compiler.
   LinearAlloc* CreateLinearAlloc();
 
+  OatFileManager& GetOatFileManager() const {
+    DCHECK(oat_file_manager_ != nullptr);
+    return *oat_file_manager_.get();
+  }
+
  private:
   static void InitPlatformSignalHandlers();
 
@@ -770,6 +776,9 @@
   // Contains the build fingerprint, if given as a parameter.
   std::string fingerprint_;
 
+  // Oat file manager, keeps track of what oat files are open.
+  std::unique_ptr<OatFileManager> oat_file_manager_;
+
   DISALLOW_COPY_AND_ASSIGN(Runtime);
 };
 std::ostream& operator<<(std::ostream& os, const Runtime::CalleeSaveType& rhs);