summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Mathieu Chartier <mathieuc@google.com> 2014-08-26 18:03:03 +0000
committer Gerrit Code Review <noreply-gerritcodereview@google.com> 2014-08-26 18:03:04 +0000
commit0038fcaa6f2457f5de5544fc93cd57a305e466de (patch)
treedaca135aa7681a8ad210aa3a4f3f8db67e914a46
parent0b05ec674139c2b2e0914b0bb0e1898f93a9c852 (diff)
parente4927f6654b7eda672312898e1fd3fecccacd6aa (diff)
Merge "Fix race condition in TransitionCollector."
-rw-r--r--runtime/gc/heap.cc8
1 files changed, 4 insertions, 4 deletions
diff --git a/runtime/gc/heap.cc b/runtime/gc/heap.cc
index 42c7cca66b..4d1845bc62 100644
--- a/runtime/gc/heap.cc
+++ b/runtime/gc/heap.cc
@@ -512,7 +512,7 @@ void Heap::DisableMovingGc() {
ScopedThreadStateChange tsc(self, kSuspended);
tl->SuspendAll();
// Something may have caused the transition to fail.
- if (!IsMovingGc(foreground_collector_type_) && non_moving_space_ != main_space_) {
+ if (!IsMovingGc(collector_type_) && non_moving_space_ != main_space_) {
CHECK(main_space_ != nullptr);
// The allocation stack may have non movable objects in it. We need to flush it since the GC
// can't only handle marking allocation stack objects of one non moving space and one main
@@ -1597,9 +1597,6 @@ void Heap::TransitionCollector(CollectorType collector_type) {
Thread* const self = Thread::Current();
ScopedThreadStateChange tsc(self, kWaitingPerformingGc);
Locks::mutator_lock_->AssertNotHeld(self);
- // Currently we only need a heap transition if we switch from a moving collector to a non moving
- // one, or visa versa.
- const bool copying_transition = IsMovingGc(collector_type_) != IsMovingGc(collector_type);
// Busy wait until we can GC (StartGC can fail if we have a non-zero
// compacting_gc_disable_count_, this should rarely occurs).
for (;;) {
@@ -1608,6 +1605,9 @@ void Heap::TransitionCollector(CollectorType collector_type) {
MutexLock mu(self, *gc_complete_lock_);
// Ensure there is only one GC at a time.
WaitForGcToCompleteLocked(kGcCauseCollectorTransition, self);
+ // Currently we only need a heap transition if we switch from a moving collector to a
+ // non-moving one, or visa versa.
+ const bool copying_transition = IsMovingGc(collector_type_) != IsMovingGc(collector_type);
// If someone else beat us to it and changed the collector before we could, exit.
// This is safe to do before the suspend all since we set the collector_type_running_ before
// we exit the loop. If another thread attempts to do the heap transition before we exit,