| 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 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 #endif // DEBUG | 409 #endif // DEBUG |
| 410 | 410 |
| 411 #if defined(DEBUG) | 411 #if defined(DEBUG) |
| 412 ReportStatisticsBeforeGC(); | 412 ReportStatisticsBeforeGC(); |
| 413 #endif // DEBUG | 413 #endif // DEBUG |
| 414 | 414 |
| 415 LiveObjectList::GCPrologue(); | 415 LiveObjectList::GCPrologue(); |
| 416 store_buffer()->GCPrologue(); | 416 store_buffer()->GCPrologue(); |
| 417 } | 417 } |
| 418 | 418 |
| 419 |
| 419 intptr_t Heap::SizeOfObjects() { | 420 intptr_t Heap::SizeOfObjects() { |
| 420 intptr_t total = 0; | 421 intptr_t total = 0; |
| 421 AllSpaces spaces; | 422 AllSpaces spaces; |
| 422 for (Space* space = spaces.next(); space != NULL; space = spaces.next()) { | 423 for (Space* space = spaces.next(); space != NULL; space = spaces.next()) { |
| 423 total += space->SizeOfObjects(); | 424 total += space->SizeOfObjects(); |
| 424 } | 425 } |
| 425 return total; | 426 return total; |
| 426 } | 427 } |
| 427 | 428 |
| 429 |
| 430 void Heap::RepairFreeListsAfterBoot() { |
| 431 PagedSpaces spaces; |
| 432 for (PagedSpace* space = spaces.next(); |
| 433 space != NULL; |
| 434 space = spaces.next()) { |
| 435 space->RepairFreeListsAfterBoot(); |
| 436 } |
| 437 } |
| 438 |
| 439 |
| 428 void Heap::GarbageCollectionEpilogue() { | 440 void Heap::GarbageCollectionEpilogue() { |
| 429 store_buffer()->GCEpilogue(); | 441 store_buffer()->GCEpilogue(); |
| 430 LiveObjectList::GCEpilogue(); | 442 LiveObjectList::GCEpilogue(); |
| 431 #ifdef DEBUG | 443 #ifdef DEBUG |
| 432 allow_allocation(true); | 444 allow_allocation(true); |
| 433 ZapFromSpace(); | 445 ZapFromSpace(); |
| 434 | 446 |
| 435 if (FLAG_verify_heap) { | 447 if (FLAG_verify_heap) { |
| 436 Verify(); | 448 Verify(); |
| 437 } | 449 } |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 660 AllocationSpace space, | 672 AllocationSpace space, |
| 661 const char* gc_reason = NULL) { | 673 const char* gc_reason = NULL) { |
| 662 heap->mark_compact_collector()->SetFlags(Heap::kAbortIncrementalMarkingMask); | 674 heap->mark_compact_collector()->SetFlags(Heap::kAbortIncrementalMarkingMask); |
| 663 bool result = heap->CollectGarbage(space, gc_reason); | 675 bool result = heap->CollectGarbage(space, gc_reason); |
| 664 heap->mark_compact_collector()->SetFlags(Heap::kNoGCFlags); | 676 heap->mark_compact_collector()->SetFlags(Heap::kNoGCFlags); |
| 665 return result; | 677 return result; |
| 666 } | 678 } |
| 667 | 679 |
| 668 | 680 |
| 669 void Heap::ReserveSpace( | 681 void Heap::ReserveSpace( |
| 670 int new_space_size, | 682 intptr_t *sizes, |
| 671 int pointer_space_size, | 683 Address *locations_out) { |
| 672 int data_space_size, | |
| 673 int code_space_size, | |
| 674 int map_space_size, | |
| 675 int cell_space_size, | |
| 676 int large_object_size) { | |
| 677 NewSpace* new_space = Heap::new_space(); | |
| 678 PagedSpace* old_pointer_space = Heap::old_pointer_space(); | |
| 679 PagedSpace* old_data_space = Heap::old_data_space(); | |
| 680 PagedSpace* code_space = Heap::code_space(); | |
| 681 PagedSpace* map_space = Heap::map_space(); | |
| 682 PagedSpace* cell_space = Heap::cell_space(); | |
| 683 LargeObjectSpace* lo_space = Heap::lo_space(); | |
| 684 bool gc_performed = true; | 684 bool gc_performed = true; |
| 685 int counter = 0; | 685 int counter = 0; |
| 686 static const int kThreshold = 20; | 686 static const int kThreshold = 20; |
| 687 while (gc_performed && counter++ < kThreshold) { | 687 while (gc_performed && counter++ < kThreshold) { |
| 688 gc_performed = false; | 688 gc_performed = false; |
| 689 if (!new_space->ReserveSpace(new_space_size)) { | 689 ASSERT(NEW_SPACE == FIRST_PAGED_SPACE - 1); |
| 690 Heap::CollectGarbage(NEW_SPACE, | 690 for (int space = NEW_SPACE; space <= LAST_PAGED_SPACE; space++) { |
| 691 "failed to reserve space in the new space"); | 691 if (sizes[space] != 0) { |
| 692 gc_performed = true; | 692 MaybeObject* allocation; |
| 693 } | 693 if (space == NEW_SPACE) { |
| 694 if (!old_pointer_space->ReserveSpace(pointer_space_size)) { | 694 allocation = new_space()->AllocateRaw(sizes[space]); |
| 695 AbortIncrementalMarkingAndCollectGarbage(this, OLD_POINTER_SPACE, | 695 } else { |
| 696 "failed to reserve space in the old pointer space"); | 696 allocation = paged_space(space)->AllocateRaw(sizes[space]); |
| 697 gc_performed = true; | 697 } |
| 698 } | 698 FreeListNode* node; |
| 699 if (!(old_data_space->ReserveSpace(data_space_size))) { | 699 if (!allocation->To<FreeListNode>(&node)) { |
| 700 AbortIncrementalMarkingAndCollectGarbage(this, OLD_DATA_SPACE, | 700 if (space == NEW_SPACE) { |
| 701 "failed to reserve space in the old data space"); | 701 Heap::CollectGarbage(NEW_SPACE, |
| 702 gc_performed = true; | 702 "failed to reserve space in the new space"); |
| 703 } | 703 } else { |
| 704 if (!(code_space->ReserveSpace(code_space_size))) { | 704 AbortIncrementalMarkingAndCollectGarbage( |
| 705 AbortIncrementalMarkingAndCollectGarbage(this, CODE_SPACE, | 705 this, |
| 706 "failed to reserve space in the code space"); | 706 static_cast<AllocationSpace>(space), |
| 707 gc_performed = true; | 707 "failed to reserve space in paged space"); |
| 708 } | 708 } |
| 709 if (!(map_space->ReserveSpace(map_space_size))) { | 709 gc_performed = true; |
| 710 AbortIncrementalMarkingAndCollectGarbage(this, MAP_SPACE, | 710 break; |
| 711 "failed to reserve space in the map space"); | 711 } else { |
| 712 gc_performed = true; | 712 // Mark with a free list node, in case we have a GC before |
| 713 } | 713 // deserializing. |
| 714 if (!(cell_space->ReserveSpace(cell_space_size))) { | 714 node->set_size(this, sizes[space]); |
| 715 AbortIncrementalMarkingAndCollectGarbage(this, CELL_SPACE, | 715 locations_out[space] = node->address(); |
| 716 "failed to reserve space in the cell space"); | 716 } |
| 717 gc_performed = true; | 717 } |
| 718 } | |
| 719 // We add a slack-factor of 2 in order to have space for a series of | |
| 720 // large-object allocations that are only just larger than the page size. | |
| 721 large_object_size *= 2; | |
| 722 // The ReserveSpace method on the large object space checks how much | |
| 723 // we can expand the old generation. This includes expansion caused by | |
| 724 // allocation in the other spaces. | |
| 725 large_object_size += cell_space_size + map_space_size + code_space_size + | |
| 726 data_space_size + pointer_space_size; | |
| 727 if (!(lo_space->ReserveSpace(large_object_size))) { | |
| 728 AbortIncrementalMarkingAndCollectGarbage(this, LO_SPACE, | |
| 729 "failed to reserve space in the large object space"); | |
| 730 gc_performed = true; | |
| 731 } | 718 } |
| 732 } | 719 } |
| 733 | 720 |
| 734 if (gc_performed) { | 721 if (gc_performed) { |
| 735 // Failed to reserve the space after several attempts. | 722 // Failed to reserve the space after several attempts. |
| 736 V8::FatalProcessOutOfMemory("Heap::ReserveSpace"); | 723 V8::FatalProcessOutOfMemory("Heap::ReserveSpace"); |
| 737 } | 724 } |
| 738 } | 725 } |
| 739 | 726 |
| 740 | 727 |
| (...skipping 6580 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7321 static_cast<int>(object_sizes_last_time_[index])); | 7308 static_cast<int>(object_sizes_last_time_[index])); |
| 7322 FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(ADJUST_LAST_TIME_OBJECT_COUNT) | 7309 FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(ADJUST_LAST_TIME_OBJECT_COUNT) |
| 7323 #undef ADJUST_LAST_TIME_OBJECT_COUNT | 7310 #undef ADJUST_LAST_TIME_OBJECT_COUNT |
| 7324 | 7311 |
| 7325 memcpy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); | 7312 memcpy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); |
| 7326 memcpy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); | 7313 memcpy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); |
| 7327 ClearObjectStats(); | 7314 ClearObjectStats(); |
| 7328 } | 7315 } |
| 7329 | 7316 |
| 7330 } } // namespace v8::internal | 7317 } } // namespace v8::internal |
| OLD | NEW |