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/v8.h" | 5 #include "src/v8.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/base/bits.h" | 9 #include "src/base/bits.h" |
10 #include "src/base/once.h" | 10 #include "src/base/once.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "src/heap/incremental-marking.h" | 21 #include "src/heap/incremental-marking.h" |
22 #include "src/heap/mark-compact.h" | 22 #include "src/heap/mark-compact.h" |
23 #include "src/heap/objects-visiting-inl.h" | 23 #include "src/heap/objects-visiting-inl.h" |
24 #include "src/heap/objects-visiting.h" | 24 #include "src/heap/objects-visiting.h" |
25 #include "src/heap/store-buffer.h" | 25 #include "src/heap/store-buffer.h" |
26 #include "src/heap-profiler.h" | 26 #include "src/heap-profiler.h" |
27 #include "src/isolate-inl.h" | 27 #include "src/isolate-inl.h" |
28 #include "src/natives.h" | 28 #include "src/natives.h" |
29 #include "src/runtime-profiler.h" | 29 #include "src/runtime-profiler.h" |
30 #include "src/scopeinfo.h" | 30 #include "src/scopeinfo.h" |
| 31 #include "src/serialize.h" |
31 #include "src/snapshot.h" | 32 #include "src/snapshot.h" |
32 #include "src/utils.h" | 33 #include "src/utils.h" |
33 #include "src/v8threads.h" | 34 #include "src/v8threads.h" |
34 #include "src/vm-state-inl.h" | 35 #include "src/vm-state-inl.h" |
35 | 36 |
36 #if V8_TARGET_ARCH_ARM && !V8_INTERPRETED_REGEXP | 37 #if V8_TARGET_ARCH_ARM && !V8_INTERPRETED_REGEXP |
37 #include "src/regexp-macro-assembler.h" // NOLINT | 38 #include "src/regexp-macro-assembler.h" // NOLINT |
38 #include "src/arm/regexp-macro-assembler-arm.h" // NOLINT | 39 #include "src/arm/regexp-macro-assembler-arm.h" // NOLINT |
39 #endif | 40 #endif |
40 #if V8_TARGET_ARCH_MIPS && !V8_INTERPRETED_REGEXP | 41 #if V8_TARGET_ARCH_MIPS && !V8_INTERPRETED_REGEXP |
(...skipping 870 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
911 | 912 |
912 static bool AbortIncrementalMarkingAndCollectGarbage( | 913 static bool AbortIncrementalMarkingAndCollectGarbage( |
913 Heap* heap, AllocationSpace space, const char* gc_reason = NULL) { | 914 Heap* heap, AllocationSpace space, const char* gc_reason = NULL) { |
914 heap->mark_compact_collector()->SetFlags(Heap::kAbortIncrementalMarkingMask); | 915 heap->mark_compact_collector()->SetFlags(Heap::kAbortIncrementalMarkingMask); |
915 bool result = heap->CollectGarbage(space, gc_reason); | 916 bool result = heap->CollectGarbage(space, gc_reason); |
916 heap->mark_compact_collector()->SetFlags(Heap::kNoGCFlags); | 917 heap->mark_compact_collector()->SetFlags(Heap::kNoGCFlags); |
917 return result; | 918 return result; |
918 } | 919 } |
919 | 920 |
920 | 921 |
921 void Heap::ReserveSpace(int* sizes, Address* locations_out) { | 922 bool Heap::ReserveSpace(Reservation* reservations) { |
922 bool gc_performed = true; | 923 bool gc_performed = true; |
923 int counter = 0; | 924 int counter = 0; |
924 static const int kThreshold = 20; | 925 static const int kThreshold = 20; |
925 while (gc_performed && counter++ < kThreshold) { | 926 while (gc_performed && counter++ < kThreshold) { |
926 gc_performed = false; | 927 gc_performed = false; |
927 for (int space = NEW_SPACE; space < Serializer::kNumberOfSpaces; space++) { | 928 for (int space = NEW_SPACE; space < Serializer::kNumberOfSpaces; space++) { |
928 if (sizes[space] == 0) continue; | 929 Reservation* reservation = &reservations[space]; |
| 930 DCHECK_LE(1, reservation->length()); |
| 931 if (reservation->at(0).size == 0) continue; |
929 bool perform_gc = false; | 932 bool perform_gc = false; |
930 if (space == LO_SPACE) { | 933 if (space == LO_SPACE) { |
931 perform_gc = !lo_space()->CanAllocateSize(sizes[space]); | 934 DCHECK_EQ(1, reservation->length()); |
| 935 perform_gc = !lo_space()->CanAllocateSize(reservation->at(0).size); |
932 } else { | 936 } else { |
933 AllocationResult allocation; | 937 for (auto& chunk : *reservation) { |
934 if (space == NEW_SPACE) { | 938 AllocationResult allocation; |
935 allocation = new_space()->AllocateRaw(sizes[space]); | 939 int size = chunk.size; |
936 } else { | 940 if (space == NEW_SPACE) { |
937 allocation = paged_space(space)->AllocateRaw(sizes[space]); | 941 allocation = new_space()->AllocateRaw(size); |
938 } | 942 } else { |
939 FreeListNode* node; | 943 allocation = paged_space(space)->AllocateRaw(size); |
940 if (allocation.To(&node)) { | 944 } |
941 // Mark with a free list node, in case we have a GC before | 945 FreeListNode* node; |
942 // deserializing. | 946 if (allocation.To(&node)) { |
943 node->set_size(this, sizes[space]); | 947 // Mark with a free list node, in case we have a GC before |
944 DCHECK(space < Serializer::kNumberOfPreallocatedSpaces); | 948 // deserializing. |
945 locations_out[space] = node->address(); | 949 node->set_size(this, size); |
946 } else { | 950 DCHECK(space < Serializer::kNumberOfPreallocatedSpaces); |
947 perform_gc = true; | 951 chunk.start = node->address(); |
| 952 chunk.end = node->address() + size; |
| 953 } else { |
| 954 perform_gc = true; |
| 955 break; |
| 956 } |
948 } | 957 } |
949 } | 958 } |
950 if (perform_gc) { | 959 if (perform_gc) { |
951 if (space == NEW_SPACE) { | 960 if (space == NEW_SPACE) { |
952 Heap::CollectGarbage(NEW_SPACE, | 961 Heap::CollectGarbage(NEW_SPACE, |
953 "failed to reserve space in the new space"); | 962 "failed to reserve space in the new space"); |
954 } else { | 963 } else { |
955 AbortIncrementalMarkingAndCollectGarbage( | 964 AbortIncrementalMarkingAndCollectGarbage( |
956 this, static_cast<AllocationSpace>(space), | 965 this, static_cast<AllocationSpace>(space), |
957 "failed to reserve space in paged or large object space"); | 966 "failed to reserve space in paged or large object space"); |
958 } | 967 } |
959 gc_performed = true; | 968 gc_performed = true; |
960 break; // Abort for-loop over spaces and retry. | 969 break; // Abort for-loop over spaces and retry. |
961 } | 970 } |
962 } | 971 } |
963 } | 972 } |
964 | 973 |
965 if (gc_performed) { | 974 return !gc_performed; |
966 // Failed to reserve the space after several attempts. | |
967 V8::FatalProcessOutOfMemory("Heap::ReserveSpace"); | |
968 } | |
969 } | 975 } |
970 | 976 |
971 | 977 |
972 void Heap::EnsureFromSpaceIsCommitted() { | 978 void Heap::EnsureFromSpaceIsCommitted() { |
973 if (new_space_.CommitFromSpaceIfNeeded()) return; | 979 if (new_space_.CommitFromSpaceIfNeeded()) return; |
974 | 980 |
975 // Committing memory to from space failed. | 981 // Committing memory to from space failed. |
976 // Memory is exhausted and we will die. | 982 // Memory is exhausted and we will die. |
977 V8::FatalProcessOutOfMemory("Committing semi space failed."); | 983 V8::FatalProcessOutOfMemory("Committing semi space failed."); |
978 } | 984 } |
(...skipping 5193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6172 static_cast<int>(object_sizes_last_time_[index])); | 6178 static_cast<int>(object_sizes_last_time_[index])); |
6173 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT) | 6179 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT) |
6174 #undef ADJUST_LAST_TIME_OBJECT_COUNT | 6180 #undef ADJUST_LAST_TIME_OBJECT_COUNT |
6175 | 6181 |
6176 MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); | 6182 MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); |
6177 MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); | 6183 MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); |
6178 ClearObjectStats(); | 6184 ClearObjectStats(); |
6179 } | 6185 } |
6180 } | 6186 } |
6181 } // namespace v8::internal | 6187 } // namespace v8::internal |
OLD | NEW |