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_) { | |
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 3552 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4119 while (buffer != NULL) { | 4131 while (buffer != NULL) { |
4120 SlotsBuffer* next_buffer = buffer->next(); | 4132 SlotsBuffer* next_buffer = buffer->next(); |
4121 DeallocateBuffer(buffer); | 4133 DeallocateBuffer(buffer); |
4122 buffer = next_buffer; | 4134 buffer = next_buffer; |
4123 } | 4135 } |
4124 *buffer_address = NULL; | 4136 *buffer_address = NULL; |
4125 } | 4137 } |
4126 | 4138 |
4127 | 4139 |
4128 } } // namespace v8::internal | 4140 } } // namespace v8::internal |
OLD | NEW |