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; | |
585 bool gc_performed = true; | 586 bool gc_performed = true; |
586 int counter = 0; | 587 bool old_space_gc_performed; |
587 static const int kThreshold = 20; | 588 while (gc_performed) { |
Vyacheslav Egorov (Chromium)
2012/01/26 16:12:05
it seems to me that this loop can go on forever. c
| |
588 while (gc_performed && counter++ < kThreshold) { | 589 old_space_gc_performed = false; |
589 gc_performed = false; | 590 gc_performed = false; |
590 if (!new_space->ReserveSpace(new_space_size)) { | 591 if (!new_space->ReserveSpace(new_space_size)) { |
591 Heap::CollectGarbage(NEW_SPACE); | 592 Heap::CollectGarbage(NEW_SPACE); |
592 gc_performed = true; | 593 gc_performed = true; |
593 } | 594 } |
594 if (!old_pointer_space->ReserveSpace(pointer_space_size)) { | 595 if (!old_pointer_space->ReserveSpace(pointer_space_size)) { |
595 Heap::CollectGarbage(OLD_POINTER_SPACE); | 596 Heap::CollectGarbage(OLD_POINTER_SPACE); |
596 gc_performed = true; | 597 gc_performed = true; |
598 old_space_gc_performed = true; | |
597 } | 599 } |
598 if (!(old_data_space->ReserveSpace(data_space_size))) { | 600 if (!(old_data_space->ReserveSpace(data_space_size))) { |
599 Heap::CollectGarbage(OLD_DATA_SPACE); | 601 Heap::CollectGarbage(OLD_DATA_SPACE); |
600 gc_performed = true; | 602 gc_performed = true; |
603 old_space_gc_performed = true; | |
601 } | 604 } |
602 if (!(code_space->ReserveSpace(code_space_size))) { | 605 if (!(code_space->ReserveSpace(code_space_size))) { |
603 Heap::CollectGarbage(CODE_SPACE); | 606 Heap::CollectGarbage(CODE_SPACE); |
604 gc_performed = true; | 607 gc_performed = true; |
608 old_space_gc_performed = true; | |
605 } | 609 } |
606 if (!(map_space->ReserveSpace(map_space_size))) { | 610 if (!(map_space->ReserveSpace(map_space_size))) { |
607 Heap::CollectGarbage(MAP_SPACE); | 611 Heap::CollectGarbage(MAP_SPACE); |
608 gc_performed = true; | 612 gc_performed = true; |
613 old_space_gc_performed = true; | |
609 } | 614 } |
610 if (!(cell_space->ReserveSpace(cell_space_size))) { | 615 if (!(cell_space->ReserveSpace(cell_space_size))) { |
611 Heap::CollectGarbage(CELL_SPACE); | 616 Heap::CollectGarbage(CELL_SPACE); |
612 gc_performed = true; | 617 gc_performed = true; |
618 old_space_gc_performed = true; | |
613 } | 619 } |
614 // We add a slack-factor of 2 in order to have space for a series of | 620 // We add a slack-factor of 2 in order to have space for a series of |
615 // large-object allocations that are only just larger than the page size. | 621 // large-object allocations that are only just larger than the page size. |
616 large_object_size *= 2; | 622 large_object_size *= 2; |
617 // The ReserveSpace method on the large object space checks how much | 623 // The ReserveSpace method on the large object space checks how much |
618 // we can expand the old generation. This includes expansion caused by | 624 // we can expand the old generation. This includes expansion caused by |
619 // allocation in the other spaces. | 625 // allocation in the other spaces. |
620 large_object_size += cell_space_size + map_space_size + code_space_size + | 626 large_object_size += cell_space_size + map_space_size + code_space_size + |
621 data_space_size + pointer_space_size; | 627 data_space_size + pointer_space_size; |
622 if (!(lo_space->ReserveSpace(large_object_size))) { | 628 |
629 // If we already did one GC in order to make space in old space, there is | |
630 // no sense in doing another one. We will attempt to force through the | |
631 // large object space allocation, which comes directly from the OS, | |
632 // regardless of any soft limit. | |
633 if (!one_old_space_gc_has_been_performed && | |
634 !(lo_space->ReserveSpace(large_object_size))) { | |
623 Heap::CollectGarbage(LO_SPACE); | 635 Heap::CollectGarbage(LO_SPACE); |
624 gc_performed = true; | 636 gc_performed = true; |
625 } | 637 } |
626 } | 638 if (old_space_gc_performed) one_old_space_gc_has_been_performed = true; |
627 | |
628 if (gc_performed) { | |
629 // Failed to reserve the space after several attempts. | |
630 V8::FatalProcessOutOfMemory("Heap::ReserveSpace"); | |
631 } | 639 } |
632 } | 640 } |
633 | 641 |
634 | 642 |
635 void Heap::EnsureFromSpaceIsCommitted() { | 643 void Heap::EnsureFromSpaceIsCommitted() { |
636 if (new_space_.CommitFromSpaceIfNeeded()) return; | 644 if (new_space_.CommitFromSpaceIfNeeded()) return; |
637 | 645 |
638 // Committing memory to from space failed. | 646 // Committing memory to from space failed. |
639 // Try shrinking and try again. | 647 // Try shrinking and try again. |
640 Shrink(); | 648 Shrink(); |
(...skipping 6094 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6735 isolate_->heap()->store_buffer()->Compact(); | 6743 isolate_->heap()->store_buffer()->Compact(); |
6736 isolate_->heap()->store_buffer()->Filter(MemoryChunk::ABOUT_TO_BE_FREED); | 6744 isolate_->heap()->store_buffer()->Filter(MemoryChunk::ABOUT_TO_BE_FREED); |
6737 for (chunk = chunks_queued_for_free_; chunk != NULL; chunk = next) { | 6745 for (chunk = chunks_queued_for_free_; chunk != NULL; chunk = next) { |
6738 next = chunk->next_chunk(); | 6746 next = chunk->next_chunk(); |
6739 isolate_->memory_allocator()->Free(chunk); | 6747 isolate_->memory_allocator()->Free(chunk); |
6740 } | 6748 } |
6741 chunks_queued_for_free_ = NULL; | 6749 chunks_queued_for_free_ = NULL; |
6742 } | 6750 } |
6743 | 6751 |
6744 } } // namespace v8::internal | 6752 } } // namespace v8::internal |
OLD | NEW |