Chromium Code Reviews| 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 "src/allocation.h" | 8 #include "src/allocation.h" |
| 9 #include "src/atomic-utils.h" | 9 #include "src/atomic-utils.h" |
| 10 #include "src/base/atomicops.h" | 10 #include "src/base/atomicops.h" |
| (...skipping 2443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2454 private: | 2454 private: |
| 2455 NewSpacePage* prev_page_; // Previous page returned. | 2455 NewSpacePage* prev_page_; // Previous page returned. |
| 2456 // Next page that will be returned. Cached here so that we can use this | 2456 // Next page that will be returned. Cached here so that we can use this |
| 2457 // iterator for operations that deallocate pages. | 2457 // iterator for operations that deallocate pages. |
| 2458 NewSpacePage* next_page_; | 2458 NewSpacePage* next_page_; |
| 2459 // Last page returned. | 2459 // Last page returned. |
| 2460 NewSpacePage* last_page_; | 2460 NewSpacePage* last_page_; |
| 2461 }; | 2461 }; |
| 2462 | 2462 |
| 2463 | 2463 |
| 2464 class InlineAllocationObserver { | |
|
Hannes Payer (out of office)
2015/10/16 15:31:17
This class needs a description and a few comments.
ofrobots
2015/10/16 21:26:35
Done.
| |
| 2465 public: | |
| 2466 typedef void (*callback_t)(int bytes_allocated, void* arg); | |
| 2467 | |
| 2468 InlineAllocationObserver(intptr_t step_size, callback_t callback, | |
| 2469 void* callback_arg) | |
| 2470 : step_size_(step_size), | |
| 2471 callback_(callback), | |
| 2472 callback_arg_(callback_arg), | |
| 2473 bytes_to_next_step_(step_size) { | |
| 2474 DCHECK(step_size > 0); | |
| 2475 } | |
| 2476 | |
| 2477 InlineAllocationObserver(const InlineAllocationObserver&) = default; | |
| 2478 InlineAllocationObserver& operator=(const InlineAllocationObserver&) = | |
| 2479 default; | |
| 2480 | |
| 2481 void step(int bytes_allocated) { | |
| 2482 bytes_to_next_step_ -= bytes_allocated; | |
| 2483 if (bytes_to_next_step_ <= 0) { | |
| 2484 callback_(static_cast<int>(step_size_ - bytes_to_next_step_), | |
| 2485 callback_arg_); | |
| 2486 bytes_to_next_step_ = step_size_; | |
| 2487 } | |
| 2488 } | |
| 2489 | |
| 2490 intptr_t step_size() const { return step_size_; } | |
| 2491 callback_t callback() const { return callback_; } | |
| 2492 | |
| 2493 private: | |
| 2494 intptr_t step_size_; | |
| 2495 callback_t callback_; | |
| 2496 void* callback_arg_; | |
| 2497 intptr_t bytes_to_next_step_; | |
| 2498 }; | |
| 2499 | |
| 2464 // ----------------------------------------------------------------------------- | 2500 // ----------------------------------------------------------------------------- |
| 2465 // The young generation space. | 2501 // The young generation space. |
| 2466 // | 2502 // |
| 2467 // The new space consists of a contiguous pair of semispaces. It simply | 2503 // The new space consists of a contiguous pair of semispaces. It simply |
| 2468 // forwards most functions to the appropriate semispace. | 2504 // forwards most functions to the appropriate semispace. |
| 2469 | 2505 |
| 2470 class NewSpace : public Space { | 2506 class NewSpace : public Space { |
| 2471 public: | 2507 public: |
| 2472 // Constructor. | 2508 // Constructor. |
| 2473 explicit NewSpace(Heap* heap) | 2509 explicit NewSpace(Heap* heap) |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2642 MUST_USE_RESULT INLINE( | 2678 MUST_USE_RESULT INLINE( |
| 2643 AllocationResult AllocateRawUnaligned(int size_in_bytes)); | 2679 AllocationResult AllocateRawUnaligned(int size_in_bytes)); |
| 2644 | 2680 |
| 2645 MUST_USE_RESULT INLINE(AllocationResult AllocateRaw( | 2681 MUST_USE_RESULT INLINE(AllocationResult AllocateRaw( |
| 2646 int size_in_bytes, AllocationAlignment alignment)); | 2682 int size_in_bytes, AllocationAlignment alignment)); |
| 2647 | 2683 |
| 2648 // Reset the allocation pointer to the beginning of the active semispace. | 2684 // Reset the allocation pointer to the beginning of the active semispace. |
| 2649 void ResetAllocationInfo(); | 2685 void ResetAllocationInfo(); |
| 2650 | 2686 |
| 2651 void UpdateInlineAllocationLimit(int size_in_bytes); | 2687 void UpdateInlineAllocationLimit(int size_in_bytes); |
| 2652 void LowerInlineAllocationLimit(intptr_t step) { | 2688 |
| 2653 inline_allocation_limit_step_ = step; | 2689 void AddInlineAllocationObserver( |
| 2690 intptr_t step_size, InlineAllocationObserver::callback_t callback, | |
| 2691 void* callback_arg); | |
| 2692 void RemoveInlineAllocationObserver( | |
| 2693 InlineAllocationObserver::callback_t callback); | |
| 2694 void DisableInlineAllocationSteps() { | |
| 2695 inline_allocation_limit_step_ = 0; | |
| 2696 top_on_previous_step_ = 0; | |
| 2654 UpdateInlineAllocationLimit(0); | 2697 UpdateInlineAllocationLimit(0); |
| 2655 top_on_previous_step_ = step ? allocation_info_.top() : 0; | |
| 2656 } | 2698 } |
| 2657 | 2699 |
| 2658 // Get the extent of the inactive semispace (for use as a marking stack, | 2700 // Get the extent of the inactive semispace (for use as a marking stack, |
| 2659 // or to zap it). Notice: space-addresses are not necessarily on the | 2701 // or to zap it). Notice: space-addresses are not necessarily on the |
| 2660 // same page, so FromSpaceStart() might be above FromSpaceEnd(). | 2702 // same page, so FromSpaceStart() might be above FromSpaceEnd(). |
| 2661 Address FromSpacePageLow() { return from_space_.page_low(); } | 2703 Address FromSpacePageLow() { return from_space_.page_low(); } |
| 2662 Address FromSpacePageHigh() { return from_space_.page_high(); } | 2704 Address FromSpacePageHigh() { return from_space_.page_high(); } |
| 2663 Address FromSpaceStart() { return from_space_.space_start(); } | 2705 Address FromSpaceStart() { return from_space_.space_start(); } |
| 2664 Address FromSpaceEnd() { return from_space_.space_end(); } | 2706 Address FromSpaceEnd() { return from_space_.space_end(); } |
| 2665 | 2707 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2721 } | 2763 } |
| 2722 | 2764 |
| 2723 bool IsFromSpaceCommitted() { return from_space_.is_committed(); } | 2765 bool IsFromSpaceCommitted() { return from_space_.is_committed(); } |
| 2724 | 2766 |
| 2725 SemiSpace* active_space() { return &to_space_; } | 2767 SemiSpace* active_space() { return &to_space_; } |
| 2726 | 2768 |
| 2727 private: | 2769 private: |
| 2728 // Update allocation info to match the current to-space page. | 2770 // Update allocation info to match the current to-space page. |
| 2729 void UpdateAllocationInfo(); | 2771 void UpdateAllocationInfo(); |
| 2730 | 2772 |
| 2773 void UpdateInlineAllocationLimitStep(); | |
| 2774 | |
| 2731 Address chunk_base_; | 2775 Address chunk_base_; |
| 2732 uintptr_t chunk_size_; | 2776 uintptr_t chunk_size_; |
| 2733 | 2777 |
| 2734 // The semispaces. | 2778 // The semispaces. |
| 2735 SemiSpace to_space_; | 2779 SemiSpace to_space_; |
| 2736 SemiSpace from_space_; | 2780 SemiSpace from_space_; |
| 2737 base::VirtualMemory reservation_; | 2781 base::VirtualMemory reservation_; |
| 2738 int pages_used_; | 2782 int pages_used_; |
| 2739 | 2783 |
| 2740 // Start address and bit mask for containment testing. | 2784 // Start address and bit mask for containment testing. |
| 2741 Address start_; | 2785 Address start_; |
| 2742 uintptr_t address_mask_; | 2786 uintptr_t address_mask_; |
| 2743 uintptr_t object_mask_; | 2787 uintptr_t object_mask_; |
| 2744 uintptr_t object_expected_; | 2788 uintptr_t object_expected_; |
| 2745 | 2789 |
| 2746 // Allocation pointer and limit for normal allocation and allocation during | 2790 // Allocation pointer and limit for normal allocation and allocation during |
| 2747 // mark-compact collection. | 2791 // mark-compact collection. |
| 2748 AllocationInfo allocation_info_; | 2792 AllocationInfo allocation_info_; |
| 2749 | 2793 |
| 2750 // When incremental marking is active we will set allocation_info_.limit | 2794 // When inline allocation stepping is active, either because of incremental |
| 2751 // to be lower than actual limit and then will gradually increase it | 2795 // marking or because of idle scavenge, we 'interrupt' inline allocation every |
| 2752 // in steps to guarantee that we do incremental marking steps even | 2796 // once in a while. This is done by setting allocation_info_.limit to be lower |
| 2753 // when all allocation is performed from inlined generated code. | 2797 // than the actual limit and and increasing it in steps to guarantee that the |
| 2798 // observers are notified periodically. | |
| 2754 intptr_t inline_allocation_limit_step_; | 2799 intptr_t inline_allocation_limit_step_; |
| 2800 List<InlineAllocationObserver> inline_allocation_observers_; | |
| 2755 | 2801 |
| 2756 Address top_on_previous_step_; | 2802 Address top_on_previous_step_; |
| 2757 | 2803 |
| 2758 HistogramInfo* allocated_histogram_; | 2804 HistogramInfo* allocated_histogram_; |
| 2759 HistogramInfo* promoted_histogram_; | 2805 HistogramInfo* promoted_histogram_; |
| 2760 | 2806 |
| 2761 bool EnsureAllocation(int size_in_bytes, AllocationAlignment alignment); | 2807 bool EnsureAllocation(int size_in_bytes, AllocationAlignment alignment); |
| 2762 | 2808 |
| 2763 // If we are doing inline allocation in steps, this method performs the 'step' | 2809 // If we are doing inline allocation in steps, this method performs the 'step' |
| 2764 // operation. Right now incremental marking is the only consumer of inline | 2810 // operation. top is the memory address of the bump pointer at the last |
| 2765 // allocation steps. top is the memory address of the bump pointer at the last | |
| 2766 // inline allocation (i.e. it determines the numbers of bytes actually | 2811 // inline allocation (i.e. it determines the numbers of bytes actually |
| 2767 // allocated since the last step.) new_top is the address of the bump pointer | 2812 // allocated since the last step.) new_top is the address of the bump pointer |
| 2768 // where the next byte is going to be allocated from. top and new_top may be | 2813 // where the next byte is going to be allocated from. top and new_top may be |
| 2769 // different when we cross a page boundary or reset the space. | 2814 // different when we cross a page boundary or reset the space. |
| 2770 void InlineAllocationStep(Address top, Address new_top); | 2815 void InlineAllocationStep(Address top, Address new_top); |
| 2771 | 2816 |
| 2772 friend class SemiSpaceIterator; | 2817 friend class SemiSpaceIterator; |
| 2773 }; | 2818 }; |
| 2774 | 2819 |
| 2775 // ----------------------------------------------------------------------------- | 2820 // ----------------------------------------------------------------------------- |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3009 count = 0; | 3054 count = 0; |
| 3010 } | 3055 } |
| 3011 // Must be small, since an iteration is used for lookup. | 3056 // Must be small, since an iteration is used for lookup. |
| 3012 static const int kMaxComments = 64; | 3057 static const int kMaxComments = 64; |
| 3013 }; | 3058 }; |
| 3014 #endif | 3059 #endif |
| 3015 } // namespace internal | 3060 } // namespace internal |
| 3016 } // namespace v8 | 3061 } // namespace v8 |
| 3017 | 3062 |
| 3018 #endif // V8_HEAP_SPACES_H_ | 3063 #endif // V8_HEAP_SPACES_H_ |
| OLD | NEW |