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

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

Issue 1284853003: Respect old generation limit in large object space allocations. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 4 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/heap.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/base/atomicops.h" 9 #include "src/base/atomicops.h"
10 #include "src/base/bits.h" 10 #include "src/base/bits.h"
(...skipping 1645 matching lines...) Expand 10 before | Expand all | Expand 10 after
1656 1656
1657 Object* object_; 1657 Object* object_;
1658 }; 1658 };
1659 1659
1660 1660
1661 STATIC_ASSERT(sizeof(AllocationResult) == kPointerSize); 1661 STATIC_ASSERT(sizeof(AllocationResult) == kPointerSize);
1662 1662
1663 1663
1664 class PagedSpace : public Space { 1664 class PagedSpace : public Space {
1665 public: 1665 public:
1666 // Creates a space with a maximum capacity, and an id. 1666 // Creates a space with an id.
1667 PagedSpace(Heap* heap, intptr_t max_capacity, AllocationSpace id, 1667 PagedSpace(Heap* heap, AllocationSpace id, Executability executable);
1668 Executability executable);
1669 1668
1670 virtual ~PagedSpace() {} 1669 virtual ~PagedSpace() {}
1671 1670
1672 // Set up the space using the given address range of virtual memory (from 1671 // Set up the space using the given address range of virtual memory (from
1673 // the memory allocator's initial chunk) if possible. If the block of 1672 // the memory allocator's initial chunk) if possible. If the block of
1674 // addresses is not big enough to contain a single page-aligned page, a 1673 // addresses is not big enough to contain a single page-aligned page, a
1675 // fresh chunk will be allocated. 1674 // fresh chunk will be allocated.
1676 bool SetUp(); 1675 bool SetUp();
1677 1676
1678 // Returns true if the space has been successfully set up and not 1677 // Returns true if the space has been successfully set up and not
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
1895 void UseEmergencyMemory(); 1894 void UseEmergencyMemory();
1896 intptr_t MaxEmergencyMemoryAllocated(); 1895 intptr_t MaxEmergencyMemoryAllocated();
1897 1896
1898 bool HasEmergencyMemory() { return emergency_memory_ != NULL; } 1897 bool HasEmergencyMemory() { return emergency_memory_ != NULL; }
1899 1898
1900 protected: 1899 protected:
1901 FreeList* free_list() { return &free_list_; } 1900 FreeList* free_list() { return &free_list_; }
1902 1901
1903 int area_size_; 1902 int area_size_;
1904 1903
1905 // Maximum capacity of this space.
1906 intptr_t max_capacity_;
1907
1908 // Accounting information for this space. 1904 // Accounting information for this space.
1909 AllocationStats accounting_stats_; 1905 AllocationStats accounting_stats_;
1910 1906
1911 // The dummy page that anchors the double linked list of pages. 1907 // The dummy page that anchors the double linked list of pages.
1912 Page anchor_; 1908 Page anchor_;
1913 1909
1914 // The space's free list. 1910 // The space's free list.
1915 FreeList free_list_; 1911 FreeList free_list_;
1916 1912
1917 // Normal allocation information. 1913 // Normal allocation information.
(...skipping 727 matching lines...) Expand 10 before | Expand all | Expand 10 after
2645 2641
2646 friend class SemiSpaceIterator; 2642 friend class SemiSpaceIterator;
2647 }; 2643 };
2648 2644
2649 2645
2650 // ----------------------------------------------------------------------------- 2646 // -----------------------------------------------------------------------------
2651 // Old object space (includes the old space of objects and code space) 2647 // Old object space (includes the old space of objects and code space)
2652 2648
2653 class OldSpace : public PagedSpace { 2649 class OldSpace : public PagedSpace {
2654 public: 2650 public:
2655 // Creates an old space object with a given maximum capacity. 2651 // Creates an old space object. The constructor does not allocate pages
2656 // The constructor does not allocate pages from OS. 2652 // from OS.
2657 OldSpace(Heap* heap, intptr_t max_capacity, AllocationSpace id, 2653 OldSpace(Heap* heap, AllocationSpace id, Executability executable)
2658 Executability executable) 2654 : PagedSpace(heap, id, executable) {}
2659 : PagedSpace(heap, max_capacity, id, executable) {}
2660 }; 2655 };
2661 2656
2662 2657
2663 // For contiguous spaces, top should be in the space (or at the end) and limit 2658 // For contiguous spaces, top should be in the space (or at the end) and limit
2664 // should be the end of the space. 2659 // should be the end of the space.
2665 #define DCHECK_SEMISPACE_ALLOCATION_INFO(info, space) \ 2660 #define DCHECK_SEMISPACE_ALLOCATION_INFO(info, space) \
2666 SLOW_DCHECK((space).page_low() <= (info).top() && \ 2661 SLOW_DCHECK((space).page_low() <= (info).top() && \
2667 (info).top() <= (space).page_high() && \ 2662 (info).top() <= (space).page_high() && \
2668 (info).limit() <= (space).page_high()) 2663 (info).limit() <= (space).page_high())
2669 2664
2670 2665
2671 // ----------------------------------------------------------------------------- 2666 // -----------------------------------------------------------------------------
2672 // Old space for all map objects 2667 // Old space for all map objects
2673 2668
2674 class MapSpace : public PagedSpace { 2669 class MapSpace : public PagedSpace {
2675 public: 2670 public:
2676 // Creates a map space object with a maximum capacity. 2671 // Creates a map space object.
2677 MapSpace(Heap* heap, intptr_t max_capacity, AllocationSpace id) 2672 MapSpace(Heap* heap, AllocationSpace id)
2678 : PagedSpace(heap, max_capacity, id, NOT_EXECUTABLE), 2673 : PagedSpace(heap, id, NOT_EXECUTABLE),
2679 max_map_space_pages_(kMaxMapPageIndex - 1) {} 2674 max_map_space_pages_(kMaxMapPageIndex - 1) {}
2680 2675
2681 // Given an index, returns the page address. 2676 // Given an index, returns the page address.
2682 // TODO(1600): this limit is artifical just to keep code compilable 2677 // TODO(1600): this limit is artifical just to keep code compilable
2683 static const int kMaxMapPageIndex = 1 << 16; 2678 static const int kMaxMapPageIndex = 1 << 16;
2684 2679
2685 virtual int RoundSizeDownToObjectAlignment(int size) { 2680 virtual int RoundSizeDownToObjectAlignment(int size) {
2686 if (base::bits::IsPowerOfTwo32(Map::kSize)) { 2681 if (base::bits::IsPowerOfTwo32(Map::kSize)) {
2687 return RoundDown(size, Map::kSize); 2682 return RoundDown(size, Map::kSize);
2688 } else { 2683 } else {
(...skipping 18 matching lines...) Expand all
2707 2702
2708 // ----------------------------------------------------------------------------- 2703 // -----------------------------------------------------------------------------
2709 // Large objects ( > Page::kMaxHeapObjectSize ) are allocated and managed by 2704 // Large objects ( > Page::kMaxHeapObjectSize ) are allocated and managed by
2710 // the large object space. A large object is allocated from OS heap with 2705 // the large object space. A large object is allocated from OS heap with
2711 // extra padding bytes (Page::kPageSize + Page::kObjectStartOffset). 2706 // extra padding bytes (Page::kPageSize + Page::kObjectStartOffset).
2712 // A large object always starts at Page::kObjectStartOffset to a page. 2707 // A large object always starts at Page::kObjectStartOffset to a page.
2713 // Large objects do not move during garbage collections. 2708 // Large objects do not move during garbage collections.
2714 2709
2715 class LargeObjectSpace : public Space { 2710 class LargeObjectSpace : public Space {
2716 public: 2711 public:
2717 LargeObjectSpace(Heap* heap, intptr_t max_capacity, AllocationSpace id); 2712 LargeObjectSpace(Heap* heap, AllocationSpace id);
2718 virtual ~LargeObjectSpace() {} 2713 virtual ~LargeObjectSpace() {}
2719 2714
2720 // Initializes internal data structures. 2715 // Initializes internal data structures.
2721 bool SetUp(); 2716 bool SetUp();
2722 2717
2723 // Releases internal resources, frees objects in this space. 2718 // Releases internal resources, frees objects in this space.
2724 void TearDown(); 2719 void TearDown();
2725 2720
2726 static intptr_t ObjectSizeFor(intptr_t chunk_size) { 2721 static intptr_t ObjectSizeFor(intptr_t chunk_size) {
2727 if (chunk_size <= (Page::kPageSize + Page::kObjectStartOffset)) return 0; 2722 if (chunk_size <= (Page::kPageSize + Page::kObjectStartOffset)) return 0;
2728 return chunk_size - Page::kPageSize - Page::kObjectStartOffset; 2723 return chunk_size - Page::kPageSize - Page::kObjectStartOffset;
2729 } 2724 }
2730 2725
2731 // Shared implementation of AllocateRaw, AllocateRawCode and 2726 // Shared implementation of AllocateRaw, AllocateRawCode and
2732 // AllocateRawFixedArray. 2727 // AllocateRawFixedArray.
2733 MUST_USE_RESULT AllocationResult 2728 MUST_USE_RESULT AllocationResult
2734 AllocateRaw(int object_size, Executability executable); 2729 AllocateRaw(int object_size, Executability executable);
2735 2730
2736 bool CanAllocateSize(int size) { return Size() + size <= max_capacity_; }
2737
2738 // Available bytes for objects in this space. 2731 // Available bytes for objects in this space.
2739 inline intptr_t Available() override; 2732 inline intptr_t Available() override;
2740 2733
2741 intptr_t Size() override { return size_; } 2734 intptr_t Size() override { return size_; }
2742 2735
2743 intptr_t SizeOfObjects() override { return objects_size_; } 2736 intptr_t SizeOfObjects() override { return objects_size_; }
2744 2737
2745 intptr_t MaximumCommittedMemory() { return maximum_committed_; } 2738 intptr_t MaximumCommittedMemory() { return maximum_committed_; }
2746 2739
2747 intptr_t CommittedMemory() override { return Size(); } 2740 intptr_t CommittedMemory() override { return Size(); }
(...skipping 29 matching lines...) Expand all
2777 #ifdef DEBUG 2770 #ifdef DEBUG
2778 void Print() override; 2771 void Print() override;
2779 void ReportStatistics(); 2772 void ReportStatistics();
2780 void CollectCodeStatistics(); 2773 void CollectCodeStatistics();
2781 #endif 2774 #endif
2782 // Checks whether an address is in the object area in this space. It 2775 // Checks whether an address is in the object area in this space. It
2783 // iterates all objects in the space. May be slow. 2776 // iterates all objects in the space. May be slow.
2784 bool SlowContains(Address addr) { return FindObject(addr)->IsHeapObject(); } 2777 bool SlowContains(Address addr) { return FindObject(addr)->IsHeapObject(); }
2785 2778
2786 private: 2779 private:
2787 intptr_t max_capacity_;
2788 intptr_t maximum_committed_; 2780 intptr_t maximum_committed_;
2789 // The head of the linked list of large object chunks. 2781 // The head of the linked list of large object chunks.
2790 LargePage* first_page_; 2782 LargePage* first_page_;
2791 intptr_t size_; // allocated bytes 2783 intptr_t size_; // allocated bytes
2792 int page_count_; // number of chunks 2784 int page_count_; // number of chunks
2793 intptr_t objects_size_; // size of objects 2785 intptr_t objects_size_; // size of objects
2794 // Map MemoryChunk::kAlignment-aligned chunks to large pages covering them 2786 // Map MemoryChunk::kAlignment-aligned chunks to large pages covering them
2795 HashMap chunk_map_; 2787 HashMap chunk_map_;
2796 2788
2797 friend class LargeObjectIterator; 2789 friend class LargeObjectIterator;
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
2879 count = 0; 2871 count = 0;
2880 } 2872 }
2881 // Must be small, since an iteration is used for lookup. 2873 // Must be small, since an iteration is used for lookup.
2882 static const int kMaxComments = 64; 2874 static const int kMaxComments = 64;
2883 }; 2875 };
2884 #endif 2876 #endif
2885 } 2877 }
2886 } // namespace v8::internal 2878 } // namespace v8::internal
2887 2879
2888 #endif // V8_HEAP_SPACES_H_ 2880 #endif // V8_HEAP_SPACES_H_
OLDNEW
« no previous file with comments | « src/heap/heap.cc ('k') | src/heap/spaces.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698