| 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 871 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 912 | 913 |
| 913 static bool AbortIncrementalMarkingAndCollectGarbage( | 914 static bool AbortIncrementalMarkingAndCollectGarbage( |
| 914 Heap* heap, AllocationSpace space, const char* gc_reason = NULL) { | 915 Heap* heap, AllocationSpace space, const char* gc_reason = NULL) { |
| 915 heap->mark_compact_collector()->SetFlags(Heap::kAbortIncrementalMarkingMask); | 916 heap->mark_compact_collector()->SetFlags(Heap::kAbortIncrementalMarkingMask); |
| 916 bool result = heap->CollectGarbage(space, gc_reason); | 917 bool result = heap->CollectGarbage(space, gc_reason); |
| 917 heap->mark_compact_collector()->SetFlags(Heap::kNoGCFlags); | 918 heap->mark_compact_collector()->SetFlags(Heap::kNoGCFlags); |
| 918 return result; | 919 return result; |
| 919 } | 920 } |
| 920 | 921 |
| 921 | 922 |
| 922 void Heap::ReserveSpace(int* sizes, Address* locations_out) { | 923 bool Heap::ReserveSpace(Reservation* reservations) { |
| 923 bool gc_performed = true; | 924 bool gc_performed = true; |
| 924 int counter = 0; | 925 int counter = 0; |
| 925 static const int kThreshold = 20; | 926 static const int kThreshold = 20; |
| 926 while (gc_performed && counter++ < kThreshold) { | 927 while (gc_performed && counter++ < kThreshold) { |
| 927 gc_performed = false; | 928 gc_performed = false; |
| 928 for (int space = NEW_SPACE; space < Serializer::kNumberOfSpaces; space++) { | 929 for (int space = NEW_SPACE; space < Serializer::kNumberOfSpaces; space++) { |
| 929 if (sizes[space] == 0) continue; | 930 Reservation* reservation = &reservations[space]; |
| 931 DCHECK_LE(1, reservation->length()); |
| 932 if (reservation->at(0).size == 0) continue; |
| 930 bool perform_gc = false; | 933 bool perform_gc = false; |
| 931 if (space == LO_SPACE) { | 934 if (space == LO_SPACE) { |
| 932 perform_gc = !lo_space()->CanAllocateSize(sizes[space]); | 935 DCHECK_EQ(1, reservation->length()); |
| 936 perform_gc = !lo_space()->CanAllocateSize(reservation->at(0).size); |
| 933 } else { | 937 } else { |
| 934 AllocationResult allocation; | 938 for (auto& chunk : *reservation) { |
| 935 if (space == NEW_SPACE) { | 939 AllocationResult allocation; |
| 936 allocation = new_space()->AllocateRaw(sizes[space]); | 940 int size = chunk.size; |
| 937 } else { | 941 if (space == NEW_SPACE) { |
| 938 allocation = paged_space(space)->AllocateRaw(sizes[space]); | 942 allocation = new_space()->AllocateRaw(size); |
| 939 } | 943 } else { |
| 940 FreeListNode* node; | 944 allocation = paged_space(space)->AllocateRaw(size); |
| 941 if (allocation.To(&node)) { | 945 } |
| 942 // Mark with a free list node, in case we have a GC before | 946 FreeListNode* node; |
| 943 // deserializing. | 947 if (allocation.To(&node)) { |
| 944 node->set_size(this, sizes[space]); | 948 // Mark with a free list node, in case we have a GC before |
| 945 DCHECK(space < Serializer::kNumberOfPreallocatedSpaces); | 949 // deserializing. |
| 946 locations_out[space] = node->address(); | 950 node->set_size(this, size); |
| 947 } else { | 951 DCHECK(space < Serializer::kNumberOfPreallocatedSpaces); |
| 948 perform_gc = true; | 952 chunk.start = node->address(); |
| 953 chunk.end = node->address() + size; |
| 954 } else { |
| 955 perform_gc = true; |
| 956 break; |
| 957 } |
| 949 } | 958 } |
| 950 } | 959 } |
| 951 if (perform_gc) { | 960 if (perform_gc) { |
| 952 if (space == NEW_SPACE) { | 961 if (space == NEW_SPACE) { |
| 953 Heap::CollectGarbage(NEW_SPACE, | 962 Heap::CollectGarbage(NEW_SPACE, |
| 954 "failed to reserve space in the new space"); | 963 "failed to reserve space in the new space"); |
| 955 } else { | 964 } else { |
| 956 AbortIncrementalMarkingAndCollectGarbage( | 965 AbortIncrementalMarkingAndCollectGarbage( |
| 957 this, static_cast<AllocationSpace>(space), | 966 this, static_cast<AllocationSpace>(space), |
| 958 "failed to reserve space in paged or large object space"); | 967 "failed to reserve space in paged or large object space"); |
| 959 } | 968 } |
| 960 gc_performed = true; | 969 gc_performed = true; |
| 961 break; // Abort for-loop over spaces and retry. | 970 break; // Abort for-loop over spaces and retry. |
| 962 } | 971 } |
| 963 } | 972 } |
| 964 } | 973 } |
| 965 | 974 |
| 966 if (gc_performed) { | 975 return !gc_performed; |
| 967 // Failed to reserve the space after several attempts. | |
| 968 V8::FatalProcessOutOfMemory("Heap::ReserveSpace"); | |
| 969 } | |
| 970 } | 976 } |
| 971 | 977 |
| 972 | 978 |
| 973 void Heap::EnsureFromSpaceIsCommitted() { | 979 void Heap::EnsureFromSpaceIsCommitted() { |
| 974 if (new_space_.CommitFromSpaceIfNeeded()) return; | 980 if (new_space_.CommitFromSpaceIfNeeded()) return; |
| 975 | 981 |
| 976 // Committing memory to from space failed. | 982 // Committing memory to from space failed. |
| 977 // Memory is exhausted and we will die. | 983 // Memory is exhausted and we will die. |
| 978 V8::FatalProcessOutOfMemory("Committing semi space failed."); | 984 V8::FatalProcessOutOfMemory("Committing semi space failed."); |
| 979 } | 985 } |
| (...skipping 5212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6192 static_cast<int>(object_sizes_last_time_[index])); | 6198 static_cast<int>(object_sizes_last_time_[index])); |
| 6193 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT) | 6199 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT) |
| 6194 #undef ADJUST_LAST_TIME_OBJECT_COUNT | 6200 #undef ADJUST_LAST_TIME_OBJECT_COUNT |
| 6195 | 6201 |
| 6196 MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); | 6202 MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); |
| 6197 MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); | 6203 MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); |
| 6198 ClearObjectStats(); | 6204 ClearObjectStats(); |
| 6199 } | 6205 } |
| 6200 } | 6206 } |
| 6201 } // namespace v8::internal | 6207 } // namespace v8::internal |
| OLD | NEW |