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

Side by Side Diff: src/spaces.cc

Issue 8507038: Fix Heap::Shrink to ensure that it does not free pages that are still in use. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « src/spaces.h ('k') | no next file » | 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 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 736 matching lines...) Expand 10 before | Expand all | Expand 10 after
747 it.next(); 747 it.next();
748 count++; 748 count++;
749 } 749 }
750 return count; 750 return count;
751 } 751 }
752 #endif 752 #endif
753 753
754 754
755 void PagedSpace::ReleasePage(Page* page) { 755 void PagedSpace::ReleasePage(Page* page) {
756 ASSERT(page->LiveBytes() == 0); 756 ASSERT(page->LiveBytes() == 0);
757
758 // Adjust list of unswept pages if the page is it's head or tail.
Michael Starzinger 2011/11/10 12:35:40 This block assumes that last_unswept_page_ is eith
759 if (first_unswept_page_ == page) {
760 first_unswept_page_ = page->next_page();
761 if (first_unswept_page_ == last_unswept_page_) {
762 first_unswept_page_ = last_unswept_page_ = Page::FromAddress(NULL);
763 }
764 }
765
766 if (page->WasSwept()) {
767 intptr_t size = free_list_.EvictFreeListItems(page);
768 accounting_stats_.AllocateBytes(size);
769 ASSERT_EQ(Page::kObjectAreaSize, static_cast<int>(size));
770 }
771
757 page->Unlink(); 772 page->Unlink();
758 if (page->IsFlagSet(MemoryChunk::CONTAINS_ONLY_DATA)) { 773 if (page->IsFlagSet(MemoryChunk::CONTAINS_ONLY_DATA)) {
759 heap()->isolate()->memory_allocator()->Free(page); 774 heap()->isolate()->memory_allocator()->Free(page);
760 } else { 775 } else {
761 heap()->QueueMemoryChunkForFree(page); 776 heap()->QueueMemoryChunkForFree(page);
762 } 777 }
763 778
764 ASSERT(Capacity() > 0); 779 ASSERT(Capacity() > 0);
765 ASSERT(Capacity() % Page::kObjectAreaSize == 0); 780 ASSERT(Capacity() % Page::kObjectAreaSize == 0);
766 accounting_stats_.ShrinkSpace(Page::kObjectAreaSize); 781 accounting_stats_.ShrinkSpace(Page::kObjectAreaSize);
767 } 782 }
768 783
769 784
770 void PagedSpace::ReleaseAllUnusedPages() { 785 void PagedSpace::ReleaseAllUnusedPages() {
771 PageIterator it(this); 786 PageIterator it(this);
772 while (it.has_next()) { 787 while (it.has_next()) {
773 Page* page = it.next(); 788 Page* page = it.next();
774 if (page->LiveBytes() == 0) { 789 if (!page->WasSwept()) {
775 ReleasePage(page); 790 if (page->LiveBytes() == 0) ReleasePage(page);
791 } else {
792 HeapObject* obj = HeapObject::FromAddress(page->body());
793 if (obj->IsFreeSpace() &&
794 FreeSpace::cast(obj)->size() == Page::kObjectAreaSize) {
795 FreeList::SizeStats sizes;
796 free_list_.CountFreeListItems(page, &sizes);
797 if (sizes.Total() == Page::kObjectAreaSize) {
Michael Starzinger 2011/11/10 12:35:40 Currently the free-list count at this point should
798 ReleasePage(page);
799 }
800 }
776 } 801 }
777 } 802 }
778 heap()->FreeQueuedChunks(); 803 heap()->FreeQueuedChunks();
779 } 804 }
780 805
781 806
782 #ifdef DEBUG 807 #ifdef DEBUG
783 void PagedSpace::Print() { } 808 void PagedSpace::Print() { }
784 #endif 809 #endif
785 810
(...skipping 1077 matching lines...) Expand 10 before | Expand all | Expand 10 after
1863 if (Page::FromAddress(n->address()) == p) { 1888 if (Page::FromAddress(n->address()) == p) {
1864 FreeSpace* free_space = reinterpret_cast<FreeSpace*>(n); 1889 FreeSpace* free_space = reinterpret_cast<FreeSpace*>(n);
1865 sum += free_space->Size(); 1890 sum += free_space->Size();
1866 } 1891 }
1867 n = n->next(); 1892 n = n->next();
1868 } 1893 }
1869 return sum; 1894 return sum;
1870 } 1895 }
1871 1896
1872 1897
1873 void FreeList::CountFreeListItems(Page* p, intptr_t* sizes) { 1898 void FreeList::CountFreeListItems(Page* p, SizeStats* sizes) {
1874 sizes[0] = CountFreeListItemsInList(small_list_, p); 1899 sizes->huge_size_ = CountFreeListItemsInList(huge_list_, p);
1875 sizes[1] = CountFreeListItemsInList(medium_list_, p); 1900 if (sizes->huge_size_ < Page::kObjectAreaSize) {
1876 sizes[2] = CountFreeListItemsInList(large_list_, p); 1901 sizes->small_size_ = CountFreeListItemsInList(small_list_, p);
1877 sizes[3] = CountFreeListItemsInList(huge_list_, p); 1902 sizes->medium_size_ = CountFreeListItemsInList(medium_list_, p);
1903 sizes->large_size_ = CountFreeListItemsInList(large_list_, p);
1904 } else {
1905 sizes->small_size_ = 0;
1906 sizes->medium_size_ = 0;
1907 sizes->large_size_ = 0;
1908 }
1878 } 1909 }
1879 1910
1911
1912 static intptr_t EvictFreeListItemsInList(FreeListNode** n, Page* p) {
1913 intptr_t sum = 0;
1914 while (*n != NULL) {
1915 if (Page::FromAddress((*n)->address()) == p) {
1916 FreeSpace* free_space = reinterpret_cast<FreeSpace*>(*n);
1917 sum += free_space->Size();
1918 *n = (*n)->next();
1919 } else {
1920 n = (*n)->next_address();
1921 }
1922 }
1923 return sum;
1924 }
1925
1926
1927 intptr_t FreeList::EvictFreeListItems(Page* p) {
1928 intptr_t sum = EvictFreeListItemsInList(&huge_list_, p);
1929
1930 if (sum < Page::kObjectAreaSize) {
1931 sum += EvictFreeListItemsInList(&small_list_, p) +
1932 EvictFreeListItemsInList(&medium_list_, p) +
1933 EvictFreeListItemsInList(&large_list_, p);
1934 }
1935
1936 available_ -= sum;
1937
1938 return sum;
1939 }
1940
1941
1880 #ifdef DEBUG 1942 #ifdef DEBUG
1881 intptr_t FreeList::SumFreeList(FreeListNode* cur) { 1943 intptr_t FreeList::SumFreeList(FreeListNode* cur) {
1882 intptr_t sum = 0; 1944 intptr_t sum = 0;
1883 while (cur != NULL) { 1945 while (cur != NULL) {
1884 ASSERT(cur->map() == HEAP->raw_unchecked_free_space_map()); 1946 ASSERT(cur->map() == HEAP->raw_unchecked_free_space_map());
1885 FreeSpace* cur_as_free_space = reinterpret_cast<FreeSpace*>(cur); 1947 FreeSpace* cur_as_free_space = reinterpret_cast<FreeSpace*>(cur);
1886 sum += cur_as_free_space->Size(); 1948 sum += cur_as_free_space->Size();
1887 cur = cur->next(); 1949 cur = cur->next();
1888 } 1950 }
1889 return sum; 1951 return sum;
(...skipping 675 matching lines...) Expand 10 before | Expand all | Expand 10 after
2565 object->ShortPrint(); 2627 object->ShortPrint();
2566 PrintF("\n"); 2628 PrintF("\n");
2567 } 2629 }
2568 printf(" --------------------------------------\n"); 2630 printf(" --------------------------------------\n");
2569 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); 2631 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes());
2570 } 2632 }
2571 2633
2572 #endif // DEBUG 2634 #endif // DEBUG
2573 2635
2574 } } // namespace v8::internal 2636 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/spaces.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698