summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBen Cheng <bccheng@android.com>2011-03-31 21:07:55 -0700
committerBen Cheng <bccheng@android.com>2011-03-31 21:40:10 -0700
commitcfa208dede8f5ecb922e51232912b426f82975d5 (patch)
treee279c9d0627583b1e28c55a772b98cd13a30d7d7
parentee15d8660ac69fa08a15f944d18653c201a7168f (diff)
downloadandroid_dalvik-cfa208dede8f5ecb922e51232912b426f82975d5.tar.gz
android_dalvik-cfa208dede8f5ecb922e51232912b426f82975d5.tar.bz2
android_dalvik-cfa208dede8f5ecb922e51232912b426f82975d5.zip
Change the tread state before acquiring the code cache lock.
Fix a deadlock situation. Bug: 4192964 Change-Id: I27f869d90d58f67e675a65444ebed6fdf2a5f518
-rw-r--r--vm/compiler/codegen/arm/Assemble.c24
1 files changed, 18 insertions, 6 deletions
diff --git a/vm/compiler/codegen/arm/Assemble.c b/vm/compiler/codegen/arm/Assemble.c
index dfc68b6f3..4f2c10a23 100644
--- a/vm/compiler/codegen/arm/Assemble.c
+++ b/vm/compiler/codegen/arm/Assemble.c
@@ -2272,13 +2272,25 @@ void dvmJitInstallClassObjectPointers(CompilationUnit *cUnit, char *codeAddress)
int numClassPointers = *(int *)classPointerP++;
intptr_t *startClassPointerP = classPointerP;
- UNPROTECT_CODE_CACHE(startClassPointerP,
- numClassPointers * sizeof(intptr_t));
/*
* Change the thread state to VM_RUNNING so that GC won't be happening
- * when the assembler looks up the class pointers.
+ * when the assembler looks up the class pointers. May suspend the current
+ * thread if there is a pending request before the state is actually
+ * changed to RUNNING.
*/
dvmChangeStatus(gDvmJit.compilerThread, THREAD_RUNNING);
+
+ /*
+ * Unprotecting the code cache will need to acquire the code cache
+ * protection lock first. Doing so after the state change may increase the
+ * time spent in the RUNNING state (which may delay the next GC request
+ * should there be contention on codeCacheProtectionLock). In practice
+ * this is probably not going to happen often since a GC is just served.
+ * More importantly, acquiring the lock before the state change will
+ * cause deadlock (b/4192964).
+ */
+ UNPROTECT_CODE_CACHE(startClassPointerP,
+ numClassPointers * sizeof(intptr_t));
#if defined(WITH_JIT_TUNING)
u8 startTime = dvmGetRelativeTimeUsec();
#endif
@@ -2305,12 +2317,12 @@ void dvmJitInstallClassObjectPointers(CompilationUnit *cUnit, char *codeAddress)
gDvmJit.maxCompilerThreadBlockGCTime = blockTime;
gDvmJit.numCompilerThreadBlockGC++;
#endif
- /* Change the thread state back to VMWAIT */
- dvmChangeStatus(gDvmJit.compilerThread, THREAD_VMWAIT);
-
UPDATE_CODE_CACHE_PATCHES();
PROTECT_CODE_CACHE(startClassPointerP, numClassPointers * sizeof(intptr_t));
+
+ /* Change the thread state back to VMWAIT */
+ dvmChangeStatus(gDvmJit.compilerThread, THREAD_VMWAIT);
}
#if defined(WITH_SELF_VERIFICATION)