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

Side by Side Diff: src/mark-compact.cc

Issue 10699051: Merged r11900, r11901, r11904 into 3.11 branch. (Closed) Base URL: https://v8.googlecode.com/svn/branches/3.11
Patch Set: Remove change of tools/merge-to-branch.sh Created 8 years, 5 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 | « src/heap.cc ('k') | src/version.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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 482 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 493
494 return static_cast<int>(ratio - ratio_threshold); 494 return static_cast<int>(ratio - ratio_threshold);
495 } 495 }
496 496
497 497
498 void MarkCompactCollector::CollectEvacuationCandidates(PagedSpace* space) { 498 void MarkCompactCollector::CollectEvacuationCandidates(PagedSpace* space) {
499 ASSERT(space->identity() == OLD_POINTER_SPACE || 499 ASSERT(space->identity() == OLD_POINTER_SPACE ||
500 space->identity() == OLD_DATA_SPACE || 500 space->identity() == OLD_DATA_SPACE ||
501 space->identity() == CODE_SPACE); 501 space->identity() == CODE_SPACE);
502 502
503 static const int kMaxMaxEvacuationCandidates = 1000;
503 int number_of_pages = space->CountTotalPages(); 504 int number_of_pages = space->CountTotalPages();
504 505 int max_evacuation_candidates =
505 const int kMaxMaxEvacuationCandidates = 1000; 506 static_cast<int>(sqrt(static_cast<double>(number_of_pages / 2)) + 1);
506 int max_evacuation_candidates = Min(
507 kMaxMaxEvacuationCandidates,
508 static_cast<int>(sqrt(static_cast<double>(number_of_pages / 2)) + 1));
509 507
510 if (FLAG_stress_compaction || FLAG_always_compact) { 508 if (FLAG_stress_compaction || FLAG_always_compact) {
511 max_evacuation_candidates = kMaxMaxEvacuationCandidates; 509 max_evacuation_candidates = kMaxMaxEvacuationCandidates;
512 } 510 }
513 511
514 class Candidate { 512 class Candidate {
515 public: 513 public:
516 Candidate() : fragmentation_(0), page_(NULL) { } 514 Candidate() : fragmentation_(0), page_(NULL) { }
517 Candidate(int f, Page* p) : fragmentation_(f), page_(p) { } 515 Candidate(int f, Page* p) : fragmentation_(f), page_(p) { }
518 516
519 int fragmentation() { return fragmentation_; } 517 int fragmentation() { return fragmentation_; }
520 Page* page() { return page_; } 518 Page* page() { return page_; }
521 519
522 private: 520 private:
523 int fragmentation_; 521 int fragmentation_;
524 Page* page_; 522 Page* page_;
525 }; 523 };
526 524
527 enum CompactionMode { 525 enum CompactionMode {
528 COMPACT_FREE_LISTS, 526 COMPACT_FREE_LISTS,
529 REDUCE_MEMORY_FOOTPRINT 527 REDUCE_MEMORY_FOOTPRINT
530 }; 528 };
531 529
532 CompactionMode mode = COMPACT_FREE_LISTS; 530 CompactionMode mode = COMPACT_FREE_LISTS;
533 531
534 intptr_t reserved = number_of_pages * space->AreaSize(); 532 intptr_t reserved = number_of_pages * space->AreaSize();
535 intptr_t over_reserved = reserved - space->SizeOfObjects(); 533 intptr_t over_reserved = reserved - space->SizeOfObjects();
536 static const intptr_t kFreenessThreshold = 50; 534 static const intptr_t kFreenessThreshold = 50;
537 535
538 if (over_reserved >= 2 * space->AreaSize() && 536 if (over_reserved >= 2 * space->AreaSize()) {
539 reduce_memory_footprint_) {
540 mode = REDUCE_MEMORY_FOOTPRINT;
541 537
542 // We expect that empty pages are easier to compact so slightly bump the 538 // If reduction of memory footprint was requested, we are aggressive
543 // limit. 539 // about choosing pages to free. We expect that half-empty pages
544 max_evacuation_candidates += 2; 540 // are easier to compact so slightly bump the limit.
541 if (reduce_memory_footprint_) {
542 mode = REDUCE_MEMORY_FOOTPRINT;
543 max_evacuation_candidates += 2;
544 }
545 545
546 if (FLAG_trace_fragmentation) { 546 // If over-usage is very high (more than a third of the space), we
547 PrintF("Estimated over reserved memory: %.1f MB (setting threshold %d)\n", 547 // try to free all mostly empty pages. We expect that almost empty
548 // pages are even easier to compact so bump the limit even more.
549 if (over_reserved > reserved / 3) {
550 mode = REDUCE_MEMORY_FOOTPRINT;
551 max_evacuation_candidates *= 2;
552 }
553
554 if (FLAG_trace_fragmentation && mode == REDUCE_MEMORY_FOOTPRINT) {
555 PrintF("Estimated over reserved memory: %.1f / %.1f MB (threshold %d)\n",
548 static_cast<double>(over_reserved) / MB, 556 static_cast<double>(over_reserved) / MB,
557 static_cast<double>(reserved) / MB,
549 static_cast<int>(kFreenessThreshold)); 558 static_cast<int>(kFreenessThreshold));
550 } 559 }
551 } 560 }
552 561
553 intptr_t estimated_release = 0; 562 intptr_t estimated_release = 0;
554 563
555 Candidate candidates[kMaxMaxEvacuationCandidates]; 564 Candidate candidates[kMaxMaxEvacuationCandidates];
556 565
566 max_evacuation_candidates =
567 Min(kMaxMaxEvacuationCandidates, max_evacuation_candidates);
568
557 int count = 0; 569 int count = 0;
558 int fragmentation = 0; 570 int fragmentation = 0;
559 Candidate* least = NULL; 571 Candidate* least = NULL;
560 572
561 PageIterator it(space); 573 PageIterator it(space);
562 if (it.has_next()) it.next(); // Never compact the first page. 574 if (it.has_next()) it.next(); // Never compact the first page.
563 575
564 while (it.has_next()) { 576 while (it.has_next()) {
565 Page* p = it.next(); 577 Page* p = it.next();
566 p->ClearEvacuationCandidate(); 578 p->ClearEvacuationCandidate();
(...skipping 3243 matching lines...) Expand 10 before | Expand all | Expand 10 after
3810 space->ClearStats(); 3822 space->ClearStats();
3811 3823
3812 PageIterator it(space); 3824 PageIterator it(space);
3813 3825
3814 intptr_t freed_bytes = 0; 3826 intptr_t freed_bytes = 0;
3815 int pages_swept = 0; 3827 int pages_swept = 0;
3816 intptr_t newspace_size = space->heap()->new_space()->Size(); 3828 intptr_t newspace_size = space->heap()->new_space()->Size();
3817 bool lazy_sweeping_active = false; 3829 bool lazy_sweeping_active = false;
3818 bool unused_page_present = false; 3830 bool unused_page_present = false;
3819 3831
3820 intptr_t old_space_size = heap()->PromotedSpaceSizeOfObjects();
3821 intptr_t space_left =
3822 Min(heap()->OldGenPromotionLimit(old_space_size),
3823 heap()->OldGenAllocationLimit(old_space_size)) - old_space_size;
3824
3825 while (it.has_next()) { 3832 while (it.has_next()) {
3826 Page* p = it.next(); 3833 Page* p = it.next();
3827 3834
3828 // Clear sweeping flags indicating that marking bits are still intact. 3835 // Clear sweeping flags indicating that marking bits are still intact.
3829 p->ClearSweptPrecisely(); 3836 p->ClearSweptPrecisely();
3830 p->ClearSweptConservatively(); 3837 p->ClearSweptConservatively();
3831 3838
3832 if (p->IsEvacuationCandidate()) { 3839 if (p->IsEvacuationCandidate()) {
3833 ASSERT(evacuation_candidates_.length() > 0); 3840 ASSERT(evacuation_candidates_.length() > 0);
3834 continue; 3841 continue;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
3874 pages_swept++; 3881 pages_swept++;
3875 break; 3882 break;
3876 } 3883 }
3877 case LAZY_CONSERVATIVE: { 3884 case LAZY_CONSERVATIVE: {
3878 if (FLAG_gc_verbose) { 3885 if (FLAG_gc_verbose) {
3879 PrintF("Sweeping 0x%" V8PRIxPTR " conservatively as needed.\n", 3886 PrintF("Sweeping 0x%" V8PRIxPTR " conservatively as needed.\n",
3880 reinterpret_cast<intptr_t>(p)); 3887 reinterpret_cast<intptr_t>(p));
3881 } 3888 }
3882 freed_bytes += SweepConservatively(space, p); 3889 freed_bytes += SweepConservatively(space, p);
3883 pages_swept++; 3890 pages_swept++;
3884 if (space_left + freed_bytes > newspace_size) { 3891 if (freed_bytes > 2 * newspace_size) {
3885 space->SetPagesToSweep(p->next_page()); 3892 space->SetPagesToSweep(p->next_page());
3886 lazy_sweeping_active = true; 3893 lazy_sweeping_active = true;
3887 } else { 3894 } else {
3888 if (FLAG_gc_verbose) { 3895 if (FLAG_gc_verbose) {
3889 PrintF("Only %" V8PRIdPTR " bytes freed. Still sweeping.\n", 3896 PrintF("Only %" V8PRIdPTR " bytes freed. Still sweeping.\n",
3890 freed_bytes); 3897 freed_bytes);
3891 } 3898 }
3892 } 3899 }
3893 break; 3900 break;
3894 } 3901 }
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
4123 while (buffer != NULL) { 4130 while (buffer != NULL) {
4124 SlotsBuffer* next_buffer = buffer->next(); 4131 SlotsBuffer* next_buffer = buffer->next();
4125 DeallocateBuffer(buffer); 4132 DeallocateBuffer(buffer);
4126 buffer = next_buffer; 4133 buffer = next_buffer;
4127 } 4134 }
4128 *buffer_address = NULL; 4135 *buffer_address = NULL;
4129 } 4136 }
4130 4137
4131 4138
4132 } } // namespace v8::internal 4139 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/heap.cc ('k') | src/version.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698