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 564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
575 int map_space_size, | 575 int map_space_size, |
576 int cell_space_size, | 576 int cell_space_size, |
577 int large_object_size) { | 577 int large_object_size) { |
578 NewSpace* new_space = Heap::new_space(); | 578 NewSpace* new_space = Heap::new_space(); |
579 PagedSpace* old_pointer_space = Heap::old_pointer_space(); | 579 PagedSpace* old_pointer_space = Heap::old_pointer_space(); |
580 PagedSpace* old_data_space = Heap::old_data_space(); | 580 PagedSpace* old_data_space = Heap::old_data_space(); |
581 PagedSpace* code_space = Heap::code_space(); | 581 PagedSpace* code_space = Heap::code_space(); |
582 PagedSpace* map_space = Heap::map_space(); | 582 PagedSpace* map_space = Heap::map_space(); |
583 PagedSpace* cell_space = Heap::cell_space(); | 583 PagedSpace* cell_space = Heap::cell_space(); |
584 LargeObjectSpace* lo_space = Heap::lo_space(); | 584 LargeObjectSpace* lo_space = Heap::lo_space(); |
585 bool one_old_space_gc_has_been_performed = false; | |
586 bool gc_performed = true; | 585 bool gc_performed = true; |
587 int counter = 0; | 586 int counter = 0; |
588 static const int kThreshold = 20; | 587 static const int kThreshold = 20; |
589 bool old_space_gc_performed; | |
590 | |
591 while (gc_performed && counter++ < kThreshold) { | 588 while (gc_performed && counter++ < kThreshold) { |
592 old_space_gc_performed = false; | |
593 gc_performed = false; | 589 gc_performed = false; |
594 if (!new_space->ReserveSpace(new_space_size)) { | 590 if (!new_space->ReserveSpace(new_space_size)) { |
595 Heap::CollectGarbage(NEW_SPACE); | 591 Heap::CollectGarbage(NEW_SPACE); |
596 gc_performed = true; | 592 gc_performed = true; |
597 } | 593 } |
598 if (!old_pointer_space->ReserveSpace(pointer_space_size)) { | 594 if (!old_pointer_space->ReserveSpace(pointer_space_size)) { |
599 Heap::CollectGarbage(OLD_POINTER_SPACE); | 595 Heap::CollectGarbage(OLD_POINTER_SPACE); |
600 gc_performed = true; | 596 gc_performed = true; |
601 old_space_gc_performed = true; | |
602 } | 597 } |
603 if (!(old_data_space->ReserveSpace(data_space_size))) { | 598 if (!(old_data_space->ReserveSpace(data_space_size))) { |
604 Heap::CollectGarbage(OLD_DATA_SPACE); | 599 Heap::CollectGarbage(OLD_DATA_SPACE); |
605 gc_performed = true; | 600 gc_performed = true; |
606 old_space_gc_performed = true; | |
607 } | 601 } |
608 if (!(code_space->ReserveSpace(code_space_size))) { | 602 if (!(code_space->ReserveSpace(code_space_size))) { |
609 Heap::CollectGarbage(CODE_SPACE); | 603 Heap::CollectGarbage(CODE_SPACE); |
610 gc_performed = true; | 604 gc_performed = true; |
611 old_space_gc_performed = true; | |
612 } | 605 } |
613 if (!(map_space->ReserveSpace(map_space_size))) { | 606 if (!(map_space->ReserveSpace(map_space_size))) { |
614 Heap::CollectGarbage(MAP_SPACE); | 607 Heap::CollectGarbage(MAP_SPACE); |
615 gc_performed = true; | 608 gc_performed = true; |
616 old_space_gc_performed = true; | |
617 } | 609 } |
618 if (!(cell_space->ReserveSpace(cell_space_size))) { | 610 if (!(cell_space->ReserveSpace(cell_space_size))) { |
619 Heap::CollectGarbage(CELL_SPACE); | 611 Heap::CollectGarbage(CELL_SPACE); |
620 gc_performed = true; | 612 gc_performed = true; |
621 old_space_gc_performed = true; | |
622 } | 613 } |
623 // We add a slack-factor of 2 in order to have space for a series of | 614 // We add a slack-factor of 2 in order to have space for a series of |
624 // large-object allocations that are only just larger than the page size. | 615 // large-object allocations that are only just larger than the page size. |
625 large_object_size *= 2; | 616 large_object_size *= 2; |
626 // The ReserveSpace method on the large object space checks how much | 617 // The ReserveSpace method on the large object space checks how much |
627 // we can expand the old generation. This includes expansion caused by | 618 // we can expand the old generation. This includes expansion caused by |
628 // allocation in the other spaces. | 619 // allocation in the other spaces. |
629 large_object_size += cell_space_size + map_space_size + code_space_size + | 620 large_object_size += cell_space_size + map_space_size + code_space_size + |
630 data_space_size + pointer_space_size; | 621 data_space_size + pointer_space_size; |
631 | 622 if (!(lo_space->ReserveSpace(large_object_size))) { |
632 // If we already did one GC in order to make space in old space, there is | |
633 // no sense in doing another one. We will attempt to force through the | |
634 // large object space allocation, which comes directly from the OS, | |
635 // regardless of any soft limit. | |
636 if (!one_old_space_gc_has_been_performed && | |
637 !(lo_space->ReserveSpace(large_object_size))) { | |
638 Heap::CollectGarbage(LO_SPACE); | 623 Heap::CollectGarbage(LO_SPACE); |
639 gc_performed = true; | 624 gc_performed = true; |
640 } | 625 } |
641 if (old_space_gc_performed) one_old_space_gc_has_been_performed = true; | |
642 } | 626 } |
643 | 627 |
644 if (gc_performed) { | 628 if (gc_performed) { |
645 // Failed to reserve the space after several attempts. | 629 // Failed to reserve the space after several attempts. |
646 V8::FatalProcessOutOfMemory("Heap.:ReserveSpace"); | 630 V8::FatalProcessOutOfMemory("Heap::ReserveSpace"); |
647 } | 631 } |
648 } | 632 } |
649 | 633 |
650 | 634 |
651 void Heap::EnsureFromSpaceIsCommitted() { | 635 void Heap::EnsureFromSpaceIsCommitted() { |
652 if (new_space_.CommitFromSpaceIfNeeded()) return; | 636 if (new_space_.CommitFromSpaceIfNeeded()) return; |
653 | 637 |
654 // Committing memory to from space failed. | 638 // Committing memory to from space failed. |
655 // Try shrinking and try again. | 639 // Try shrinking and try again. |
656 Shrink(); | 640 Shrink(); |
(...skipping 6197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6854 isolate_->heap()->store_buffer()->Compact(); | 6838 isolate_->heap()->store_buffer()->Compact(); |
6855 isolate_->heap()->store_buffer()->Filter(MemoryChunk::ABOUT_TO_BE_FREED); | 6839 isolate_->heap()->store_buffer()->Filter(MemoryChunk::ABOUT_TO_BE_FREED); |
6856 for (chunk = chunks_queued_for_free_; chunk != NULL; chunk = next) { | 6840 for (chunk = chunks_queued_for_free_; chunk != NULL; chunk = next) { |
6857 next = chunk->next_chunk(); | 6841 next = chunk->next_chunk(); |
6858 isolate_->memory_allocator()->Free(chunk); | 6842 isolate_->memory_allocator()->Free(chunk); |
6859 } | 6843 } |
6860 chunks_queued_for_free_ = NULL; | 6844 chunks_queued_for_free_ = NULL; |
6861 } | 6845 } |
6862 | 6846 |
6863 } } // namespace v8::internal | 6847 } } // namespace v8::internal |
OLD | NEW |