Separate MemMap from DexFile completely
Create a container class for holding ownership of MemMap and segregate
that functionality to dex_file_loader. This removes the dependency
between dex_file.cc and mem_map.cc.
Bug: 22322814
Test: make test-art-host
Change-Id: I96db6fd10cdbad774c2f1f85c249418a154fbd52
diff --git a/runtime/dex_file.h b/runtime/dex_file.h
index 53e1f9e..c895e0d 100644
--- a/runtime/dex_file.h
+++ b/runtime/dex_file.h
@@ -39,6 +39,21 @@
class StringPiece;
class ZipArchive;
+// Some instances of DexFile own the storage referred to by DexFile. Clients who create
+// such management do so by subclassing Container.
+class DexFileContainer {
+ public:
+ DexFileContainer() { }
+ virtual ~DexFileContainer() { }
+ virtual int GetPermissions() = 0;
+ virtual bool IsReadOnly() = 0;
+ virtual bool EnableWrite() = 0;
+ virtual bool DisableWrite() = 0;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(DexFileContainer);
+};
+
// Dex file is the API that exposes native dex files (ordinary dex files) and CompactDex.
// Originally, the dex file format used by ART was mostly the same as APKs. The only change was
// quickened opcodes and layout optimizations.
@@ -993,7 +1008,8 @@
size_t size,
const std::string& location,
uint32_t location_checksum,
- const OatDexFile* oat_dex_file);
+ const OatDexFile* oat_dex_file,
+ DexFileContainer* container);
// Top-level initializer that calls other Init methods.
bool Init(std::string* error_msg);
@@ -1018,9 +1034,6 @@
const uint32_t location_checksum_;
- // Manages the underlying memory allocation.
- std::unique_ptr<MemMap> mem_map_;
-
// Points to the header section.
const Header* const header_;
@@ -1059,6 +1072,9 @@
// null.
mutable const OatDexFile* oat_dex_file_;
+ // Manages the underlying memory allocation.
+ std::unique_ptr<DexFileContainer> container_;
+
friend class DexFileLoader;
friend class DexFileVerifierTest;
friend class OatWriter;