blob: 60c9e0d64e51e56f28560b931d0b7e32e9f9662e [file] [log] [blame]
Elliott Hughes2faa5f12012-01-30 14:42:07 -08001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Carl Shapiro69759ea2011-07-21 18:13:35 -070016
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070017#include "mark_stack.h"
Carl Shapiro69759ea2011-07-21 18:13:35 -070018
19#include <sys/mman.h>
20
Elliott Hughes90a33692011-08-30 13:27:07 -070021#include "UniquePtr.h"
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070022#include "globals.h"
23#include "logging.h"
Elliott Hughesf0605a02012-01-13 20:12:02 -080024#include "utils.h"
Carl Shapiro69759ea2011-07-21 18:13:35 -070025
26namespace art {
27
Brian Carlstrom4a289ed2011-08-16 17:17:49 -070028MarkStack* MarkStack::Create() {
Elliott Hughes90a33692011-08-30 13:27:07 -070029 UniquePtr<MarkStack> mark_stack(new MarkStack);
Jesse Wilson078f9b02011-11-18 17:51:47 -050030 mark_stack->Init();
31 return mark_stack.release();
Carl Shapiro69759ea2011-07-21 18:13:35 -070032}
33
Jesse Wilson078f9b02011-11-18 17:51:47 -050034void MarkStack::Init() {
Carl Shapiro69759ea2011-07-21 18:13:35 -070035 size_t length = 64 * MB;
Brian Carlstrom89521892011-12-07 22:05:07 -080036 mem_map_.reset(MemMap::MapAnonymous("dalvik-mark-stack", NULL, length, PROT_READ | PROT_WRITE));
Elliott Hughesf0605a02012-01-13 20:12:02 -080037 if (mem_map_.get() == NULL) {
38 std::string maps;
39 ReadFileToString("/proc/self/maps", &maps);
40 LOG(FATAL) << "couldn't allocate mark stack\n" << maps;
41 }
Ian Rogers30fab402012-01-23 15:43:46 -080042 byte* addr = mem_map_->Begin();
Elliott Hughesf0605a02012-01-13 20:12:02 -080043 CHECK(addr != NULL);
Ian Rogers30fab402012-01-23 15:43:46 -080044 begin_ = reinterpret_cast<const Object**>(addr);
Brian Carlstromdb4d5402011-08-09 12:18:28 -070045 limit_ = reinterpret_cast<const Object**>(addr + length);
Carl Shapiro69759ea2011-07-21 18:13:35 -070046 ptr_ = reinterpret_cast<Object const**>(addr);
47 int result = madvise(addr, length, MADV_DONTNEED);
48 if (result == -1) {
49 PLOG(WARNING) << "madvise failed";
50 }
Carl Shapiro69759ea2011-07-21 18:13:35 -070051}
52
Elliott Hughes28a452a2012-01-17 20:39:44 -080053MarkStack::~MarkStack() {
54 CHECK(IsEmpty());
55}
Carl Shapiro69759ea2011-07-21 18:13:35 -070056
57} // namespace art