OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/heap/heap.h" | 5 #include "src/heap/heap.h" |
6 | 6 |
7 #include "src/accessors.h" | 7 #include "src/accessors.h" |
8 #include "src/api.h" | 8 #include "src/api.h" |
9 #include "src/ast/context-slot-cache.h" | 9 #include "src/ast/context-slot-cache.h" |
10 #include "src/base/bits.h" | 10 #include "src/base/bits.h" |
(...skipping 1101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1112 } | 1112 } |
1113 }; | 1113 }; |
1114 | 1114 |
1115 | 1115 |
1116 static void VerifyStringTable(Heap* heap) { | 1116 static void VerifyStringTable(Heap* heap) { |
1117 StringTableVerifier verifier; | 1117 StringTableVerifier verifier; |
1118 heap->string_table()->IterateElements(&verifier); | 1118 heap->string_table()->IterateElements(&verifier); |
1119 } | 1119 } |
1120 #endif // VERIFY_HEAP | 1120 #endif // VERIFY_HEAP |
1121 | 1121 |
1122 | 1122 bool Heap::ReserveSpace(Reservation* reservations, List<Address>* maps) { |
1123 bool Heap::ReserveSpace(Reservation* reservations) { | |
1124 bool gc_performed = true; | 1123 bool gc_performed = true; |
1125 int counter = 0; | 1124 int counter = 0; |
1126 static const int kThreshold = 20; | 1125 static const int kThreshold = 20; |
1127 while (gc_performed && counter++ < kThreshold) { | 1126 while (gc_performed && counter++ < kThreshold) { |
1128 gc_performed = false; | 1127 gc_performed = false; |
1129 for (int space = NEW_SPACE; space < SerializerDeserializer::kNumberOfSpaces; | 1128 for (int space = NEW_SPACE; space < SerializerDeserializer::kNumberOfSpaces; |
1130 space++) { | 1129 space++) { |
1131 Reservation* reservation = &reservations[space]; | 1130 Reservation* reservation = &reservations[space]; |
1132 DCHECK_LE(1, reservation->length()); | 1131 DCHECK_LE(1, reservation->length()); |
1133 if (reservation->at(0).size == 0) continue; | 1132 if (reservation->at(0).size == 0) continue; |
1134 bool perform_gc = false; | 1133 bool perform_gc = false; |
1135 if (space == LO_SPACE) { | 1134 if (space == MAP_SPACE) { |
| 1135 // We allocate each map individually to avoid fragmentation. |
| 1136 maps->Clear(); |
| 1137 DCHECK_EQ(1, reservation->length()); |
| 1138 int num_maps = reservation->at(0).size / Map::kSize; |
| 1139 for (int i = 0; i < num_maps; i++) { |
| 1140 // The deserializer will update the skip list. |
| 1141 AllocationResult allocation = map_space()->AllocateRawUnaligned( |
| 1142 Map::kSize, PagedSpace::IGNORE_SKIP_LIST); |
| 1143 HeapObject* free_space = nullptr; |
| 1144 if (allocation.To(&free_space)) { |
| 1145 // Mark with a free list node, in case we have a GC before |
| 1146 // deserializing. |
| 1147 Address free_space_address = free_space->address(); |
| 1148 CreateFillerObjectAt(free_space_address, Map::kSize, |
| 1149 ClearRecordedSlots::kNo); |
| 1150 maps->Add(free_space_address); |
| 1151 } else { |
| 1152 perform_gc = true; |
| 1153 break; |
| 1154 } |
| 1155 } |
| 1156 } else if (space == LO_SPACE) { |
| 1157 // Just check that we can allocate during deserialization. |
1136 DCHECK_EQ(1, reservation->length()); | 1158 DCHECK_EQ(1, reservation->length()); |
1137 perform_gc = !CanExpandOldGeneration(reservation->at(0).size); | 1159 perform_gc = !CanExpandOldGeneration(reservation->at(0).size); |
1138 } else { | 1160 } else { |
1139 for (auto& chunk : *reservation) { | 1161 for (auto& chunk : *reservation) { |
1140 AllocationResult allocation; | 1162 AllocationResult allocation; |
1141 int size = chunk.size; | 1163 int size = chunk.size; |
1142 DCHECK_LE(size, MemoryAllocator::PageAreaSize( | 1164 DCHECK_LE(size, MemoryAllocator::PageAreaSize( |
1143 static_cast<AllocationSpace>(space))); | 1165 static_cast<AllocationSpace>(space))); |
1144 if (space == NEW_SPACE) { | 1166 if (space == NEW_SPACE) { |
1145 allocation = new_space()->AllocateRawUnaligned(size); | 1167 allocation = new_space()->AllocateRawUnaligned(size); |
(...skipping 5315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6461 } | 6483 } |
6462 | 6484 |
6463 | 6485 |
6464 // static | 6486 // static |
6465 int Heap::GetStaticVisitorIdForMap(Map* map) { | 6487 int Heap::GetStaticVisitorIdForMap(Map* map) { |
6466 return StaticVisitorBase::GetVisitorId(map); | 6488 return StaticVisitorBase::GetVisitorId(map); |
6467 } | 6489 } |
6468 | 6490 |
6469 } // namespace internal | 6491 } // namespace internal |
6470 } // namespace v8 | 6492 } // namespace v8 |
OLD | NEW |