Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(438)

Side by Side Diff: src/heap/spaces.h

Issue 1404523002: [heap] inline allocation steps refactor (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Add tests and comments Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/heap/incremental-marking.cc ('k') | src/heap/spaces.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 2442 matching lines...) Expand 10 before | Expand all | Expand 10 after
2453 2453
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 // -----------------------------------------------------------------------------
2464 // Allows observation of inline allocation in the new space. This class is not
2465 // publicly instantiable; use NewSpace::AddInlineAllocationObserver.
2466 class InlineAllocationObserver {
2467 public:
2468 typedef void (*callback_t)(int bytes_allocated, void* arg);
2469
2470 InlineAllocationObserver(const InlineAllocationObserver&) = default;
2471 InlineAllocationObserver& operator=(const InlineAllocationObserver&) =
2472 default;
2473
2474 private:
2475 explicit InlineAllocationObserver(intptr_t step_size, callback_t callback,
2476 void* callback_arg)
2477 : step_size_(step_size),
2478 callback_(callback),
2479 callback_arg_(callback_arg),
2480 bytes_to_next_step_(step_size) {
2481 DCHECK(step_size >= kPointerSize);
2482 }
2483
2484 intptr_t step_size() const { return step_size_; }
2485 callback_t callback() const { return callback_; }
2486
2487 // Called each time the new space does an inline allocation step. This may be
2488 // more frequently than the step_size we are monitoring (e.g. when there are
2489 // multiple observers, or when page or space boundary is encountered.) The
2490 // callback is only called once at least step_size bytes have been allocated.
2491 void step(int bytes_allocated) {
2492 bytes_to_next_step_ -= bytes_allocated;
2493 if (bytes_to_next_step_ <= 0) {
2494 callback_(static_cast<int>(step_size_ - bytes_to_next_step_),
2495 callback_arg_);
2496 bytes_to_next_step_ = step_size_;
2497 }
2498 }
2499
2500 intptr_t step_size_;
2501 callback_t callback_;
2502 void* callback_arg_;
2503 intptr_t bytes_to_next_step_;
2504
2505 friend class NewSpace;
2506 };
2463 2507
2464 // ----------------------------------------------------------------------------- 2508 // -----------------------------------------------------------------------------
2465 // The young generation space. 2509 // The young generation space.
2466 // 2510 //
2467 // The new space consists of a contiguous pair of semispaces. It simply 2511 // The new space consists of a contiguous pair of semispaces. It simply
2468 // forwards most functions to the appropriate semispace. 2512 // forwards most functions to the appropriate semispace.
2469 2513
2470 class NewSpace : public Space { 2514 class NewSpace : public Space {
2471 public: 2515 public:
2472 // Constructor. 2516 // Constructor.
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
2642 MUST_USE_RESULT INLINE( 2686 MUST_USE_RESULT INLINE(
2643 AllocationResult AllocateRawUnaligned(int size_in_bytes)); 2687 AllocationResult AllocateRawUnaligned(int size_in_bytes));
2644 2688
2645 MUST_USE_RESULT INLINE(AllocationResult AllocateRaw( 2689 MUST_USE_RESULT INLINE(AllocationResult AllocateRaw(
2646 int size_in_bytes, AllocationAlignment alignment)); 2690 int size_in_bytes, AllocationAlignment alignment));
2647 2691
2648 // Reset the allocation pointer to the beginning of the active semispace. 2692 // Reset the allocation pointer to the beginning of the active semispace.
2649 void ResetAllocationInfo(); 2693 void ResetAllocationInfo();
2650 2694
2651 void UpdateInlineAllocationLimit(int size_in_bytes); 2695 void UpdateInlineAllocationLimit(int size_in_bytes);
2652 void LowerInlineAllocationLimit(intptr_t step) { 2696
2653 inline_allocation_limit_step_ = step; 2697 // Allows observation of inline allocation. The callback gets after every
ulan 2015/10/21 09:06:12 The callback gets called
ofrobots 2015/10/22 02:42:22 Done.
2698 // step_size bytes have been allocated (approximately). This works by
2699 // adjusting the allocation limit to a lower value and adjusting it
2700 // after each step. The callback_arg argument is passed to the callback each
2701 // time it is called.
2702 void AddInlineAllocationObserver(
2703 intptr_t step_size, InlineAllocationObserver::callback_t callback,
2704 void* callback_arg);
2705
2706 // Removes a previously installed callback function. For duplicate functions
2707 // they are removed in the order of insertion (one at a time.)
2708 void RemoveInlineAllocationObserver(
2709 InlineAllocationObserver::callback_t callback);
2710
2711 void DisableInlineAllocationSteps() {
2712 inline_allocation_limit_step_ = 0;
2713 top_on_previous_step_ = 0;
2654 UpdateInlineAllocationLimit(0); 2714 UpdateInlineAllocationLimit(0);
2655 top_on_previous_step_ = step ? allocation_info_.top() : 0;
2656 } 2715 }
2657 2716
2658 // Get the extent of the inactive semispace (for use as a marking stack, 2717 // 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 2718 // or to zap it). Notice: space-addresses are not necessarily on the
2660 // same page, so FromSpaceStart() might be above FromSpaceEnd(). 2719 // same page, so FromSpaceStart() might be above FromSpaceEnd().
2661 Address FromSpacePageLow() { return from_space_.page_low(); } 2720 Address FromSpacePageLow() { return from_space_.page_low(); }
2662 Address FromSpacePageHigh() { return from_space_.page_high(); } 2721 Address FromSpacePageHigh() { return from_space_.page_high(); }
2663 Address FromSpaceStart() { return from_space_.space_start(); } 2722 Address FromSpaceStart() { return from_space_.space_start(); }
2664 Address FromSpaceEnd() { return from_space_.space_end(); } 2723 Address FromSpaceEnd() { return from_space_.space_end(); }
2665 2724
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
2721 } 2780 }
2722 2781
2723 bool IsFromSpaceCommitted() { return from_space_.is_committed(); } 2782 bool IsFromSpaceCommitted() { return from_space_.is_committed(); }
2724 2783
2725 SemiSpace* active_space() { return &to_space_; } 2784 SemiSpace* active_space() { return &to_space_; }
2726 2785
2727 private: 2786 private:
2728 // Update allocation info to match the current to-space page. 2787 // Update allocation info to match the current to-space page.
2729 void UpdateAllocationInfo(); 2788 void UpdateAllocationInfo();
2730 2789
2790 void UpdateInlineAllocationLimitStep();
2791
2731 Address chunk_base_; 2792 Address chunk_base_;
2732 uintptr_t chunk_size_; 2793 uintptr_t chunk_size_;
2733 2794
2734 // The semispaces. 2795 // The semispaces.
2735 SemiSpace to_space_; 2796 SemiSpace to_space_;
2736 SemiSpace from_space_; 2797 SemiSpace from_space_;
2737 base::VirtualMemory reservation_; 2798 base::VirtualMemory reservation_;
2738 int pages_used_; 2799 int pages_used_;
2739 2800
2740 // Start address and bit mask for containment testing. 2801 // Start address and bit mask for containment testing.
2741 Address start_; 2802 Address start_;
2742 uintptr_t address_mask_; 2803 uintptr_t address_mask_;
2743 uintptr_t object_mask_; 2804 uintptr_t object_mask_;
2744 uintptr_t object_expected_; 2805 uintptr_t object_expected_;
2745 2806
2746 // Allocation pointer and limit for normal allocation and allocation during 2807 // Allocation pointer and limit for normal allocation and allocation during
2747 // mark-compact collection. 2808 // mark-compact collection.
2748 AllocationInfo allocation_info_; 2809 AllocationInfo allocation_info_;
2749 2810
2750 // When incremental marking is active we will set allocation_info_.limit 2811 // When inline allocation stepping is active, either because of incremental
2751 // to be lower than actual limit and then will gradually increase it 2812 // marking or because of idle scavenge, we 'interrupt' inline allocation every
2752 // in steps to guarantee that we do incremental marking steps even 2813 // 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. 2814 // than the actual limit and and increasing it in steps to guarantee that the
2815 // observers are notified periodically.
2754 intptr_t inline_allocation_limit_step_; 2816 intptr_t inline_allocation_limit_step_;
2817 List<InlineAllocationObserver> inline_allocation_observers_;
2755 2818
2756 Address top_on_previous_step_; 2819 Address top_on_previous_step_;
2757 2820
2758 HistogramInfo* allocated_histogram_; 2821 HistogramInfo* allocated_histogram_;
2759 HistogramInfo* promoted_histogram_; 2822 HistogramInfo* promoted_histogram_;
2760 2823
2761 bool EnsureAllocation(int size_in_bytes, AllocationAlignment alignment); 2824 bool EnsureAllocation(int size_in_bytes, AllocationAlignment alignment);
2762 2825
2763 // If we are doing inline allocation in steps, this method performs the 'step' 2826 // 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 2827 // 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 2828 // 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 2829 // 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 2830 // 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. 2831 // different when we cross a page boundary or reset the space.
2770 void InlineAllocationStep(Address top, Address new_top); 2832 void InlineAllocationStep(Address top, Address new_top);
2771 2833
2772 friend class SemiSpaceIterator; 2834 friend class SemiSpaceIterator;
2773 }; 2835 };
2774 2836
2775 // ----------------------------------------------------------------------------- 2837 // -----------------------------------------------------------------------------
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
3009 count = 0; 3071 count = 0;
3010 } 3072 }
3011 // Must be small, since an iteration is used for lookup. 3073 // Must be small, since an iteration is used for lookup.
3012 static const int kMaxComments = 64; 3074 static const int kMaxComments = 64;
3013 }; 3075 };
3014 #endif 3076 #endif
3015 } // namespace internal 3077 } // namespace internal
3016 } // namespace v8 3078 } // namespace v8
3017 3079
3018 #endif // V8_HEAP_SPACES_H_ 3080 #endif // V8_HEAP_SPACES_H_
OLDNEW
« no previous file with comments | « src/heap/incremental-marking.cc ('k') | src/heap/spaces.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698