| 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/base/bits.h" | 9 #include "src/base/bits.h" |
| 10 #include "src/base/once.h" | 10 #include "src/base/once.h" |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 maximum_size_scavenges_(0), | 115 maximum_size_scavenges_(0), |
| 116 max_gc_pause_(0.0), | 116 max_gc_pause_(0.0), |
| 117 total_gc_time_ms_(0.0), | 117 total_gc_time_ms_(0.0), |
| 118 max_alive_after_gc_(0), | 118 max_alive_after_gc_(0), |
| 119 min_in_mutator_(kMaxInt), | 119 min_in_mutator_(kMaxInt), |
| 120 marking_time_(0.0), | 120 marking_time_(0.0), |
| 121 sweeping_time_(0.0), | 121 sweeping_time_(0.0), |
| 122 last_idle_notification_time_(0.0), | 122 last_idle_notification_time_(0.0), |
| 123 last_gc_time_(0.0), | 123 last_gc_time_(0.0), |
| 124 scavenge_collector_(nullptr), | 124 scavenge_collector_(nullptr), |
| 125 mark_compact_collector_(this), | 125 mark_compact_collector_(nullptr), |
| 126 store_buffer_(this), | 126 store_buffer_(this), |
| 127 incremental_marking_(nullptr), | 127 incremental_marking_(nullptr), |
| 128 gc_idle_time_handler_(nullptr), | 128 gc_idle_time_handler_(nullptr), |
| 129 memory_reducer_(nullptr), | 129 memory_reducer_(nullptr), |
| 130 object_stats_(nullptr), | 130 object_stats_(nullptr), |
| 131 scavenge_job_(nullptr), | 131 scavenge_job_(nullptr), |
| 132 full_codegen_bytes_generated_(0), | 132 full_codegen_bytes_generated_(0), |
| 133 crankshaft_codegen_bytes_generated_(0), | 133 crankshaft_codegen_bytes_generated_(0), |
| 134 new_space_allocation_counter_(0), | 134 new_space_allocation_counter_(0), |
| 135 old_generation_allocation_counter_(0), | 135 old_generation_allocation_counter_(0), |
| (...skipping 815 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 951 } | 951 } |
| 952 | 952 |
| 953 if (collector == MARK_COMPACTOR && !ShouldFinalizeIncrementalMarking() && | 953 if (collector == MARK_COMPACTOR && !ShouldFinalizeIncrementalMarking() && |
| 954 !ShouldAbortIncrementalMarking() && !incremental_marking()->IsStopped() && | 954 !ShouldAbortIncrementalMarking() && !incremental_marking()->IsStopped() && |
| 955 !incremental_marking()->should_hurry() && FLAG_incremental_marking) { | 955 !incremental_marking()->should_hurry() && FLAG_incremental_marking) { |
| 956 // Make progress in incremental marking. | 956 // Make progress in incremental marking. |
| 957 const intptr_t kStepSizeWhenDelayedByScavenge = 1 * MB; | 957 const intptr_t kStepSizeWhenDelayedByScavenge = 1 * MB; |
| 958 incremental_marking()->Step(kStepSizeWhenDelayedByScavenge, | 958 incremental_marking()->Step(kStepSizeWhenDelayedByScavenge, |
| 959 IncrementalMarking::NO_GC_VIA_STACK_GUARD); | 959 IncrementalMarking::NO_GC_VIA_STACK_GUARD); |
| 960 if (!incremental_marking()->IsComplete() && | 960 if (!incremental_marking()->IsComplete() && |
| 961 !mark_compact_collector_.marking_deque_.IsEmpty() && !FLAG_gc_global) { | 961 !mark_compact_collector()->marking_deque_.IsEmpty() && |
| 962 !FLAG_gc_global) { |
| 962 if (FLAG_trace_incremental_marking) { | 963 if (FLAG_trace_incremental_marking) { |
| 963 PrintF("[IncrementalMarking] Delaying MarkSweep.\n"); | 964 PrintF("[IncrementalMarking] Delaying MarkSweep.\n"); |
| 964 } | 965 } |
| 965 collector = SCAVENGER; | 966 collector = SCAVENGER; |
| 966 collector_reason = "incremental marking delaying mark-sweep"; | 967 collector_reason = "incremental marking delaying mark-sweep"; |
| 967 } | 968 } |
| 968 } | 969 } |
| 969 | 970 |
| 970 bool next_gc_likely_to_collect_more = false; | 971 bool next_gc_likely_to_collect_more = false; |
| 971 intptr_t committed_memory_before = 0; | 972 intptr_t committed_memory_before = 0; |
| (...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1291 | 1292 |
| 1292 isolate_->counters()->objs_since_last_young()->Set(0); | 1293 isolate_->counters()->objs_since_last_young()->Set(0); |
| 1293 | 1294 |
| 1294 if (collector != SCAVENGER) { | 1295 if (collector != SCAVENGER) { |
| 1295 // Callbacks that fire after this point might trigger nested GCs and | 1296 // Callbacks that fire after this point might trigger nested GCs and |
| 1296 // restart incremental marking, the assertion can't be moved down. | 1297 // restart incremental marking, the assertion can't be moved down. |
| 1297 DCHECK(incremental_marking()->IsStopped()); | 1298 DCHECK(incremental_marking()->IsStopped()); |
| 1298 | 1299 |
| 1299 // We finished a marking cycle. We can uncommit the marking deque until | 1300 // We finished a marking cycle. We can uncommit the marking deque until |
| 1300 // we start marking again. | 1301 // we start marking again. |
| 1301 mark_compact_collector_.marking_deque()->Uninitialize(); | 1302 mark_compact_collector()->marking_deque()->Uninitialize(); |
| 1302 mark_compact_collector_.EnsureMarkingDequeIsCommitted( | 1303 mark_compact_collector()->EnsureMarkingDequeIsCommitted( |
| 1303 MarkCompactCollector::kMinMarkingDequeSize); | 1304 MarkCompactCollector::kMinMarkingDequeSize); |
| 1304 } | 1305 } |
| 1305 | 1306 |
| 1306 gc_post_processing_depth_++; | 1307 gc_post_processing_depth_++; |
| 1307 { | 1308 { |
| 1308 AllowHeapAllocation allow_allocation; | 1309 AllowHeapAllocation allow_allocation; |
| 1309 GCTracer::Scope scope(tracer(), GCTracer::Scope::EXTERNAL); | 1310 GCTracer::Scope scope(tracer(), GCTracer::Scope::EXTERNAL); |
| 1310 freed_global_handles = | 1311 freed_global_handles = |
| 1311 isolate_->global_handles()->PostGarbageCollectionProcessing( | 1312 isolate_->global_handles()->PostGarbageCollectionProcessing( |
| 1312 collector, gc_callback_flags); | 1313 collector, gc_callback_flags); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1386 } | 1387 } |
| 1387 } | 1388 } |
| 1388 | 1389 |
| 1389 | 1390 |
| 1390 void Heap::MarkCompact() { | 1391 void Heap::MarkCompact() { |
| 1391 gc_state_ = MARK_COMPACT; | 1392 gc_state_ = MARK_COMPACT; |
| 1392 LOG(isolate_, ResourceEvent("markcompact", "begin")); | 1393 LOG(isolate_, ResourceEvent("markcompact", "begin")); |
| 1393 | 1394 |
| 1394 uint64_t size_of_objects_before_gc = SizeOfObjects(); | 1395 uint64_t size_of_objects_before_gc = SizeOfObjects(); |
| 1395 | 1396 |
| 1396 mark_compact_collector_.Prepare(); | 1397 mark_compact_collector()->Prepare(); |
| 1397 | 1398 |
| 1398 ms_count_++; | 1399 ms_count_++; |
| 1399 | 1400 |
| 1400 MarkCompactPrologue(); | 1401 MarkCompactPrologue(); |
| 1401 | 1402 |
| 1402 mark_compact_collector_.CollectGarbage(); | 1403 mark_compact_collector()->CollectGarbage(); |
| 1403 | 1404 |
| 1404 LOG(isolate_, ResourceEvent("markcompact", "end")); | 1405 LOG(isolate_, ResourceEvent("markcompact", "end")); |
| 1405 | 1406 |
| 1406 MarkCompactEpilogue(); | 1407 MarkCompactEpilogue(); |
| 1407 | 1408 |
| 1408 if (FLAG_allocation_site_pretenuring) { | 1409 if (FLAG_allocation_site_pretenuring) { |
| 1409 EvaluateOldSpaceLocalPretenuring(size_of_objects_before_gc); | 1410 EvaluateOldSpaceLocalPretenuring(size_of_objects_before_gc); |
| 1410 } | 1411 } |
| 1411 } | 1412 } |
| 1412 | 1413 |
| (...skipping 2651 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4064 new_space_.Shrink(); | 4065 new_space_.Shrink(); |
| 4065 UncommitFromSpace(); | 4066 UncommitFromSpace(); |
| 4066 } | 4067 } |
| 4067 } | 4068 } |
| 4068 | 4069 |
| 4069 | 4070 |
| 4070 void Heap::FinalizeIncrementalMarkingIfComplete(const char* comment) { | 4071 void Heap::FinalizeIncrementalMarkingIfComplete(const char* comment) { |
| 4071 if (FLAG_overapproximate_weak_closure && incremental_marking()->IsMarking() && | 4072 if (FLAG_overapproximate_weak_closure && incremental_marking()->IsMarking() && |
| 4072 (incremental_marking()->IsReadyToOverApproximateWeakClosure() || | 4073 (incremental_marking()->IsReadyToOverApproximateWeakClosure() || |
| 4073 (!incremental_marking()->weak_closure_was_overapproximated() && | 4074 (!incremental_marking()->weak_closure_was_overapproximated() && |
| 4074 mark_compact_collector_.marking_deque()->IsEmpty()))) { | 4075 mark_compact_collector()->marking_deque()->IsEmpty()))) { |
| 4075 OverApproximateWeakClosure(comment); | 4076 OverApproximateWeakClosure(comment); |
| 4076 } else if (incremental_marking()->IsComplete() || | 4077 } else if (incremental_marking()->IsComplete() || |
| 4077 (mark_compact_collector_.marking_deque()->IsEmpty())) { | 4078 (mark_compact_collector()->marking_deque()->IsEmpty())) { |
| 4078 CollectAllGarbage(current_gc_flags_, comment); | 4079 CollectAllGarbage(current_gc_flags_, comment); |
| 4079 } | 4080 } |
| 4080 } | 4081 } |
| 4081 | 4082 |
| 4082 | 4083 |
| 4083 bool Heap::TryFinalizeIdleIncrementalMarking(double idle_time_in_ms) { | 4084 bool Heap::TryFinalizeIdleIncrementalMarking(double idle_time_in_ms) { |
| 4084 size_t size_of_objects = static_cast<size_t>(SizeOfObjects()); | 4085 size_t size_of_objects = static_cast<size_t>(SizeOfObjects()); |
| 4085 size_t final_incremental_mark_compact_speed_in_bytes_per_ms = | 4086 size_t final_incremental_mark_compact_speed_in_bytes_per_ms = |
| 4086 static_cast<size_t>( | 4087 static_cast<size_t>( |
| 4087 tracer()->FinalIncrementalMarkCompactSpeedInBytesPerMillisecond()); | 4088 tracer()->FinalIncrementalMarkCompactSpeedInBytesPerMillisecond()); |
| 4088 if (FLAG_overapproximate_weak_closure && | 4089 if (FLAG_overapproximate_weak_closure && |
| 4089 (incremental_marking()->IsReadyToOverApproximateWeakClosure() || | 4090 (incremental_marking()->IsReadyToOverApproximateWeakClosure() || |
| 4090 (!incremental_marking()->weak_closure_was_overapproximated() && | 4091 (!incremental_marking()->weak_closure_was_overapproximated() && |
| 4091 mark_compact_collector_.marking_deque()->IsEmpty() && | 4092 mark_compact_collector()->marking_deque()->IsEmpty() && |
| 4092 gc_idle_time_handler_->ShouldDoOverApproximateWeakClosure( | 4093 gc_idle_time_handler_->ShouldDoOverApproximateWeakClosure( |
| 4093 static_cast<size_t>(idle_time_in_ms))))) { | 4094 static_cast<size_t>(idle_time_in_ms))))) { |
| 4094 OverApproximateWeakClosure( | 4095 OverApproximateWeakClosure( |
| 4095 "Idle notification: overapproximate weak closure"); | 4096 "Idle notification: overapproximate weak closure"); |
| 4096 return true; | 4097 return true; |
| 4097 } else if (incremental_marking()->IsComplete() || | 4098 } else if (incremental_marking()->IsComplete() || |
| 4098 (mark_compact_collector_.marking_deque()->IsEmpty() && | 4099 (mark_compact_collector()->marking_deque()->IsEmpty() && |
| 4099 gc_idle_time_handler_->ShouldDoFinalIncrementalMarkCompact( | 4100 gc_idle_time_handler_->ShouldDoFinalIncrementalMarkCompact( |
| 4100 static_cast<size_t>(idle_time_in_ms), size_of_objects, | 4101 static_cast<size_t>(idle_time_in_ms), size_of_objects, |
| 4101 final_incremental_mark_compact_speed_in_bytes_per_ms))) { | 4102 final_incremental_mark_compact_speed_in_bytes_per_ms))) { |
| 4102 CollectAllGarbage(current_gc_flags_, | 4103 CollectAllGarbage(current_gc_flags_, |
| 4103 "idle notification: finalize incremental"); | 4104 "idle notification: finalize incremental"); |
| 4104 return true; | 4105 return true; |
| 4105 } | 4106 } |
| 4106 return false; | 4107 return false; |
| 4107 } | 4108 } |
| 4108 | 4109 |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4410 new_space_.Verify(); | 4411 new_space_.Verify(); |
| 4411 | 4412 |
| 4412 old_space_->Verify(&visitor); | 4413 old_space_->Verify(&visitor); |
| 4413 map_space_->Verify(&visitor); | 4414 map_space_->Verify(&visitor); |
| 4414 | 4415 |
| 4415 VerifyPointersVisitor no_dirty_regions_visitor; | 4416 VerifyPointersVisitor no_dirty_regions_visitor; |
| 4416 code_space_->Verify(&no_dirty_regions_visitor); | 4417 code_space_->Verify(&no_dirty_regions_visitor); |
| 4417 | 4418 |
| 4418 lo_space_->Verify(); | 4419 lo_space_->Verify(); |
| 4419 | 4420 |
| 4420 mark_compact_collector_.VerifyWeakEmbeddedObjectsInCode(); | 4421 mark_compact_collector()->VerifyWeakEmbeddedObjectsInCode(); |
| 4421 if (FLAG_omit_map_checks_for_leaf_maps) { | 4422 if (FLAG_omit_map_checks_for_leaf_maps) { |
| 4422 mark_compact_collector_.VerifyOmittedMapChecks(); | 4423 mark_compact_collector()->VerifyOmittedMapChecks(); |
| 4423 } | 4424 } |
| 4424 } | 4425 } |
| 4425 #endif | 4426 #endif |
| 4426 | 4427 |
| 4427 | 4428 |
| 4428 void Heap::ZapFromSpace() { | 4429 void Heap::ZapFromSpace() { |
| 4429 if (!new_space_.IsFromSpaceCommitted()) return; | 4430 if (!new_space_.IsFromSpaceCommitted()) return; |
| 4430 NewSpacePageIterator it(new_space_.FromSpaceStart(), | 4431 NewSpacePageIterator it(new_space_.FromSpaceStart(), |
| 4431 new_space_.FromSpaceEnd()); | 4432 new_space_.FromSpaceEnd()); |
| 4432 while (it.has_next()) { | 4433 while (it.has_next()) { |
| (...skipping 629 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5062 | 5063 |
| 5063 for (int i = 0; i < static_cast<int>(v8::Isolate::kUseCounterFeatureCount); | 5064 for (int i = 0; i < static_cast<int>(v8::Isolate::kUseCounterFeatureCount); |
| 5064 i++) { | 5065 i++) { |
| 5065 deferred_counters_[i] = 0; | 5066 deferred_counters_[i] = 0; |
| 5066 } | 5067 } |
| 5067 | 5068 |
| 5068 tracer_ = new GCTracer(this); | 5069 tracer_ = new GCTracer(this); |
| 5069 | 5070 |
| 5070 scavenge_collector_ = new Scavenger(this); | 5071 scavenge_collector_ = new Scavenger(this); |
| 5071 | 5072 |
| 5073 mark_compact_collector_ = new MarkCompactCollector(this); |
| 5074 |
| 5072 gc_idle_time_handler_ = new GCIdleTimeHandler(); | 5075 gc_idle_time_handler_ = new GCIdleTimeHandler(); |
| 5073 | 5076 |
| 5074 memory_reducer_ = new MemoryReducer(this); | 5077 memory_reducer_ = new MemoryReducer(this); |
| 5075 | 5078 |
| 5076 object_stats_ = new ObjectStats(this); | 5079 object_stats_ = new ObjectStats(this); |
| 5077 object_stats_->ClearObjectStats(true); | 5080 object_stats_->ClearObjectStats(true); |
| 5078 | 5081 |
| 5079 scavenge_job_ = new ScavengeJob(); | 5082 scavenge_job_ = new ScavengeJob(); |
| 5080 | 5083 |
| 5081 array_buffer_tracker_ = new ArrayBufferTracker(this); | 5084 array_buffer_tracker_ = new ArrayBufferTracker(this); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5182 PrintF("\n\n"); | 5185 PrintF("\n\n"); |
| 5183 } | 5186 } |
| 5184 | 5187 |
| 5185 if (FLAG_verify_predictable) { | 5188 if (FLAG_verify_predictable) { |
| 5186 PrintAlloctionsHash(); | 5189 PrintAlloctionsHash(); |
| 5187 } | 5190 } |
| 5188 | 5191 |
| 5189 delete scavenge_collector_; | 5192 delete scavenge_collector_; |
| 5190 scavenge_collector_ = nullptr; | 5193 scavenge_collector_ = nullptr; |
| 5191 | 5194 |
| 5195 if (mark_compact_collector_ != nullptr) { |
| 5196 mark_compact_collector_->TearDown(); |
| 5197 delete mark_compact_collector_; |
| 5198 mark_compact_collector_ = nullptr; |
| 5199 } |
| 5200 |
| 5192 delete incremental_marking_; | 5201 delete incremental_marking_; |
| 5193 incremental_marking_ = nullptr; | 5202 incremental_marking_ = nullptr; |
| 5194 | 5203 |
| 5195 delete gc_idle_time_handler_; | 5204 delete gc_idle_time_handler_; |
| 5196 gc_idle_time_handler_ = nullptr; | 5205 gc_idle_time_handler_ = nullptr; |
| 5197 | 5206 |
| 5198 if (memory_reducer_ != nullptr) { | 5207 if (memory_reducer_ != nullptr) { |
| 5199 memory_reducer_->TearDown(); | 5208 memory_reducer_->TearDown(); |
| 5200 delete memory_reducer_; | 5209 delete memory_reducer_; |
| 5201 memory_reducer_ = nullptr; | 5210 memory_reducer_ = nullptr; |
| 5202 } | 5211 } |
| 5203 | 5212 |
| 5204 delete object_stats_; | 5213 delete object_stats_; |
| 5205 object_stats_ = nullptr; | 5214 object_stats_ = nullptr; |
| 5206 | 5215 |
| 5207 delete scavenge_job_; | 5216 delete scavenge_job_; |
| 5208 scavenge_job_ = nullptr; | 5217 scavenge_job_ = nullptr; |
| 5209 | 5218 |
| 5210 WaitUntilUnmappingOfFreeChunksCompleted(); | 5219 WaitUntilUnmappingOfFreeChunksCompleted(); |
| 5211 | 5220 |
| 5212 delete array_buffer_tracker_; | 5221 delete array_buffer_tracker_; |
| 5213 array_buffer_tracker_ = nullptr; | 5222 array_buffer_tracker_ = nullptr; |
| 5214 | 5223 |
| 5215 isolate_->global_handles()->TearDown(); | 5224 isolate_->global_handles()->TearDown(); |
| 5216 | 5225 |
| 5217 external_string_table_.TearDown(); | 5226 external_string_table_.TearDown(); |
| 5218 | 5227 |
| 5219 mark_compact_collector()->TearDown(); | |
| 5220 | |
| 5221 delete tracer_; | 5228 delete tracer_; |
| 5222 tracer_ = nullptr; | 5229 tracer_ = nullptr; |
| 5223 | 5230 |
| 5224 new_space_.TearDown(); | 5231 new_space_.TearDown(); |
| 5225 | 5232 |
| 5226 if (old_space_ != NULL) { | 5233 if (old_space_ != NULL) { |
| 5227 delete old_space_; | 5234 delete old_space_; |
| 5228 old_space_ = NULL; | 5235 old_space_ = NULL; |
| 5229 } | 5236 } |
| 5230 | 5237 |
| (...skipping 882 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6113 } | 6120 } |
| 6114 | 6121 |
| 6115 | 6122 |
| 6116 // static | 6123 // static |
| 6117 int Heap::GetStaticVisitorIdForMap(Map* map) { | 6124 int Heap::GetStaticVisitorIdForMap(Map* map) { |
| 6118 return StaticVisitorBase::GetVisitorId(map); | 6125 return StaticVisitorBase::GetVisitorId(map); |
| 6119 } | 6126 } |
| 6120 | 6127 |
| 6121 } // namespace internal | 6128 } // namespace internal |
| 6122 } // namespace v8 | 6129 } // namespace v8 |
| OLD | NEW |