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 #ifndef V8_HEAP_SPACES_H_ | 5 #ifndef V8_HEAP_SPACES_H_ |
6 #define V8_HEAP_SPACES_H_ | 6 #define V8_HEAP_SPACES_H_ |
7 | 7 |
8 #include <list> | 8 #include <list> |
9 #include <memory> | 9 #include <memory> |
10 #include <unordered_set> | 10 #include <unordered_set> |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 // It is divided into the header and the body. Chunk start is always | 227 // It is divided into the header and the body. Chunk start is always |
228 // 1MB aligned. Start of the body is aligned so it can accommodate | 228 // 1MB aligned. Start of the body is aligned so it can accommodate |
229 // any heap object. | 229 // any heap object. |
230 class MemoryChunk { | 230 class MemoryChunk { |
231 public: | 231 public: |
232 enum Flag { | 232 enum Flag { |
233 NO_FLAGS = 0u, | 233 NO_FLAGS = 0u, |
234 IS_EXECUTABLE = 1u << 0, | 234 IS_EXECUTABLE = 1u << 0, |
235 POINTERS_TO_HERE_ARE_INTERESTING = 1u << 1, | 235 POINTERS_TO_HERE_ARE_INTERESTING = 1u << 1, |
236 POINTERS_FROM_HERE_ARE_INTERESTING = 1u << 2, | 236 POINTERS_FROM_HERE_ARE_INTERESTING = 1u << 2, |
237 | |
238 // A page in new space has one of the next to flags set. | 237 // A page in new space has one of the next to flags set. |
239 IN_FROM_SPACE = 1u << 3, | 238 IN_FROM_SPACE = 1u << 3, |
240 IN_TO_SPACE = 1u << 4, | 239 IN_TO_SPACE = 1u << 4, |
241 // |IN_INTERMEDIATE_GENERATION|: Flag indicates whether this page contains | 240 NEW_SPACE_BELOW_AGE_MARK = 1u << 5, |
242 // objects that have already been copied once. | |
243 IN_INTERMEDIATE_GENERATION = 1u << 5, | |
244 | |
245 EVACUATION_CANDIDATE = 1u << 6, | 241 EVACUATION_CANDIDATE = 1u << 6, |
246 NEVER_EVACUATE = 1u << 7, | 242 NEVER_EVACUATE = 1u << 7, |
247 | 243 |
248 // Large objects can have a progress bar in their page header. These object | 244 // Large objects can have a progress bar in their page header. These object |
249 // are scanned in increments and will be kept black while being scanned. | 245 // are scanned in increments and will be kept black while being scanned. |
250 // Even if the mutator writes to them they will be kept black and a white | 246 // Even if the mutator writes to them they will be kept black and a white |
251 // to grey transition is performed in the value. | 247 // to grey transition is performed in the value. |
252 HAS_PROGRESS_BAR = 1u << 8, | 248 HAS_PROGRESS_BAR = 1u << 8, |
253 | 249 |
254 // |PAGE_NEW_OLD_PROMOTION|: A page tagged with this flag has been promoted | 250 // |PAGE_NEW_OLD_PROMOTION|: A page tagged with this flag has been promoted |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
556 Executability executable() { | 552 Executability executable() { |
557 return IsFlagSet(IS_EXECUTABLE) ? EXECUTABLE : NOT_EXECUTABLE; | 553 return IsFlagSet(IS_EXECUTABLE) ? EXECUTABLE : NOT_EXECUTABLE; |
558 } | 554 } |
559 | 555 |
560 bool InNewSpace() { return (flags_ & kIsInNewSpaceMask) != 0; } | 556 bool InNewSpace() { return (flags_ & kIsInNewSpaceMask) != 0; } |
561 | 557 |
562 bool InToSpace() { return IsFlagSet(IN_TO_SPACE); } | 558 bool InToSpace() { return IsFlagSet(IN_TO_SPACE); } |
563 | 559 |
564 bool InFromSpace() { return IsFlagSet(IN_FROM_SPACE); } | 560 bool InFromSpace() { return IsFlagSet(IN_FROM_SPACE); } |
565 | 561 |
566 bool InIntermediateGeneration() { | |
567 return IsFlagSet(IN_INTERMEDIATE_GENERATION); | |
568 } | |
569 | |
570 MemoryChunk* next_chunk() { return next_chunk_.Value(); } | 562 MemoryChunk* next_chunk() { return next_chunk_.Value(); } |
571 | 563 |
572 MemoryChunk* prev_chunk() { return prev_chunk_.Value(); } | 564 MemoryChunk* prev_chunk() { return prev_chunk_.Value(); } |
573 | 565 |
574 void set_next_chunk(MemoryChunk* next) { next_chunk_.SetValue(next); } | 566 void set_next_chunk(MemoryChunk* next) { next_chunk_.SetValue(next); } |
575 | 567 |
576 void set_prev_chunk(MemoryChunk* prev) { prev_chunk_.SetValue(prev); } | 568 void set_prev_chunk(MemoryChunk* prev) { prev_chunk_.SetValue(prev); } |
577 | 569 |
578 Space* owner() const { | 570 Space* owner() const { |
579 if ((reinterpret_cast<intptr_t>(owner_) & kPageHeaderTagMask) == | 571 if ((reinterpret_cast<intptr_t>(owner_) & kPageHeaderTagMask) == |
(...skipping 1648 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2228 public: | 2220 public: |
2229 typedef PageIterator iterator; | 2221 typedef PageIterator iterator; |
2230 | 2222 |
2231 static void Swap(SemiSpace* from, SemiSpace* to); | 2223 static void Swap(SemiSpace* from, SemiSpace* to); |
2232 | 2224 |
2233 SemiSpace(Heap* heap, SemiSpaceId semispace) | 2225 SemiSpace(Heap* heap, SemiSpaceId semispace) |
2234 : Space(heap, NEW_SPACE, NOT_EXECUTABLE), | 2226 : Space(heap, NEW_SPACE, NOT_EXECUTABLE), |
2235 current_capacity_(0), | 2227 current_capacity_(0), |
2236 maximum_capacity_(0), | 2228 maximum_capacity_(0), |
2237 minimum_capacity_(0), | 2229 minimum_capacity_(0), |
| 2230 age_mark_(nullptr), |
2238 committed_(false), | 2231 committed_(false), |
2239 id_(semispace), | 2232 id_(semispace), |
2240 anchor_(this), | 2233 anchor_(this), |
2241 current_page_(nullptr), | 2234 current_page_(nullptr), |
2242 pages_used_(0) {} | 2235 pages_used_(0) {} |
2243 | 2236 |
2244 inline bool Contains(HeapObject* o); | 2237 inline bool Contains(HeapObject* o); |
2245 inline bool Contains(Object* o); | 2238 inline bool Contains(Object* o); |
2246 inline bool ContainsSlow(Address a); | 2239 inline bool ContainsSlow(Address a); |
2247 | 2240 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2296 pages_used_++; | 2289 pages_used_++; |
2297 return true; | 2290 return true; |
2298 } | 2291 } |
2299 | 2292 |
2300 // Resets the space to using the first page. | 2293 // Resets the space to using the first page. |
2301 void Reset(); | 2294 void Reset(); |
2302 | 2295 |
2303 void RemovePage(Page* page); | 2296 void RemovePage(Page* page); |
2304 void PrependPage(Page* page); | 2297 void PrependPage(Page* page); |
2305 | 2298 |
| 2299 // Age mark accessors. |
| 2300 Address age_mark() { return age_mark_; } |
| 2301 void set_age_mark(Address mark); |
| 2302 |
2306 // Returns the current capacity of the semispace. | 2303 // Returns the current capacity of the semispace. |
2307 int current_capacity() { return current_capacity_; } | 2304 int current_capacity() { return current_capacity_; } |
2308 | 2305 |
2309 // Returns the maximum capacity of the semispace. | 2306 // Returns the maximum capacity of the semispace. |
2310 int maximum_capacity() { return maximum_capacity_; } | 2307 int maximum_capacity() { return maximum_capacity_; } |
2311 | 2308 |
2312 // Returns the initial capacity of the semispace. | 2309 // Returns the initial capacity of the semispace. |
2313 int minimum_capacity() { return minimum_capacity_; } | 2310 int minimum_capacity() { return minimum_capacity_; } |
2314 | 2311 |
2315 SemiSpaceId id() { return id_; } | 2312 SemiSpaceId id() { return id_; } |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2364 // The currently committed space capacity. | 2361 // The currently committed space capacity. |
2365 int current_capacity_; | 2362 int current_capacity_; |
2366 | 2363 |
2367 // The maximum capacity that can be used by this space. A space cannot grow | 2364 // The maximum capacity that can be used by this space. A space cannot grow |
2368 // beyond that size. | 2365 // beyond that size. |
2369 int maximum_capacity_; | 2366 int maximum_capacity_; |
2370 | 2367 |
2371 // The minimum capacity for the space. A space cannot shrink below this size. | 2368 // The minimum capacity for the space. A space cannot shrink below this size. |
2372 int minimum_capacity_; | 2369 int minimum_capacity_; |
2373 | 2370 |
| 2371 // Used to govern object promotion during mark-compact collection. |
| 2372 Address age_mark_; |
| 2373 |
2374 bool committed_; | 2374 bool committed_; |
2375 SemiSpaceId id_; | 2375 SemiSpaceId id_; |
2376 | 2376 |
2377 Page anchor_; | 2377 Page anchor_; |
2378 Page* current_page_; | 2378 Page* current_page_; |
2379 int pages_used_; | 2379 int pages_used_; |
2380 | 2380 |
2381 friend class NewSpace; | 2381 friend class NewSpace; |
2382 friend class SemiSpaceIterator; | 2382 friend class SemiSpaceIterator; |
2383 }; | 2383 }; |
(...skipping 30 matching lines...) Expand all Loading... |
2414 public: | 2414 public: |
2415 typedef PageIterator iterator; | 2415 typedef PageIterator iterator; |
2416 | 2416 |
2417 explicit NewSpace(Heap* heap) | 2417 explicit NewSpace(Heap* heap) |
2418 : Space(heap, NEW_SPACE, NOT_EXECUTABLE), | 2418 : Space(heap, NEW_SPACE, NOT_EXECUTABLE), |
2419 to_space_(heap, kToSpace), | 2419 to_space_(heap, kToSpace), |
2420 from_space_(heap, kFromSpace), | 2420 from_space_(heap, kFromSpace), |
2421 reservation_(), | 2421 reservation_(), |
2422 top_on_previous_step_(0), | 2422 top_on_previous_step_(0), |
2423 allocated_histogram_(nullptr), | 2423 allocated_histogram_(nullptr), |
2424 promoted_histogram_(nullptr), | 2424 promoted_histogram_(nullptr) {} |
2425 fragmentation_in_intermediate_generation_(0) {} | |
2426 | 2425 |
2427 inline bool Contains(HeapObject* o); | 2426 inline bool Contains(HeapObject* o); |
2428 inline bool ContainsSlow(Address a); | 2427 inline bool ContainsSlow(Address a); |
2429 inline bool Contains(Object* o); | 2428 inline bool Contains(Object* o); |
2430 | 2429 |
2431 bool SetUp(int initial_semispace_capacity, int max_semispace_capacity); | 2430 bool SetUp(int initial_semispace_capacity, int max_semispace_capacity); |
2432 | 2431 |
2433 // Tears down the space. Heap memory was not allocated by the space, so it | 2432 // Tears down the space. Heap memory was not allocated by the space, so it |
2434 // is not deallocated here. | 2433 // is not deallocated here. |
2435 void TearDown(); | 2434 void TearDown(); |
(...skipping 12 matching lines...) Expand all Loading... |
2448 | 2447 |
2449 // Shrink the capacity of the semispaces. | 2448 // Shrink the capacity of the semispaces. |
2450 void Shrink(); | 2449 void Shrink(); |
2451 | 2450 |
2452 // Return the allocated bytes in the active semispace. | 2451 // Return the allocated bytes in the active semispace. |
2453 intptr_t Size() override { | 2452 intptr_t Size() override { |
2454 return to_space_.pages_used() * Page::kAllocatableMemory + | 2453 return to_space_.pages_used() * Page::kAllocatableMemory + |
2455 static_cast<int>(top() - to_space_.page_low()); | 2454 static_cast<int>(top() - to_space_.page_low()); |
2456 } | 2455 } |
2457 | 2456 |
2458 intptr_t SizeOfObjects() override { | 2457 intptr_t SizeOfObjects() override { return Size(); } |
2459 return Size() - | |
2460 static_cast<intptr_t>(fragmentation_in_intermediate_generation_); | |
2461 } | |
2462 | 2458 |
2463 // Return the allocatable capacity of a semispace. | 2459 // Return the allocatable capacity of a semispace. |
2464 intptr_t Capacity() { | 2460 intptr_t Capacity() { |
2465 SLOW_DCHECK(to_space_.current_capacity() == from_space_.current_capacity()); | 2461 SLOW_DCHECK(to_space_.current_capacity() == from_space_.current_capacity()); |
2466 return (to_space_.current_capacity() / Page::kPageSize) * | 2462 return (to_space_.current_capacity() / Page::kPageSize) * |
2467 Page::kAllocatableMemory; | 2463 Page::kAllocatableMemory; |
2468 } | 2464 } |
2469 | 2465 |
2470 // Return the current size of a semispace, allocatable and non-allocatable | 2466 // Return the current size of a semispace, allocatable and non-allocatable |
2471 // memory. | 2467 // memory. |
(...skipping 12 matching lines...) Expand all Loading... |
2484 return from_space_.MaximumCommittedMemory() + | 2480 return from_space_.MaximumCommittedMemory() + |
2485 to_space_.MaximumCommittedMemory(); | 2481 to_space_.MaximumCommittedMemory(); |
2486 } | 2482 } |
2487 | 2483 |
2488 // Approximate amount of physical memory committed for this space. | 2484 // Approximate amount of physical memory committed for this space. |
2489 size_t CommittedPhysicalMemory() override; | 2485 size_t CommittedPhysicalMemory() override; |
2490 | 2486 |
2491 // Return the available bytes without growing. | 2487 // Return the available bytes without growing. |
2492 intptr_t Available() override { return Capacity() - Size(); } | 2488 intptr_t Available() override { return Capacity() - Size(); } |
2493 | 2489 |
2494 inline size_t AllocatedSinceLastGC(); | 2490 size_t AllocatedSinceLastGC() { |
| 2491 bool seen_age_mark = false; |
| 2492 Address age_mark = to_space_.age_mark(); |
| 2493 Page* current_page = to_space_.first_page(); |
| 2494 Page* age_mark_page = Page::FromAddress(age_mark); |
| 2495 Page* last_page = Page::FromAddress(top() - kPointerSize); |
| 2496 if (age_mark_page == last_page) { |
| 2497 if (top() - age_mark >= 0) { |
| 2498 return top() - age_mark; |
| 2499 } |
| 2500 // Top was reset at some point, invalidating this metric. |
| 2501 return 0; |
| 2502 } |
| 2503 while (current_page != last_page) { |
| 2504 if (current_page == age_mark_page) { |
| 2505 seen_age_mark = true; |
| 2506 break; |
| 2507 } |
| 2508 current_page = current_page->next_page(); |
| 2509 } |
| 2510 if (!seen_age_mark) { |
| 2511 // Top was reset at some point, invalidating this metric. |
| 2512 return 0; |
| 2513 } |
| 2514 intptr_t allocated = age_mark_page->area_end() - age_mark; |
| 2515 DCHECK_EQ(current_page, age_mark_page); |
| 2516 current_page = age_mark_page->next_page(); |
| 2517 while (current_page != last_page) { |
| 2518 allocated += Page::kAllocatableMemory; |
| 2519 current_page = current_page->next_page(); |
| 2520 } |
| 2521 allocated += top() - current_page->area_start(); |
| 2522 DCHECK_LE(0, allocated); |
| 2523 DCHECK_LE(allocated, Size()); |
| 2524 return static_cast<size_t>(allocated); |
| 2525 } |
2495 | 2526 |
2496 void MovePageFromSpaceToSpace(Page* page) { | 2527 void MovePageFromSpaceToSpace(Page* page) { |
2497 DCHECK(page->InFromSpace()); | 2528 DCHECK(page->InFromSpace()); |
2498 from_space_.RemovePage(page); | 2529 from_space_.RemovePage(page); |
2499 to_space_.PrependPage(page); | 2530 to_space_.PrependPage(page); |
2500 } | 2531 } |
2501 | 2532 |
2502 bool Rebalance(); | 2533 bool Rebalance(); |
2503 | 2534 |
2504 // Return the maximum capacity of a semispace. | 2535 // Return the maximum capacity of a semispace. |
(...skipping 18 matching lines...) Expand all Loading... |
2523 | 2554 |
2524 // Return the address of the allocation pointer limit in the active semispace. | 2555 // Return the address of the allocation pointer limit in the active semispace. |
2525 Address limit() { | 2556 Address limit() { |
2526 DCHECK(to_space_.current_page()->ContainsLimit(allocation_info_.limit())); | 2557 DCHECK(to_space_.current_page()->ContainsLimit(allocation_info_.limit())); |
2527 return allocation_info_.limit(); | 2558 return allocation_info_.limit(); |
2528 } | 2559 } |
2529 | 2560 |
2530 // Return the address of the first object in the active semispace. | 2561 // Return the address of the first object in the active semispace. |
2531 Address bottom() { return to_space_.space_start(); } | 2562 Address bottom() { return to_space_.space_start(); } |
2532 | 2563 |
2533 // Seal the intermediate generation of the active semispace. | 2564 // Get the age mark of the inactive semispace. |
2534 void SealIntermediateGeneration(); | 2565 Address age_mark() { return from_space_.age_mark(); } |
| 2566 // Set the age mark in the active semispace. |
| 2567 void set_age_mark(Address mark) { to_space_.set_age_mark(mark); } |
2535 | 2568 |
2536 // The allocation top and limit address. | 2569 // The allocation top and limit address. |
2537 Address* allocation_top_address() { return allocation_info_.top_address(); } | 2570 Address* allocation_top_address() { return allocation_info_.top_address(); } |
2538 | 2571 |
2539 // The allocation limit address. | 2572 // The allocation limit address. |
2540 Address* allocation_limit_address() { | 2573 Address* allocation_limit_address() { |
2541 return allocation_info_.limit_address(); | 2574 return allocation_info_.limit_address(); |
2542 } | 2575 } |
2543 | 2576 |
2544 MUST_USE_RESULT INLINE(AllocationResult AllocateRawAligned( | 2577 MUST_USE_RESULT INLINE(AllocationResult AllocateRawAligned( |
2545 int size_in_bytes, AllocationAlignment alignment)); | 2578 int size_in_bytes, AllocationAlignment alignment)); |
2546 | 2579 |
2547 MUST_USE_RESULT INLINE( | 2580 MUST_USE_RESULT INLINE( |
2548 AllocationResult AllocateRawUnaligned(int size_in_bytes)); | 2581 AllocationResult AllocateRawUnaligned(int size_in_bytes)); |
2549 | 2582 |
2550 MUST_USE_RESULT INLINE(AllocationResult AllocateRaw( | 2583 MUST_USE_RESULT INLINE(AllocationResult AllocateRaw( |
2551 int size_in_bytes, AllocationAlignment alignment)); | 2584 int size_in_bytes, AllocationAlignment alignment)); |
2552 | 2585 |
2553 MUST_USE_RESULT inline AllocationResult AllocateRawSynchronized( | 2586 MUST_USE_RESULT inline AllocationResult AllocateRawSynchronized( |
2554 int size_in_bytes, AllocationAlignment alignment); | 2587 int size_in_bytes, AllocationAlignment alignment); |
2555 | 2588 |
2556 // Reset the allocation pointer to the beginning of the active semispace. | 2589 // Reset the allocation pointer to the beginning of the active semispace. |
2557 void ResetAllocationInfo(); | 2590 void ResetAllocationInfo(); |
2558 | 2591 |
2559 void SetAllocationInfo(Address top, Address limit) { | |
2560 allocation_info_.Reset(top, limit); | |
2561 } | |
2562 | |
2563 // When inline allocation stepping is active, either because of incremental | 2592 // When inline allocation stepping is active, either because of incremental |
2564 // marking, idle scavenge, or allocation statistics gathering, we 'interrupt' | 2593 // marking, idle scavenge, or allocation statistics gathering, we 'interrupt' |
2565 // inline allocation every once in a while. This is done by setting | 2594 // inline allocation every once in a while. This is done by setting |
2566 // allocation_info_.limit to be lower than the actual limit and and increasing | 2595 // allocation_info_.limit to be lower than the actual limit and and increasing |
2567 // it in steps to guarantee that the observers are notified periodically. | 2596 // it in steps to guarantee that the observers are notified periodically. |
2568 void UpdateInlineAllocationLimit(int size_in_bytes); | 2597 void UpdateInlineAllocationLimit(int size_in_bytes); |
2569 | 2598 |
2570 void DisableInlineAllocationSteps() { | 2599 void DisableInlineAllocationSteps() { |
2571 top_on_previous_step_ = 0; | 2600 top_on_previous_step_ = 0; |
2572 UpdateInlineAllocationLimit(0); | 2601 UpdateInlineAllocationLimit(0); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2663 | 2692 |
2664 // Allocation pointer and limit for normal allocation and allocation during | 2693 // Allocation pointer and limit for normal allocation and allocation during |
2665 // mark-compact collection. | 2694 // mark-compact collection. |
2666 AllocationInfo allocation_info_; | 2695 AllocationInfo allocation_info_; |
2667 | 2696 |
2668 Address top_on_previous_step_; | 2697 Address top_on_previous_step_; |
2669 | 2698 |
2670 HistogramInfo* allocated_histogram_; | 2699 HistogramInfo* allocated_histogram_; |
2671 HistogramInfo* promoted_histogram_; | 2700 HistogramInfo* promoted_histogram_; |
2672 | 2701 |
2673 size_t fragmentation_in_intermediate_generation_; | |
2674 | |
2675 bool EnsureAllocation(int size_in_bytes, AllocationAlignment alignment); | 2702 bool EnsureAllocation(int size_in_bytes, AllocationAlignment alignment); |
2676 | 2703 |
2677 // If we are doing inline allocation in steps, this method performs the 'step' | 2704 // If we are doing inline allocation in steps, this method performs the 'step' |
2678 // operation. top is the memory address of the bump pointer at the last | 2705 // operation. top is the memory address of the bump pointer at the last |
2679 // inline allocation (i.e. it determines the numbers of bytes actually | 2706 // inline allocation (i.e. it determines the numbers of bytes actually |
2680 // allocated since the last step.) new_top is the address of the bump pointer | 2707 // allocated since the last step.) new_top is the address of the bump pointer |
2681 // where the next byte is going to be allocated from. top and new_top may be | 2708 // where the next byte is going to be allocated from. top and new_top may be |
2682 // different when we cross a page boundary or reset the space. | 2709 // different when we cross a page boundary or reset the space. |
2683 void InlineAllocationStep(Address top, Address new_top, Address soon_object, | 2710 void InlineAllocationStep(Address top, Address new_top, Address soon_object, |
2684 size_t size); | 2711 size_t size); |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2921 PageIterator old_iterator_; | 2948 PageIterator old_iterator_; |
2922 PageIterator code_iterator_; | 2949 PageIterator code_iterator_; |
2923 PageIterator map_iterator_; | 2950 PageIterator map_iterator_; |
2924 LargePageIterator lo_iterator_; | 2951 LargePageIterator lo_iterator_; |
2925 }; | 2952 }; |
2926 | 2953 |
2927 } // namespace internal | 2954 } // namespace internal |
2928 } // namespace v8 | 2955 } // namespace v8 |
2929 | 2956 |
2930 #endif // V8_HEAP_SPACES_H_ | 2957 #endif // V8_HEAP_SPACES_H_ |
OLD | NEW |