Fail in the right place when we cannot allocate a mark stack.
Previously we'd keep going and then crash when dereferencing
the mark stack later. I expected dalvikvm to throw an OutOfMemoryError
in this scenario but it also aborts.
Change-Id: I3cd995113561f40b191fcb51ecfcb1f032bed4ec
diff --git a/src/mark_stack.cc b/src/mark_stack.cc
index 34bad7d..a35fa2d 100644
--- a/src/mark_stack.cc
+++ b/src/mark_stack.cc
@@ -12,20 +12,14 @@
MarkStack* MarkStack::Create() {
UniquePtr<MarkStack> mark_stack(new MarkStack);
- bool success = mark_stack->Init();
- if (!success) {
- return NULL;
- } else {
- return mark_stack.release();
- }
+ mark_stack->Init();
+ return mark_stack.release();
}
-bool MarkStack::Init() {
+void MarkStack::Init() {
size_t length = 64 * MB;
mem_map_.reset(MemMap::Map("dalvik-mark-stack", NULL, length, PROT_READ | PROT_WRITE));
- if (mem_map_.get() == NULL) {
- return false;
- }
+ CHECK(mem_map_.get() != NULL) << "MemMap::Map() failed; aborting";
byte* addr = mem_map_->GetAddress();
base_ = reinterpret_cast<const Object**>(addr);
limit_ = reinterpret_cast<const Object**>(addr + length);
@@ -34,7 +28,6 @@
if (result == -1) {
PLOG(WARNING) << "madvise failed";
}
- return true;
}
MarkStack::~MarkStack() {}
diff --git a/src/mark_stack.h b/src/mark_stack.h
index f8beaff..47d18cd 100644
--- a/src/mark_stack.h
+++ b/src/mark_stack.h
@@ -41,7 +41,7 @@
base_(NULL), limit_(NULL), ptr_(NULL) {
}
- bool Init();
+ void Init();
// Memory mapping of the mark stack.
UniquePtr<MemMap> mem_map_;
diff --git a/src/mark_sweep.cc b/src/mark_sweep.cc
index bf4f1bf..d44796c 100644
--- a/src/mark_sweep.cc
+++ b/src/mark_sweep.cc
@@ -22,12 +22,8 @@
namespace art {
-bool MarkSweep::Init() {
+void MarkSweep::Init() {
mark_stack_ = MarkStack::Create();
- if (mark_stack_ == NULL) {
- return false;
- }
-
mark_bitmap_ = Heap::GetMarkBits();
live_bitmap_ = Heap::GetLiveBits();
@@ -36,8 +32,6 @@
// TODO: if concurrent, enable card marking in compiler
// TODO: check that the mark bitmap is entirely clear.
-
- return true;
}
inline void MarkSweep::MarkObject0(const Object* obj, bool check_finger) {
diff --git a/src/mark_sweep.h b/src/mark_sweep.h
index 11afd1c..c517246 100644
--- a/src/mark_sweep.h
+++ b/src/mark_sweep.h
@@ -29,7 +29,7 @@
~MarkSweep();
// Initializes internal structures.
- bool Init();
+ void Init();
// Marks the root set at the start of a garbage collection.
void MarkRoots();