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/mark-compact.cc

Issue 1293773002: [heap] Simplify MarkingDeque implementation. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebased. 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/mark-compact.h ('k') | src/heap/mark-compact-inl.h » ('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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 #include "src/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/base/atomicops.h" 7 #include "src/base/atomicops.h"
8 #include "src/base/bits.h" 8 #include "src/base/bits.h"
9 #include "src/code-stubs.h" 9 #include "src/code-stubs.h"
10 #include "src/compilation-cache.h" 10 #include "src/compilation-cache.h"
(...skipping 1716 matching lines...) Expand 10 before | Expand all | Expand 10 after
1727 return NULL; 1727 return NULL;
1728 } 1728 }
1729 } 1729 }
1730 }; 1730 };
1731 1731
1732 1732
1733 // Fill the marking stack with overflowed objects returned by the given 1733 // Fill the marking stack with overflowed objects returned by the given
1734 // iterator. Stop when the marking stack is filled or the end of the space 1734 // iterator. Stop when the marking stack is filled or the end of the space
1735 // is reached, whichever comes first. 1735 // is reached, whichever comes first.
1736 template <class T> 1736 template <class T>
1737 static void DiscoverGreyObjectsWithIterator(Heap* heap, 1737 void MarkCompactCollector::DiscoverGreyObjectsWithIterator(T* it) {
1738 MarkingDeque* marking_deque,
1739 T* it) {
1740 // The caller should ensure that the marking stack is initially not full, 1738 // The caller should ensure that the marking stack is initially not full,
1741 // so that we don't waste effort pointlessly scanning for objects. 1739 // so that we don't waste effort pointlessly scanning for objects.
1742 DCHECK(!marking_deque->IsFull()); 1740 DCHECK(!marking_deque()->IsFull());
1743 1741
1744 Map* filler_map = heap->one_pointer_filler_map(); 1742 Map* filler_map = heap()->one_pointer_filler_map();
1745 for (HeapObject* object = it->Next(); object != NULL; object = it->Next()) { 1743 for (HeapObject* object = it->Next(); object != NULL; object = it->Next()) {
1746 MarkBit markbit = Marking::MarkBitFrom(object); 1744 MarkBit markbit = Marking::MarkBitFrom(object);
1747 if ((object->map() != filler_map) && Marking::IsGrey(markbit)) { 1745 if ((object->map() != filler_map) && Marking::IsGrey(markbit)) {
1748 Marking::GreyToBlack(markbit); 1746 Marking::GreyToBlack(markbit);
1749 MemoryChunk::IncrementLiveBytesFromGC(object, object->Size()); 1747 PushBlack(object);
1750 marking_deque->PushBlack(object); 1748 if (marking_deque()->IsFull()) return;
1751 if (marking_deque->IsFull()) return;
1752 } 1749 }
1753 } 1750 }
1754 } 1751 }
1755 1752
1756 1753
1757 static inline int MarkWordToObjectStarts(uint32_t mark_bits, int* starts); 1754 static inline int MarkWordToObjectStarts(uint32_t mark_bits, int* starts);
1758 1755
1759 1756
1760 static void DiscoverGreyObjectsOnPage(MarkingDeque* marking_deque, 1757 void MarkCompactCollector::DiscoverGreyObjectsOnPage(MemoryChunk* p) {
1761 MemoryChunk* p) { 1758 DCHECK(!marking_deque()->IsFull());
1762 DCHECK(!marking_deque->IsFull());
1763 DCHECK(strcmp(Marking::kWhiteBitPattern, "00") == 0); 1759 DCHECK(strcmp(Marking::kWhiteBitPattern, "00") == 0);
1764 DCHECK(strcmp(Marking::kBlackBitPattern, "10") == 0); 1760 DCHECK(strcmp(Marking::kBlackBitPattern, "10") == 0);
1765 DCHECK(strcmp(Marking::kGreyBitPattern, "11") == 0); 1761 DCHECK(strcmp(Marking::kGreyBitPattern, "11") == 0);
1766 DCHECK(strcmp(Marking::kImpossibleBitPattern, "01") == 0); 1762 DCHECK(strcmp(Marking::kImpossibleBitPattern, "01") == 0);
1767 1763
1768 for (MarkBitCellIterator it(p); !it.Done(); it.Advance()) { 1764 for (MarkBitCellIterator it(p); !it.Done(); it.Advance()) {
1769 Address cell_base = it.CurrentCellBase(); 1765 Address cell_base = it.CurrentCellBase();
1770 MarkBit::CellType* cell = it.CurrentCell(); 1766 MarkBit::CellType* cell = it.CurrentCell();
1771 1767
1772 const MarkBit::CellType current_cell = *cell; 1768 const MarkBit::CellType current_cell = *cell;
(...skipping 11 matching lines...) Expand all
1784 int offset = 0; 1780 int offset = 0;
1785 while (grey_objects != 0) { 1781 while (grey_objects != 0) {
1786 int trailing_zeros = base::bits::CountTrailingZeros32(grey_objects); 1782 int trailing_zeros = base::bits::CountTrailingZeros32(grey_objects);
1787 grey_objects >>= trailing_zeros; 1783 grey_objects >>= trailing_zeros;
1788 offset += trailing_zeros; 1784 offset += trailing_zeros;
1789 MarkBit markbit(cell, 1 << offset); 1785 MarkBit markbit(cell, 1 << offset);
1790 DCHECK(Marking::IsGrey(markbit)); 1786 DCHECK(Marking::IsGrey(markbit));
1791 Marking::GreyToBlack(markbit); 1787 Marking::GreyToBlack(markbit);
1792 Address addr = cell_base + offset * kPointerSize; 1788 Address addr = cell_base + offset * kPointerSize;
1793 HeapObject* object = HeapObject::FromAddress(addr); 1789 HeapObject* object = HeapObject::FromAddress(addr);
1794 MemoryChunk::IncrementLiveBytesFromGC(object, object->Size()); 1790 PushBlack(object);
1795 marking_deque->PushBlack(object); 1791 if (marking_deque()->IsFull()) return;
1796 if (marking_deque->IsFull()) return;
1797 offset += 2; 1792 offset += 2;
1798 grey_objects >>= 2; 1793 grey_objects >>= 2;
1799 } 1794 }
1800 1795
1801 grey_objects >>= (Bitmap::kBitsPerCell - 1); 1796 grey_objects >>= (Bitmap::kBitsPerCell - 1);
1802 } 1797 }
1803 } 1798 }
1804 1799
1805 1800
1806 int MarkCompactCollector::DiscoverAndEvacuateBlackObjectsOnPage( 1801 int MarkCompactCollector::DiscoverAndEvacuateBlackObjectsOnPage(
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1859 1854
1860 MigrateObject(HeapObject::cast(target), object, size, NEW_SPACE); 1855 MigrateObject(HeapObject::cast(target), object, size, NEW_SPACE);
1861 heap()->IncrementSemiSpaceCopiedObjectSize(size); 1856 heap()->IncrementSemiSpaceCopiedObjectSize(size);
1862 } 1857 }
1863 *cells = 0; 1858 *cells = 0;
1864 } 1859 }
1865 return survivors_size; 1860 return survivors_size;
1866 } 1861 }
1867 1862
1868 1863
1869 static void DiscoverGreyObjectsInSpace(Heap* heap, MarkingDeque* marking_deque, 1864 void MarkCompactCollector::DiscoverGreyObjectsInSpace(PagedSpace* space) {
1870 PagedSpace* space) {
1871 PageIterator it(space); 1865 PageIterator it(space);
1872 while (it.has_next()) { 1866 while (it.has_next()) {
1873 Page* p = it.next(); 1867 Page* p = it.next();
1874 DiscoverGreyObjectsOnPage(marking_deque, p); 1868 DiscoverGreyObjectsOnPage(p);
1875 if (marking_deque->IsFull()) return; 1869 if (marking_deque()->IsFull()) return;
1876 } 1870 }
1877 } 1871 }
1878 1872
1879 1873
1880 static void DiscoverGreyObjectsInNewSpace(Heap* heap, 1874 void MarkCompactCollector::DiscoverGreyObjectsInNewSpace() {
1881 MarkingDeque* marking_deque) { 1875 NewSpace* space = heap()->new_space();
1882 NewSpace* space = heap->new_space();
1883 NewSpacePageIterator it(space->bottom(), space->top()); 1876 NewSpacePageIterator it(space->bottom(), space->top());
1884 while (it.has_next()) { 1877 while (it.has_next()) {
1885 NewSpacePage* page = it.next(); 1878 NewSpacePage* page = it.next();
1886 DiscoverGreyObjectsOnPage(marking_deque, page); 1879 DiscoverGreyObjectsOnPage(page);
1887 if (marking_deque->IsFull()) return; 1880 if (marking_deque()->IsFull()) return;
1888 } 1881 }
1889 } 1882 }
1890 1883
1891 1884
1892 bool MarkCompactCollector::IsUnmarkedHeapObject(Object** p) { 1885 bool MarkCompactCollector::IsUnmarkedHeapObject(Object** p) {
1893 Object* o = *p; 1886 Object* o = *p;
1894 if (!o->IsHeapObject()) return false; 1887 if (!o->IsHeapObject()) return false;
1895 HeapObject* heap_object = HeapObject::cast(o); 1888 HeapObject* heap_object = HeapObject::cast(o);
1896 MarkBit mark = Marking::MarkBitFrom(heap_object); 1889 MarkBit mark = Marking::MarkBitFrom(heap_object);
1897 return Marking::IsWhite(mark); 1890 return Marking::IsWhite(mark);
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
2002 1995
2003 // Sweep the heap for overflowed objects, clear their overflow bits, and 1996 // Sweep the heap for overflowed objects, clear their overflow bits, and
2004 // push them on the marking stack. Stop early if the marking stack fills 1997 // push them on the marking stack. Stop early if the marking stack fills
2005 // before sweeping completes. If sweeping completes, there are no remaining 1998 // before sweeping completes. If sweeping completes, there are no remaining
2006 // overflowed objects in the heap so the overflow flag on the markings stack 1999 // overflowed objects in the heap so the overflow flag on the markings stack
2007 // is cleared. 2000 // is cleared.
2008 void MarkCompactCollector::RefillMarkingDeque() { 2001 void MarkCompactCollector::RefillMarkingDeque() {
2009 isolate()->CountUsage(v8::Isolate::UseCounterFeature::kMarkDequeOverflow); 2002 isolate()->CountUsage(v8::Isolate::UseCounterFeature::kMarkDequeOverflow);
2010 DCHECK(marking_deque_.overflowed()); 2003 DCHECK(marking_deque_.overflowed());
2011 2004
2012 DiscoverGreyObjectsInNewSpace(heap(), &marking_deque_); 2005 DiscoverGreyObjectsInNewSpace();
2013 if (marking_deque_.IsFull()) return; 2006 if (marking_deque_.IsFull()) return;
2014 2007
2015 DiscoverGreyObjectsInSpace(heap(), &marking_deque_, heap()->old_space()); 2008 DiscoverGreyObjectsInSpace(heap()->old_space());
2016 if (marking_deque_.IsFull()) return; 2009 if (marking_deque_.IsFull()) return;
2017 2010
2018 DiscoverGreyObjectsInSpace(heap(), &marking_deque_, heap()->code_space()); 2011 DiscoverGreyObjectsInSpace(heap()->code_space());
2019 if (marking_deque_.IsFull()) return; 2012 if (marking_deque_.IsFull()) return;
2020 2013
2021 DiscoverGreyObjectsInSpace(heap(), &marking_deque_, heap()->map_space()); 2014 DiscoverGreyObjectsInSpace(heap()->map_space());
2022 if (marking_deque_.IsFull()) return; 2015 if (marking_deque_.IsFull()) return;
2023 2016
2024 LargeObjectIterator lo_it(heap()->lo_space()); 2017 LargeObjectIterator lo_it(heap()->lo_space());
2025 DiscoverGreyObjectsWithIterator(heap(), &marking_deque_, &lo_it); 2018 DiscoverGreyObjectsWithIterator(&lo_it);
2026 if (marking_deque_.IsFull()) return; 2019 if (marking_deque_.IsFull()) return;
2027 2020
2028 marking_deque_.ClearOverflowed(); 2021 marking_deque_.ClearOverflowed();
2029 } 2022 }
2030 2023
2031 2024
2032 // Mark all objects reachable (transitively) from objects on the marking 2025 // Mark all objects reachable (transitively) from objects on the marking
2033 // stack. Before: the marking stack contains zero or more heap object 2026 // stack. Before: the marking stack contains zero or more heap object
2034 // pointers. After: the marking stack is empty and there are no overflowed 2027 // pointers. After: the marking stack is empty and there are no overflowed
2035 // objects in the heap. 2028 // objects in the heap.
(...skipping 2699 matching lines...) Expand 10 before | Expand all | Expand 10 after
4735 SlotsBuffer* buffer = *buffer_address; 4728 SlotsBuffer* buffer = *buffer_address;
4736 while (buffer != NULL) { 4729 while (buffer != NULL) {
4737 SlotsBuffer* next_buffer = buffer->next(); 4730 SlotsBuffer* next_buffer = buffer->next();
4738 DeallocateBuffer(buffer); 4731 DeallocateBuffer(buffer);
4739 buffer = next_buffer; 4732 buffer = next_buffer;
4740 } 4733 }
4741 *buffer_address = NULL; 4734 *buffer_address = NULL;
4742 } 4735 }
4743 } // namespace internal 4736 } // namespace internal
4744 } // namespace v8 4737 } // namespace v8
OLDNEW
« no previous file with comments | « src/heap/mark-compact.h ('k') | src/heap/mark-compact-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698