summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Mathieu Chartier <mathieuc@google.com> 2014-02-03 14:00:42 -0800
committer Mathieu Chartier <mathieuc@google.com> 2014-02-03 16:00:05 -0800
commit1f3b5358b28a83f0929bdd8ce738f06908677fb7 (patch)
tree81545b9a91de8bde45f55c7dbc8a9d5358a89bdb
parent1f00671edaaa34578319d0fdaf605600ed539d41 (diff)
Move SwapBitmaps to ContinuousMemMapAllocSpace.
Moved the SwapBitmaps function to ContinuousMemMapAllocSpace since the zygote space uses this function during full GC. Fixed a place where we were casting a ZygoteSpace to a MallocSpace, somehow this didn't cause any issues in non-debug builds. Moved the CollectGarbage in PreZygoteFork before the lock to prevent an occasional lock level violation caused by attempting to enqueue java lang references with the a lock. Bug: 12876255 Change-Id: I77439e46d5b26b37724bdcee3a0948410f1b0eb4
-rw-r--r--runtime/gc/collector/garbage_collector.cc5
-rw-r--r--runtime/gc/collector/sticky_mark_sweep.cc2
-rw-r--r--runtime/gc/heap.cc2
-rw-r--r--runtime/gc/space/malloc_space.cc8
-rw-r--r--runtime/gc/space/malloc_space.h3
-rw-r--r--runtime/gc/space/space-inl.h2
-rw-r--r--runtime/gc/space/space.cc18
-rw-r--r--runtime/gc/space/space.h2
-rw-r--r--runtime/native/dalvik_system_VMDebug.cc7
9 files changed, 26 insertions, 23 deletions
diff --git a/runtime/gc/collector/garbage_collector.cc b/runtime/gc/collector/garbage_collector.cc
index 25e8966814..ae04074c93 100644
--- a/runtime/gc/collector/garbage_collector.cc
+++ b/runtime/gc/collector/garbage_collector.cc
@@ -151,10 +151,11 @@ void GarbageCollector::SwapBitmaps() {
space->GetGcRetentionPolicy() == space::kGcRetentionPolicyFullCollect)) {
accounting::SpaceBitmap* live_bitmap = space->GetLiveBitmap();
accounting::SpaceBitmap* mark_bitmap = space->GetMarkBitmap();
- if (live_bitmap != mark_bitmap) {
+ if (live_bitmap != nullptr && live_bitmap != mark_bitmap) {
heap_->GetLiveBitmap()->ReplaceBitmap(live_bitmap, mark_bitmap);
heap_->GetMarkBitmap()->ReplaceBitmap(mark_bitmap, live_bitmap);
- space->AsMallocSpace()->SwapBitmaps();
+ CHECK(space->IsContinuousMemMapAllocSpace());
+ space->AsContinuousMemMapAllocSpace()->SwapBitmaps();
}
}
}
diff --git a/runtime/gc/collector/sticky_mark_sweep.cc b/runtime/gc/collector/sticky_mark_sweep.cc
index 30f3753ab4..9e3adb44be 100644
--- a/runtime/gc/collector/sticky_mark_sweep.cc
+++ b/runtime/gc/collector/sticky_mark_sweep.cc
@@ -38,7 +38,7 @@ void StickyMarkSweep::BindBitmaps() {
// know what was allocated since the last GC. A side-effect of binding the allocation space mark
// and live bitmap is that marking the objects will place them in the live bitmap.
for (const auto& space : GetHeap()->GetContinuousSpaces()) {
- if (space->IsMallocSpace() &&
+ if (space->IsContinuousMemMapAllocSpace() &&
space->GetGcRetentionPolicy() == space::kGcRetentionPolicyAlwaysCollect) {
DCHECK(space->IsContinuousMemMapAllocSpace());
space->AsContinuousMemMapAllocSpace()->BindLiveToMarkBitmap();
diff --git a/runtime/gc/heap.cc b/runtime/gc/heap.cc
index eb38310d8f..309adb7416 100644
--- a/runtime/gc/heap.cc
+++ b/runtime/gc/heap.cc
@@ -1431,6 +1431,7 @@ void Heap::UnBindBitmaps() {
}
void Heap::PreZygoteFork() {
+ CollectGarbageInternal(collector::kGcTypeFull, kGcCauseBackground, false);
static Mutex zygote_creation_lock_("zygote creation lock", kZygoteCreationLock);
Thread* self = Thread::Current();
MutexLock mu(self, zygote_creation_lock_);
@@ -1439,7 +1440,6 @@ void Heap::PreZygoteFork() {
return;
}
VLOG(heap) << "Starting PreZygoteFork";
- CollectGarbageInternal(collector::kGcTypeFull, kGcCauseBackground, false);
// Trim the pages at the end of the non moving space.
non_moving_space_->Trim();
non_moving_space_->GetMemMap()->Protect(PROT_READ | PROT_WRITE);
diff --git a/runtime/gc/space/malloc_space.cc b/runtime/gc/space/malloc_space.cc
index 9ca4eac523..6c6cb97d7e 100644
--- a/runtime/gc/space/malloc_space.cc
+++ b/runtime/gc/space/malloc_space.cc
@@ -95,14 +95,6 @@ MemMap* MallocSpace::CreateMemMap(const std::string& name, size_t starting_size,
return mem_map;
}
-void MallocSpace::SwapBitmaps() {
- live_bitmap_.swap(mark_bitmap_);
- // Swap names to get more descriptive diagnostics.
- std::string temp_name(live_bitmap_->GetName());
- live_bitmap_->SetName(mark_bitmap_->GetName());
- mark_bitmap_->SetName(temp_name);
-}
-
mirror::Class* MallocSpace::FindRecentFreedObject(const mirror::Object* obj) {
size_t pos = recent_free_pos_;
// Start at the most recently freed object and work our way back since there may be duplicates
diff --git a/runtime/gc/space/malloc_space.h b/runtime/gc/space/malloc_space.h
index 58cfe8b6b9..9a42e2cd88 100644
--- a/runtime/gc/space/malloc_space.h
+++ b/runtime/gc/space/malloc_space.h
@@ -109,9 +109,6 @@ class MallocSpace : public ContinuousMemMapAllocSpace {
void SetGrowthLimit(size_t growth_limit);
- // Swap the live and mark bitmaps of this space. This is used by the GC for concurrent sweeping.
- void SwapBitmaps();
-
virtual MallocSpace* CreateInstance(const std::string& name, MemMap* mem_map, void* allocator,
byte* begin, byte* end, byte* limit, size_t growth_limit) = 0;
diff --git a/runtime/gc/space/space-inl.h b/runtime/gc/space/space-inl.h
index e94c44e7f5..02a63f6e73 100644
--- a/runtime/gc/space/space-inl.h
+++ b/runtime/gc/space/space-inl.h
@@ -32,7 +32,7 @@ inline ImageSpace* Space::AsImageSpace() {
}
inline MallocSpace* Space::AsMallocSpace() {
- DCHECK(GetType() == kSpaceTypeMallocSpace);
+ DCHECK(IsMallocSpace());
DCHECK(IsDlMallocSpace() || IsRosAllocSpace());
return down_cast<MallocSpace*>(down_cast<MemMapSpace*>(this));
}
diff --git a/runtime/gc/space/space.cc b/runtime/gc/space/space.cc
index 5478d5b1b4..32a00bc4a1 100644
--- a/runtime/gc/space/space.cc
+++ b/runtime/gc/space/space.cc
@@ -77,10 +77,12 @@ void ContinuousMemMapAllocSpace::Sweep(bool swap_bitmaps, size_t* freed_objects,
void ContinuousMemMapAllocSpace::BindLiveToMarkBitmap() {
CHECK(!HasBoundBitmaps());
accounting::SpaceBitmap* live_bitmap = GetLiveBitmap();
- accounting::SpaceBitmap* mark_bitmap = mark_bitmap_.release();
- Runtime::Current()->GetHeap()->GetMarkBitmap()->ReplaceBitmap(mark_bitmap, live_bitmap);
- temp_bitmap_.reset(mark_bitmap);
- mark_bitmap_.reset(live_bitmap);
+ if (live_bitmap != mark_bitmap_.get()) {
+ accounting::SpaceBitmap* mark_bitmap = mark_bitmap_.release();
+ Runtime::Current()->GetHeap()->GetMarkBitmap()->ReplaceBitmap(mark_bitmap, live_bitmap);
+ temp_bitmap_.reset(mark_bitmap);
+ mark_bitmap_.reset(live_bitmap);
+ }
}
bool ContinuousMemMapAllocSpace::HasBoundBitmaps() const {
@@ -97,6 +99,14 @@ void ContinuousMemMapAllocSpace::UnBindBitmaps() {
DCHECK(temp_bitmap_.get() == nullptr);
}
+void ContinuousMemMapAllocSpace::SwapBitmaps() {
+ live_bitmap_.swap(mark_bitmap_);
+ // Swap names to get more descriptive diagnostics.
+ std::string temp_name(live_bitmap_->GetName());
+ live_bitmap_->SetName(mark_bitmap_->GetName());
+ mark_bitmap_->SetName(temp_name);
+}
+
} // namespace space
} // namespace gc
} // namespace art
diff --git a/runtime/gc/space/space.h b/runtime/gc/space/space.h
index 32230b3529..95a79ec48d 100644
--- a/runtime/gc/space/space.h
+++ b/runtime/gc/space/space.h
@@ -411,6 +411,8 @@ class ContinuousMemMapAllocSpace : public MemMapSpace, public AllocSpace {
void BindLiveToMarkBitmap()
EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_);
void UnBindBitmaps() EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_);
+ // Swap the live and mark bitmaps of this space. This is used by the GC for concurrent sweeping.
+ void SwapBitmaps();
virtual void Clear() {
LOG(FATAL) << "Unimplemented";
diff --git a/runtime/native/dalvik_system_VMDebug.cc b/runtime/native/dalvik_system_VMDebug.cc
index 4a84cfecff..dceea5c545 100644
--- a/runtime/native/dalvik_system_VMDebug.cc
+++ b/runtime/native/dalvik_system_VMDebug.cc
@@ -24,6 +24,7 @@
#include "gc/space/dlmalloc_space.h"
#include "gc/space/large_object_space.h"
#include "gc/space/space-inl.h"
+#include "gc/space/zygote_space.h"
#include "hprof/hprof.h"
#include "jni_internal.h"
#include "mirror/class.h"
@@ -265,9 +266,9 @@ static void VMDebug_getHeapSpaceStats(JNIEnv* env, jclass, jlongArray data) {
if (space->IsImageSpace()) {
// Currently don't include the image space.
} else if (space->IsZygoteSpace()) {
- gc::space::MallocSpace* malloc_space = space->AsMallocSpace();
- zygoteSize += malloc_space->GetFootprint();
- zygoteUsed += malloc_space->GetBytesAllocated();
+ gc::space::ZygoteSpace* zygote_space = space->AsZygoteSpace();
+ zygoteSize += zygote_space->Size();
+ zygoteUsed += zygote_space->GetBytesAllocated();
} else if (space->IsMallocSpace()) {
// This is a malloc space.
gc::space::MallocSpace* malloc_space = space->AsMallocSpace();