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_stack.cc b/src/mark_stack.cc
index 60c9e0d..e269455 100644
--- a/src/mark_stack.cc
+++ b/src/mark_stack.cc
@@ -41,9 +41,20 @@
}
byte* addr = mem_map_->Begin();
CHECK(addr != NULL);
+
begin_ = reinterpret_cast<const Object**>(addr);
limit_ = reinterpret_cast<const Object**>(addr + length);
- ptr_ = reinterpret_cast<Object const**>(addr);
+
+ Reset();
+}
+
+void MarkStack::Reset() {
+ DCHECK(mem_map_.get() != NULL);
+ DCHECK(begin_ != NULL);
+ DCHECK(limit_ != NULL);
+ byte* addr = const_cast<byte*>(reinterpret_cast<const byte*>(begin_));
+ const size_t length = limit_ - begin_;
+ ptr_ = reinterpret_cast<const Object**>(addr);
int result = madvise(addr, length, MADV_DONTNEED);
if (result == -1) {
PLOG(WARNING) << "madvise failed";