blob: 34bad7d9660863ff61faaa1181d707f77c48d33d [file] [log] [blame]
Carl Shapiro69759ea2011-07-21 18:13:35 -07001// Copyright 2011 Google Inc. All Rights Reserved.
Carl Shapiro69759ea2011-07-21 18:13:35 -07002
Brian Carlstrom578bbdc2011-07-21 14:07:47 -07003#include "mark_stack.h"
Carl Shapiro69759ea2011-07-21 18:13:35 -07004
5#include <sys/mman.h>
6
Elliott Hughes90a33692011-08-30 13:27:07 -07007#include "UniquePtr.h"
Brian Carlstrom578bbdc2011-07-21 14:07:47 -07008#include "globals.h"
9#include "logging.h"
Carl Shapiro69759ea2011-07-21 18:13:35 -070010
11namespace art {
12
Brian Carlstrom4a289ed2011-08-16 17:17:49 -070013MarkStack* MarkStack::Create() {
Elliott Hughes90a33692011-08-30 13:27:07 -070014 UniquePtr<MarkStack> mark_stack(new MarkStack);
Brian Carlstrom4a289ed2011-08-16 17:17:49 -070015 bool success = mark_stack->Init();
Carl Shapiro69759ea2011-07-21 18:13:35 -070016 if (!success) {
17 return NULL;
18 } else {
19 return mark_stack.release();
20 }
21}
22
Brian Carlstrom4a289ed2011-08-16 17:17:49 -070023bool MarkStack::Init() {
Carl Shapiro69759ea2011-07-21 18:13:35 -070024 size_t length = 64 * MB;
Elliott Hughes6c9c06d2011-11-07 16:43:47 -080025 mem_map_.reset(MemMap::Map("dalvik-mark-stack", NULL, length, PROT_READ | PROT_WRITE));
Elliott Hughes90a33692011-08-30 13:27:07 -070026 if (mem_map_.get() == NULL) {
Carl Shapiro69759ea2011-07-21 18:13:35 -070027 return false;
28 }
Brian Carlstromdb4d5402011-08-09 12:18:28 -070029 byte* addr = mem_map_->GetAddress();
Carl Shapiro69759ea2011-07-21 18:13:35 -070030 base_ = reinterpret_cast<const Object**>(addr);
Brian Carlstromdb4d5402011-08-09 12:18:28 -070031 limit_ = reinterpret_cast<const Object**>(addr + length);
Carl Shapiro69759ea2011-07-21 18:13:35 -070032 ptr_ = reinterpret_cast<Object const**>(addr);
33 int result = madvise(addr, length, MADV_DONTNEED);
34 if (result == -1) {
35 PLOG(WARNING) << "madvise failed";
36 }
37 return true;
38}
39
Brian Carlstromdb4d5402011-08-09 12:18:28 -070040MarkStack::~MarkStack() {}
Carl Shapiro69759ea2011-07-21 18:13:35 -070041
42} // namespace art