Android-x86
Fork
Donation

  • R/O
  • HTTP
  • SSH
  • HTTPS

dalvik: Commit

dalvik


Commit MetaInfo

Revision36e356c96640775f0a3f167bd2426ea0f0093b8b (tree)
Time2014-03-18 05:02:20
AuthorJeff Hao <jeffhao@goog...>
CommiterJeff Hao

Log Message

Changed dvmDexCacheStatus to check for odex file first.

This prevents the generation of a new dexfile when an odex file already
exists when switching between Art and Dalvik.

Bug: 13463154
Change-Id: I55ef9abe1fe172ee656550e78556381f95698c33

Change Summary

Incremental Difference

--- a/vm/JarFile.cpp
+++ b/vm/JarFile.cpp
@@ -82,6 +82,8 @@ bail:
8282 /*
8383 * Checks the dependencies of the dex cache file corresponding
8484 * to the jar file at the absolute path "fileName".
85+ *
86+ * Note: This should parallel the logic of dvmJarFileOpen.
8587 */
8688 DexCacheStatus dvmDexCacheStatus(const char *fileName)
8789 {
@@ -99,72 +101,72 @@ DexCacheStatus dvmDexCacheStatus(const char *fileName)
99101 return DEX_CACHE_OK;
100102 }
101103
102- //TODO: match dvmJarFileOpen()'s logic. Not super-important
103- // (the odex-first logic is only necessary for dexpreopt)
104- // but it would be nice to be consistent.
105-
106104 /* Try to find the dex file inside of the archive.
107105 */
108106 if (dexZipOpenArchive(fileName, &archive) != 0) {
109107 return DEX_CACHE_BAD_ARCHIVE;
110108 }
111- entry = dexZipFindEntry(&archive, kDexInJarName);
112- if (entry != NULL) {
113- bool newFile = false;
114-
115- /*
116- * See if there's an up-to-date copy of the optimized dex
117- * in the cache, but don't create one if there isn't.
118- */
119- ALOGV("dvmDexCacheStatus: Checking cache for %s", fileName);
120- cachedName = dexOptGenerateCacheFileName(fileName, kDexInJarName);
121- if (cachedName == NULL)
122- return DEX_CACHE_BAD_ARCHIVE;
123-
124- fd = dvmOpenCachedDexFile(fileName, cachedName,
125- dexGetZipEntryModTime(&archive, entry),
126- dexGetZipEntryCrc32(&archive, entry),
127- /*isBootstrap=*/false, &newFile, /*createIfMissing=*/false);
128- ALOGV("dvmOpenCachedDexFile returned fd %d", fd);
129- if (fd < 0) {
130- result = DEX_CACHE_STALE;
131- goto bail;
132- }
133109
134- /* dvmOpenCachedDexFile locks the file as a side-effect.
135- * Unlock and close it.
136- */
137- if (!dvmUnlockCachedDexFile(fd)) {
138- /* uh oh -- this process needs to exit or we'll wedge the system */
139- ALOGE("Unable to unlock DEX file");
140- goto bail;
110+ /* First, look for a ".odex" alongside the jar file. It will
111+ * have the same name/path except for the extension.
112+ */
113+ fd = openAlternateSuffix(fileName, "odex", O_RDONLY, &cachedName);
114+ if (fd >= 0) {
115+ ALOGV("Using alternate file (odex) for %s ...", fileName);
116+ if (!dvmCheckOptHeaderAndDependencies(fd, false, 0, 0, true, true)) {
117+ ALOGE("%s odex has stale dependencies", fileName);
118+ free(cachedName);
119+ cachedName = NULL;
120+ close(fd);
121+ fd = -1;
122+ goto tryArchive;
123+ } else {
124+ ALOGV("%s odex has good dependencies", fileName);
141125 }
142-
143- /* When createIfMissing is false, dvmOpenCachedDexFile() only
144- * returns a valid fd if the cache file is up-to-date.
145- */
146126 } else {
127+
128+tryArchive:
147129 /*
148- * There's no dex file in the jar file. See if there's an
149- * optimized dex file living alongside the jar.
130+ * Pre-created .odex absent or stale. Look inside the jar for a
131+ * "classes.dex".
150132 */
151- fd = openAlternateSuffix(fileName, "odex", O_RDONLY, &cachedName);
152- if (fd < 0) {
133+ entry = dexZipFindEntry(&archive, kDexInJarName);
134+ if (entry != NULL) {
135+ bool newFile = false;
136+
137+ /*
138+ * See if there's an up-to-date copy of the optimized dex
139+ * in the cache, but don't create one if there isn't.
140+ */
141+ ALOGV("dvmDexCacheStatus: Checking cache for %s", fileName);
142+ cachedName = dexOptGenerateCacheFileName(fileName, kDexInJarName);
143+ if (cachedName == NULL)
144+ return DEX_CACHE_BAD_ARCHIVE;
145+
146+ fd = dvmOpenCachedDexFile(fileName, cachedName,
147+ dexGetZipEntryModTime(&archive, entry),
148+ dexGetZipEntryCrc32(&archive, entry),
149+ /*isBootstrap=*/false, &newFile, /*createIfMissing=*/false);
150+ ALOGV("dvmOpenCachedDexFile returned fd %d", fd);
151+ if (fd < 0) {
152+ result = DEX_CACHE_STALE;
153+ goto bail;
154+ }
155+
156+ /* dvmOpenCachedDexFile locks the file as a side-effect.
157+ * Unlock and close it.
158+ */
159+ if (!dvmUnlockCachedDexFile(fd)) {
160+ /* uh oh -- this process needs to exit or we'll wedge the system */
161+ ALOGE("Unable to unlock DEX file");
162+ goto bail;
163+ }
164+ } else {
153165 ALOGI("Zip is good, but no %s inside, and no .odex "
154166 "file in the same directory", kDexInJarName);
155167 result = DEX_CACHE_BAD_ARCHIVE;
156168 goto bail;
157169 }
158-
159- ALOGV("Using alternate file (odex) for %s ...", fileName);
160- if (!dvmCheckOptHeaderAndDependencies(fd, false, 0, 0, true, true)) {
161- ALOGE("%s odex has stale dependencies", fileName);
162- ALOGE("odex source not available -- failing");
163- result = DEX_CACHE_STALE_ODEX;
164- goto bail;
165- } else {
166- ALOGV("%s odex has good dependencies", fileName);
167- }
168170 }
169171 result = DEX_CACHE_OK;
170172
@@ -184,6 +186,8 @@ bail:
184186 *
185187 * If "isBootstrap" is not set, the optimizer/verifier regards this DEX as
186188 * being part of a different class loader.
189+ *
190+ * Note: This should parallel the logic of dvmDexCacheStatus.
187191 */
188192 int dvmJarFileOpen(const char* fileName, const char* odexOutputName,
189193 JarFile** ppJarFile, bool isBootstrap)
Show on old repository browser