| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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; |
| 587 bool old_space_gc_performed; |
| 586 while (gc_performed) { | 588 while (gc_performed) { |
| 589 old_space_gc_performed = false; |
| 587 gc_performed = false; | 590 gc_performed = false; |
| 588 if (!new_space->ReserveSpace(new_space_size)) { | 591 if (!new_space->ReserveSpace(new_space_size)) { |
| 589 Heap::CollectGarbage(NEW_SPACE); | 592 Heap::CollectGarbage(NEW_SPACE); |
| 590 gc_performed = true; | 593 gc_performed = true; |
| 591 } | 594 } |
| 592 if (!old_pointer_space->ReserveSpace(pointer_space_size)) { | 595 if (!old_pointer_space->ReserveSpace(pointer_space_size)) { |
| 593 Heap::CollectGarbage(OLD_POINTER_SPACE); | 596 Heap::CollectGarbage(OLD_POINTER_SPACE); |
| 594 gc_performed = true; | 597 gc_performed = true; |
| 598 old_space_gc_performed = true; |
| 595 } | 599 } |
| 596 if (!(old_data_space->ReserveSpace(data_space_size))) { | 600 if (!(old_data_space->ReserveSpace(data_space_size))) { |
| 597 Heap::CollectGarbage(OLD_DATA_SPACE); | 601 Heap::CollectGarbage(OLD_DATA_SPACE); |
| 598 gc_performed = true; | 602 gc_performed = true; |
| 603 old_space_gc_performed = true; |
| 599 } | 604 } |
| 600 if (!(code_space->ReserveSpace(code_space_size))) { | 605 if (!(code_space->ReserveSpace(code_space_size))) { |
| 601 Heap::CollectGarbage(CODE_SPACE); | 606 Heap::CollectGarbage(CODE_SPACE); |
| 602 gc_performed = true; | 607 gc_performed = true; |
| 608 old_space_gc_performed = true; |
| 603 } | 609 } |
| 604 if (!(map_space->ReserveSpace(map_space_size))) { | 610 if (!(map_space->ReserveSpace(map_space_size))) { |
| 605 Heap::CollectGarbage(MAP_SPACE); | 611 Heap::CollectGarbage(MAP_SPACE); |
| 606 gc_performed = true; | 612 gc_performed = true; |
| 613 old_space_gc_performed = true; |
| 607 } | 614 } |
| 608 if (!(cell_space->ReserveSpace(cell_space_size))) { | 615 if (!(cell_space->ReserveSpace(cell_space_size))) { |
| 609 Heap::CollectGarbage(CELL_SPACE); | 616 Heap::CollectGarbage(CELL_SPACE); |
| 610 gc_performed = true; | 617 gc_performed = true; |
| 618 old_space_gc_performed = true; |
| 611 } | 619 } |
| 612 // 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 |
| 613 // 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. |
| 614 large_object_size *= 2; | 622 large_object_size *= 2; |
| 615 // The ReserveSpace method on the large object space checks how much | 623 // The ReserveSpace method on the large object space checks how much |
| 616 // we can expand the old generation. This includes expansion caused by | 624 // we can expand the old generation. This includes expansion caused by |
| 617 // allocation in the other spaces. | 625 // allocation in the other spaces. |
| 618 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 + |
| 619 data_space_size + pointer_space_size; | 627 data_space_size + pointer_space_size; |
| 620 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))) { |
| 621 Heap::CollectGarbage(LO_SPACE); | 635 Heap::CollectGarbage(LO_SPACE); |
| 622 gc_performed = true; | 636 gc_performed = true; |
| 623 } | 637 } |
| 638 if (old_space_gc_performed) one_old_space_gc_has_been_performed = true; |
| 624 } | 639 } |
| 625 } | 640 } |
| 626 | 641 |
| 627 | 642 |
| 628 void Heap::EnsureFromSpaceIsCommitted() { | 643 void Heap::EnsureFromSpaceIsCommitted() { |
| 629 if (new_space_.CommitFromSpaceIfNeeded()) return; | 644 if (new_space_.CommitFromSpaceIfNeeded()) return; |
| 630 | 645 |
| 631 // Committing memory to from space failed. | 646 // Committing memory to from space failed. |
| 632 // Try shrinking and try again. | 647 // Try shrinking and try again. |
| 633 Shrink(); | 648 Shrink(); |
| (...skipping 6020 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6654 isolate_->heap()->store_buffer()->Compact(); | 6669 isolate_->heap()->store_buffer()->Compact(); |
| 6655 isolate_->heap()->store_buffer()->Filter(MemoryChunk::ABOUT_TO_BE_FREED); | 6670 isolate_->heap()->store_buffer()->Filter(MemoryChunk::ABOUT_TO_BE_FREED); |
| 6656 for (chunk = chunks_queued_for_free_; chunk != NULL; chunk = next) { | 6671 for (chunk = chunks_queued_for_free_; chunk != NULL; chunk = next) { |
| 6657 next = chunk->next_chunk(); | 6672 next = chunk->next_chunk(); |
| 6658 isolate_->memory_allocator()->Free(chunk); | 6673 isolate_->memory_allocator()->Free(chunk); |
| 6659 } | 6674 } |
| 6660 chunks_queued_for_free_ = NULL; | 6675 chunks_queued_for_free_ = NULL; |
| 6661 } | 6676 } |
| 6662 | 6677 |
| 6663 } } // namespace v8::internal | 6678 } } // namespace v8::internal |
| OLD | NEW |