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/scopeinfo.h" | 9 #include "src/ast/scopeinfo.h" |
10 #include "src/base/bits.h" | 10 #include "src/base/bits.h" |
(...skipping 875 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
886 // garbage. | 886 // garbage. |
887 // Note: as weak callbacks can execute arbitrary code, we cannot | 887 // Note: as weak callbacks can execute arbitrary code, we cannot |
888 // hope that eventually there will be no weak callbacks invocations. | 888 // hope that eventually there will be no weak callbacks invocations. |
889 // Therefore stop recollecting after several attempts. | 889 // Therefore stop recollecting after several attempts. |
890 if (isolate()->concurrent_recompilation_enabled()) { | 890 if (isolate()->concurrent_recompilation_enabled()) { |
891 // The optimizing compiler may be unnecessarily holding on to memory. | 891 // The optimizing compiler may be unnecessarily holding on to memory. |
892 DisallowHeapAllocation no_recursive_gc; | 892 DisallowHeapAllocation no_recursive_gc; |
893 isolate()->optimizing_compile_dispatcher()->Flush(); | 893 isolate()->optimizing_compile_dispatcher()->Flush(); |
894 } | 894 } |
895 isolate()->ClearSerializerData(); | 895 isolate()->ClearSerializerData(); |
896 set_current_gc_flags(kMakeHeapIterableMask | kReduceMemoryFootprintMask); | 896 set_current_gc_flags(kAbortIncrementalMarkingMask | |
| 897 kReduceMemoryFootprintMask); |
897 isolate_->compilation_cache()->Clear(); | 898 isolate_->compilation_cache()->Clear(); |
898 const int kMaxNumberOfAttempts = 7; | 899 const int kMaxNumberOfAttempts = 7; |
899 const int kMinNumberOfAttempts = 2; | 900 const int kMinNumberOfAttempts = 2; |
900 for (int attempt = 0; attempt < kMaxNumberOfAttempts; attempt++) { | 901 for (int attempt = 0; attempt < kMaxNumberOfAttempts; attempt++) { |
901 if (!CollectGarbage(MARK_COMPACTOR, gc_reason, NULL, | 902 if (!CollectGarbage(MARK_COMPACTOR, gc_reason, NULL, |
902 v8::kGCCallbackFlagCollectAllAvailableGarbage) && | 903 v8::kGCCallbackFlagCollectAllAvailableGarbage) && |
903 attempt + 1 >= kMinNumberOfAttempts) { | 904 attempt + 1 >= kMinNumberOfAttempts) { |
904 break; | 905 break; |
905 } | 906 } |
906 } | 907 } |
(...skipping 3118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4025 Struct* result = nullptr; | 4026 Struct* result = nullptr; |
4026 { | 4027 { |
4027 AllocationResult allocation = Allocate(map, OLD_SPACE); | 4028 AllocationResult allocation = Allocate(map, OLD_SPACE); |
4028 if (!allocation.To(&result)) return allocation; | 4029 if (!allocation.To(&result)) return allocation; |
4029 } | 4030 } |
4030 result->InitializeBody(size); | 4031 result->InitializeBody(size); |
4031 return result; | 4032 return result; |
4032 } | 4033 } |
4033 | 4034 |
4034 | 4035 |
4035 bool Heap::IsHeapIterable() { | |
4036 // TODO(hpayer): This function is not correct. Allocation folding in old | |
4037 // space breaks the iterability. | |
4038 return new_space_top_after_last_gc_ == new_space()->top(); | |
4039 } | |
4040 | |
4041 | |
4042 void Heap::MakeHeapIterable() { | 4036 void Heap::MakeHeapIterable() { |
4043 DCHECK(AllowHeapAllocation::IsAllowed()); | |
4044 if (!IsHeapIterable()) { | |
4045 CollectAllGarbage(kMakeHeapIterableMask, "Heap::MakeHeapIterable"); | |
4046 } | |
4047 if (mark_compact_collector()->sweeping_in_progress()) { | 4037 if (mark_compact_collector()->sweeping_in_progress()) { |
4048 mark_compact_collector()->EnsureSweepingCompleted(); | 4038 mark_compact_collector()->EnsureSweepingCompleted(); |
4049 } | 4039 } |
4050 DCHECK(IsHeapIterable()); | |
4051 } | 4040 } |
4052 | 4041 |
4053 | 4042 |
4054 static double ComputeMutatorUtilization(double mutator_speed, double gc_speed) { | 4043 static double ComputeMutatorUtilization(double mutator_speed, double gc_speed) { |
4055 const double kMinMutatorUtilization = 0.0; | 4044 const double kMinMutatorUtilization = 0.0; |
4056 const double kConservativeGcSpeedInBytesPerMillisecond = 200000; | 4045 const double kConservativeGcSpeedInBytesPerMillisecond = 200000; |
4057 if (mutator_speed == 0) return kMinMutatorUtilization; | 4046 if (mutator_speed == 0) return kMinMutatorUtilization; |
4058 if (gc_speed == 0) gc_speed = kConservativeGcSpeedInBytesPerMillisecond; | 4047 if (gc_speed == 0) gc_speed = kConservativeGcSpeedInBytesPerMillisecond; |
4059 // Derivation: | 4048 // Derivation: |
4060 // mutator_utilization = mutator_time / (mutator_time + gc_time) | 4049 // mutator_utilization = mutator_time / (mutator_time + gc_time) |
(...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4585 return false; | 4574 return false; |
4586 } | 4575 } |
4587 } | 4576 } |
4588 | 4577 |
4589 | 4578 |
4590 #ifdef VERIFY_HEAP | 4579 #ifdef VERIFY_HEAP |
4591 void Heap::Verify() { | 4580 void Heap::Verify() { |
4592 CHECK(HasBeenSetUp()); | 4581 CHECK(HasBeenSetUp()); |
4593 HandleScope scope(isolate()); | 4582 HandleScope scope(isolate()); |
4594 | 4583 |
4595 if (mark_compact_collector()->sweeping_in_progress()) { | 4584 MakeHeapIterable(); |
4596 // We have to wait here for the sweeper threads to have an iterable heap. | |
4597 mark_compact_collector()->EnsureSweepingCompleted(); | |
4598 } | |
4599 | 4585 |
4600 VerifyPointersVisitor visitor; | 4586 VerifyPointersVisitor visitor; |
4601 IterateRoots(&visitor, VISIT_ONLY_STRONG); | 4587 IterateRoots(&visitor, VISIT_ONLY_STRONG); |
4602 | 4588 |
4603 VerifySmisVisitor smis_visitor; | 4589 VerifySmisVisitor smis_visitor; |
4604 IterateSmiRoots(&smis_visitor); | 4590 IterateSmiRoots(&smis_visitor); |
4605 | 4591 |
4606 new_space_.Verify(); | 4592 new_space_.Verify(); |
4607 | 4593 |
4608 old_space_->Verify(&visitor); | 4594 old_space_->Verify(&visitor); |
(...skipping 1738 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6347 } | 6333 } |
6348 | 6334 |
6349 | 6335 |
6350 // static | 6336 // static |
6351 int Heap::GetStaticVisitorIdForMap(Map* map) { | 6337 int Heap::GetStaticVisitorIdForMap(Map* map) { |
6352 return StaticVisitorBase::GetVisitorId(map); | 6338 return StaticVisitorBase::GetVisitorId(map); |
6353 } | 6339 } |
6354 | 6340 |
6355 } // namespace internal | 6341 } // namespace internal |
6356 } // namespace v8 | 6342 } // namespace v8 |
OLD | NEW |