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

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

Issue 1322523004: [heap] Make compaction space accept external memory. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Properly free spaces and allocator Created 5 years, 3 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 | « no previous file | 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 1573 matching lines...) Expand 10 before | Expand all | Expand 10 after
1584 // starting at 'start' is placed on the free list. The return value is the 1584 // starting at 'start' is placed on the free list. The return value is the
1585 // number of bytes that have been lost due to internal fragmentation by 1585 // number of bytes that have been lost due to internal fragmentation by
1586 // freeing the block. Bookkeeping information will be written to the block, 1586 // freeing the block. Bookkeeping information will be written to the block,
1587 // i.e., its contents will be destroyed. The start address should be word 1587 // i.e., its contents will be destroyed. The start address should be word
1588 // aligned, and the size should be a non-zero multiple of the word size. 1588 // aligned, and the size should be a non-zero multiple of the word size.
1589 int Free(Address start, int size_in_bytes); 1589 int Free(Address start, int size_in_bytes);
1590 1590
1591 // This method returns how much memory can be allocated after freeing 1591 // This method returns how much memory can be allocated after freeing
1592 // maximum_freed memory. 1592 // maximum_freed memory.
1593 static inline int GuaranteedAllocatable(int maximum_freed) { 1593 static inline int GuaranteedAllocatable(int maximum_freed) {
1594 if (maximum_freed < kSmallListMin) { 1594 if (maximum_freed <= kSmallListMin) {
1595 return 0; 1595 return 0;
1596 } else if (maximum_freed <= kSmallListMax) { 1596 } else if (maximum_freed <= kSmallListMax) {
1597 return kSmallAllocationMax; 1597 return kSmallAllocationMax;
1598 } else if (maximum_freed <= kMediumListMax) { 1598 } else if (maximum_freed <= kMediumListMax) {
1599 return kMediumAllocationMax; 1599 return kMediumAllocationMax;
1600 } else if (maximum_freed <= kLargeListMax) { 1600 } else if (maximum_freed <= kLargeListMax) {
1601 return kLargeAllocationMax; 1601 return kLargeAllocationMax;
1602 } 1602 }
1603 return maximum_freed; 1603 return maximum_freed;
1604 } 1604 }
(...skipping 19 matching lines...) Expand all
1624 void RepairLists(Heap* heap); 1624 void RepairLists(Heap* heap);
1625 1625
1626 intptr_t EvictFreeListItems(Page* p); 1626 intptr_t EvictFreeListItems(Page* p);
1627 bool ContainsPageFreeListItems(Page* p); 1627 bool ContainsPageFreeListItems(Page* p);
1628 1628
1629 FreeListCategory* small_list() { return &small_list_; } 1629 FreeListCategory* small_list() { return &small_list_; }
1630 FreeListCategory* medium_list() { return &medium_list_; } 1630 FreeListCategory* medium_list() { return &medium_list_; }
1631 FreeListCategory* large_list() { return &large_list_; } 1631 FreeListCategory* large_list() { return &large_list_; }
1632 FreeListCategory* huge_list() { return &huge_list_; } 1632 FreeListCategory* huge_list() { return &huge_list_; }
1633 1633
1634 static const int kSmallListMin = 0x20 * kPointerSize;
1635
1636 private: 1634 private:
1637 // The size range of blocks, in bytes. 1635 // The size range of blocks, in bytes.
1638 static const int kMinBlockSize = 3 * kPointerSize; 1636 static const int kMinBlockSize = 3 * kPointerSize;
1639 static const int kMaxBlockSize = Page::kMaxRegularHeapObjectSize; 1637 static const int kMaxBlockSize = Page::kMaxRegularHeapObjectSize;
1640 1638
1639 static const int kSmallListMin = 0x1f * kPointerSize;
1640 static const int kSmallListMax = 0xff * kPointerSize;
1641 static const int kMediumListMax = 0x7ff * kPointerSize;
1642 static const int kLargeListMax = 0x3fff * kPointerSize;
1643 static const int kSmallAllocationMax = kSmallListMin;
1644 static const int kMediumAllocationMax = kSmallListMax;
1645 static const int kLargeAllocationMax = kMediumListMax;
1646
1641 FreeSpace* FindNodeFor(int size_in_bytes, int* node_size); 1647 FreeSpace* FindNodeFor(int size_in_bytes, int* node_size);
1642 1648
1643 PagedSpace* owner_; 1649 PagedSpace* owner_;
1644 Heap* heap_; 1650 Heap* heap_;
1645
1646 static const int kSmallListMax = 0xff * kPointerSize;
1647 static const int kMediumListMax = 0x7ff * kPointerSize;
1648 static const int kLargeListMax = 0x3fff * kPointerSize;
1649 static const int kSmallAllocationMax = kSmallListMin - kPointerSize;
1650 static const int kMediumAllocationMax = kSmallListMax;
1651 static const int kLargeAllocationMax = kMediumListMax;
1652 FreeListCategory small_list_; 1651 FreeListCategory small_list_;
1653 FreeListCategory medium_list_; 1652 FreeListCategory medium_list_;
1654 FreeListCategory large_list_; 1653 FreeListCategory large_list_;
1655 FreeListCategory huge_list_; 1654 FreeListCategory huge_list_;
1656 1655
1657 DISALLOW_IMPLICIT_CONSTRUCTORS(FreeList); 1656 DISALLOW_IMPLICIT_CONSTRUCTORS(FreeList);
1658 }; 1657 };
1659 1658
1660 1659
1661 class AllocationResult { 1660 class AllocationResult {
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
1799 // The allocation limit address. 1798 // The allocation limit address.
1800 Address* allocation_limit_address() { 1799 Address* allocation_limit_address() {
1801 return allocation_info_.limit_address(); 1800 return allocation_info_.limit_address();
1802 } 1801 }
1803 1802
1804 // Allocate the requested number of bytes in the space if possible, return a 1803 // Allocate the requested number of bytes in the space if possible, return a
1805 // failure object if not. 1804 // failure object if not.
1806 MUST_USE_RESULT inline AllocationResult AllocateRawUnaligned( 1805 MUST_USE_RESULT inline AllocationResult AllocateRawUnaligned(
1807 int size_in_bytes); 1806 int size_in_bytes);
1808 1807
1808 MUST_USE_RESULT inline AllocationResult AllocateRawUnalignedSynchronized(
1809 int size_in_bytes);
1810
1809 // Allocate the requested number of bytes in the space double aligned if 1811 // Allocate the requested number of bytes in the space double aligned if
1810 // possible, return a failure object if not. 1812 // possible, return a failure object if not.
1811 MUST_USE_RESULT inline AllocationResult AllocateRawAligned( 1813 MUST_USE_RESULT inline AllocationResult AllocateRawAligned(
1812 int size_in_bytes, AllocationAlignment alignment); 1814 int size_in_bytes, AllocationAlignment alignment);
1813 1815
1814 // Allocate the requested number of bytes in the space and consider allocation 1816 // Allocate the requested number of bytes in the space and consider allocation
1815 // alignment if needed. 1817 // alignment if needed.
1816 MUST_USE_RESULT inline AllocationResult AllocateRaw( 1818 MUST_USE_RESULT inline AllocationResult AllocateRaw(
1817 int size_in_bytes, AllocationAlignment alignment); 1819 int size_in_bytes, AllocationAlignment alignment);
1818 1820
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
1995 // and sweep these pages concurrently. They will stop sweeping after the 1997 // and sweep these pages concurrently. They will stop sweeping after the
1996 // end_of_unswept_pages_ page. 1998 // end_of_unswept_pages_ page.
1997 Page* end_of_unswept_pages_; 1999 Page* end_of_unswept_pages_;
1998 2000
1999 // Emergency memory is the memory of a full page for a given space, allocated 2001 // Emergency memory is the memory of a full page for a given space, allocated
2000 // conservatively before evacuating a page. If compaction fails due to out 2002 // conservatively before evacuating a page. If compaction fails due to out
2001 // of memory error the emergency memory can be used to complete compaction. 2003 // of memory error the emergency memory can be used to complete compaction.
2002 // If not used, the emergency memory is released after compaction. 2004 // If not used, the emergency memory is released after compaction.
2003 MemoryChunk* emergency_memory_; 2005 MemoryChunk* emergency_memory_;
2004 2006
2007 // Mutex guarding any concurrent access to the space.
2008 base::Mutex space_mutex_;
2009
2010 friend class MarkCompactCollector;
2005 friend class PageIterator; 2011 friend class PageIterator;
2006 friend class MarkCompactCollector;
2007 }; 2012 };
2008 2013
2009 2014
2010 class NumberAndSizeInfo BASE_EMBEDDED { 2015 class NumberAndSizeInfo BASE_EMBEDDED {
2011 public: 2016 public:
2012 NumberAndSizeInfo() : number_(0), bytes_(0) {} 2017 NumberAndSizeInfo() : number_(0), bytes_(0) {}
2013 2018
2014 int number() const { return number_; } 2019 int number() const { return number_; }
2015 void increment_number(int num) { number_ += num; } 2020 void increment_number(int num) { number_ += num; }
2016 2021
(...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after
2678 }; 2683 };
2679 2684
2680 // ----------------------------------------------------------------------------- 2685 // -----------------------------------------------------------------------------
2681 // Compaction space that is used temporarily during compaction. 2686 // Compaction space that is used temporarily during compaction.
2682 2687
2683 class CompactionSpace : public PagedSpace { 2688 class CompactionSpace : public PagedSpace {
2684 public: 2689 public:
2685 CompactionSpace(Heap* heap, AllocationSpace id, Executability executable) 2690 CompactionSpace(Heap* heap, AllocationSpace id, Executability executable)
2686 : PagedSpace(heap, id, executable) {} 2691 : PagedSpace(heap, id, executable) {}
2687 2692
2693 // Adds external memory starting at {start} of {size_in_bytes} to the space.
2694 void AddExternalMemory(Address start, int size_in_bytes) {
2695 IncreaseCapacity(size_in_bytes);
2696 Free(start, size_in_bytes);
2697 }
2698
2688 protected: 2699 protected:
2689 // The space is temporary and not included in any snapshots. 2700 // The space is temporary and not included in any snapshots.
2690 virtual bool snapshotable() { return false; } 2701 virtual bool snapshotable() { return false; }
2691 }; 2702 };
2692 2703
2693 2704
2694 // ----------------------------------------------------------------------------- 2705 // -----------------------------------------------------------------------------
2695 // Old object space (includes the old space of objects and code space) 2706 // Old object space (includes the old space of objects and code space)
2696 2707
2697 class OldSpace : public PagedSpace { 2708 class OldSpace : public PagedSpace {
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
2884 count = 0; 2895 count = 0;
2885 } 2896 }
2886 // Must be small, since an iteration is used for lookup. 2897 // Must be small, since an iteration is used for lookup.
2887 static const int kMaxComments = 64; 2898 static const int kMaxComments = 64;
2888 }; 2899 };
2889 #endif 2900 #endif
2890 } 2901 }
2891 } // namespace v8::internal 2902 } // namespace v8::internal
2892 2903
2893 #endif // V8_HEAP_SPACES_H_ 2904 #endif // V8_HEAP_SPACES_H_
OLDNEW
« no previous file with comments | « no previous file | src/heap/spaces.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698