| OLD | NEW |
| 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 Loading... |
| 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_) { | 537 // If reduction of memory footprint was requested, we are aggressive |
| 540 mode = REDUCE_MEMORY_FOOTPRINT; | 538 // about choosing pages to free. We expect that half-empty pages |
| 539 // are easier to compact so slightly bump the limit. |
| 540 if (reduce_memory_footprint_) { |
| 541 mode = REDUCE_MEMORY_FOOTPRINT; |
| 542 max_evacuation_candidates += 2; |
| 543 } |
| 541 | 544 |
| 542 // We expect that empty pages are easier to compact so slightly bump the | 545 // If over-usage is very high (more than a third of the space), we |
| 543 // limit. | 546 // try to free all mostly empty pages. We expect that almost empty |
| 544 max_evacuation_candidates += 2; | 547 // pages are even easier to compact so bump the limit even more. |
| 548 if (over_reserved > reserved / 3) { |
| 549 mode = REDUCE_MEMORY_FOOTPRINT; |
| 550 max_evacuation_candidates *= 2; |
| 551 } |
| 545 | 552 |
| 546 if (FLAG_trace_fragmentation) { | 553 if (FLAG_trace_fragmentation && mode == REDUCE_MEMORY_FOOTPRINT) { |
| 547 PrintF("Estimated over reserved memory: %.1f MB (setting threshold %d)\n", | 554 PrintF("Estimated over reserved memory: %.1f / %.1f MB (threshold %d)\n", |
| 548 static_cast<double>(over_reserved) / MB, | 555 static_cast<double>(over_reserved) / MB, |
| 556 static_cast<double>(reserved) / MB, |
| 549 static_cast<int>(kFreenessThreshold)); | 557 static_cast<int>(kFreenessThreshold)); |
| 550 } | 558 } |
| 551 } | 559 } |
| 552 | 560 |
| 553 intptr_t estimated_release = 0; | 561 intptr_t estimated_release = 0; |
| 554 | 562 |
| 555 Candidate candidates[kMaxMaxEvacuationCandidates]; | 563 Candidate candidates[kMaxMaxEvacuationCandidates]; |
| 556 | 564 |
| 565 max_evacuation_candidates = |
| 566 Min(kMaxMaxEvacuationCandidates, max_evacuation_candidates); |
| 567 |
| 557 int count = 0; | 568 int count = 0; |
| 558 int fragmentation = 0; | 569 int fragmentation = 0; |
| 559 Candidate* least = NULL; | 570 Candidate* least = NULL; |
| 560 | 571 |
| 561 PageIterator it(space); | 572 PageIterator it(space); |
| 562 if (it.has_next()) it.next(); // Never compact the first page. | 573 if (it.has_next()) it.next(); // Never compact the first page. |
| 563 | 574 |
| 564 while (it.has_next()) { | 575 while (it.has_next()) { |
| 565 Page* p = it.next(); | 576 Page* p = it.next(); |
| 566 p->ClearEvacuationCandidate(); | 577 p->ClearEvacuationCandidate(); |
| (...skipping 3264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3831 space->ClearStats(); | 3842 space->ClearStats(); |
| 3832 | 3843 |
| 3833 PageIterator it(space); | 3844 PageIterator it(space); |
| 3834 | 3845 |
| 3835 intptr_t freed_bytes = 0; | 3846 intptr_t freed_bytes = 0; |
| 3836 int pages_swept = 0; | 3847 int pages_swept = 0; |
| 3837 intptr_t newspace_size = space->heap()->new_space()->Size(); | 3848 intptr_t newspace_size = space->heap()->new_space()->Size(); |
| 3838 bool lazy_sweeping_active = false; | 3849 bool lazy_sweeping_active = false; |
| 3839 bool unused_page_present = false; | 3850 bool unused_page_present = false; |
| 3840 | 3851 |
| 3841 intptr_t old_space_size = heap()->PromotedSpaceSize(); | |
| 3842 intptr_t space_left = | |
| 3843 Min(heap()->OldGenPromotionLimit(old_space_size), | |
| 3844 heap()->OldGenAllocationLimit(old_space_size)) - old_space_size; | |
| 3845 | |
| 3846 while (it.has_next()) { | 3852 while (it.has_next()) { |
| 3847 Page* p = it.next(); | 3853 Page* p = it.next(); |
| 3848 | 3854 |
| 3849 // Clear sweeping flags indicating that marking bits are still intact. | 3855 // Clear sweeping flags indicating that marking bits are still intact. |
| 3850 p->ClearSweptPrecisely(); | 3856 p->ClearSweptPrecisely(); |
| 3851 p->ClearSweptConservatively(); | 3857 p->ClearSweptConservatively(); |
| 3852 | 3858 |
| 3853 if (p->IsEvacuationCandidate()) { | 3859 if (p->IsEvacuationCandidate()) { |
| 3854 ASSERT(evacuation_candidates_.length() > 0); | 3860 ASSERT(evacuation_candidates_.length() > 0); |
| 3855 continue; | 3861 continue; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3895 pages_swept++; | 3901 pages_swept++; |
| 3896 break; | 3902 break; |
| 3897 } | 3903 } |
| 3898 case LAZY_CONSERVATIVE: { | 3904 case LAZY_CONSERVATIVE: { |
| 3899 if (FLAG_gc_verbose) { | 3905 if (FLAG_gc_verbose) { |
| 3900 PrintF("Sweeping 0x%" V8PRIxPTR " conservatively as needed.\n", | 3906 PrintF("Sweeping 0x%" V8PRIxPTR " conservatively as needed.\n", |
| 3901 reinterpret_cast<intptr_t>(p)); | 3907 reinterpret_cast<intptr_t>(p)); |
| 3902 } | 3908 } |
| 3903 freed_bytes += SweepConservatively(space, p); | 3909 freed_bytes += SweepConservatively(space, p); |
| 3904 pages_swept++; | 3910 pages_swept++; |
| 3905 if (space_left + freed_bytes > newspace_size) { | 3911 if (freed_bytes > 2 * newspace_size) { |
| 3906 space->SetPagesToSweep(p->next_page()); | 3912 space->SetPagesToSweep(p->next_page()); |
| 3907 lazy_sweeping_active = true; | 3913 lazy_sweeping_active = true; |
| 3908 } else { | 3914 } else { |
| 3909 if (FLAG_gc_verbose) { | 3915 if (FLAG_gc_verbose) { |
| 3910 PrintF("Only %" V8PRIdPTR " bytes freed. Still sweeping.\n", | 3916 PrintF("Only %" V8PRIdPTR " bytes freed. Still sweeping.\n", |
| 3911 freed_bytes); | 3917 freed_bytes); |
| 3912 } | 3918 } |
| 3913 } | 3919 } |
| 3914 break; | 3920 break; |
| 3915 } | 3921 } |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4144 while (buffer != NULL) { | 4150 while (buffer != NULL) { |
| 4145 SlotsBuffer* next_buffer = buffer->next(); | 4151 SlotsBuffer* next_buffer = buffer->next(); |
| 4146 DeallocateBuffer(buffer); | 4152 DeallocateBuffer(buffer); |
| 4147 buffer = next_buffer; | 4153 buffer = next_buffer; |
| 4148 } | 4154 } |
| 4149 *buffer_address = NULL; | 4155 *buffer_address = NULL; |
| 4150 } | 4156 } |
| 4151 | 4157 |
| 4152 | 4158 |
| 4153 } } // namespace v8::internal | 4159 } } // namespace v8::internal |
| OLD | NEW |