OSDN Git Service

Fix CC collector thread flip and JNI critical section deadlocks.
authorHiroshi Yamauchi <yamauchi@google.com>
Fri, 19 Feb 2016 23:44:06 +0000 (15:44 -0800)
committerHiroshi Yamauchi <yamauchi@google.com>
Mon, 22 Feb 2016 19:41:18 +0000 (11:41 -0800)
commit20a0be0299183b54be9643820294e011d3358823
treeb5f13c1362dc146675792d438ec7528a39c286a4
parenteeb3b0bf5339e24b6f5e22c5a884910000c9bcfb
Fix CC collector thread flip and JNI critical section deadlocks.

There's a bug in the synchronization between the CC collector's thread
flip and JNI critical sections where it incorrectly attempts to make
the synchronization scheme to be writer (GC) preference to avoid
starvation of GC in the presence of frequent JNI critical section
enter/exit. This could cause a deadlock between them if a thread
enters a nested JNI critical section after a thread flip occurs. This
is reproduced in the added test.

The fix is to use a thread local disable counter in addition to the
global counter to detect a nested enter by the same thread and avoid
waiting if nested.

Bug: 19235243
Bug: 12687968
Change-Id: Idf7720a6906c9ea508219935af3727f76680d2d8
runtime/gc/heap.cc
runtime/gc/heap.h
runtime/thread.h
test/004-JniTest/jni_test.cc
test/004-JniTest/src/Main.java