blob: 47aaf0c503266312f723802081481fb61f311fdf [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
Brian Carlstrom578bbdc2011-07-21 14:07:47 -07007#include "globals.h"
8#include "logging.h"
9#include "scoped_ptr.h"
Carl Shapiro69759ea2011-07-21 18:13:35 -070010
11namespace art {
12
13MarkStack* MarkStack::Create(size_t maximum_size) {
14 scoped_ptr<MarkStack> mark_stack(new MarkStack());
15 bool success = mark_stack->Init(maximum_size);
16 if (!success) {
17 return NULL;
18 } else {
19 return mark_stack.release();
20 }
21}
22
23bool MarkStack::Init(size_t maximum_size) {
24 size_t length = 64 * MB;
Brian Carlstrom4a96b602011-07-26 16:40:23 -070025 void* addr = mmap(NULL, length, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
Carl Shapiro69759ea2011-07-21 18:13:35 -070026 if (addr == MAP_FAILED) {
27 PLOG(ERROR) << "mmap failed";
28 return false;
29 }
30 base_ = reinterpret_cast<const Object**>(addr);
31 limit_ = reinterpret_cast<const Object**>((byte*)addr + length);
32 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
40MarkStack::~MarkStack() {
41 int result = munmap((void*)base_, limit_ - base_);
42 if (result == -1) {
43 PLOG(WARNING) << "munmap failed";
44 }
45}
46
47} // namespace art