OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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/spaces.h" | 5 #include "src/heap/spaces.h" |
6 | 6 |
7 #include "src/base/bits.h" | 7 #include "src/base/bits.h" |
8 #include "src/base/platform/platform.h" | 8 #include "src/base/platform/platform.h" |
9 #include "src/full-codegen/full-codegen.h" | 9 #include "src/full-codegen/full-codegen.h" |
10 #include "src/heap/slots-buffer.h" | 10 #include "src/heap/slots-buffer.h" |
(...skipping 966 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
977 accounting_stats_.Clear(); | 977 accounting_stats_.Clear(); |
978 } | 978 } |
979 | 979 |
980 | 980 |
981 void PagedSpace::AddMemory(Address start, intptr_t size) { | 981 void PagedSpace::AddMemory(Address start, intptr_t size) { |
982 accounting_stats_.ExpandSpace(static_cast<int>(size)); | 982 accounting_stats_.ExpandSpace(static_cast<int>(size)); |
983 Free(start, static_cast<int>(size)); | 983 Free(start, static_cast<int>(size)); |
984 } | 984 } |
985 | 985 |
986 | 986 |
987 FreeSpace* PagedSpace::TryRemoveMemory(intptr_t size_in_bytes) { | |
988 FreeSpace* free_space = free_list()->TryRemoveMemory(size_in_bytes); | |
989 if (free_space != nullptr) { | |
990 accounting_stats_.DecreaseCapacity(free_space->size()); | |
991 } | |
992 return free_space; | |
993 } | |
994 | |
995 | |
996 void PagedSpace::DivideUponCompactionSpaces(CompactionSpaceCollection** other, | |
997 int num, intptr_t limit) { | |
998 DCHECK_GT(num, 0); | |
999 DCHECK(other != nullptr); | |
1000 | |
1001 if (limit == 0) limit = std::numeric_limits<intptr_t>::max(); | |
1002 | |
1003 EmptyAllocationInfo(); | |
1004 | |
1005 bool memory_available = true; | |
1006 bool spaces_need_memory = true; | |
1007 FreeSpace* node = nullptr; | |
1008 CompactionSpace* current_space = nullptr; | |
1009 // Iterate over spaces and memory as long as we have memory and there are | |
1010 // spaces in need of some. | |
1011 while (memory_available && spaces_need_memory) { | |
1012 spaces_need_memory = false; | |
1013 // Round-robin over all spaces. | |
1014 for (int i = 0; i < num; i++) { | |
1015 current_space = other[i]->Get(identity()); | |
1016 if (current_space->free_list()->Available() < limit) { | |
1017 // Space has not reached its limit. Try to get some memory. | |
1018 spaces_need_memory = true; | |
1019 node = TryRemoveMemory(limit - current_space->free_list()->Available()); | |
1020 if (node != nullptr) { | |
1021 CHECK(current_space->identity() == identity()); | |
1022 current_space->AddMemory(node->address(), node->size()); | |
1023 } else { | |
1024 memory_available = false; | |
1025 break; | |
1026 } | |
1027 } | |
1028 } | |
1029 } | |
1030 } | |
1031 | |
1032 | |
1033 void PagedSpace::RefillFreeList() { | 987 void PagedSpace::RefillFreeList() { |
1034 MarkCompactCollector* collector = heap()->mark_compact_collector(); | 988 MarkCompactCollector* collector = heap()->mark_compact_collector(); |
1035 FreeList* free_list = nullptr; | 989 FreeList* free_list = nullptr; |
1036 if (this == heap()->old_space()) { | 990 if (this == heap()->old_space()) { |
1037 free_list = collector->free_list_old_space().get(); | 991 free_list = collector->free_list_old_space().get(); |
1038 } else if (this == heap()->code_space()) { | 992 } else if (this == heap()->code_space()) { |
1039 free_list = collector->free_list_code_space().get(); | 993 free_list = collector->free_list_code_space().get(); |
1040 } else if (this == heap()->map_space()) { | 994 } else if (this == heap()->map_space()) { |
1041 free_list = collector->free_list_map_space().get(); | 995 free_list = collector->free_list_map_space().get(); |
1042 } else { | 996 } else { |
(...skipping 22 matching lines...) Expand all Loading... |
1065 intptr_t refilled = 0; | 1019 intptr_t refilled = 0; |
1066 while (refilled < kCompactionMemoryWanted) { | 1020 while (refilled < kCompactionMemoryWanted) { |
1067 FreeSpace* node = | 1021 FreeSpace* node = |
1068 free_list->TryRemoveMemory(kCompactionMemoryWanted - refilled); | 1022 free_list->TryRemoveMemory(kCompactionMemoryWanted - refilled); |
1069 if (node == nullptr) return; | 1023 if (node == nullptr) return; |
1070 refilled += node->size(); | 1024 refilled += node->size(); |
1071 AddMemory(node->address(), node->size()); | 1025 AddMemory(node->address(), node->size()); |
1072 } | 1026 } |
1073 } | 1027 } |
1074 | 1028 |
1075 | |
1076 void PagedSpace::MoveOverFreeMemory(PagedSpace* other) { | 1029 void PagedSpace::MoveOverFreeMemory(PagedSpace* other) { |
1077 DCHECK(identity() == other->identity()); | 1030 DCHECK(identity() == other->identity()); |
1078 // Destroy the linear allocation space of {other}. This is needed to | 1031 // Destroy the linear allocation space of {other}. This is needed to |
1079 // (a) not waste the memory and | 1032 // (a) not waste the memory and |
1080 // (b) keep the rest of the chunk in an iterable state (filler is needed). | 1033 // (b) keep the rest of the chunk in an iterable state (filler is needed). |
1081 other->EmptyAllocationInfo(); | 1034 other->EmptyAllocationInfo(); |
1082 | 1035 |
1083 // Move over the free list. Concatenate makes sure that the source free list | 1036 // Move over the free list. Concatenate makes sure that the source free list |
1084 // gets properly reset after moving over all nodes. | 1037 // gets properly reset after moving over all nodes. |
1085 intptr_t added = free_list_.Concatenate(other->free_list()); | 1038 intptr_t added = free_list_.Concatenate(other->free_list()); |
(...skipping 2199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3285 object->ShortPrint(); | 3238 object->ShortPrint(); |
3286 PrintF("\n"); | 3239 PrintF("\n"); |
3287 } | 3240 } |
3288 printf(" --------------------------------------\n"); | 3241 printf(" --------------------------------------\n"); |
3289 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); | 3242 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); |
3290 } | 3243 } |
3291 | 3244 |
3292 #endif // DEBUG | 3245 #endif // DEBUG |
3293 } // namespace internal | 3246 } // namespace internal |
3294 } // namespace v8 | 3247 } // namespace v8 |
OLD | NEW |