summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--compiler/driver/compiler_driver.cc1
-rw-r--r--compiler/driver/compiler_driver.h2
-rw-r--r--compiler/elf_writer.cc1
-rw-r--r--compiler/llvm/compiler_llvm.cc1
-rw-r--r--runtime/class_linker.cc55
-rw-r--r--runtime/class_linker.h2
-rw-r--r--runtime/gc/heap.cc133
-rw-r--r--runtime/gc/heap.h6
-rw-r--r--runtime/gc/space/image_space.cc188
-rw-r--r--runtime/gc/space/image_space.h39
-rw-r--r--runtime/oat_file.h9
11 files changed, 254 insertions, 183 deletions
diff --git a/compiler/driver/compiler_driver.cc b/compiler/driver/compiler_driver.cc
index c99d103c17..9e71dff464 100644
--- a/compiler/driver/compiler_driver.cc
+++ b/compiler/driver/compiler_driver.cc
@@ -26,7 +26,6 @@
#include "dex_compilation_unit.h"
#include "dex_file-inl.h"
#include "jni_internal.h"
-#include "oat_file.h"
#include "object_utils.h"
#include "runtime.h"
#include "gc/accounting/card_table-inl.h"
diff --git a/compiler/driver/compiler_driver.h b/compiler/driver/compiler_driver.h
index d37f494ef1..4d7f0cf7b6 100644
--- a/compiler/driver/compiler_driver.h
+++ b/compiler/driver/compiler_driver.h
@@ -29,7 +29,7 @@
#include "instruction_set.h"
#include "invoke_type.h"
#include "method_reference.h"
-#include "oat_file.h"
+#include "os.h"
#include "runtime.h"
#include "safe_map.h"
#include "thread_pool.h"
diff --git a/compiler/elf_writer.cc b/compiler/elf_writer.cc
index 0823a53f87..70d17de102 100644
--- a/compiler/elf_writer.cc
+++ b/compiler/elf_writer.cc
@@ -27,7 +27,6 @@
#include "mirror/abstract_method-inl.h"
#include "mirror/object-inl.h"
#include "oat.h"
-#include "oat_file.h"
#include "scoped_thread_state_change.h"
namespace art {
diff --git a/compiler/llvm/compiler_llvm.cc b/compiler/llvm/compiler_llvm.cc
index afca223192..4475b25043 100644
--- a/compiler/llvm/compiler_llvm.cc
+++ b/compiler/llvm/compiler_llvm.cc
@@ -26,7 +26,6 @@
#include "ir_builder.h"
#include "jni/portable/jni_compiler.h"
#include "llvm_compilation_unit.h"
-#include "oat_file.h"
#include "utils_llvm.h"
#include "verifier/method_verifier.h"
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc
index e35b95c1e9..fbceb597f0 100644
--- a/runtime/class_linker.cc
+++ b/runtime/class_linker.cc
@@ -680,35 +680,12 @@ void ClassLinker::RegisterOatFileLocked(const OatFile& oat_file) {
oat_files_.push_back(&oat_file);
}
-OatFile* ClassLinker::OpenOat(const gc::space::ImageSpace* space) {
+OatFile& ClassLinker::GetImageOatFile(gc::space::ImageSpace* space) {
+ VLOG(startup) << "ClassLinker::GetImageOatFile entering";
+ OatFile& oat_file = space->ReleaseOatFile();
WriterMutexLock mu(Thread::Current(), dex_lock_);
- const Runtime* runtime = Runtime::Current();
- const ImageHeader& image_header = space->GetImageHeader();
- // Grab location but don't use Object::AsString as we haven't yet initialized the roots to
- // check the down cast
- mirror::String* oat_location =
- down_cast<mirror::String*>(image_header.GetImageRoot(ImageHeader::kOatLocation));
- std::string oat_filename;
- oat_filename += runtime->GetHostPrefix();
- oat_filename += oat_location->ToModifiedUtf8();
- runtime->GetHeap()->UnReserveOatFileAddressRange();
- OatFile* oat_file = OatFile::Open(oat_filename, oat_filename, image_header.GetOatDataBegin(),
- !Runtime::Current()->IsCompiler());
- VLOG(startup) << "ClassLinker::OpenOat entering oat_filename=" << oat_filename;
- if (oat_file == NULL) {
- LOG(ERROR) << "Failed to open oat file " << oat_filename << " referenced from image.";
- return NULL;
- }
- uint32_t oat_checksum = oat_file->GetOatHeader().GetChecksum();
- uint32_t image_oat_checksum = image_header.GetOatChecksum();
- if (oat_checksum != image_oat_checksum) {
- LOG(ERROR) << "Failed to match oat file checksum " << std::hex << oat_checksum
- << " to expected oat checksum " << std::hex << image_oat_checksum
- << " in image";
- return NULL;
- }
- RegisterOatFileLocked(*oat_file);
- VLOG(startup) << "ClassLinker::OpenOat exiting";
+ RegisterOatFileLocked(oat_file);
+ VLOG(startup) << "ClassLinker::GetImageOatFile exiting";
return oat_file;
}
@@ -952,13 +929,13 @@ void ClassLinker::InitFromImage() {
gc::Heap* heap = Runtime::Current()->GetHeap();
gc::space::ImageSpace* space = heap->GetImageSpace();
- OatFile* oat_file = OpenOat(space);
- CHECK(oat_file != NULL) << "Failed to open oat file for image";
- CHECK_EQ(oat_file->GetOatHeader().GetImageFileLocationOatChecksum(), 0U);
- CHECK_EQ(oat_file->GetOatHeader().GetImageFileLocationOatDataBegin(), 0U);
- CHECK(oat_file->GetOatHeader().GetImageFileLocation().empty());
- portable_resolution_trampoline_ = oat_file->GetOatHeader().GetPortableResolutionTrampoline();
- quick_resolution_trampoline_ = oat_file->GetOatHeader().GetQuickResolutionTrampoline();
+ CHECK(space != NULL);
+ OatFile& oat_file = GetImageOatFile(space);
+ CHECK_EQ(oat_file.GetOatHeader().GetImageFileLocationOatChecksum(), 0U);
+ CHECK_EQ(oat_file.GetOatHeader().GetImageFileLocationOatDataBegin(), 0U);
+ CHECK(oat_file.GetOatHeader().GetImageFileLocation().empty());
+ portable_resolution_trampoline_ = oat_file.GetOatHeader().GetPortableResolutionTrampoline();
+ quick_resolution_trampoline_ = oat_file.GetOatHeader().GetQuickResolutionTrampoline();
mirror::Object* dex_caches_object = space->GetImageHeader().GetImageRoot(ImageHeader::kDexCaches);
mirror::ObjectArray<mirror::DexCache>* dex_caches =
dex_caches_object->AsObjectArray<mirror::DexCache>();
@@ -971,18 +948,18 @@ void ClassLinker::InitFromImage() {
// as being Strings or not
mirror::String::SetClass(GetClassRoot(kJavaLangString));
- CHECK_EQ(oat_file->GetOatHeader().GetDexFileCount(),
+ CHECK_EQ(oat_file.GetOatHeader().GetDexFileCount(),
static_cast<uint32_t>(dex_caches->GetLength()));
Thread* self = Thread::Current();
for (int i = 0; i < dex_caches->GetLength(); i++) {
SirtRef<mirror::DexCache> dex_cache(self, dex_caches->Get(i));
const std::string& dex_file_location(dex_cache->GetLocation()->ToModifiedUtf8());
- const OatFile::OatDexFile* oat_dex_file = oat_file->GetOatDexFile(dex_file_location);
- CHECK(oat_dex_file != NULL) << oat_file->GetLocation() << " " << dex_file_location;
+ const OatFile::OatDexFile* oat_dex_file = oat_file.GetOatDexFile(dex_file_location);
+ CHECK(oat_dex_file != NULL) << oat_file.GetLocation() << " " << dex_file_location;
const DexFile* dex_file = oat_dex_file->OpenDexFile();
if (dex_file == NULL) {
LOG(FATAL) << "Failed to open dex file " << dex_file_location
- << " from within oat file " << oat_file->GetLocation();
+ << " from within oat file " << oat_file.GetLocation();
}
CHECK_EQ(dex_file->GetLocationChecksum(), oat_dex_file->GetDexFileLocationChecksum());
diff --git a/runtime/class_linker.h b/runtime/class_linker.h
index df336724fa..df1ecc6207 100644
--- a/runtime/class_linker.h
+++ b/runtime/class_linker.h
@@ -359,7 +359,7 @@ class ClassLinker {
// Initialize class linker from one or more images.
void InitFromImage() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
- OatFile* OpenOat(const gc::space::ImageSpace* space)
+ OatFile& GetImageOatFile(gc::space::ImageSpace* space)
LOCKS_EXCLUDED(dex_lock_)
SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
static void InitFromImageCallback(mirror::Object* obj, void* arg)
diff --git a/runtime/gc/heap.cc b/runtime/gc/heap.cc
index a68cc02435..53b8cd9550 100644
--- a/runtime/gc/heap.cc
+++ b/runtime/gc/heap.cc
@@ -18,8 +18,6 @@
#define ATRACE_TAG ATRACE_TAG_DALVIK
#include <cutils/trace.h>
-#include <sys/types.h>
-#include <sys/wait.h>
#include <limits>
#include <vector>
@@ -66,96 +64,6 @@ static const bool kDumpGcPerformanceOnShutdown = false;
static const size_t kMinConcurrentRemainingBytes = 128 * KB;
const double Heap::kDefaultTargetUtilization = 0.5;
-static bool GenerateImage(const std::string& image_file_name) {
- const std::string boot_class_path_string(Runtime::Current()->GetBootClassPathString());
- std::vector<std::string> boot_class_path;
- Split(boot_class_path_string, ':', boot_class_path);
- if (boot_class_path.empty()) {
- LOG(FATAL) << "Failed to generate image because no boot class path specified";
- }
-
- std::vector<char*> arg_vector;
-
- std::string dex2oat_string(GetAndroidRoot());
- dex2oat_string += (kIsDebugBuild ? "/bin/dex2oatd" : "/bin/dex2oat");
- const char* dex2oat = dex2oat_string.c_str();
- arg_vector.push_back(strdup(dex2oat));
-
- std::string image_option_string("--image=");
- image_option_string += image_file_name;
- const char* image_option = image_option_string.c_str();
- arg_vector.push_back(strdup(image_option));
-
- arg_vector.push_back(strdup("--runtime-arg"));
- arg_vector.push_back(strdup("-Xms64m"));
-
- arg_vector.push_back(strdup("--runtime-arg"));
- arg_vector.push_back(strdup("-Xmx64m"));
-
- for (size_t i = 0; i < boot_class_path.size(); i++) {
- std::string dex_file_option_string("--dex-file=");
- dex_file_option_string += boot_class_path[i];
- const char* dex_file_option = dex_file_option_string.c_str();
- arg_vector.push_back(strdup(dex_file_option));
- }
-
- std::string oat_file_option_string("--oat-file=");
- oat_file_option_string += image_file_name;
- oat_file_option_string.erase(oat_file_option_string.size() - 3);
- oat_file_option_string += "oat";
- const char* oat_file_option = oat_file_option_string.c_str();
- arg_vector.push_back(strdup(oat_file_option));
-
- std::string base_option_string(StringPrintf("--base=0x%x", ART_BASE_ADDRESS));
- arg_vector.push_back(strdup(base_option_string.c_str()));
-
- if (kIsTargetBuild) {
- arg_vector.push_back(strdup("--image-classes-zip=/system/framework/framework.jar"));
- arg_vector.push_back(strdup("--image-classes=preloaded-classes"));
- } else {
- arg_vector.push_back(strdup("--host"));
- }
-
- std::string command_line(Join(arg_vector, ' '));
- LOG(INFO) << command_line;
-
- arg_vector.push_back(NULL);
- char** argv = &arg_vector[0];
-
- // fork and exec dex2oat
- pid_t pid = fork();
- if (pid == 0) {
- // no allocation allowed between fork and exec
-
- // change process groups, so we don't get reaped by ProcessManager
- setpgid(0, 0);
-
- execv(dex2oat, argv);
-
- PLOG(FATAL) << "execv(" << dex2oat << ") failed";
- return false;
- } else {
- STLDeleteElements(&arg_vector);
-
- // wait for dex2oat to finish
- int status;
- pid_t got_pid = TEMP_FAILURE_RETRY(waitpid(pid, &status, 0));
- if (got_pid != pid) {
- PLOG(ERROR) << "waitpid failed: wanted " << pid << ", got " << got_pid;
- return false;
- }
- if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) {
- LOG(ERROR) << dex2oat << " failed: " << command_line;
- return false;
- }
- }
- return true;
-}
-
-void Heap::UnReserveOatFileAddressRange() {
- oat_file_map_.reset(NULL);
-}
-
Heap::Heap(size_t initial_size, size_t growth_limit, size_t min_free, size_t max_free,
double target_utilization, size_t capacity,
const std::string& original_image_file_name, bool concurrent_gc)
@@ -206,45 +114,20 @@ Heap::Heap(size_t initial_size, size_t growth_limit, size_t min_free, size_t max
mark_bitmap_.reset(new accounting::HeapBitmap(this));
// Requested begin for the alloc space, to follow the mapped image and oat files
- byte* requested_begin = NULL;
+ byte* requested_alloc_space_begin = NULL;
std::string image_file_name(original_image_file_name);
if (!image_file_name.empty()) {
- space::ImageSpace* image_space = NULL;
-
- if (OS::FileExists(image_file_name.c_str())) {
- // If the /system file exists, it should be up-to-date, don't try to generate
- image_space = space::ImageSpace::Create(image_file_name);
- } else {
- // If the /system file didn't exist, we need to use one from the dalvik-cache.
- // If the cache file exists, try to open, but if it fails, regenerate.
- // If it does not exist, generate.
- image_file_name = GetDalvikCacheFilenameOrDie(image_file_name);
- if (OS::FileExists(image_file_name.c_str())) {
- image_space = space::ImageSpace::Create(image_file_name);
- }
- if (image_space == NULL) {
- CHECK(GenerateImage(image_file_name)) << "Failed to generate image: " << image_file_name;
- image_space = space::ImageSpace::Create(image_file_name);
- }
- }
-
- CHECK(image_space != NULL) << "Failed to create space from " << image_file_name;
+ space::ImageSpace* image_space = space::ImageSpace::Create(image_file_name);
+ CHECK(image_space != NULL) << "Failed to create space for " << image_file_name;
AddContinuousSpace(image_space);
// Oat files referenced by image files immediately follow them in memory, ensure alloc space
// isn't going to get in the middle
byte* oat_file_end_addr = image_space->GetImageHeader().GetOatFileEnd();
CHECK_GT(oat_file_end_addr, image_space->End());
-
- // Reserve address range from image_space->End() to image_space->GetImageHeader().GetOatEnd()
- uintptr_t reserve_begin = RoundUp(reinterpret_cast<uintptr_t>(image_space->End()), kPageSize);
- uintptr_t reserve_end = RoundUp(reinterpret_cast<uintptr_t>(oat_file_end_addr), kPageSize);
- oat_file_map_.reset(MemMap::MapAnonymous("oat file reserve",
- reinterpret_cast<byte*>(reserve_begin),
- reserve_end - reserve_begin, PROT_NONE));
-
- if (oat_file_end_addr > requested_begin) {
- requested_begin = reinterpret_cast<byte*>(RoundUp(reinterpret_cast<uintptr_t>(oat_file_end_addr),
- kPageSize));
+ if (oat_file_end_addr > requested_alloc_space_begin) {
+ requested_alloc_space_begin =
+ reinterpret_cast<byte*>(RoundUp(reinterpret_cast<uintptr_t>(oat_file_end_addr),
+ kPageSize));
}
}
@@ -261,7 +144,7 @@ Heap::Heap(size_t initial_size, size_t growth_limit, size_t min_free, size_t max
alloc_space_ = space::DlMallocSpace::Create("alloc space",
initial_size,
growth_limit, capacity,
- requested_begin);
+ requested_alloc_space_begin);
CHECK(alloc_space_ != NULL) << "Failed to create alloc space";
alloc_space_->SetFootprintLimit(alloc_space_->Capacity());
AddContinuousSpace(alloc_space_);
diff --git a/runtime/gc/heap.h b/runtime/gc/heap.h
index 790ab0216d..e6c92211d4 100644
--- a/runtime/gc/heap.h
+++ b/runtime/gc/heap.h
@@ -373,9 +373,6 @@ class Heap {
void DumpSpaces();
- // UnReserve the address range where the oat file will be placed.
- void UnReserveOatFileAddressRange();
-
// GC performance measuring
void DumpGcPerformanceInfo(std::ostream& os);
@@ -599,9 +596,6 @@ class Heap {
std::vector<collector::MarkSweep*> mark_sweep_collectors_;
- // A map that we use to temporarily reserve address range for the oat file.
- UniquePtr<MemMap> oat_file_map_;
-
friend class collector::MarkSweep;
friend class VerifyReferenceCardVisitor;
friend class VerifyReferenceVisitor;
diff --git a/runtime/gc/space/image_space.cc b/runtime/gc/space/image_space.cc
index 46c39378d7..c279ecf1ff 100644
--- a/runtime/gc/space/image_space.cc
+++ b/runtime/gc/space/image_space.cc
@@ -16,11 +16,16 @@
#include "image_space.h"
+#include <sys/types.h>
+#include <sys/wait.h>
+
+#include "base/stl_util.h"
#include "base/unix_file/fd_file.h"
#include "gc/accounting/space_bitmap-inl.h"
#include "mirror/abstract_method.h"
#include "mirror/class-inl.h"
#include "mirror/object-inl.h"
+#include "oat_file.h"
#include "os.h"
#include "runtime.h"
#include "space-inl.h"
@@ -41,13 +46,118 @@ ImageSpace::ImageSpace(const std::string& name, MemMap* mem_map)
DCHECK(live_bitmap_.get() != NULL) << "could not create imagespace live bitmap #" << bitmap_index;
}
-ImageSpace* ImageSpace::Create(const std::string& image_file_name) {
+static bool GenerateImage(const std::string& image_file_name) {
+ const std::string boot_class_path_string(Runtime::Current()->GetBootClassPathString());
+ std::vector<std::string> boot_class_path;
+ Split(boot_class_path_string, ':', boot_class_path);
+ if (boot_class_path.empty()) {
+ LOG(FATAL) << "Failed to generate image because no boot class path specified";
+ }
+
+ std::vector<char*> arg_vector;
+
+ std::string dex2oat_string(GetAndroidRoot());
+ dex2oat_string += (kIsDebugBuild ? "/bin/dex2oatd" : "/bin/dex2oat");
+ const char* dex2oat = dex2oat_string.c_str();
+ arg_vector.push_back(strdup(dex2oat));
+
+ std::string image_option_string("--image=");
+ image_option_string += image_file_name;
+ const char* image_option = image_option_string.c_str();
+ arg_vector.push_back(strdup(image_option));
+
+ arg_vector.push_back(strdup("--runtime-arg"));
+ arg_vector.push_back(strdup("-Xms64m"));
+
+ arg_vector.push_back(strdup("--runtime-arg"));
+ arg_vector.push_back(strdup("-Xmx64m"));
+
+ for (size_t i = 0; i < boot_class_path.size(); i++) {
+ std::string dex_file_option_string("--dex-file=");
+ dex_file_option_string += boot_class_path[i];
+ const char* dex_file_option = dex_file_option_string.c_str();
+ arg_vector.push_back(strdup(dex_file_option));
+ }
+
+ std::string oat_file_option_string("--oat-file=");
+ oat_file_option_string += image_file_name;
+ oat_file_option_string.erase(oat_file_option_string.size() - 3);
+ oat_file_option_string += "oat";
+ const char* oat_file_option = oat_file_option_string.c_str();
+ arg_vector.push_back(strdup(oat_file_option));
+
+ std::string base_option_string(StringPrintf("--base=0x%x", ART_BASE_ADDRESS));
+ arg_vector.push_back(strdup(base_option_string.c_str()));
+
+ if (kIsTargetBuild) {
+ arg_vector.push_back(strdup("--image-classes-zip=/system/framework/framework.jar"));
+ arg_vector.push_back(strdup("--image-classes=preloaded-classes"));
+ } else {
+ arg_vector.push_back(strdup("--host"));
+ }
+
+ std::string command_line(Join(arg_vector, ' '));
+ LOG(INFO) << "GenerateImage: " << command_line;
+
+ arg_vector.push_back(NULL);
+ char** argv = &arg_vector[0];
+
+ // fork and exec dex2oat
+ pid_t pid = fork();
+ if (pid == 0) {
+ // no allocation allowed between fork and exec
+
+ // change process groups, so we don't get reaped by ProcessManager
+ setpgid(0, 0);
+
+ execv(dex2oat, argv);
+
+ PLOG(FATAL) << "execv(" << dex2oat << ") failed";
+ return false;
+ } else {
+ STLDeleteElements(&arg_vector);
+
+ // wait for dex2oat to finish
+ int status;
+ pid_t got_pid = TEMP_FAILURE_RETRY(waitpid(pid, &status, 0));
+ if (got_pid != pid) {
+ PLOG(ERROR) << "waitpid failed: wanted " << pid << ", got " << got_pid;
+ return false;
+ }
+ if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) {
+ LOG(ERROR) << dex2oat << " failed: " << command_line;
+ return false;
+ }
+ }
+ return true;
+}
+
+ImageSpace* ImageSpace::Create(const std::string& original_image_file_name) {
+ if (OS::FileExists(original_image_file_name.c_str())) {
+ // If the /system file exists, it should be up-to-date, don't try to generate
+ return space::ImageSpace::Init(original_image_file_name, false);
+ }
+ // If the /system file didn't exist, we need to use one from the dalvik-cache.
+ // If the cache file exists, try to open, but if it fails, regenerate.
+ // If it does not exist, generate.
+ std::string image_file_name(GetDalvikCacheFilenameOrDie(original_image_file_name));
+ if (OS::FileExists(image_file_name.c_str())) {
+ space::ImageSpace* image_space = space::ImageSpace::Init(image_file_name, true);
+ if (image_space != NULL) {
+ return image_space;
+ }
+ }
+ CHECK(GenerateImage(image_file_name)) << "Failed to generate image: " << image_file_name;
+ return space::ImageSpace::Init(image_file_name, true);
+}
+
+ImageSpace* ImageSpace::Init(const std::string& image_file_name, bool validate_oat_file) {
CHECK(!image_file_name.empty());
uint64_t start_time = 0;
if (VLOG_IS_ON(heap) || VLOG_IS_ON(startup)) {
start_time = NanoTime();
- LOG(INFO) << "Space::CreateImageSpace entering" << " image_file_name=" << image_file_name;
+ LOG(INFO) << "ImageSpace::Init entering image_file_name=" << image_file_name;
}
UniquePtr<File> file(OS::OpenFile(image_file_name.c_str(), false));
@@ -86,12 +196,78 @@ ImageSpace* ImageSpace::Create(const std::string& image_file_name) {
callee_save_method = image_header.GetImageRoot(ImageHeader::kRefsAndArgsSaveMethod);
runtime->SetCalleeSaveMethod(down_cast<mirror::AbstractMethod*>(callee_save_method), Runtime::kRefsAndArgs);
- ImageSpace* space = new ImageSpace(image_file_name, map.release());
+ UniquePtr<ImageSpace> space(new ImageSpace(image_file_name, map.release()));
+
+ space->oat_file_.reset(space->OpenOatFile());
+ if (space->oat_file_.get() == NULL) {
+ LOG(ERROR) << "Failed to open oat file for image: " << image_file_name;
+ return NULL;
+ }
+
+ if (validate_oat_file && !space->ValidateOatFile()) {
+ LOG(WARNING) << "Failed to validate oat file for image: " << image_file_name;
+ return NULL;
+ }
+
if (VLOG_IS_ON(heap) || VLOG_IS_ON(startup)) {
- LOG(INFO) << "Space::CreateImageSpace exiting (" << PrettyDuration(NanoTime() - start_time)
- << ") " << *space;
+ LOG(INFO) << "ImageSpace::Init exiting (" << PrettyDuration(NanoTime() - start_time)
+ << ") " << *space.get();
}
- return space;
+ return space.release();
+}
+
+OatFile* ImageSpace::OpenOatFile() const {
+ const Runtime* runtime = Runtime::Current();
+ const ImageHeader& image_header = GetImageHeader();
+ // Grab location but don't use Object::AsString as we haven't yet initialized the roots to
+ // check the down cast
+ mirror::String* oat_location =
+ down_cast<mirror::String*>(image_header.GetImageRoot(ImageHeader::kOatLocation));
+ std::string oat_filename;
+ oat_filename += runtime->GetHostPrefix();
+ oat_filename += oat_location->ToModifiedUtf8();
+ OatFile* oat_file = OatFile::Open(oat_filename, oat_filename, image_header.GetOatDataBegin(),
+ !Runtime::Current()->IsCompiler());
+ if (oat_file == NULL) {
+ LOG(ERROR) << "Failed to open oat file " << oat_filename << " referenced from image.";
+ return NULL;
+ }
+ uint32_t oat_checksum = oat_file->GetOatHeader().GetChecksum();
+ uint32_t image_oat_checksum = image_header.GetOatChecksum();
+ if (oat_checksum != image_oat_checksum) {
+ LOG(ERROR) << "Failed to match oat file checksum " << std::hex << oat_checksum
+ << " to expected oat checksum " << std::hex << image_oat_checksum
+ << " in image";
+ return NULL;
+ }
+ return oat_file;
+}
+
+bool ImageSpace::ValidateOatFile() const {
+ CHECK(oat_file_.get() != NULL);
+ std::vector<const OatFile::OatDexFile*> oat_dex_files = oat_file_->GetOatDexFiles();
+ for (size_t i = 0; i < oat_dex_files.size(); i++) {
+ const OatFile::OatDexFile* oat_dex_file = oat_dex_files[i];
+ const std::string& dex_file_location = oat_dex_file->GetDexFileLocation();
+ uint32_t dex_file_location_checksum;
+ if (!DexFile::GetChecksum(dex_file_location.c_str(), dex_file_location_checksum)) {
+ LOG(WARNING) << "ValidateOatFile could not find checksum for " << dex_file_location;
+ return false;
+ }
+ if (dex_file_location_checksum != oat_dex_file->GetDexFileLocationChecksum()) {
+ LOG(WARNING) << "ValidateOatFile found checksum mismatch between oat file "
+ << oat_file_->GetLocation() << " and dex file " << dex_file_location
+ << " (" << oat_dex_file->GetDexFileLocationChecksum() << " != "
+ << dex_file_location_checksum << ")";
+ return false;
+ }
+ }
+ return true;
+}
+
+OatFile& ImageSpace::ReleaseOatFile() {
+ CHECK(oat_file_.get() != NULL);
+ return *oat_file_.release();
}
void ImageSpace::RecordImageAllocations(accounting::SpaceBitmap* live_bitmap) const {
diff --git a/runtime/gc/space/image_space.h b/runtime/gc/space/image_space.h
index afec5b7305..833fb8d73a 100644
--- a/runtime/gc/space/image_space.h
+++ b/runtime/gc/space/image_space.h
@@ -20,6 +20,9 @@
#include "space.h"
namespace art {
+
+class OatFile;
+
namespace gc {
namespace space {
@@ -34,10 +37,22 @@ class ImageSpace : public MemMapSpace {
return kSpaceTypeImageSpace;
}
- // create a Space from an image file. cannot be used for future allocation or collected.
+ // Create a Space from an image file. Cannot be used for future
+ // allocation or collected.
+ //
+ // Create also opens the OatFile associated with the image file so
+ // that it be contiguously allocated with the image before the
+ // 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* Create(const std::string& image)
SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
+ // Releases the OatFile from the ImageSpace so it can be transfer to
+ // the caller, presumably the ClassLinker.
+ OatFile& ReleaseOatFile()
+ SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
+
const ImageHeader& GetImageHeader() const {
return *reinterpret_cast<ImageHeader*>(Begin());
}
@@ -63,6 +78,23 @@ class ImageSpace : public MemMapSpace {
void Dump(std::ostream& os) const;
private:
+
+ // Tries to initialize an ImageSpace from the given image path,
+ // returning NULL on error.
+ //
+ // If validate_oat_file is false (for /system), do not verify that
+ // image's OatFile is up-to-date relative to its DexFile
+ // inputs. Otherwise (for /data), validate the inputs and generate
+ // the OatFile in /data/dalvik-cache if necessary.
+ static ImageSpace* Init(const std::string& image, bool validate_oat_file)
+ SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
+
+ OatFile* OpenOatFile() const
+ SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
+
+ bool ValidateOatFile() const
+ SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
+
friend class Space;
static size_t bitmap_index_;
@@ -71,6 +103,11 @@ class ImageSpace : public MemMapSpace {
ImageSpace(const std::string& name, MemMap* mem_map);
+ // The OatFile associated with the image during early startup to
+ // reserve space contiguous to the image. It is later released to
+ // the ClassLinker during it's initialization.
+ UniquePtr<OatFile> oat_file_;
+
DISALLOW_COPY_AND_ASSIGN(ImageSpace);
};
diff --git a/runtime/oat_file.h b/runtime/oat_file.h
index e3fd0025f0..ecc8d0c965 100644
--- a/runtime/oat_file.h
+++ b/runtime/oat_file.h
@@ -166,18 +166,25 @@ class OatFile {
class OatDexFile {
public:
+ // Opens the DexFile referred to by this OatDexFile from within the containing OatFile.
const DexFile* OpenDexFile() const;
- const OatClass* GetOatClass(uint32_t class_def_index) const;
+
+ // Returns the size of the DexFile refered to by this OatDexFile.
size_t FileSize() const;
+ // Returns original path of DexFile that was the source of this OatDexFile.
const std::string& GetDexFileLocation() const {
return dex_file_location_;
}
+ // Returns checksum of original DexFile that was the source of this OatDexFile;
uint32_t GetDexFileLocationChecksum() const {
return dex_file_location_checksum_;
}
+ // Returns the OatClass for the class specified by the given DexFile class_def_index.
+ const OatClass* GetOatClass(uint32_t class_def_index) const;
+
~OatDexFile();
private: