OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/base/atomicops.h" | 7 #include "src/base/atomicops.h" |
8 #include "src/base/bits.h" | 8 #include "src/base/bits.h" |
9 #include "src/code-stubs.h" | 9 #include "src/code-stubs.h" |
10 #include "src/compilation-cache.h" | 10 #include "src/compilation-cache.h" |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 VerifyEvacuation(heap->new_space()); | 219 VerifyEvacuation(heap->new_space()); |
220 | 220 |
221 VerifyEvacuationVisitor visitor; | 221 VerifyEvacuationVisitor visitor; |
222 heap->IterateStrongRoots(&visitor, VISIT_ALL); | 222 heap->IterateStrongRoots(&visitor, VISIT_ALL); |
223 } | 223 } |
224 #endif // VERIFY_HEAP | 224 #endif // VERIFY_HEAP |
225 | 225 |
226 | 226 |
227 void MarkCompactCollector::SetUp() { | 227 void MarkCompactCollector::SetUp() { |
228 free_list_old_space_.Reset(new FreeList(heap_->old_space())); | 228 free_list_old_space_.Reset(new FreeList(heap_->old_space())); |
| 229 EnsureMarkingDequeIsCommittedAndInitialize(256 * KB); |
229 } | 230 } |
230 | 231 |
231 | 232 |
232 void MarkCompactCollector::TearDown() { | 233 void MarkCompactCollector::TearDown() { |
233 AbortCompaction(); | 234 AbortCompaction(); |
234 delete marking_deque_memory_; | 235 delete marking_deque_memory_; |
235 } | 236 } |
236 | 237 |
237 | 238 |
238 void MarkCompactCollector::AddEvacuationCandidate(Page* p) { | 239 void MarkCompactCollector::AddEvacuationCandidate(Page* p) { |
(...skipping 2011 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2250 } | 2251 } |
2251 Object* undefined = heap()->undefined_value(); | 2252 Object* undefined = heap()->undefined_value(); |
2252 for (int i = new_length; i < length; i++) { | 2253 for (int i = new_length; i < length; i++) { |
2253 retained_maps->Clear(i, undefined); | 2254 retained_maps->Clear(i, undefined); |
2254 } | 2255 } |
2255 if (new_length != length) retained_maps->SetLength(new_length); | 2256 if (new_length != length) retained_maps->SetLength(new_length); |
2256 ProcessMarkingDeque(); | 2257 ProcessMarkingDeque(); |
2257 } | 2258 } |
2258 | 2259 |
2259 | 2260 |
2260 void MarkCompactCollector::EnsureMarkingDequeIsCommittedAndInitialize() { | 2261 void MarkCompactCollector::EnsureMarkingDequeIsCommittedAndInitialize( |
2261 if (marking_deque_memory_ == NULL) { | 2262 size_t max_size) { |
2262 marking_deque_memory_ = new base::VirtualMemory(4 * MB); | 2263 // If the marking deque is too small, we try to allocate a bigger one. |
| 2264 // If that fails, make do with a smaller one. |
| 2265 for (size_t size = max_size; size >= 256 * KB; size >>= 1) { |
| 2266 base::VirtualMemory* memory = marking_deque_memory_; |
| 2267 bool is_committed = marking_deque_memory_committed_; |
| 2268 |
| 2269 if (memory == NULL || memory->size() < size) { |
| 2270 // If we don't have memory or we only have small memory, then |
| 2271 // try to reserve a new one. |
| 2272 memory = new base::VirtualMemory(size); |
| 2273 is_committed = false; |
| 2274 } |
| 2275 if (is_committed) return; |
| 2276 if (memory->IsReserved() && |
| 2277 memory->Commit(reinterpret_cast<Address>(memory->address()), |
| 2278 memory->size(), |
| 2279 false)) { // Not executable. |
| 2280 if (marking_deque_memory_ != NULL && marking_deque_memory_ != memory) { |
| 2281 delete marking_deque_memory_; |
| 2282 } |
| 2283 marking_deque_memory_ = memory; |
| 2284 marking_deque_memory_committed_ = true; |
| 2285 InitializeMarkingDeque(); |
| 2286 return; |
| 2287 } else { |
| 2288 // Commit failed, so we are under memory pressure. If this was the |
| 2289 // previously reserved area we tried to commit, then remove references |
| 2290 // to it before deleting it and unreserving it. |
| 2291 if (marking_deque_memory_ == memory) { |
| 2292 marking_deque_memory_ = NULL; |
| 2293 marking_deque_memory_committed_ = false; |
| 2294 } |
| 2295 delete memory; // Will also unreserve the virtual allocation. |
| 2296 } |
2263 } | 2297 } |
2264 if (!marking_deque_memory_committed_) { | 2298 V8::FatalProcessOutOfMemory("EnsureMarkingDequeIsCommitted"); |
2265 if (!marking_deque_memory_->Commit( | |
2266 reinterpret_cast<Address>(marking_deque_memory_->address()), | |
2267 marking_deque_memory_->size(), | |
2268 false)) { // Not executable. | |
2269 V8::FatalProcessOutOfMemory("EnsureMarkingDequeIsCommitted"); | |
2270 } | |
2271 marking_deque_memory_committed_ = true; | |
2272 InitializeMarkingDeque(); | |
2273 } | |
2274 } | 2299 } |
2275 | 2300 |
2276 | 2301 |
2277 void MarkCompactCollector::InitializeMarkingDeque() { | 2302 void MarkCompactCollector::InitializeMarkingDeque() { |
2278 if (marking_deque_memory_committed_) { | 2303 if (marking_deque_memory_committed_) { |
2279 Address addr = static_cast<Address>(marking_deque_memory_->address()); | 2304 Address addr = static_cast<Address>(marking_deque_memory_->address()); |
2280 size_t size = marking_deque_memory_->size(); | 2305 size_t size = marking_deque_memory_->size(); |
2281 if (FLAG_force_marking_deque_overflows) size = 64 * kPointerSize; | 2306 if (FLAG_force_marking_deque_overflows) size = 64 * kPointerSize; |
2282 marking_deque_.Initialize(addr, addr + size); | 2307 marking_deque_.Initialize(addr, addr + size); |
2283 } | 2308 } |
(...skipping 2473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4757 SlotsBuffer* buffer = *buffer_address; | 4782 SlotsBuffer* buffer = *buffer_address; |
4758 while (buffer != NULL) { | 4783 while (buffer != NULL) { |
4759 SlotsBuffer* next_buffer = buffer->next(); | 4784 SlotsBuffer* next_buffer = buffer->next(); |
4760 DeallocateBuffer(buffer); | 4785 DeallocateBuffer(buffer); |
4761 buffer = next_buffer; | 4786 buffer = next_buffer; |
4762 } | 4787 } |
4763 *buffer_address = NULL; | 4788 *buffer_address = NULL; |
4764 } | 4789 } |
4765 } | 4790 } |
4766 } // namespace v8::internal | 4791 } // namespace v8::internal |
OLD | NEW |