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

Side by Side Diff: src/spaces.cc

Issue 165453: Changed Heap::Shrink to free as many pages as possible.... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 11 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | 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 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 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 708 matching lines...) Expand 10 before | Expand all | Expand 10 after
719 return count; 719 return count;
720 } 720 }
721 #endif 721 #endif
722 722
723 723
724 void PagedSpace::Shrink() { 724 void PagedSpace::Shrink() {
725 // Release half of free pages. 725 // Release half of free pages.
726 Page* top_page = AllocationTopPage(); 726 Page* top_page = AllocationTopPage();
727 ASSERT(top_page->is_valid()); 727 ASSERT(top_page->is_valid());
728 728
729 // Loop over the pages from the top page to the end of the space to count 729 // Count the number of pages we would like to free.
730 // the number of pages to keep and find the last page to keep. 730 int pages_to_free = 0;
731 int free_pages = 0; 731 for (Page* p = top_page->next_page(); p->is_valid(); p = p->next_page()) {
732 int pages_to_keep = 0; // Of the free pages. 732 pages_to_free++;
733 Page* last_page_to_keep = top_page;
734 Page* current_page = top_page->next_page();
735 // Loop over the pages to the end of the space.
736 while (current_page->is_valid()) {
737 #if defined(ANDROID)
738 // Free all chunks if possible
739 #else
740 // Advance last_page_to_keep every other step to end up at the midpoint.
741 if ((free_pages & 0x1) == 1) {
742 pages_to_keep++;
743 last_page_to_keep = last_page_to_keep->next_page();
744 }
745 #endif
746 free_pages++;
747 current_page = current_page->next_page();
748 } 733 }
749 734
750 // Free pages after last_page_to_keep, and adjust the next_page link. 735 // Free pages after top_page.
751 Page* p = MemoryAllocator::FreePages(last_page_to_keep->next_page()); 736 Page* p = MemoryAllocator::FreePages(top_page->next_page());
752 MemoryAllocator::SetNextPage(last_page_to_keep, p); 737 MemoryAllocator::SetNextPage(top_page, p);
753 738
754 // Since pages are only freed in whole chunks, we may have kept more 739 // Find out how many pages we failed to free and update last_page_.
755 // than pages_to_keep. Count the extra pages and cache the new last 740 // Please note pages can only be freed in whole chunks.
756 // page in the space. 741 last_page_ = top_page;
757 last_page_ = last_page_to_keep; 742 for (Page* p = top_page->next_page(); p->is_valid(); p = p->next_page()) {
758 while (p->is_valid()) { 743 pages_to_free--;
759 pages_to_keep++;
760 last_page_ = p; 744 last_page_ = p;
761 p = p->next_page();
762 } 745 }
763 746
764 // The difference between free_pages and pages_to_keep is the number of 747 accounting_stats_.ShrinkSpace(pages_to_free * Page::kObjectAreaSize);
765 // pages actually freed.
766 ASSERT(pages_to_keep <= free_pages);
767 int bytes_freed = (free_pages - pages_to_keep) * Page::kObjectAreaSize;
768 accounting_stats_.ShrinkSpace(bytes_freed);
769
770 ASSERT(Capacity() == CountTotalPages() * Page::kObjectAreaSize); 748 ASSERT(Capacity() == CountTotalPages() * Page::kObjectAreaSize);
771 } 749 }
772 750
773 751
774 bool PagedSpace::EnsureCapacity(int capacity) { 752 bool PagedSpace::EnsureCapacity(int capacity) {
775 if (Capacity() >= capacity) return true; 753 if (Capacity() >= capacity) return true;
776 754
777 // Start from the allocation top and loop to the last page in the space. 755 // Start from the allocation top and loop to the last page in the space.
778 Page* last_page = AllocationTopPage(); 756 Page* last_page = AllocationTopPage();
779 Page* next_page = last_page->next_page(); 757 Page* next_page = last_page->next_page();
(...skipping 1846 matching lines...) Expand 10 before | Expand all | Expand 10 after
2626 reinterpret_cast<Object**>(object->address() 2604 reinterpret_cast<Object**>(object->address()
2627 + Page::kObjectAreaSize), 2605 + Page::kObjectAreaSize),
2628 allocation_top); 2606 allocation_top);
2629 PrintF("\n"); 2607 PrintF("\n");
2630 } 2608 }
2631 } 2609 }
2632 } 2610 }
2633 #endif // DEBUG 2611 #endif // DEBUG
2634 2612
2635 } } // namespace v8::internal 2613 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698