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(kAbortIncrementalMarkingMask | | 896 set_current_gc_flags(kMakeHeapIterableMask | kReduceMemoryFootprintMask); |
897 kReduceMemoryFootprintMask); | |
898 isolate_->compilation_cache()->Clear(); | 897 isolate_->compilation_cache()->Clear(); |
899 const int kMaxNumberOfAttempts = 7; | 898 const int kMaxNumberOfAttempts = 7; |
900 const int kMinNumberOfAttempts = 2; | 899 const int kMinNumberOfAttempts = 2; |
901 for (int attempt = 0; attempt < kMaxNumberOfAttempts; attempt++) { | 900 for (int attempt = 0; attempt < kMaxNumberOfAttempts; attempt++) { |
902 if (!CollectGarbage(MARK_COMPACTOR, gc_reason, NULL, | 901 if (!CollectGarbage(MARK_COMPACTOR, gc_reason, NULL, |
903 v8::kGCCallbackFlagCollectAllAvailableGarbage) && | 902 v8::kGCCallbackFlagCollectAllAvailableGarbage) && |
904 attempt + 1 >= kMinNumberOfAttempts) { | 903 attempt + 1 >= kMinNumberOfAttempts) { |
905 break; | 904 break; |
906 } | 905 } |
907 } | 906 } |
(...skipping 3118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4026 Struct* result = nullptr; | 4025 Struct* result = nullptr; |
4027 { | 4026 { |
4028 AllocationResult allocation = Allocate(map, OLD_SPACE); | 4027 AllocationResult allocation = Allocate(map, OLD_SPACE); |
4029 if (!allocation.To(&result)) return allocation; | 4028 if (!allocation.To(&result)) return allocation; |
4030 } | 4029 } |
4031 result->InitializeBody(size); | 4030 result->InitializeBody(size); |
4032 return result; | 4031 return result; |
4033 } | 4032 } |
4034 | 4033 |
4035 | 4034 |
| 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 |
4036 void Heap::MakeHeapIterable() { | 4042 void Heap::MakeHeapIterable() { |
| 4043 DCHECK(AllowHeapAllocation::IsAllowed()); |
| 4044 if (!IsHeapIterable()) { |
| 4045 CollectAllGarbage(kMakeHeapIterableMask, "Heap::MakeHeapIterable"); |
| 4046 } |
4037 if (mark_compact_collector()->sweeping_in_progress()) { | 4047 if (mark_compact_collector()->sweeping_in_progress()) { |
4038 mark_compact_collector()->EnsureSweepingCompleted(); | 4048 mark_compact_collector()->EnsureSweepingCompleted(); |
4039 } | 4049 } |
| 4050 DCHECK(IsHeapIterable()); |
4040 } | 4051 } |
4041 | 4052 |
4042 | 4053 |
4043 static double ComputeMutatorUtilization(double mutator_speed, double gc_speed) { | 4054 static double ComputeMutatorUtilization(double mutator_speed, double gc_speed) { |
4044 const double kMinMutatorUtilization = 0.0; | 4055 const double kMinMutatorUtilization = 0.0; |
4045 const double kConservativeGcSpeedInBytesPerMillisecond = 200000; | 4056 const double kConservativeGcSpeedInBytesPerMillisecond = 200000; |
4046 if (mutator_speed == 0) return kMinMutatorUtilization; | 4057 if (mutator_speed == 0) return kMinMutatorUtilization; |
4047 if (gc_speed == 0) gc_speed = kConservativeGcSpeedInBytesPerMillisecond; | 4058 if (gc_speed == 0) gc_speed = kConservativeGcSpeedInBytesPerMillisecond; |
4048 // Derivation: | 4059 // Derivation: |
4049 // mutator_utilization = mutator_time / (mutator_time + gc_time) | 4060 // mutator_utilization = mutator_time / (mutator_time + gc_time) |
(...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4574 return false; | 4585 return false; |
4575 } | 4586 } |
4576 } | 4587 } |
4577 | 4588 |
4578 | 4589 |
4579 #ifdef VERIFY_HEAP | 4590 #ifdef VERIFY_HEAP |
4580 void Heap::Verify() { | 4591 void Heap::Verify() { |
4581 CHECK(HasBeenSetUp()); | 4592 CHECK(HasBeenSetUp()); |
4582 HandleScope scope(isolate()); | 4593 HandleScope scope(isolate()); |
4583 | 4594 |
4584 MakeHeapIterable(); | 4595 if (mark_compact_collector()->sweeping_in_progress()) { |
| 4596 // We have to wait here for the sweeper threads to have an iterable heap. |
| 4597 mark_compact_collector()->EnsureSweepingCompleted(); |
| 4598 } |
4585 | 4599 |
4586 VerifyPointersVisitor visitor; | 4600 VerifyPointersVisitor visitor; |
4587 IterateRoots(&visitor, VISIT_ONLY_STRONG); | 4601 IterateRoots(&visitor, VISIT_ONLY_STRONG); |
4588 | 4602 |
4589 VerifySmisVisitor smis_visitor; | 4603 VerifySmisVisitor smis_visitor; |
4590 IterateSmiRoots(&smis_visitor); | 4604 IterateSmiRoots(&smis_visitor); |
4591 | 4605 |
4592 new_space_.Verify(); | 4606 new_space_.Verify(); |
4593 | 4607 |
4594 old_space_->Verify(&visitor); | 4608 old_space_->Verify(&visitor); |
(...skipping 1738 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6333 } | 6347 } |
6334 | 6348 |
6335 | 6349 |
6336 // static | 6350 // static |
6337 int Heap::GetStaticVisitorIdForMap(Map* map) { | 6351 int Heap::GetStaticVisitorIdForMap(Map* map) { |
6338 return StaticVisitorBase::GetVisitorId(map); | 6352 return StaticVisitorBase::GetVisitorId(map); |
6339 } | 6353 } |
6340 | 6354 |
6341 } // namespace internal | 6355 } // namespace internal |
6342 } // namespace v8 | 6356 } // namespace v8 |
OLD | NEW |