Elliott Hughes | 2faa5f1 | 2012-01-30 14:42:07 -0800 | [diff] [blame] | 1 | /* |
| 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 Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 16 | |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 17 | #include "mark_stack.h" |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 18 | |
| 19 | #include <sys/mman.h> |
| 20 | |
Elliott Hughes | 90a3369 | 2011-08-30 13:27:07 -0700 | [diff] [blame] | 21 | #include "UniquePtr.h" |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 22 | #include "globals.h" |
| 23 | #include "logging.h" |
Elliott Hughes | f0605a0 | 2012-01-13 20:12:02 -0800 | [diff] [blame] | 24 | #include "utils.h" |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 25 | |
| 26 | namespace art { |
| 27 | |
Brian Carlstrom | 4a289ed | 2011-08-16 17:17:49 -0700 | [diff] [blame] | 28 | MarkStack* MarkStack::Create() { |
Elliott Hughes | 90a3369 | 2011-08-30 13:27:07 -0700 | [diff] [blame] | 29 | UniquePtr<MarkStack> mark_stack(new MarkStack); |
Jesse Wilson | 078f9b0 | 2011-11-18 17:51:47 -0500 | [diff] [blame] | 30 | mark_stack->Init(); |
| 31 | return mark_stack.release(); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 32 | } |
| 33 | |
Jesse Wilson | 078f9b0 | 2011-11-18 17:51:47 -0500 | [diff] [blame] | 34 | void MarkStack::Init() { |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 35 | size_t length = 64 * MB; |
Brian Carlstrom | 8952189 | 2011-12-07 22:05:07 -0800 | [diff] [blame] | 36 | mem_map_.reset(MemMap::MapAnonymous("dalvik-mark-stack", NULL, length, PROT_READ | PROT_WRITE)); |
Elliott Hughes | f0605a0 | 2012-01-13 20:12:02 -0800 | [diff] [blame] | 37 | 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 Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 42 | byte* addr = mem_map_->Begin(); |
Elliott Hughes | f0605a0 | 2012-01-13 20:12:02 -0800 | [diff] [blame] | 43 | CHECK(addr != NULL); |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 44 | begin_ = reinterpret_cast<const Object**>(addr); |
Brian Carlstrom | db4d540 | 2011-08-09 12:18:28 -0700 | [diff] [blame] | 45 | limit_ = reinterpret_cast<const Object**>(addr + length); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 46 | 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 Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 51 | } |
| 52 | |
Elliott Hughes | 28a452a | 2012-01-17 20:39:44 -0800 | [diff] [blame] | 53 | MarkStack::~MarkStack() { |
| 54 | CHECK(IsEmpty()); |
| 55 | } |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 56 | |
| 57 | } // namespace art |