Avoid a deadlock between GC and debugger's SuspendAllForDebugger where
GC gets suspended during GC.
Fix the jdwp tests with the CC collector, but the deadlock is NOT
specific to the CC collector.
Bug:
25800335
Bug:
12687968
Change-Id: I8f2869872bce4692d943020072e35ebf5a4e68a5
}
void Dbg::SuspendVM() {
+ // Avoid a deadlock between GC and debugger where GC gets suspended during GC. b/25800335.
+ gc::ScopedGCCriticalSection gcs(Thread::Current(),
+ gc::kGcCauseDebugger,
+ gc::kCollectorTypeDebugger);
Runtime::Current()->GetThreadList()->SuspendAllForDebugger();
}
// Suspend other threads if the invoke is not single-threaded.
if ((pReq->options & JDWP::INVOKE_SINGLE_THREADED) == 0) {
ScopedThreadSuspension sts(soa.Self(), kWaitingForDebuggerSuspension);
+ // Avoid a deadlock between GC and debugger where GC gets suspended during GC. b/25800335.
+ gc::ScopedGCCriticalSection gcs(soa.Self(), gc::kGcCauseDebugger, gc::kCollectorTypeDebugger);
VLOG(jdwp) << " Suspending all threads";
Runtime::Current()->GetThreadList()->SuspendAllForDebugger();
}
kCollectorTypeInstrumentation,
// Fake collector for adding or removing application image spaces.
kCollectorTypeAddRemoveAppImageSpace,
+ // Fake collector used to implement exclusion between GC and debugger.
+ kCollectorTypeDebugger,
// A homogeneous space compaction collector used in background transition
// when both foreground and background collector are CMS.
kCollectorTypeHomogeneousSpaceCompact,
case kGcCauseTrim: return "HeapTrim";
case kGcCauseInstrumentation: return "Instrumentation";
case kGcCauseAddRemoveAppImageSpace: return "AddRemoveAppImageSpace";
+ case kGcCauseDebugger: return "Debugger";
default:
LOG(FATAL) << "Unreachable";
UNREACHABLE();
kGcCauseInstrumentation,
// Not a real GC cause, used to add or remove app image spaces.
kGcCauseAddRemoveAppImageSpace,
+ // Not a real GC cause, used to implement exclusion between GC and debugger.
+ kGcCauseDebugger,
// GC triggered for background transition when both foreground and background collector are CMS.
kGcCauseHomogeneousSpaceCompact,
};