Working dex2oat and oatexec
adb shell dex2oatd --dex-file=/system/framework/core.jar --image=/system/framework/boot.oat --base=0x50000000 "'--method=Ljava/lang/System;logI(Ljava/lang/String;)V'" "'--method=Ljava/lang/System;log(CLjava/lang/String;Ljava/lang/Throwable;)V'"
adb shell dex2oatd --boot-dex-file=/system/framework/core.jar --boot=/system/framework/boot.oat --dex-file=/system/framework/art-test-dex-HelloWorld.jar --image=/system/framework/art-test-dex-HelloWorld.oat
adb shell oatexecd -Xbootclasspath:/system/framework/core.jar -Xbootimage:/system/framework/boot.oat -classpath /system/framework/art-test-dex-HelloWorld.jar -Ximage:/system/framework/art-test-dex-HelloWorld.oat HelloWorld
09-05 17:58:18.912 2385 2385 I System : Hello, world!
Change-Id: I53e534068584f0c3a837313e4d517a0e4a7154fc
diff --git a/src/dex_file.cc b/src/dex_file.cc
index ad0b3b9..b982291 100644
--- a/src/dex_file.cc
+++ b/src/dex_file.cc
@@ -42,6 +42,19 @@
reinterpret_cast<const DexFile::ClassDef*>(NULL));
}
+const DexFile* DexFile::Open(const std::string& filename) {
+ if (filename.size() < 4) {
+ LOG(WARNING) << "Ignoring short classpath entry '" << filename << "'";
+ return NULL;
+ }
+ std::string suffix(filename.substr(filename.size() - 4));
+ if (suffix == ".zip" || suffix == ".jar" || suffix == ".apk") {
+ return DexFile::OpenZip(filename);
+ } else {
+ return DexFile::OpenFile(filename);
+ }
+}
+
DexFile::Closer::~Closer() {}
DexFile::MmapCloser::MmapCloser(void* addr, size_t length) : addr_(addr), length_(length) {
@@ -89,7 +102,7 @@
static LockedFd* CreateAndLock(std::string& name, mode_t mode) {
int fd = open(name.c_str(), O_CREAT | O_RDWR, mode);
if (fd == -1) {
- PLOG(ERROR) << "Can't open file '" << name << "'";
+ PLOG(ERROR) << "Failed to open file '" << name << "'";
return NULL;
}
fchmod(fd, mode);
@@ -101,7 +114,7 @@
result = flock(fd, LOCK_EX);
}
if (result == -1 ) {
- PLOG(ERROR) << "Can't lock file '" << name << "'";
+ PLOG(ERROR) << "Failed to lock file '" << name << "'";
close(fd);
return NULL;
}
@@ -149,6 +162,7 @@
size_t found = adjacent_dex_filename.find_last_of(".");
if (found == std::string::npos) {
LOG(WARNING) << "No . in filename" << filename;
+ return NULL;
}
adjacent_dex_filename.replace(adjacent_dex_filename.begin() + found,
adjacent_dex_filename.end(),
@@ -168,7 +182,7 @@
char resolved[PATH_MAX];
char* absolute_path = realpath(filename.c_str(), resolved);
if (absolute_path == NULL) {
- LOG(WARNING) << "Could not create absolute path for " << filename
+ LOG(WARNING) << "Failed to create absolute path for " << filename
<< " when looking for classes.dex";
return NULL;
}
@@ -180,7 +194,7 @@
const char* data_root = getenv("ANDROID_DATA");
if (data_root == NULL) {
- data_root = "/data";
+ data_root = "/data";
}
std::string cache_path_tmp = StringPrintf("%s/art-cache/%s", data_root, cache_file.c_str());
@@ -188,12 +202,12 @@
UniquePtr<ZipArchive> zip_archive(ZipArchive::Open(filename));
if (zip_archive.get() == NULL) {
- LOG(WARNING) << "Could not open " << filename << " when looking for classes.dex";
+ LOG(WARNING) << "Failed to open " << filename << " when looking for classes.dex";
return NULL;
}
UniquePtr<ZipEntry> zip_entry(zip_archive->Find(kClassesDex));
if (zip_entry.get() == NULL) {
- LOG(WARNING) << "Could not find classes.dex within " << filename;
+ LOG(WARNING) << "Failed to find classes.dex within " << filename;
return NULL;
}
@@ -235,7 +249,7 @@
struct stat fd_stat;
int fd_stat_result = fstat(fd->GetFd(), &fd_stat);
if (fd_stat_result == -1) {
- PLOG(ERROR) << "Can't stat open file '" << cache_path_tmp << "'";
+ PLOG(ERROR) << "Failed to stat open file '" << cache_path_tmp << "'";
return NULL;
}
struct stat file_stat;
@@ -287,7 +301,7 @@
}
int rename_result = rename(cache_path_tmp.c_str(), cache_path.c_str());
if (rename_result == -1) {
- PLOG(ERROR) << "Can't install dex cache file '" << cache_path << "'"
+ PLOG(ERROR) << "Failed to install dex cache file '" << cache_path << "'"
<< " from '" << cache_path_tmp << "'";
unlink(cache_path.c_str());
}