| 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/incremental-marking.h" | 5 #include "src/heap/incremental-marking.h" |
| 6 | 6 |
| 7 #include "src/code-stubs.h" | 7 #include "src/code-stubs.h" |
| 8 #include "src/compilation-cache.h" | 8 #include "src/compilation-cache.h" |
| 9 #include "src/conversions.h" | 9 #include "src/conversions.h" |
| 10 #include "src/heap/gc-idle-time-handler.h" | 10 #include "src/heap/gc-idle-time-handler.h" |
| (...skipping 724 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 735 } else { | 735 } else { |
| 736 new_age = FLAG_retain_maps_for_n_gc; | 736 new_age = FLAG_retain_maps_for_n_gc; |
| 737 } | 737 } |
| 738 // Compact the array and update the age. | 738 // Compact the array and update the age. |
| 739 if (new_age != age) { | 739 if (new_age != age) { |
| 740 retained_maps->Set(i + 1, Smi::FromInt(new_age)); | 740 retained_maps->Set(i + 1, Smi::FromInt(new_age)); |
| 741 } | 741 } |
| 742 } | 742 } |
| 743 } | 743 } |
| 744 | 744 |
| 745 | |
| 746 void IncrementalMarking::FinalizeIncrementally() { | 745 void IncrementalMarking::FinalizeIncrementally() { |
| 747 TRACE_GC(heap()->tracer(), GCTracer::Scope::MC_INCREMENTAL_FINALIZE_BODY); | 746 TRACE_GC(heap()->tracer(), GCTracer::Scope::MC_INCREMENTAL_FINALIZE_BODY); |
| 748 DCHECK(!finalize_marking_completed_); | 747 DCHECK(!finalize_marking_completed_); |
| 749 DCHECK(IsMarking()); | 748 DCHECK(IsMarking()); |
| 750 | 749 |
| 751 double start = heap_->MonotonicallyIncreasingTimeInMs(); | 750 double start = heap_->MonotonicallyIncreasingTimeInMs(); |
| 752 | 751 |
| 753 int old_marking_deque_top = | 752 int old_marking_deque_top = |
| 754 heap_->mark_compact_collector()->marking_deque()->top(); | 753 heap_->mark_compact_collector()->marking_deque()->top(); |
| 755 | 754 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 768 // Map retaining is needed for perfromance, not correctness, | 767 // Map retaining is needed for perfromance, not correctness, |
| 769 // so we can do it only once at the beginning of the finalization. | 768 // so we can do it only once at the beginning of the finalization. |
| 770 RetainMaps(); | 769 RetainMaps(); |
| 771 } | 770 } |
| 772 ProcessWeakCells(); | 771 ProcessWeakCells(); |
| 773 | 772 |
| 774 int marking_progress = | 773 int marking_progress = |
| 775 abs(old_marking_deque_top - | 774 abs(old_marking_deque_top - |
| 776 heap_->mark_compact_collector()->marking_deque()->top()); | 775 heap_->mark_compact_collector()->marking_deque()->top()); |
| 777 | 776 |
| 777 marking_progress += |
| 778 static_cast<int>(heap_->mark_compact_collector()->wrappers_to_trace()); |
| 779 |
| 778 double end = heap_->MonotonicallyIncreasingTimeInMs(); | 780 double end = heap_->MonotonicallyIncreasingTimeInMs(); |
| 779 double delta = end - start; | 781 double delta = end - start; |
| 780 heap_->tracer()->AddMarkingTime(delta); | 782 heap_->tracer()->AddMarkingTime(delta); |
| 781 if (FLAG_trace_incremental_marking) { | 783 if (FLAG_trace_incremental_marking) { |
| 782 PrintF( | 784 PrintF( |
| 783 "[IncrementalMarking] Finalize incrementally round %d, " | 785 "[IncrementalMarking] Finalize incrementally round %d, " |
| 784 "spent %d ms, marking progress %d.\n", | 786 "spent %d ms, marking progress %d.\n", |
| 785 static_cast<int>(delta), incremental_marking_finalization_rounds_, | 787 static_cast<int>(delta), incremental_marking_finalization_rounds_, |
| 786 marking_progress); | 788 marking_progress); |
| 787 } | 789 } |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1041 ->FinalIncrementalMarkCompactSpeedInBytesPerMillisecond()); | 1043 ->FinalIncrementalMarkCompactSpeedInBytesPerMillisecond()); |
| 1042 double remaining_time_in_ms = 0.0; | 1044 double remaining_time_in_ms = 0.0; |
| 1043 intptr_t bytes_processed = 0; | 1045 intptr_t bytes_processed = 0; |
| 1044 | 1046 |
| 1045 do { | 1047 do { |
| 1046 bytes_processed = | 1048 bytes_processed = |
| 1047 Step(step_size_in_bytes, step_actions.completion_action, | 1049 Step(step_size_in_bytes, step_actions.completion_action, |
| 1048 step_actions.force_marking, step_actions.force_completion); | 1050 step_actions.force_marking, step_actions.force_completion); |
| 1049 remaining_time_in_ms = | 1051 remaining_time_in_ms = |
| 1050 deadline_in_ms - heap()->MonotonicallyIncreasingTimeInMs(); | 1052 deadline_in_ms - heap()->MonotonicallyIncreasingTimeInMs(); |
| 1051 } while (bytes_processed > 0 && | 1053 } while (!heap_->mark_compact_collector()->marking_deque()->IsEmpty() && |
| 1052 remaining_time_in_ms >= | 1054 remaining_time_in_ms >= |
| 1053 2.0 * GCIdleTimeHandler::kIncrementalMarkingStepTimeInMs && | 1055 2.0 * GCIdleTimeHandler::kIncrementalMarkingStepTimeInMs && |
| 1054 !IsComplete() && | 1056 !IsComplete() && |
| 1055 !heap()->mark_compact_collector()->marking_deque()->IsEmpty()); | 1057 !heap()->mark_compact_collector()->marking_deque()->IsEmpty()); |
| 1056 return remaining_time_in_ms; | 1058 return remaining_time_in_ms; |
| 1057 } | 1059 } |
| 1058 | 1060 |
| 1059 | 1061 |
| 1060 void IncrementalMarking::OldSpaceStep(intptr_t allocated) { | 1062 void IncrementalMarking::OldSpaceStep(intptr_t allocated) { |
| 1061 if (IsStopped() && ShouldActivateEvenWithoutIdleNotification()) { | 1063 if (IsStopped() && ShouldActivateEvenWithoutIdleNotification()) { |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1199 write_barriers_invoked_since_last_step_ = 0; | 1201 write_barriers_invoked_since_last_step_ = 0; |
| 1200 | 1202 |
| 1201 bytes_scanned_ += bytes_to_process; | 1203 bytes_scanned_ += bytes_to_process; |
| 1202 | 1204 |
| 1203 // TODO(hpayer): Do not account for sweeping finalization while marking. | 1205 // TODO(hpayer): Do not account for sweeping finalization while marking. |
| 1204 if (state_ == SWEEPING) { | 1206 if (state_ == SWEEPING) { |
| 1205 FinalizeSweeping(); | 1207 FinalizeSweeping(); |
| 1206 } | 1208 } |
| 1207 | 1209 |
| 1208 if (state_ == MARKING) { | 1210 if (state_ == MARKING) { |
| 1209 bytes_processed = ProcessMarkingDeque(bytes_to_process); | 1211 const bool incremental_wrapper_tracing = |
| 1210 if (FLAG_incremental_marking_wrappers && | 1212 FLAG_incremental_marking_wrappers && heap_->UsingEmbedderHeapTracer(); |
| 1211 heap_->UsingEmbedderHeapTracer()) { | 1213 const bool process_wrappers = |
| 1214 incremental_wrapper_tracing && |
| 1215 (heap_->mark_compact_collector() |
| 1216 ->RequiresImmediateWrapperProcessing() || |
| 1217 heap_->mark_compact_collector()->marking_deque()->IsEmpty()); |
| 1218 bool wrapper_work_left = incremental_wrapper_tracing; |
| 1219 if (!process_wrappers) { |
| 1220 bytes_processed = ProcessMarkingDeque(bytes_to_process); |
| 1221 } else { |
| 1222 const double kWrapperTracngStepMs = 1.0; |
| 1223 const double wrapper_deadline = |
| 1224 heap_->MonotonicallyIncreasingTimeInMs() + kWrapperTracngStepMs; |
| 1212 TRACE_GC(heap()->tracer(), | 1225 TRACE_GC(heap()->tracer(), |
| 1213 GCTracer::Scope::MC_INCREMENTAL_WRAPPER_TRACING); | 1226 GCTracer::Scope::MC_INCREMENTAL_WRAPPER_TRACING); |
| 1214 // This currently marks through all registered wrappers and does not | |
| 1215 // respect bytes_to_process. | |
| 1216 // TODO(hpayer): Integrate incremental marking of wrappers into | |
| 1217 // bytes_to_process logic. | |
| 1218 heap_->mark_compact_collector() | 1227 heap_->mark_compact_collector() |
| 1219 ->RegisterWrappersWithEmbedderHeapTracer(); | 1228 ->RegisterWrappersWithEmbedderHeapTracer(); |
| 1220 heap_->mark_compact_collector()->embedder_heap_tracer()->AdvanceTracing( | 1229 wrapper_work_left = |
| 1221 0, | 1230 heap_->mark_compact_collector() |
| 1222 EmbedderHeapTracer::AdvanceTracingActions( | 1231 ->embedder_heap_tracer() |
| 1223 EmbedderHeapTracer::ForceCompletionAction::FORCE_COMPLETION)); | 1232 ->AdvanceTracing(wrapper_deadline, |
| 1233 EmbedderHeapTracer::AdvanceTracingActions( |
| 1234 EmbedderHeapTracer::ForceCompletionAction:: |
| 1235 DO_NOT_FORCE_COMPLETION)); |
| 1224 } | 1236 } |
| 1225 if (heap_->mark_compact_collector()->marking_deque()->IsEmpty()) { | 1237 |
| 1238 if (heap_->mark_compact_collector()->marking_deque()->IsEmpty() && |
| 1239 !wrapper_work_left) { |
| 1226 if (completion == FORCE_COMPLETION || | 1240 if (completion == FORCE_COMPLETION || |
| 1227 IsIdleMarkingDelayCounterLimitReached()) { | 1241 IsIdleMarkingDelayCounterLimitReached()) { |
| 1228 if (!finalize_marking_completed_) { | 1242 if (!finalize_marking_completed_) { |
| 1229 FinalizeMarking(action); | 1243 FinalizeMarking(action); |
| 1230 } else { | 1244 } else { |
| 1231 MarkingComplete(action); | 1245 MarkingComplete(action); |
| 1232 } | 1246 } |
| 1233 } else { | 1247 } else { |
| 1234 IncrementIdleMarkingDelayCounter(); | 1248 IncrementIdleMarkingDelayCounter(); |
| 1235 } | 1249 } |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1279 void IncrementalMarking::IncrementIdleMarkingDelayCounter() { | 1293 void IncrementalMarking::IncrementIdleMarkingDelayCounter() { |
| 1280 idle_marking_delay_counter_++; | 1294 idle_marking_delay_counter_++; |
| 1281 } | 1295 } |
| 1282 | 1296 |
| 1283 | 1297 |
| 1284 void IncrementalMarking::ClearIdleMarkingDelayCounter() { | 1298 void IncrementalMarking::ClearIdleMarkingDelayCounter() { |
| 1285 idle_marking_delay_counter_ = 0; | 1299 idle_marking_delay_counter_ = 0; |
| 1286 } | 1300 } |
| 1287 } // namespace internal | 1301 } // namespace internal |
| 1288 } // namespace v8 | 1302 } // namespace v8 |
| OLD | NEW |