Mark stack create once per heap.
Mark stack is now created during heap initialization and is then re-used for each GC. This helps to prevent fragmentation of the heap.
Change-Id: I5dd1bdfb58452415b88bfeb0c05a41ecbca09696
diff --git a/src/mark_sweep.cc b/src/mark_sweep.cc
index 381c7f0..b80d1f6 100644
--- a/src/mark_sweep.cc
+++ b/src/mark_sweep.cc
@@ -36,12 +36,27 @@
namespace art {
-void MarkSweep::Init() {
- mark_stack_ = MarkStack::Create();
+MarkSweep::MarkSweep(MarkStack* mark_stack)
+ : mark_stack_(mark_stack),
+ heap_(NULL),
+ mark_bitmap_(NULL),
+ live_bitmap_(NULL),
+ finger_(NULL),
+ condemned_(NULL),
+ soft_reference_list_(NULL),
+ weak_reference_list_(NULL),
+ finalizer_reference_list_(NULL),
+ phantom_reference_list_(NULL),
+ cleared_reference_list_(NULL),
+ class_count_(0), array_count_(0), other_count_(0) {
+ DCHECK(mark_stack_ != NULL);
+}
+void MarkSweep::Init() {
heap_ = Runtime::Current()->GetHeap();
mark_bitmap_ = heap_->GetMarkBits();
live_bitmap_ = heap_->GetLiveBits();
+ mark_stack_->Reset();
// TODO: if concurrent, clear the card table.
@@ -598,8 +613,8 @@
#ifndef NDEBUG
VLOG(heap) << "MarkSweep scanned classes=" << class_count_ << " arrays=" << array_count_ << " other=" << other_count_;
#endif
- delete mark_stack_;
mark_bitmap_->Clear();
+ mark_stack_->Reset();
}
} // namespace art