OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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/bits.h" | 7 #include "src/base/bits.h" |
8 #include "src/base/platform/platform.h" | 8 #include "src/base/platform/platform.h" |
9 #include "src/full-codegen.h" | 9 #include "src/full-codegen.h" |
10 #include "src/heap/mark-compact.h" | 10 #include "src/heap/mark-compact.h" |
(...skipping 2182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2193 free_bytes += huge_list_.Concatenate(free_list->huge_list()); | 2193 free_bytes += huge_list_.Concatenate(free_list->huge_list()); |
2194 return free_bytes; | 2194 return free_bytes; |
2195 } | 2195 } |
2196 | 2196 |
2197 | 2197 |
2198 void FreeList::Reset() { | 2198 void FreeList::Reset() { |
2199 small_list_.Reset(); | 2199 small_list_.Reset(); |
2200 medium_list_.Reset(); | 2200 medium_list_.Reset(); |
2201 large_list_.Reset(); | 2201 large_list_.Reset(); |
2202 huge_list_.Reset(); | 2202 huge_list_.Reset(); |
2203 unreported_allocation_ = 0; | |
2204 } | 2203 } |
2205 | 2204 |
2206 | 2205 |
2207 int FreeList::Free(Address start, int size_in_bytes) { | 2206 int FreeList::Free(Address start, int size_in_bytes) { |
2208 if (size_in_bytes == 0) return 0; | 2207 if (size_in_bytes == 0) return 0; |
2209 | 2208 |
2210 heap_->CreateFillerObjectAt(start, size_in_bytes); | 2209 heap_->CreateFillerObjectAt(start, size_in_bytes); |
2211 | 2210 |
2212 Page* page = Page::FromAddress(start); | 2211 Page* page = Page::FromAddress(start); |
2213 | 2212 |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2341 page = Page::FromAddress(node->address()); | 2340 page = Page::FromAddress(node->address()); |
2342 page->add_available_in_large_free_list(-(*node_size)); | 2341 page->add_available_in_large_free_list(-(*node_size)); |
2343 } | 2342 } |
2344 } | 2343 } |
2345 | 2344 |
2346 DCHECK(IsVeryLong() || available() == SumFreeLists()); | 2345 DCHECK(IsVeryLong() || available() == SumFreeLists()); |
2347 return node; | 2346 return node; |
2348 } | 2347 } |
2349 | 2348 |
2350 | 2349 |
2351 void PagedSpace::SetTopAndLimit(Address top, Address limit) { | |
2352 DCHECK(top == limit || | |
2353 Page::FromAddress(top) == Page::FromAddress(limit - 1)); | |
2354 MemoryChunk::UpdateHighWaterMark(allocation_info_.top()); | |
2355 allocation_info_.set_top(top); | |
2356 allocation_info_.set_limit(limit); | |
2357 } | |
2358 | |
2359 | |
2360 // Allocation on the old space free list. If it succeeds then a new linear | 2350 // Allocation on the old space free list. If it succeeds then a new linear |
2361 // allocation space has been set up with the top and limit of the space. If | 2351 // allocation space has been set up with the top and limit of the space. If |
2362 // the allocation fails then NULL is returned, and the caller can perform a GC | 2352 // the allocation fails then NULL is returned, and the caller can perform a GC |
2363 // or allocate a new page before retrying. | 2353 // or allocate a new page before retrying. |
2364 HeapObject* FreeList::Allocate(int size_in_bytes) { | 2354 HeapObject* FreeList::Allocate(int size_in_bytes) { |
2365 DCHECK(0 < size_in_bytes); | 2355 DCHECK(0 < size_in_bytes); |
2366 DCHECK(size_in_bytes <= kMaxBlockSize); | 2356 DCHECK(size_in_bytes <= kMaxBlockSize); |
2367 DCHECK(IsAligned(size_in_bytes, kPointerSize)); | 2357 DCHECK(IsAligned(size_in_bytes, kPointerSize)); |
2368 // Don't free list allocate if there is linear space available. | 2358 // Don't free list allocate if there is linear space available. |
2369 DCHECK(owner_->limit() - owner_->top() < size_in_bytes); | 2359 DCHECK(owner_->limit() - owner_->top() < size_in_bytes); |
2370 | 2360 |
2371 int old_linear_size = static_cast<int>(owner_->limit() - owner_->top()); | 2361 int old_linear_size = static_cast<int>(owner_->limit() - owner_->top()); |
2372 // Mark the old linear allocation area with a free space map so it can be | 2362 // Mark the old linear allocation area with a free space map so it can be |
2373 // skipped when scanning the heap. This also puts it back in the free list | 2363 // skipped when scanning the heap. This also puts it back in the free list |
2374 // if it is big enough. | 2364 // if it is big enough. |
2375 owner_->Free(owner_->top(), old_linear_size); | 2365 owner_->Free(owner_->top(), old_linear_size); |
2376 | 2366 |
| 2367 owner_->heap()->incremental_marking()->OldSpaceStep(size_in_bytes - |
| 2368 old_linear_size); |
| 2369 |
2377 int new_node_size = 0; | 2370 int new_node_size = 0; |
2378 FreeSpace* new_node = FindNodeFor(size_in_bytes, &new_node_size); | 2371 FreeSpace* new_node = FindNodeFor(size_in_bytes, &new_node_size); |
2379 if (new_node == NULL) { | 2372 if (new_node == NULL) { |
2380 owner_->SetTopAndLimit(NULL, NULL); | 2373 owner_->SetTopAndLimit(NULL, NULL); |
2381 return NULL; | 2374 return NULL; |
2382 } | 2375 } |
2383 | 2376 |
2384 int bytes_left = new_node_size - size_in_bytes; | 2377 int bytes_left = new_node_size - size_in_bytes; |
2385 DCHECK(bytes_left >= 0); | 2378 DCHECK(bytes_left >= 0); |
2386 | 2379 |
2387 #ifdef DEBUG | 2380 #ifdef DEBUG |
2388 for (int i = 0; i < size_in_bytes / kPointerSize; i++) { | 2381 for (int i = 0; i < size_in_bytes / kPointerSize; i++) { |
2389 reinterpret_cast<Object**>(new_node->address())[i] = | 2382 reinterpret_cast<Object**>(new_node->address())[i] = |
2390 Smi::FromInt(kCodeZapValue); | 2383 Smi::FromInt(kCodeZapValue); |
2391 } | 2384 } |
2392 #endif | 2385 #endif |
2393 | 2386 |
2394 // The old-space-step might have finished sweeping and restarted marking. | 2387 // The old-space-step might have finished sweeping and restarted marking. |
2395 // Verify that it did not turn the page of the new node into an evacuation | 2388 // Verify that it did not turn the page of the new node into an evacuation |
2396 // candidate. | 2389 // candidate. |
2397 DCHECK(!MarkCompactCollector::IsOnEvacuationCandidate(new_node)); | 2390 DCHECK(!MarkCompactCollector::IsOnEvacuationCandidate(new_node)); |
2398 | 2391 |
2399 // An old-space step will mark more data per byte allocated, because old space | 2392 const int kThreshold = IncrementalMarking::kAllocatedThreshold; |
2400 // allocation is more serious. We don't want the pause to be bigger, so we | |
2401 // do marking after a smaller amount of allocation. | |
2402 const int kThreshold = IncrementalMarking::kAllocatedThreshold * | |
2403 IncrementalMarking::kOldSpaceAllocationMarkingFactor; | |
2404 | 2393 |
2405 // Memory in the linear allocation area is counted as allocated. We may free | 2394 // Memory in the linear allocation area is counted as allocated. We may free |
2406 // a little of this again immediately - see below. | 2395 // a little of this again immediately - see below. |
2407 owner_->Allocate(new_node_size); | 2396 owner_->Allocate(new_node_size); |
2408 | 2397 |
2409 unreported_allocation_ += new_node_size; | |
2410 | |
2411 if (owner_->heap()->inline_allocation_disabled()) { | 2398 if (owner_->heap()->inline_allocation_disabled()) { |
2412 // Keep the linear allocation area empty if requested to do so, just | 2399 // Keep the linear allocation area empty if requested to do so, just |
2413 // return area back to the free list instead. | 2400 // return area back to the free list instead. |
2414 owner_->Free(new_node->address() + size_in_bytes, bytes_left); | 2401 owner_->Free(new_node->address() + size_in_bytes, bytes_left); |
2415 DCHECK(owner_->top() == NULL && owner_->limit() == NULL); | 2402 DCHECK(owner_->top() == NULL && owner_->limit() == NULL); |
2416 } else if (bytes_left > kThreshold && | 2403 } else if (bytes_left > kThreshold && |
2417 owner_->heap()->incremental_marking()->CanDoSteps()) { | 2404 owner_->heap()->incremental_marking()->IsMarkingIncomplete() && |
| 2405 FLAG_incremental_marking_steps) { |
2418 int linear_size = owner_->RoundSizeDownToObjectAlignment(kThreshold); | 2406 int linear_size = owner_->RoundSizeDownToObjectAlignment(kThreshold); |
2419 | |
2420 // We don't want to give too large linear areas to the allocator while | 2407 // We don't want to give too large linear areas to the allocator while |
2421 // incremental marking is going on, because we won't check again whether | 2408 // incremental marking is going on, because we won't check again whether |
2422 // we want to do another increment until the linear area is used up. | 2409 // we want to do another increment until the linear area is used up. |
2423 owner_->Free(new_node->address() + size_in_bytes + linear_size, | 2410 owner_->Free(new_node->address() + size_in_bytes + linear_size, |
2424 new_node_size - size_in_bytes - linear_size); | 2411 new_node_size - size_in_bytes - linear_size); |
2425 owner_->SetTopAndLimit(new_node->address() + size_in_bytes, | 2412 owner_->SetTopAndLimit(new_node->address() + size_in_bytes, |
2426 new_node->address() + size_in_bytes + linear_size); | 2413 new_node->address() + size_in_bytes + linear_size); |
2427 owner_->heap()->incremental_marking()->OldSpaceStep(size_in_bytes + | 2414 } else if (bytes_left > 0) { |
2428 linear_size); | 2415 // Normally we give the rest of the node to the allocator as its new |
2429 unreported_allocation_ = 0; | 2416 // linear allocation area. |
| 2417 owner_->SetTopAndLimit(new_node->address() + size_in_bytes, |
| 2418 new_node->address() + new_node_size); |
2430 } else { | 2419 } else { |
2431 if (unreported_allocation_ > kThreshold) { | 2420 // TODO(gc) Try not freeing linear allocation region when bytes_left |
2432 // This may start the incremental marker, or do a little work if it's | 2421 // are zero. |
2433 // already started. | 2422 owner_->SetTopAndLimit(NULL, NULL); |
2434 owner_->heap()->incremental_marking()->OldSpaceStep( | |
2435 Min(kThreshold, unreported_allocation_)); | |
2436 unreported_allocation_ = 0; | |
2437 } | |
2438 if (bytes_left > 0) { | |
2439 // Normally we give the rest of the node to the allocator as its new | |
2440 // linear allocation area. | |
2441 owner_->SetTopAndLimit(new_node->address() + size_in_bytes, | |
2442 new_node->address() + new_node_size); | |
2443 } else { | |
2444 // TODO(gc) Try not freeing linear allocation region when bytes_left | |
2445 // are zero. | |
2446 owner_->SetTopAndLimit(NULL, NULL); | |
2447 } | |
2448 } | 2423 } |
2449 | 2424 |
2450 return new_node; | 2425 return new_node; |
2451 } | 2426 } |
2452 | 2427 |
2453 | 2428 |
2454 intptr_t FreeList::EvictFreeListItems(Page* p) { | 2429 intptr_t FreeList::EvictFreeListItems(Page* p) { |
2455 intptr_t sum = huge_list_.EvictFreeListItemsInList(p); | 2430 intptr_t sum = huge_list_.EvictFreeListItemsInList(p); |
2456 p->set_available_in_huge_free_list(0); | 2431 p->set_available_in_huge_free_list(0); |
2457 | 2432 |
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2924 MSAN_ALLOCATED_UNINITIALIZED_MEMORY(object->address(), object_size); | 2899 MSAN_ALLOCATED_UNINITIALIZED_MEMORY(object->address(), object_size); |
2925 | 2900 |
2926 if (Heap::ShouldZapGarbage()) { | 2901 if (Heap::ShouldZapGarbage()) { |
2927 // Make the object consistent so the heap can be verified in OldSpaceStep. | 2902 // Make the object consistent so the heap can be verified in OldSpaceStep. |
2928 // We only need to do this in debug builds or if verify_heap is on. | 2903 // We only need to do this in debug builds or if verify_heap is on. |
2929 reinterpret_cast<Object**>(object->address())[0] = | 2904 reinterpret_cast<Object**>(object->address())[0] = |
2930 heap()->fixed_array_map(); | 2905 heap()->fixed_array_map(); |
2931 reinterpret_cast<Object**>(object->address())[1] = Smi::FromInt(0); | 2906 reinterpret_cast<Object**>(object->address())[1] = Smi::FromInt(0); |
2932 } | 2907 } |
2933 | 2908 |
2934 // We would like to tell the incremental marker to do a lot of work, since | 2909 heap()->incremental_marking()->OldSpaceStep(object_size); |
2935 // we just made a large allocation in old space, but that might cause a huge | |
2936 // pause. Underreporting here may cause the marker to speed up because it | |
2937 // will perceive that it is not keeping up with allocation. Although this | |
2938 // causes some big incremental marking steps they are not as big as this one | |
2939 // might have been. In testing, a very large pause was divided up into about | |
2940 // 12 parts. | |
2941 const int kThreshold = IncrementalMarking::kAllocatedThreshold * | |
2942 IncrementalMarking::kOldSpaceAllocationMarkingFactor; | |
2943 heap()->incremental_marking()->OldSpaceStep(kThreshold); | |
2944 return object; | 2910 return object; |
2945 } | 2911 } |
2946 | 2912 |
2947 | 2913 |
2948 size_t LargeObjectSpace::CommittedPhysicalMemory() { | 2914 size_t LargeObjectSpace::CommittedPhysicalMemory() { |
2949 if (!base::VirtualMemory::HasLazyCommits()) return CommittedMemory(); | 2915 if (!base::VirtualMemory::HasLazyCommits()) return CommittedMemory(); |
2950 size_t size = 0; | 2916 size_t size = 0; |
2951 LargePage* current = first_page_; | 2917 LargePage* current = first_page_; |
2952 while (current != NULL) { | 2918 while (current != NULL) { |
2953 size += current->CommittedPhysicalMemory(); | 2919 size += current->CommittedPhysicalMemory(); |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3156 object->ShortPrint(); | 3122 object->ShortPrint(); |
3157 PrintF("\n"); | 3123 PrintF("\n"); |
3158 } | 3124 } |
3159 printf(" --------------------------------------\n"); | 3125 printf(" --------------------------------------\n"); |
3160 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); | 3126 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); |
3161 } | 3127 } |
3162 | 3128 |
3163 #endif // DEBUG | 3129 #endif // DEBUG |
3164 } | 3130 } |
3165 } // namespace v8::internal | 3131 } // namespace v8::internal |
OLD | NEW |