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 545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
556 int cell_space_size, | 556 int cell_space_size, |
557 int large_object_size) { | 557 int large_object_size) { |
558 NewSpace* new_space = Heap::new_space(); | 558 NewSpace* new_space = Heap::new_space(); |
559 PagedSpace* old_pointer_space = Heap::old_pointer_space(); | 559 PagedSpace* old_pointer_space = Heap::old_pointer_space(); |
560 PagedSpace* old_data_space = Heap::old_data_space(); | 560 PagedSpace* old_data_space = Heap::old_data_space(); |
561 PagedSpace* code_space = Heap::code_space(); | 561 PagedSpace* code_space = Heap::code_space(); |
562 PagedSpace* map_space = Heap::map_space(); | 562 PagedSpace* map_space = Heap::map_space(); |
563 PagedSpace* cell_space = Heap::cell_space(); | 563 PagedSpace* cell_space = Heap::cell_space(); |
564 LargeObjectSpace* lo_space = Heap::lo_space(); | 564 LargeObjectSpace* lo_space = Heap::lo_space(); |
565 bool gc_performed = true; | 565 bool gc_performed = true; |
566 while (gc_performed) { | 566 int counter = 0; |
| 567 static const int kThreshold = 20; |
| 568 while (gc_performed && counter++ < kThreshold) { |
567 gc_performed = false; | 569 gc_performed = false; |
568 if (!new_space->ReserveSpace(new_space_size)) { | 570 if (!new_space->ReserveSpace(new_space_size)) { |
569 Heap::CollectGarbage(NEW_SPACE); | 571 Heap::CollectGarbage(NEW_SPACE); |
570 gc_performed = true; | 572 gc_performed = true; |
571 } | 573 } |
572 if (!old_pointer_space->ReserveSpace(pointer_space_size)) { | 574 if (!old_pointer_space->ReserveSpace(pointer_space_size)) { |
573 Heap::CollectGarbage(OLD_POINTER_SPACE); | 575 Heap::CollectGarbage(OLD_POINTER_SPACE); |
574 gc_performed = true; | 576 gc_performed = true; |
575 } | 577 } |
576 if (!(old_data_space->ReserveSpace(data_space_size))) { | 578 if (!(old_data_space->ReserveSpace(data_space_size))) { |
(...skipping 18 matching lines...) Expand all Loading... |
595 // The ReserveSpace method on the large object space checks how much | 597 // The ReserveSpace method on the large object space checks how much |
596 // we can expand the old generation. This includes expansion caused by | 598 // we can expand the old generation. This includes expansion caused by |
597 // allocation in the other spaces. | 599 // allocation in the other spaces. |
598 large_object_size += cell_space_size + map_space_size + code_space_size + | 600 large_object_size += cell_space_size + map_space_size + code_space_size + |
599 data_space_size + pointer_space_size; | 601 data_space_size + pointer_space_size; |
600 if (!(lo_space->ReserveSpace(large_object_size))) { | 602 if (!(lo_space->ReserveSpace(large_object_size))) { |
601 Heap::CollectGarbage(LO_SPACE); | 603 Heap::CollectGarbage(LO_SPACE); |
602 gc_performed = true; | 604 gc_performed = true; |
603 } | 605 } |
604 } | 606 } |
| 607 |
| 608 if (gc_performed) { |
| 609 // Failed to reserve the space after several attempts. |
| 610 V8::FatalProcessOutOfMemory("Heap::ReserveSpace"); |
| 611 } |
605 } | 612 } |
606 | 613 |
607 | 614 |
608 void Heap::EnsureFromSpaceIsCommitted() { | 615 void Heap::EnsureFromSpaceIsCommitted() { |
609 if (new_space_.CommitFromSpaceIfNeeded()) return; | 616 if (new_space_.CommitFromSpaceIfNeeded()) return; |
610 | 617 |
611 // Committing memory to from space failed. | 618 // Committing memory to from space failed. |
612 // Try shrinking and try again. | 619 // Try shrinking and try again. |
613 PagedSpaces spaces; | 620 PagedSpaces spaces; |
614 for (PagedSpace* space = spaces.next(); | 621 for (PagedSpace* space = spaces.next(); |
(...skipping 5671 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6286 } | 6293 } |
6287 | 6294 |
6288 | 6295 |
6289 void ExternalStringTable::TearDown() { | 6296 void ExternalStringTable::TearDown() { |
6290 new_space_strings_.Free(); | 6297 new_space_strings_.Free(); |
6291 old_space_strings_.Free(); | 6298 old_space_strings_.Free(); |
6292 } | 6299 } |
6293 | 6300 |
6294 | 6301 |
6295 } } // namespace v8::internal | 6302 } } // namespace v8::internal |
OLD | NEW |