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 | 9 |
10 #include "src/allocation.h" | 10 #include "src/allocation.h" |
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 // Large objects can have a progress bar in their page header. These object | 418 // Large objects can have a progress bar in their page header. These object |
419 // are scanned in increments and will be kept black while being scanned. | 419 // are scanned in increments and will be kept black while being scanned. |
420 // Even if the mutator writes to them they will be kept black and a white | 420 // Even if the mutator writes to them they will be kept black and a white |
421 // to grey transition is performed in the value. | 421 // to grey transition is performed in the value. |
422 HAS_PROGRESS_BAR, | 422 HAS_PROGRESS_BAR, |
423 | 423 |
424 // |PAGE_NEW_OLD_PROMOTION|: A page tagged with this flag has been promoted | 424 // |PAGE_NEW_OLD_PROMOTION|: A page tagged with this flag has been promoted |
425 // from new to old space during evacuation. | 425 // from new to old space during evacuation. |
426 PAGE_NEW_OLD_PROMOTION, | 426 PAGE_NEW_OLD_PROMOTION, |
427 | 427 |
| 428 // |PAGE_NEW_NEW_PROMOTION|: A page tagged with this flag has been moved |
| 429 // within the new space during evacuation. |
| 430 PAGE_NEW_NEW_PROMOTION, |
| 431 |
428 // A black page has all mark bits set to 1 (black). A black page currently | 432 // A black page has all mark bits set to 1 (black). A black page currently |
429 // cannot be iterated because it is not swept. Moreover live bytes are also | 433 // cannot be iterated because it is not swept. Moreover live bytes are also |
430 // not updated. | 434 // not updated. |
431 BLACK_PAGE, | 435 BLACK_PAGE, |
432 | 436 |
433 // This flag is intended to be used for testing. Works only when both | 437 // This flag is intended to be used for testing. Works only when both |
434 // FLAG_stress_compaction and FLAG_manual_evacuation_candidates_selection | 438 // FLAG_stress_compaction and FLAG_manual_evacuation_candidates_selection |
435 // are set. It forces the page to become an evacuation candidate at next | 439 // are set. It forces the page to become an evacuation candidate at next |
436 // candidates selection cycle. | 440 // candidates selection cycle. |
437 FORCE_EVACUATION_CANDIDATE_FOR_TESTING, | 441 FORCE_EVACUATION_CANDIDATE_FOR_TESTING, |
(...skipping 1986 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2424 | 2428 |
2425 // Grow the semispace to the new capacity. The new capacity requested must | 2429 // Grow the semispace to the new capacity. The new capacity requested must |
2426 // be larger than the current capacity and less than the maximum capacity. | 2430 // be larger than the current capacity and less than the maximum capacity. |
2427 bool GrowTo(int new_capacity); | 2431 bool GrowTo(int new_capacity); |
2428 | 2432 |
2429 // Shrinks the semispace to the new capacity. The new capacity requested | 2433 // Shrinks the semispace to the new capacity. The new capacity requested |
2430 // must be more than the amount of used memory in the semispace and less | 2434 // must be more than the amount of used memory in the semispace and less |
2431 // than the current capacity. | 2435 // than the current capacity. |
2432 bool ShrinkTo(int new_capacity); | 2436 bool ShrinkTo(int new_capacity); |
2433 | 2437 |
| 2438 bool EnsureCurrentCapacity(); |
| 2439 |
2434 // Returns the start address of the first page of the space. | 2440 // Returns the start address of the first page of the space. |
2435 Address space_start() { | 2441 Address space_start() { |
2436 DCHECK_NE(anchor_.next_page(), anchor()); | 2442 DCHECK_NE(anchor_.next_page(), anchor()); |
2437 return anchor_.next_page()->area_start(); | 2443 return anchor_.next_page()->area_start(); |
2438 } | 2444 } |
2439 | 2445 |
2440 Page* first_page() { return anchor_.next_page(); } | 2446 Page* first_page() { return anchor_.next_page(); } |
2441 Page* current_page() { return current_page_; } | 2447 Page* current_page() { return current_page_; } |
2442 | 2448 |
2443 // Returns one past the end address of the space. | 2449 // Returns one past the end address of the space. |
2444 Address space_end() { return anchor_.prev_page()->area_end(); } | 2450 Address space_end() { return anchor_.prev_page()->area_end(); } |
2445 | 2451 |
2446 // Returns the start address of the current page of the space. | 2452 // Returns the start address of the current page of the space. |
2447 Address page_low() { return current_page_->area_start(); } | 2453 Address page_low() { return current_page_->area_start(); } |
2448 | 2454 |
2449 // Returns one past the end address of the current page of the space. | 2455 // Returns one past the end address of the current page of the space. |
2450 Address page_high() { return current_page_->area_end(); } | 2456 Address page_high() { return current_page_->area_end(); } |
2451 | 2457 |
2452 bool AdvancePage() { | 2458 bool AdvancePage() { |
2453 Page* next_page = current_page_->next_page(); | 2459 Page* next_page = current_page_->next_page(); |
2454 if (next_page == anchor()) return false; | 2460 if (next_page == anchor()) return false; |
2455 current_page_ = next_page; | 2461 current_page_ = next_page; |
2456 return true; | 2462 return true; |
2457 } | 2463 } |
2458 | 2464 |
2459 // Resets the space to using the first page. | 2465 // Resets the space to using the first page. |
2460 void Reset(); | 2466 void Reset(); |
2461 | 2467 |
2462 bool ReplaceWithEmptyPage(Page* page); | 2468 void RemovePage(Page* page); |
| 2469 void PrependPage(Page* page); |
2463 | 2470 |
2464 // Age mark accessors. | 2471 // Age mark accessors. |
2465 Address age_mark() { return age_mark_; } | 2472 Address age_mark() { return age_mark_; } |
2466 void set_age_mark(Address mark); | 2473 void set_age_mark(Address mark); |
2467 | 2474 |
2468 // Returns the current capacity of the semispace. | 2475 // Returns the current capacity of the semispace. |
2469 int current_capacity() { return current_capacity_; } | 2476 int current_capacity() { return current_capacity_; } |
2470 | 2477 |
2471 // Returns the maximum capacity of the semispace. | 2478 // Returns the maximum capacity of the semispace. |
2472 int maximum_capacity() { return maximum_capacity_; } | 2479 int maximum_capacity() { return maximum_capacity_; } |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2528 | 2535 |
2529 // Used to govern object promotion during mark-compact collection. | 2536 // Used to govern object promotion during mark-compact collection. |
2530 Address age_mark_; | 2537 Address age_mark_; |
2531 | 2538 |
2532 bool committed_; | 2539 bool committed_; |
2533 SemiSpaceId id_; | 2540 SemiSpaceId id_; |
2534 | 2541 |
2535 Page anchor_; | 2542 Page anchor_; |
2536 Page* current_page_; | 2543 Page* current_page_; |
2537 | 2544 |
| 2545 friend class NewSpace; |
| 2546 friend class NewSpacePageIterator; |
2538 friend class SemiSpaceIterator; | 2547 friend class SemiSpaceIterator; |
2539 friend class NewSpacePageIterator; | |
2540 }; | 2548 }; |
2541 | 2549 |
2542 | 2550 |
2543 // A SemiSpaceIterator is an ObjectIterator that iterates over the active | 2551 // A SemiSpaceIterator is an ObjectIterator that iterates over the active |
2544 // semispace of the heap's new space. It iterates over the objects in the | 2552 // semispace of the heap's new space. It iterates over the objects in the |
2545 // semispace from a given start address (defaulting to the bottom of the | 2553 // semispace from a given start address (defaulting to the bottom of the |
2546 // semispace) to the top of the semispace. New objects allocated after the | 2554 // semispace) to the top of the semispace. New objects allocated after the |
2547 // iterator is created are not iterated. | 2555 // iterator is created are not iterated. |
2548 class SemiSpaceIterator : public ObjectIterator { | 2556 class SemiSpaceIterator : public ObjectIterator { |
2549 public: | 2557 public: |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2708 while (current_page != last_page) { | 2716 while (current_page != last_page) { |
2709 allocated += Page::kAllocatableMemory; | 2717 allocated += Page::kAllocatableMemory; |
2710 current_page = current_page->next_page(); | 2718 current_page = current_page->next_page(); |
2711 } | 2719 } |
2712 allocated += top() - current_page->area_start(); | 2720 allocated += top() - current_page->area_start(); |
2713 DCHECK_LE(0, allocated); | 2721 DCHECK_LE(0, allocated); |
2714 DCHECK_LE(allocated, Size()); | 2722 DCHECK_LE(allocated, Size()); |
2715 return static_cast<size_t>(allocated); | 2723 return static_cast<size_t>(allocated); |
2716 } | 2724 } |
2717 | 2725 |
2718 bool ReplaceWithEmptyPage(Page* page) { | 2726 void MovePageFromSpaceToSpace(Page* page) { |
2719 // This method is called after flipping the semispace. | |
2720 DCHECK(page->InFromSpace()); | 2727 DCHECK(page->InFromSpace()); |
2721 return from_space_.ReplaceWithEmptyPage(page); | 2728 from_space_.RemovePage(page); |
| 2729 to_space_.PrependPage(page); |
| 2730 pages_used_++; |
2722 } | 2731 } |
2723 | 2732 |
| 2733 bool Rebalance(); |
| 2734 |
2724 // Return the maximum capacity of a semispace. | 2735 // Return the maximum capacity of a semispace. |
2725 int MaximumCapacity() { | 2736 int MaximumCapacity() { |
2726 DCHECK(to_space_.maximum_capacity() == from_space_.maximum_capacity()); | 2737 DCHECK(to_space_.maximum_capacity() == from_space_.maximum_capacity()); |
2727 return to_space_.maximum_capacity(); | 2738 return to_space_.maximum_capacity(); |
2728 } | 2739 } |
2729 | 2740 |
2730 bool IsAtMaximumCapacity() { return TotalCapacity() == MaximumCapacity(); } | 2741 bool IsAtMaximumCapacity() { return TotalCapacity() == MaximumCapacity(); } |
2731 | 2742 |
2732 // Returns the initial capacity of a semispace. | 2743 // Returns the initial capacity of a semispace. |
2733 int InitialTotalCapacity() { | 2744 int InitialTotalCapacity() { |
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3148 count = 0; | 3159 count = 0; |
3149 } | 3160 } |
3150 // Must be small, since an iteration is used for lookup. | 3161 // Must be small, since an iteration is used for lookup. |
3151 static const int kMaxComments = 64; | 3162 static const int kMaxComments = 64; |
3152 }; | 3163 }; |
3153 #endif | 3164 #endif |
3154 } // namespace internal | 3165 } // namespace internal |
3155 } // namespace v8 | 3166 } // namespace v8 |
3156 | 3167 |
3157 #endif // V8_HEAP_SPACES_H_ | 3168 #endif // V8_HEAP_SPACES_H_ |
OLD | NEW |