| 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 2503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2514 class InlineAllocationObserver { | 2514 class InlineAllocationObserver { |
| 2515 public: | 2515 public: |
| 2516 explicit InlineAllocationObserver(intptr_t step_size) | 2516 explicit InlineAllocationObserver(intptr_t step_size) |
| 2517 : step_size_(step_size), bytes_to_next_step_(step_size) { | 2517 : step_size_(step_size), bytes_to_next_step_(step_size) { |
| 2518 DCHECK(step_size >= kPointerSize && (step_size & kHeapObjectTagMask) == 0); | 2518 DCHECK(step_size >= kPointerSize && (step_size & kHeapObjectTagMask) == 0); |
| 2519 } | 2519 } |
| 2520 virtual ~InlineAllocationObserver() {} | 2520 virtual ~InlineAllocationObserver() {} |
| 2521 | 2521 |
| 2522 private: | 2522 private: |
| 2523 intptr_t step_size() const { return step_size_; } | 2523 intptr_t step_size() const { return step_size_; } |
| 2524 intptr_t bytes_to_next_step() const { return bytes_to_next_step_; } |
| 2524 | 2525 |
| 2525 // Pure virtual method provided by the subclasses that gets called when more | 2526 // Pure virtual method provided by the subclasses that gets called when more |
| 2526 // than step_size byte have been allocated. | 2527 // than step_size byte have been allocated. |
| 2527 virtual void Step(int bytes_allocated) = 0; | 2528 virtual void Step(int bytes_allocated) = 0; |
| 2528 | 2529 |
| 2529 // Called each time the new space does an inline allocation step. This may be | 2530 // Called each time the new space does an inline allocation step. This may be |
| 2530 // more frequently than the step_size we are monitoring (e.g. when there are | 2531 // more frequently than the step_size we are monitoring (e.g. when there are |
| 2531 // multiple observers, or when page or space boundary is encountered.) The | 2532 // multiple observers, or when page or space boundary is encountered.) The |
| 2532 // Step method is only called once more than step_size bytes have been | 2533 // Step method is only called once more than step_size bytes have been |
| 2533 // allocated. | 2534 // allocated. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 2554 // forwards most functions to the appropriate semispace. | 2555 // forwards most functions to the appropriate semispace. |
| 2555 | 2556 |
| 2556 class NewSpace : public Space { | 2557 class NewSpace : public Space { |
| 2557 public: | 2558 public: |
| 2558 // Constructor. | 2559 // Constructor. |
| 2559 explicit NewSpace(Heap* heap) | 2560 explicit NewSpace(Heap* heap) |
| 2560 : Space(heap, NEW_SPACE, NOT_EXECUTABLE), | 2561 : Space(heap, NEW_SPACE, NOT_EXECUTABLE), |
| 2561 to_space_(heap, kToSpace), | 2562 to_space_(heap, kToSpace), |
| 2562 from_space_(heap, kFromSpace), | 2563 from_space_(heap, kFromSpace), |
| 2563 reservation_(), | 2564 reservation_(), |
| 2564 inline_allocation_limit_step_(0), | |
| 2565 top_on_previous_step_(0) {} | 2565 top_on_previous_step_(0) {} |
| 2566 | 2566 |
| 2567 // Sets up the new space using the given chunk. | 2567 // Sets up the new space using the given chunk. |
| 2568 bool SetUp(int reserved_semispace_size_, int max_semi_space_size); | 2568 bool SetUp(int reserved_semispace_size_, int max_semi_space_size); |
| 2569 | 2569 |
| 2570 // Tears down the space. Heap memory was not allocated by the space, so it | 2570 // Tears down the space. Heap memory was not allocated by the space, so it |
| 2571 // is not deallocated here. | 2571 // is not deallocated here. |
| 2572 void TearDown(); | 2572 void TearDown(); |
| 2573 | 2573 |
| 2574 // True if the space has been set up but not torn down. | 2574 // True if the space has been set up but not torn down. |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2728 MUST_USE_RESULT INLINE( | 2728 MUST_USE_RESULT INLINE( |
| 2729 AllocationResult AllocateRawUnaligned(int size_in_bytes)); | 2729 AllocationResult AllocateRawUnaligned(int size_in_bytes)); |
| 2730 | 2730 |
| 2731 MUST_USE_RESULT INLINE(AllocationResult AllocateRaw( | 2731 MUST_USE_RESULT INLINE(AllocationResult AllocateRaw( |
| 2732 int size_in_bytes, AllocationAlignment alignment)); | 2732 int size_in_bytes, AllocationAlignment alignment)); |
| 2733 | 2733 |
| 2734 // Reset the allocation pointer to the beginning of the active semispace. | 2734 // Reset the allocation pointer to the beginning of the active semispace. |
| 2735 void ResetAllocationInfo(); | 2735 void ResetAllocationInfo(); |
| 2736 | 2736 |
| 2737 void UpdateInlineAllocationLimit(int size_in_bytes); | 2737 void UpdateInlineAllocationLimit(int size_in_bytes); |
| 2738 void UpdateInlineAllocationLimitStep(); | 2738 void StartNextInlineAllocationStep(); |
| 2739 | 2739 |
| 2740 // Allows observation of inline allocation. The observer->Step() method gets | 2740 // Allows observation of inline allocation. The observer->Step() method gets |
| 2741 // called after every step_size bytes have been allocated (approximately). | 2741 // called after every step_size bytes have been allocated (approximately). |
| 2742 // This works by adjusting the allocation limit to a lower value and adjusting | 2742 // This works by adjusting the allocation limit to a lower value and adjusting |
| 2743 // it after each step. | 2743 // it after each step. |
| 2744 void AddInlineAllocationObserver(InlineAllocationObserver* observer); | 2744 void AddInlineAllocationObserver(InlineAllocationObserver* observer); |
| 2745 | 2745 |
| 2746 // Removes a previously installed observer. | 2746 // Removes a previously installed observer. |
| 2747 void RemoveInlineAllocationObserver(InlineAllocationObserver* observer); | 2747 void RemoveInlineAllocationObserver(InlineAllocationObserver* observer); |
| 2748 | 2748 |
| 2749 void DisableInlineAllocationSteps() { | 2749 void DisableInlineAllocationSteps() { |
| 2750 inline_allocation_limit_step_ = 0; | |
| 2751 top_on_previous_step_ = 0; | 2750 top_on_previous_step_ = 0; |
| 2752 UpdateInlineAllocationLimit(0); | 2751 UpdateInlineAllocationLimit(0); |
| 2753 } | 2752 } |
| 2754 | 2753 |
| 2755 // Get the extent of the inactive semispace (for use as a marking stack, | 2754 // Get the extent of the inactive semispace (for use as a marking stack, |
| 2756 // or to zap it). Notice: space-addresses are not necessarily on the | 2755 // or to zap it). Notice: space-addresses are not necessarily on the |
| 2757 // same page, so FromSpaceStart() might be above FromSpaceEnd(). | 2756 // same page, so FromSpaceStart() might be above FromSpaceEnd(). |
| 2758 Address FromSpacePageLow() { return from_space_.page_low(); } | 2757 Address FromSpacePageLow() { return from_space_.page_low(); } |
| 2759 Address FromSpacePageHigh() { return from_space_.page_high(); } | 2758 Address FromSpacePageHigh() { return from_space_.page_high(); } |
| 2760 Address FromSpaceStart() { return from_space_.space_start(); } | 2759 Address FromSpaceStart() { return from_space_.space_start(); } |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2842 | 2841 |
| 2843 // Allocation pointer and limit for normal allocation and allocation during | 2842 // Allocation pointer and limit for normal allocation and allocation during |
| 2844 // mark-compact collection. | 2843 // mark-compact collection. |
| 2845 AllocationInfo allocation_info_; | 2844 AllocationInfo allocation_info_; |
| 2846 | 2845 |
| 2847 // When inline allocation stepping is active, either because of incremental | 2846 // When inline allocation stepping is active, either because of incremental |
| 2848 // marking or because of idle scavenge, we 'interrupt' inline allocation every | 2847 // marking or because of idle scavenge, we 'interrupt' inline allocation every |
| 2849 // once in a while. This is done by setting allocation_info_.limit to be lower | 2848 // once in a while. This is done by setting allocation_info_.limit to be lower |
| 2850 // than the actual limit and and increasing it in steps to guarantee that the | 2849 // than the actual limit and and increasing it in steps to guarantee that the |
| 2851 // observers are notified periodically. | 2850 // observers are notified periodically. |
| 2852 intptr_t inline_allocation_limit_step_; | |
| 2853 List<InlineAllocationObserver*> inline_allocation_observers_; | 2851 List<InlineAllocationObserver*> inline_allocation_observers_; |
| 2854 | 2852 |
| 2855 Address top_on_previous_step_; | 2853 Address top_on_previous_step_; |
| 2856 | 2854 |
| 2857 HistogramInfo* allocated_histogram_; | 2855 HistogramInfo* allocated_histogram_; |
| 2858 HistogramInfo* promoted_histogram_; | 2856 HistogramInfo* promoted_histogram_; |
| 2859 | 2857 |
| 2860 bool EnsureAllocation(int size_in_bytes, AllocationAlignment alignment); | 2858 bool EnsureAllocation(int size_in_bytes, AllocationAlignment alignment); |
| 2861 | 2859 |
| 2862 // If we are doing inline allocation in steps, this method performs the 'step' | 2860 // If we are doing inline allocation in steps, this method performs the 'step' |
| 2863 // operation. top is the memory address of the bump pointer at the last | 2861 // operation. top is the memory address of the bump pointer at the last |
| 2864 // inline allocation (i.e. it determines the numbers of bytes actually | 2862 // inline allocation (i.e. it determines the numbers of bytes actually |
| 2865 // allocated since the last step.) new_top is the address of the bump pointer | 2863 // allocated since the last step.) new_top is the address of the bump pointer |
| 2866 // where the next byte is going to be allocated from. top and new_top may be | 2864 // where the next byte is going to be allocated from. top and new_top may be |
| 2867 // different when we cross a page boundary or reset the space. | 2865 // different when we cross a page boundary or reset the space. |
| 2868 void InlineAllocationStep(Address top, Address new_top); | 2866 void InlineAllocationStep(Address top, Address new_top); |
| 2867 intptr_t GetNextInlineAllocationStepSize(); |
| 2869 | 2868 |
| 2870 friend class SemiSpaceIterator; | 2869 friend class SemiSpaceIterator; |
| 2871 }; | 2870 }; |
| 2872 | 2871 |
| 2873 // ----------------------------------------------------------------------------- | 2872 // ----------------------------------------------------------------------------- |
| 2874 // Compaction space that is used temporarily during compaction. | 2873 // Compaction space that is used temporarily during compaction. |
| 2875 | 2874 |
| 2876 class CompactionSpace : public PagedSpace { | 2875 class CompactionSpace : public PagedSpace { |
| 2877 public: | 2876 public: |
| 2878 CompactionSpace(Heap* heap, AllocationSpace id, Executability executable) | 2877 CompactionSpace(Heap* heap, AllocationSpace id, Executability executable) |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3127 count = 0; | 3126 count = 0; |
| 3128 } | 3127 } |
| 3129 // Must be small, since an iteration is used for lookup. | 3128 // Must be small, since an iteration is used for lookup. |
| 3130 static const int kMaxComments = 64; | 3129 static const int kMaxComments = 64; |
| 3131 }; | 3130 }; |
| 3132 #endif | 3131 #endif |
| 3133 } // namespace internal | 3132 } // namespace internal |
| 3134 } // namespace v8 | 3133 } // namespace v8 |
| 3135 | 3134 |
| 3136 #endif // V8_HEAP_SPACES_H_ | 3135 #endif // V8_HEAP_SPACES_H_ |
| OLD | NEW |