diff options
author | Brian Carlstrom <bdc@google.com> | 2011-10-13 10:50:45 -0700 |
---|---|---|
committer | Brian Carlstrom <bdc@google.com> | 2011-10-13 11:27:45 -0700 |
commit | 1d9f52b7ca91c6d30b7acfac1c9ab24d93fff470 (patch) | |
tree | 0b78747cefb673ffb907a5706f1a1021542f19f4 /src/dalvik_system_DexFile.cc | |
parent | 03a20ba67cfdc46f5ad8d77242a666a4cb0512f2 (diff) | |
download | art-1d9f52b7ca91c6d30b7acfac1c9ab24d93fff470.zip art-1d9f52b7ca91c6d30b7acfac1c9ab24d93fff470.tar.gz art-1d9f52b7ca91c6d30b7acfac1c9ab24d93fff470.tar.bz2 |
Implement DexFile_isDexOptNeeded
Change-Id: Ib4d641ca7000b0f563cb9ab9c0970d6b8ad92060
Diffstat (limited to 'src/dalvik_system_DexFile.cc')
-rw-r--r-- | src/dalvik_system_DexFile.cc | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/src/dalvik_system_DexFile.cc b/src/dalvik_system_DexFile.cc index cad1acd..e6d45e3 100644 --- a/src/dalvik_system_DexFile.cc +++ b/src/dalvik_system_DexFile.cc @@ -14,10 +14,13 @@ * limitations under the License. */ +#include <unistd.h> + #include "class_loader.h" #include "class_linker.h" #include "dex_file.h" #include "logging.h" +#include "os.h" #include "runtime.h" #include "toStringArray.h" #include "ScopedUtfChars.h" @@ -158,10 +161,34 @@ jobjectArray DexFile_getClassNameList(JNIEnv* env, jclass, jint cookie) { jboolean DexFile_isDexOptNeeded(JNIEnv* env, jclass, jstring javaFilename) { ScopedUtfChars filename(env, javaFilename); if (filename.c_str() == NULL) { - return JNI_FALSE; + return JNI_TRUE; + } + + if (!OS::FileExists(filename.c_str())) { + jniThrowExceptionFmt(env, "java/io/FileNotFoundException", "%s", filename.c_str()); + return JNI_TRUE; + } + + // Always treat elements of the bootclasspath as up-to-date. The + // fact that code is running at all means that this should be true. + ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); + const std::vector<const DexFile*>& boot_class_path = class_linker->GetBootClassPath(); + for (size_t i = 0; i < boot_class_path.size(); i++) { + if (boot_class_path[i]->GetLocation() == filename.c_str()) { + return JNI_FALSE; + } + } + + UniquePtr<const DexFile> dex_file(DexFile::Open(filename.c_str(), "")); + if (dex_file.get() == NULL) { + return JNI_TRUE; } - // TODO: return true if we need to extract dex or run dex2oat - UNIMPLEMENTED(WARNING) << filename.c_str(); + + UniquePtr<const OatFile> oat_file(class_linker->FindOatFile(*dex_file.get())); + if (oat_file.get() == NULL) { + return JNI_TRUE; + } + return JNI_FALSE; } |