| 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_(nullptr), | 125 mark_compact_collector_(this), |
| 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 798 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 934 } | 934 } |
| 935 | 935 |
| 936 if (collector == MARK_COMPACTOR && !ShouldFinalizeIncrementalMarking() && | 936 if (collector == MARK_COMPACTOR && !ShouldFinalizeIncrementalMarking() && |
| 937 !ShouldAbortIncrementalMarking() && !incremental_marking()->IsStopped() && | 937 !ShouldAbortIncrementalMarking() && !incremental_marking()->IsStopped() && |
| 938 !incremental_marking()->should_hurry() && FLAG_incremental_marking) { | 938 !incremental_marking()->should_hurry() && FLAG_incremental_marking) { |
| 939 // Make progress in incremental marking. | 939 // Make progress in incremental marking. |
| 940 const intptr_t kStepSizeWhenDelayedByScavenge = 1 * MB; | 940 const intptr_t kStepSizeWhenDelayedByScavenge = 1 * MB; |
| 941 incremental_marking()->Step(kStepSizeWhenDelayedByScavenge, | 941 incremental_marking()->Step(kStepSizeWhenDelayedByScavenge, |
| 942 IncrementalMarking::NO_GC_VIA_STACK_GUARD); | 942 IncrementalMarking::NO_GC_VIA_STACK_GUARD); |
| 943 if (!incremental_marking()->IsComplete() && | 943 if (!incremental_marking()->IsComplete() && |
| 944 !mark_compact_collector()->marking_deque_.IsEmpty() && | 944 !mark_compact_collector_.marking_deque_.IsEmpty() && !FLAG_gc_global) { |
| 945 !FLAG_gc_global) { | |
| 946 if (FLAG_trace_incremental_marking) { | 945 if (FLAG_trace_incremental_marking) { |
| 947 PrintF("[IncrementalMarking] Delaying MarkSweep.\n"); | 946 PrintF("[IncrementalMarking] Delaying MarkSweep.\n"); |
| 948 } | 947 } |
| 949 collector = SCAVENGER; | 948 collector = SCAVENGER; |
| 950 collector_reason = "incremental marking delaying mark-sweep"; | 949 collector_reason = "incremental marking delaying mark-sweep"; |
| 951 } | 950 } |
| 952 } | 951 } |
| 953 | 952 |
| 954 bool next_gc_likely_to_collect_more = false; | 953 bool next_gc_likely_to_collect_more = false; |
| 955 intptr_t committed_memory_before = 0; | 954 intptr_t committed_memory_before = 0; |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1276 | 1275 |
| 1277 isolate_->counters()->objs_since_last_young()->Set(0); | 1276 isolate_->counters()->objs_since_last_young()->Set(0); |
| 1278 | 1277 |
| 1279 if (collector != SCAVENGER) { | 1278 if (collector != SCAVENGER) { |
| 1280 // Callbacks that fire after this point might trigger nested GCs and | 1279 // Callbacks that fire after this point might trigger nested GCs and |
| 1281 // restart incremental marking, the assertion can't be moved down. | 1280 // restart incremental marking, the assertion can't be moved down. |
| 1282 DCHECK(incremental_marking()->IsStopped()); | 1281 DCHECK(incremental_marking()->IsStopped()); |
| 1283 | 1282 |
| 1284 // We finished a marking cycle. We can uncommit the marking deque until | 1283 // We finished a marking cycle. We can uncommit the marking deque until |
| 1285 // we start marking again. | 1284 // we start marking again. |
| 1286 mark_compact_collector()->marking_deque()->Uninitialize(); | 1285 mark_compact_collector_.marking_deque()->Uninitialize(); |
| 1287 mark_compact_collector()->EnsureMarkingDequeIsCommitted( | 1286 mark_compact_collector_.EnsureMarkingDequeIsCommitted( |
| 1288 MarkCompactCollector::kMinMarkingDequeSize); | 1287 MarkCompactCollector::kMinMarkingDequeSize); |
| 1289 } | 1288 } |
| 1290 | 1289 |
| 1291 gc_post_processing_depth_++; | 1290 gc_post_processing_depth_++; |
| 1292 { | 1291 { |
| 1293 AllowHeapAllocation allow_allocation; | 1292 AllowHeapAllocation allow_allocation; |
| 1294 GCTracer::Scope scope(tracer(), GCTracer::Scope::EXTERNAL); | 1293 GCTracer::Scope scope(tracer(), GCTracer::Scope::EXTERNAL); |
| 1295 freed_global_handles = | 1294 freed_global_handles = |
| 1296 isolate_->global_handles()->PostGarbageCollectionProcessing( | 1295 isolate_->global_handles()->PostGarbageCollectionProcessing( |
| 1297 collector, gc_callback_flags); | 1296 collector, gc_callback_flags); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1371 } | 1370 } |
| 1372 } | 1371 } |
| 1373 | 1372 |
| 1374 | 1373 |
| 1375 void Heap::MarkCompact() { | 1374 void Heap::MarkCompact() { |
| 1376 gc_state_ = MARK_COMPACT; | 1375 gc_state_ = MARK_COMPACT; |
| 1377 LOG(isolate_, ResourceEvent("markcompact", "begin")); | 1376 LOG(isolate_, ResourceEvent("markcompact", "begin")); |
| 1378 | 1377 |
| 1379 uint64_t size_of_objects_before_gc = SizeOfObjects(); | 1378 uint64_t size_of_objects_before_gc = SizeOfObjects(); |
| 1380 | 1379 |
| 1381 mark_compact_collector()->Prepare(); | 1380 mark_compact_collector_.Prepare(); |
| 1382 | 1381 |
| 1383 ms_count_++; | 1382 ms_count_++; |
| 1384 | 1383 |
| 1385 MarkCompactPrologue(); | 1384 MarkCompactPrologue(); |
| 1386 | 1385 |
| 1387 mark_compact_collector()->CollectGarbage(); | 1386 mark_compact_collector_.CollectGarbage(); |
| 1388 | 1387 |
| 1389 LOG(isolate_, ResourceEvent("markcompact", "end")); | 1388 LOG(isolate_, ResourceEvent("markcompact", "end")); |
| 1390 | 1389 |
| 1391 MarkCompactEpilogue(); | 1390 MarkCompactEpilogue(); |
| 1392 | 1391 |
| 1393 if (FLAG_allocation_site_pretenuring) { | 1392 if (FLAG_allocation_site_pretenuring) { |
| 1394 EvaluateOldSpaceLocalPretenuring(size_of_objects_before_gc); | 1393 EvaluateOldSpaceLocalPretenuring(size_of_objects_before_gc); |
| 1395 } | 1394 } |
| 1396 } | 1395 } |
| 1397 | 1396 |
| (...skipping 2643 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4041 new_space_.Shrink(); | 4040 new_space_.Shrink(); |
| 4042 UncommitFromSpace(); | 4041 UncommitFromSpace(); |
| 4043 } | 4042 } |
| 4044 } | 4043 } |
| 4045 | 4044 |
| 4046 | 4045 |
| 4047 void Heap::FinalizeIncrementalMarkingIfComplete(const char* comment) { | 4046 void Heap::FinalizeIncrementalMarkingIfComplete(const char* comment) { |
| 4048 if (FLAG_overapproximate_weak_closure && incremental_marking()->IsMarking() && | 4047 if (FLAG_overapproximate_weak_closure && incremental_marking()->IsMarking() && |
| 4049 (incremental_marking()->IsReadyToOverApproximateWeakClosure() || | 4048 (incremental_marking()->IsReadyToOverApproximateWeakClosure() || |
| 4050 (!incremental_marking()->weak_closure_was_overapproximated() && | 4049 (!incremental_marking()->weak_closure_was_overapproximated() && |
| 4051 mark_compact_collector()->marking_deque()->IsEmpty()))) { | 4050 mark_compact_collector_.marking_deque()->IsEmpty()))) { |
| 4052 OverApproximateWeakClosure(comment); | 4051 OverApproximateWeakClosure(comment); |
| 4053 } else if (incremental_marking()->IsComplete() || | 4052 } else if (incremental_marking()->IsComplete() || |
| 4054 (mark_compact_collector()->marking_deque()->IsEmpty())) { | 4053 (mark_compact_collector_.marking_deque()->IsEmpty())) { |
| 4055 CollectAllGarbage(current_gc_flags_, comment); | 4054 CollectAllGarbage(current_gc_flags_, comment); |
| 4056 } | 4055 } |
| 4057 } | 4056 } |
| 4058 | 4057 |
| 4059 | 4058 |
| 4060 bool Heap::TryFinalizeIdleIncrementalMarking(double idle_time_in_ms) { | 4059 bool Heap::TryFinalizeIdleIncrementalMarking(double idle_time_in_ms) { |
| 4061 size_t size_of_objects = static_cast<size_t>(SizeOfObjects()); | 4060 size_t size_of_objects = static_cast<size_t>(SizeOfObjects()); |
| 4062 size_t final_incremental_mark_compact_speed_in_bytes_per_ms = | 4061 size_t final_incremental_mark_compact_speed_in_bytes_per_ms = |
| 4063 static_cast<size_t>( | 4062 static_cast<size_t>( |
| 4064 tracer()->FinalIncrementalMarkCompactSpeedInBytesPerMillisecond()); | 4063 tracer()->FinalIncrementalMarkCompactSpeedInBytesPerMillisecond()); |
| 4065 if (FLAG_overapproximate_weak_closure && | 4064 if (FLAG_overapproximate_weak_closure && |
| 4066 (incremental_marking()->IsReadyToOverApproximateWeakClosure() || | 4065 (incremental_marking()->IsReadyToOverApproximateWeakClosure() || |
| 4067 (!incremental_marking()->weak_closure_was_overapproximated() && | 4066 (!incremental_marking()->weak_closure_was_overapproximated() && |
| 4068 mark_compact_collector()->marking_deque()->IsEmpty() && | 4067 mark_compact_collector_.marking_deque()->IsEmpty() && |
| 4069 gc_idle_time_handler_->ShouldDoOverApproximateWeakClosure( | 4068 gc_idle_time_handler_->ShouldDoOverApproximateWeakClosure( |
| 4070 static_cast<size_t>(idle_time_in_ms))))) { | 4069 static_cast<size_t>(idle_time_in_ms))))) { |
| 4071 OverApproximateWeakClosure( | 4070 OverApproximateWeakClosure( |
| 4072 "Idle notification: overapproximate weak closure"); | 4071 "Idle notification: overapproximate weak closure"); |
| 4073 return true; | 4072 return true; |
| 4074 } else if (incremental_marking()->IsComplete() || | 4073 } else if (incremental_marking()->IsComplete() || |
| 4075 (mark_compact_collector()->marking_deque()->IsEmpty() && | 4074 (mark_compact_collector_.marking_deque()->IsEmpty() && |
| 4076 gc_idle_time_handler_->ShouldDoFinalIncrementalMarkCompact( | 4075 gc_idle_time_handler_->ShouldDoFinalIncrementalMarkCompact( |
| 4077 static_cast<size_t>(idle_time_in_ms), size_of_objects, | 4076 static_cast<size_t>(idle_time_in_ms), size_of_objects, |
| 4078 final_incremental_mark_compact_speed_in_bytes_per_ms))) { | 4077 final_incremental_mark_compact_speed_in_bytes_per_ms))) { |
| 4079 CollectAllGarbage(current_gc_flags_, | 4078 CollectAllGarbage(current_gc_flags_, |
| 4080 "idle notification: finalize incremental"); | 4079 "idle notification: finalize incremental"); |
| 4081 return true; | 4080 return true; |
| 4082 } | 4081 } |
| 4083 return false; | 4082 return false; |
| 4084 } | 4083 } |
| 4085 | 4084 |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4388 new_space_.Verify(); | 4387 new_space_.Verify(); |
| 4389 | 4388 |
| 4390 old_space_->Verify(&visitor); | 4389 old_space_->Verify(&visitor); |
| 4391 map_space_->Verify(&visitor); | 4390 map_space_->Verify(&visitor); |
| 4392 | 4391 |
| 4393 VerifyPointersVisitor no_dirty_regions_visitor; | 4392 VerifyPointersVisitor no_dirty_regions_visitor; |
| 4394 code_space_->Verify(&no_dirty_regions_visitor); | 4393 code_space_->Verify(&no_dirty_regions_visitor); |
| 4395 | 4394 |
| 4396 lo_space_->Verify(); | 4395 lo_space_->Verify(); |
| 4397 | 4396 |
| 4398 mark_compact_collector()->VerifyWeakEmbeddedObjectsInCode(); | 4397 mark_compact_collector_.VerifyWeakEmbeddedObjectsInCode(); |
| 4399 if (FLAG_omit_map_checks_for_leaf_maps) { | 4398 if (FLAG_omit_map_checks_for_leaf_maps) { |
| 4400 mark_compact_collector()->VerifyOmittedMapChecks(); | 4399 mark_compact_collector_.VerifyOmittedMapChecks(); |
| 4401 } | 4400 } |
| 4402 } | 4401 } |
| 4403 #endif | 4402 #endif |
| 4404 | 4403 |
| 4405 | 4404 |
| 4406 void Heap::ZapFromSpace() { | 4405 void Heap::ZapFromSpace() { |
| 4407 if (!new_space_.IsFromSpaceCommitted()) return; | 4406 if (!new_space_.IsFromSpaceCommitted()) return; |
| 4408 NewSpacePageIterator it(new_space_.FromSpaceStart(), | 4407 NewSpacePageIterator it(new_space_.FromSpaceStart(), |
| 4409 new_space_.FromSpaceEnd()); | 4408 new_space_.FromSpaceEnd()); |
| 4410 while (it.has_next()) { | 4409 while (it.has_next()) { |
| (...skipping 629 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5040 | 5039 |
| 5041 for (int i = 0; i < static_cast<int>(v8::Isolate::kUseCounterFeatureCount); | 5040 for (int i = 0; i < static_cast<int>(v8::Isolate::kUseCounterFeatureCount); |
| 5042 i++) { | 5041 i++) { |
| 5043 deferred_counters_[i] = 0; | 5042 deferred_counters_[i] = 0; |
| 5044 } | 5043 } |
| 5045 | 5044 |
| 5046 tracer_ = new GCTracer(this); | 5045 tracer_ = new GCTracer(this); |
| 5047 | 5046 |
| 5048 scavenge_collector_ = new Scavenger(this); | 5047 scavenge_collector_ = new Scavenger(this); |
| 5049 | 5048 |
| 5050 mark_compact_collector_ = new MarkCompactCollector(this); | |
| 5051 | |
| 5052 gc_idle_time_handler_ = new GCIdleTimeHandler(); | 5049 gc_idle_time_handler_ = new GCIdleTimeHandler(); |
| 5053 | 5050 |
| 5054 memory_reducer_ = new MemoryReducer(this); | 5051 memory_reducer_ = new MemoryReducer(this); |
| 5055 | 5052 |
| 5056 object_stats_ = new ObjectStats(this); | 5053 object_stats_ = new ObjectStats(this); |
| 5057 object_stats_->ClearObjectStats(true); | 5054 object_stats_->ClearObjectStats(true); |
| 5058 | 5055 |
| 5059 scavenge_job_ = new ScavengeJob(); | 5056 scavenge_job_ = new ScavengeJob(); |
| 5060 | 5057 |
| 5061 array_buffer_tracker_ = new ArrayBufferTracker(this); | 5058 array_buffer_tracker_ = new ArrayBufferTracker(this); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5162 PrintF("\n\n"); | 5159 PrintF("\n\n"); |
| 5163 } | 5160 } |
| 5164 | 5161 |
| 5165 if (FLAG_verify_predictable) { | 5162 if (FLAG_verify_predictable) { |
| 5166 PrintAlloctionsHash(); | 5163 PrintAlloctionsHash(); |
| 5167 } | 5164 } |
| 5168 | 5165 |
| 5169 delete scavenge_collector_; | 5166 delete scavenge_collector_; |
| 5170 scavenge_collector_ = nullptr; | 5167 scavenge_collector_ = nullptr; |
| 5171 | 5168 |
| 5172 if (mark_compact_collector_ != nullptr) { | |
| 5173 mark_compact_collector_->TearDown(); | |
| 5174 delete mark_compact_collector_; | |
| 5175 mark_compact_collector_ = nullptr; | |
| 5176 } | |
| 5177 | |
| 5178 delete incremental_marking_; | 5169 delete incremental_marking_; |
| 5179 incremental_marking_ = nullptr; | 5170 incremental_marking_ = nullptr; |
| 5180 | 5171 |
| 5181 delete gc_idle_time_handler_; | 5172 delete gc_idle_time_handler_; |
| 5182 gc_idle_time_handler_ = nullptr; | 5173 gc_idle_time_handler_ = nullptr; |
| 5183 | 5174 |
| 5184 if (memory_reducer_ != nullptr) { | 5175 if (memory_reducer_ != nullptr) { |
| 5185 memory_reducer_->TearDown(); | 5176 memory_reducer_->TearDown(); |
| 5186 delete memory_reducer_; | 5177 delete memory_reducer_; |
| 5187 memory_reducer_ = nullptr; | 5178 memory_reducer_ = nullptr; |
| 5188 } | 5179 } |
| 5189 | 5180 |
| 5190 delete object_stats_; | 5181 delete object_stats_; |
| 5191 object_stats_ = nullptr; | 5182 object_stats_ = nullptr; |
| 5192 | 5183 |
| 5193 delete scavenge_job_; | 5184 delete scavenge_job_; |
| 5194 scavenge_job_ = nullptr; | 5185 scavenge_job_ = nullptr; |
| 5195 | 5186 |
| 5196 WaitUntilUnmappingOfFreeChunksCompleted(); | 5187 WaitUntilUnmappingOfFreeChunksCompleted(); |
| 5197 | 5188 |
| 5198 delete array_buffer_tracker_; | 5189 delete array_buffer_tracker_; |
| 5199 array_buffer_tracker_ = nullptr; | 5190 array_buffer_tracker_ = nullptr; |
| 5200 | 5191 |
| 5201 isolate_->global_handles()->TearDown(); | 5192 isolate_->global_handles()->TearDown(); |
| 5202 | 5193 |
| 5203 external_string_table_.TearDown(); | 5194 external_string_table_.TearDown(); |
| 5204 | 5195 |
| 5196 mark_compact_collector()->TearDown(); |
| 5197 |
| 5205 delete tracer_; | 5198 delete tracer_; |
| 5206 tracer_ = nullptr; | 5199 tracer_ = nullptr; |
| 5207 | 5200 |
| 5208 new_space_.TearDown(); | 5201 new_space_.TearDown(); |
| 5209 | 5202 |
| 5210 if (old_space_ != NULL) { | 5203 if (old_space_ != NULL) { |
| 5211 delete old_space_; | 5204 delete old_space_; |
| 5212 old_space_ = NULL; | 5205 old_space_ = NULL; |
| 5213 } | 5206 } |
| 5214 | 5207 |
| (...skipping 882 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6097 } | 6090 } |
| 6098 | 6091 |
| 6099 | 6092 |
| 6100 // static | 6093 // static |
| 6101 int Heap::GetStaticVisitorIdForMap(Map* map) { | 6094 int Heap::GetStaticVisitorIdForMap(Map* map) { |
| 6102 return StaticVisitorBase::GetVisitorId(map); | 6095 return StaticVisitorBase::GetVisitorId(map); |
| 6103 } | 6096 } |
| 6104 | 6097 |
| 6105 } // namespace internal | 6098 } // namespace internal |
| 6106 } // namespace v8 | 6099 } // namespace v8 |
| OLD | NEW |