blob: e1aa6161d3c865ecf4f88ce0d00a01ab5e98d556 [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
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070019#include "globals.h"
20#include "logging.h"
Elliott Hughesa168c832012-06-12 15:34:20 -070021#include "UniquePtr.h"
Elliott Hughesf0605a02012-01-13 20:12:02 -080022#include "utils.h"
Carl Shapiro69759ea2011-07-21 18:13:35 -070023
24namespace art {
25
Brian Carlstrom4a289ed2011-08-16 17:17:49 -070026MarkStack* MarkStack::Create() {
Elliott Hughes90a33692011-08-30 13:27:07 -070027 UniquePtr<MarkStack> mark_stack(new MarkStack);
Jesse Wilson078f9b02011-11-18 17:51:47 -050028 mark_stack->Init();
29 return mark_stack.release();
Carl Shapiro69759ea2011-07-21 18:13:35 -070030}
31
Jesse Wilson078f9b02011-11-18 17:51:47 -050032void MarkStack::Init() {
Carl Shapiro69759ea2011-07-21 18:13:35 -070033 size_t length = 64 * MB;
Brian Carlstrom89521892011-12-07 22:05:07 -080034 mem_map_.reset(MemMap::MapAnonymous("dalvik-mark-stack", NULL, length, PROT_READ | PROT_WRITE));
Elliott Hughesf0605a02012-01-13 20:12:02 -080035 if (mem_map_.get() == NULL) {
36 std::string maps;
37 ReadFileToString("/proc/self/maps", &maps);
38 LOG(FATAL) << "couldn't allocate mark stack\n" << maps;
39 }
Ian Rogers30fab402012-01-23 15:43:46 -080040 byte* addr = mem_map_->Begin();
Elliott Hughesf0605a02012-01-13 20:12:02 -080041 CHECK(addr != NULL);
Mathieu Chartier5301cd22012-05-31 12:11:36 -070042
Ian Rogers30fab402012-01-23 15:43:46 -080043 begin_ = reinterpret_cast<const Object**>(addr);
Brian Carlstromdb4d5402011-08-09 12:18:28 -070044 limit_ = reinterpret_cast<const Object**>(addr + length);
Mathieu Chartier5301cd22012-05-31 12:11:36 -070045
46 Reset();
47}
48
49void MarkStack::Reset() {
50 DCHECK(mem_map_.get() != NULL);
51 DCHECK(begin_ != NULL);
52 DCHECK(limit_ != NULL);
53 byte* addr = const_cast<byte*>(reinterpret_cast<const byte*>(begin_));
54 const size_t length = limit_ - begin_;
55 ptr_ = reinterpret_cast<const Object**>(addr);
Carl Shapiro69759ea2011-07-21 18:13:35 -070056 int result = madvise(addr, length, MADV_DONTNEED);
57 if (result == -1) {
58 PLOG(WARNING) << "madvise failed";
59 }
Carl Shapiro69759ea2011-07-21 18:13:35 -070060}
61
Elliott Hughes28a452a2012-01-17 20:39:44 -080062MarkStack::~MarkStack() {
63 CHECK(IsEmpty());
64}
Carl Shapiro69759ea2011-07-21 18:13:35 -070065
66} // namespace art