if (pDexOrJar == NULL)
return false;
- u4 hash = dvmComputeUtf8Hash(pDexOrJar->fileName);
+ u4 hash = cookie;
dvmHashTableLock(gDvm.userDexFiles);
void* result = dvmHashTableLookup(gDvm.userDexFiles, hash, pDexOrJar,
hashcmpDexOrJar, false);
* To optimize this away we could search for existing entries in the hash
* table and refCount them. Requires atomic ops or adding "synchronized"
* to the non-native code that calls here.
+ *
+ * TODO: should be using "long" for a pointer.
*/
static void Dalvik_dalvik_system_DexFile_openDexFile(const u4* args,
JValue* pResult)
if (pDexOrJar != NULL) {
pDexOrJar->fileName = sourceName;
- /* add to hash table */
- u4 hash = dvmComputeUtf8Hash(sourceName);
+ /*
+ * Add to hash table.
+ *
+ * Later on we will receive this pointer as an argument and need
+ * to find it in the hash table without knowing if it's valid or
+ * not, which means we can't compute a hash value from anything
+ * inside DexOrJar. We don't share DexOrJar structs when the same
+ * file is opened multiple times, so we can just use the low 32
+ * bits of the pointer as the hash.
+ */
+ u4 hash = (u4) pDexOrJar;
void* result;
dvmHashTableLock(gDvm.userDexFiles);
result = dvmHashTableLookup(gDvm.userDexFiles, hash, pDexOrJar,
if (pDexOrJar == NULL)
RETURN_VOID();
-
- LOGV("Closing DEX file %p (%s)\n", pDexOrJar, pDexOrJar->fileName);
-
if (!validateCookie(cookie))
RETURN_VOID();
+ LOGV("Closing DEX file %p (%s)\n", pDexOrJar, pDexOrJar->fileName);
+
/*
* We can't just free arbitrary DEX files because they have bits and
* pieces of loaded classes. The only exception to this rule is if
* them when the VM shuts down.
*/
if (pDexOrJar->okayToFree) {
- u4 hash = dvmComputeUtf8Hash(pDexOrJar->fileName);
+ u4 hash = (u4) pDexOrJar;
dvmHashTableLock(gDvm.userDexFiles);
if (!dvmHashTableRemove(gDvm.userDexFiles, hash, pDexOrJar)) {
LOGW("WARNING: could not remove '%s' from DEX hash table\n",