Add support for opening classes.dex file from zip, jar, apk
Adding new ZipArchive class and test
src/zip_archive.h
src/zip_archive.cc
src/zip_archive_test.cc
build/Android.common.mk
Change from host only use of build dex file for libcore to using host
and target core.jar containing classes.dex files. This requires
setting up an ANDROID_DATA directory to containing an art-cache file
for the extracted dex files, similar to the dalvik-cache for odex
files. A unique ANDROID_DATA and art-cache is created and cleaned up
for each test run (similar to vogar).
src/common_test.h
Add dependency for libcore jar files to test targets to support
RuntimeTest use of core.jar
Android.mk
Extract common includes to ART_C_INCLUDES when adding zlib dependency
build/Android.common.mk
build/Android.libart.mk
build/Android.test.mk
Adding TODO regarding unordered map for ClassLinker::classes_ table.
src/class_linker.h
Adding DexFile::OpenZip (also changed OpenFile to take
src/dex_file.cc
src/dex_file.h
Adding kPageSize of 4096, validated by Runtime::Init
src/globals.h
src/runtime.cc
Updated to use kPageSize where it seemed appropriate.
src/jni_compiler.cc
src/jni_compiler_test.cc
src/space.cc
src/thread.cc
src/thread_x86.cc
Changed thread_list_ and class_linker_ to be declared in Runtime::Init
initialization order.
src/runtime.h
Change-Id: Id626abe5b6c1990e4f93598256ee0fae000818f6
diff --git a/src/common_test.h b/src/common_test.h
index cfc0a5f..f5d7059 100644
--- a/src/common_test.h
+++ b/src/common_test.h
@@ -1,5 +1,9 @@
// Copyright 2011 Google Inc. All Rights Reserved.
+#include <dirent.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
#include "base64.h"
#include "heap.h"
#include "thread.h"
@@ -189,6 +193,17 @@
virtual void SetUp() {
is_host_ = getenv("ANDROID_BUILD_TOP") != NULL;
+ android_data_.reset(strdup(is_host_ ? "/tmp/art-data-XXXXXX" : "/sdcard/art-data-XXXXXX"));
+ ASSERT_TRUE(android_data_ != NULL);
+ const char* android_data_modified = mkdtemp(android_data_.get());
+ // note that mkdtemp side effects android_data_ as well
+ ASSERT_TRUE(android_data_modified != NULL);
+ setenv("ANDROID_DATA", android_data_modified, 1);
+ art_cache_.append(android_data_.get());
+ art_cache_.append("/art-cache");
+ int mkdir_result = mkdir(art_cache_.c_str(), 0700);
+ ASSERT_EQ(mkdir_result, 0);
+
java_lang_dex_file_.reset(OpenDexFileBase64(kJavaLangDex));
std::vector<DexFile*> boot_class_path;
@@ -199,16 +214,47 @@
class_linker_ = runtime_->GetClassLinker();
}
- DexFile* GetLibCoreDex() {
- // TODO add host support when we have DexFile::OpenJar
- // TODO switch to jar when we have DexFile::OpenJar
- if (!is_host_) {
- return NULL;
+ virtual void TearDown() {
+ const char* android_data = getenv("ANDROID_DATA");
+ ASSERT_TRUE(android_data != NULL);
+ DIR* dir = opendir(art_cache_.c_str());
+ ASSERT_TRUE(dir != NULL);
+ while (true) {
+ struct dirent entry;
+ struct dirent* entry_ptr;
+ int readdir_result = readdir_r(dir, &entry, &entry_ptr);
+ ASSERT_EQ(0, readdir_result);
+ if (entry_ptr == NULL) {
+ break;
+ }
+ if ((strcmp(entry_ptr->d_name, ".") == 0) || (strcmp(entry_ptr->d_name, "..") == 0)) {
+ continue;
+ }
+ std::string filename(art_cache_);
+ filename.push_back('/');
+ filename.append(entry_ptr->d_name);
+ int unlink_result = unlink(filename.c_str());
+ ASSERT_EQ(0, unlink_result);
}
+ closedir(dir);
+ int rmdir_cache_result = rmdir(art_cache_.c_str());
+ ASSERT_EQ(0, rmdir_cache_result);
+ int rmdir_data_result = rmdir(android_data_.get());
+ ASSERT_EQ(0, rmdir_data_result);
+ }
- std::string libcore_dex_file_name = StringPrintf("%s/out/target/common/obj/JAVA_LIBRARIES/core_intermediates/noproguard.classes.dex",
- getenv("ANDROID_BUILD_TOP"));
- return DexFile::OpenFile(libcore_dex_file_name.c_str());
+ std::string GetLibCoreDexFileName() {
+ if (is_host_) {
+ const char* host_dir = getenv("ANDROID_HOST_OUT");
+ CHECK(host_dir != NULL);
+ return StringPrintf("%s/framework/core-hostdex.jar", host_dir);
+ }
+ return std::string("/system/framework/core.jar");
+ }
+
+ DexFile* GetLibCoreDex() {
+ std::string libcore_dex_file_name = GetLibCoreDexFileName();
+ return DexFile::OpenZip(libcore_dex_file_name.c_str());
}
void UseLibCoreDex() {
@@ -224,6 +270,8 @@
}
bool is_host_;
+ scoped_ptr_malloc<char> android_data_;
+ std::string art_cache_;
scoped_ptr<DexFile> java_lang_dex_file_;
scoped_ptr<Runtime> runtime_;
ClassLinker* class_linker_;