From 4306ef8a7ec8e3887e51f64e80d940d974cc3ac3 Mon Sep 17 00:00:00 2001 From: Mathieu Chartier Date: Fri, 19 Dec 2014 18:41:47 -0800 Subject: Don't allow suspension from FindLocksAtDexPc Transitioning to suspended from runnable sometimes runs dump checkpoints in ThreadStress which can cause deadlocks. This happens since FindLocksAtDexPC runs the verifier which calls AllowThreadSuspension. This results in a blocked thread which holds the monitor lock, and if another thread tries to do a monitor enter, it deadlocks while holding the mutator lock (assuming the GC is suspending all). The fix for avoiding this deadlock is not calling AllowThreadSuspension from FindLocksAtDexPc. Bug: 18576985 Change-Id: I7e5faaf3bbbd5b5f680de95d53c33b5106705b0c --- runtime/verifier/method_verifier.h | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'runtime/verifier/method_verifier.h') diff --git a/runtime/verifier/method_verifier.h b/runtime/verifier/method_verifier.h index 15a09c5..b83e647 100644 --- a/runtime/verifier/method_verifier.h +++ b/runtime/verifier/method_verifier.h @@ -207,10 +207,11 @@ class MethodVerifier { const DexFile::CodeItem* code_item, uint32_t method_idx, Handle method, uint32_t access_flags, bool can_load_classes, bool allow_soft_failures, - bool need_precise_constants) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) + bool need_precise_constants, bool allow_thread_suspension) + SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) : MethodVerifier(self, dex_file, dex_cache, class_loader, class_def, code_item, method_idx, method, access_flags, can_load_classes, allow_soft_failures, - need_precise_constants, false) {} + need_precise_constants, false, allow_thread_suspension) {} ~MethodVerifier(); @@ -260,7 +261,7 @@ class MethodVerifier { const DexFile::CodeItem* code_item, uint32_t method_idx, Handle method, uint32_t access_flags, bool can_load_classes, bool allow_soft_failures, bool need_precise_constants, - bool verify_to_dump) + bool verify_to_dump, bool allow_thread_suspension) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); // Adds the given string to the beginning of the last failure message. @@ -729,6 +730,11 @@ class MethodVerifier { // VerifyMethodAndDump. const bool verify_to_dump_; + // Whether or not we call AllowThreadSuspension periodically, we want a way to disable this for + // thread dumping checkpoints since we may get thread suspension at an inopportune time due to + // FindLocksAtDexPC, resulting in deadlocks. + const bool allow_thread_suspension_; + DISALLOW_COPY_AND_ASSIGN(MethodVerifier); }; std::ostream& operator<<(std::ostream& os, const MethodVerifier::FailureKind& rhs); -- cgit v1.1