ART: Refactor ImageSpace loading
Make the code more straightforward so it is easier to reason
about and extend.
Also change return types to unique pointers so it's clear that
it is the caller's responsibility to free those when necessary.
Bug: 30832951
Test: m test-art-host
Test: device booting
Change-Id: I3216eb702e45357a48af5158dacbe40e79bd1ae9
diff --git a/runtime/gc/space/image_space.h b/runtime/gc/space/image_space.h
index c9741d0..534232d 100644
--- a/runtime/gc/space/image_space.h
+++ b/runtime/gc/space/image_space.h
@@ -43,24 +43,19 @@
// creation of the alloc space. The ReleaseOatFile will later be
// used to transfer ownership of the OatFile to the ClassLinker when
// it is initialized.
- static ImageSpace* CreateBootImage(const char* image,
+ static std::unique_ptr<ImageSpace> CreateBootImage(const char* image,
InstructionSet image_isa,
bool secondary_image,
std::string* error_msg)
SHARED_REQUIRES(Locks::mutator_lock_);
// Try to open an existing app image space.
- static ImageSpace* CreateFromAppImage(const char* image,
- const OatFile* oat_file,
- std::string* error_msg)
+ static std::unique_ptr<ImageSpace> CreateFromAppImage(const char* image,
+ const OatFile* oat_file,
+ std::string* error_msg)
SHARED_REQUIRES(Locks::mutator_lock_);
// Reads the image header from the specified image location for the
- // instruction set image_isa or dies trying.
- static ImageHeader* ReadImageHeaderOrDie(const char* image_location,
- InstructionSet image_isa);
-
- // Reads the image header from the specified image location for the
// instruction set image_isa. Returns null on failure, with
// reason in error_msg.
static ImageHeader* ReadImageHeader(const char* image_location,
@@ -158,21 +153,13 @@
// relative to its DexFile inputs. Otherwise (for /data), validate the inputs and generate the
// OatFile in /data/dalvik-cache if necessary. If the oat_file is null, it uses the oat file from
// the image.
- static ImageSpace* Init(const char* image_filename,
- const char* image_location,
- bool validate_oat_file,
- const OatFile* oat_file,
- std::string* error_msg)
+ static std::unique_ptr<ImageSpace> Init(const char* image_filename,
+ const char* image_location,
+ bool validate_oat_file,
+ const OatFile* oat_file,
+ std::string* error_msg)
SHARED_REQUIRES(Locks::mutator_lock_);
- OatFile* OpenOatFile(const char* image, std::string* error_msg) const
- SHARED_REQUIRES(Locks::mutator_lock_);
-
- bool ValidateOatFile(std::string* error_msg) const
- SHARED_REQUIRES(Locks::mutator_lock_);
-
- friend class Space;
-
static Atomic<uint32_t> bitmap_index_;
std::unique_ptr<accounting::ContinuousSpaceBitmap> live_bitmap_;
@@ -194,6 +181,9 @@
const std::string image_location_;
+ friend class ImageSpaceLoader;
+ friend class Space;
+
private:
DISALLOW_COPY_AND_ASSIGN(ImageSpace);
};