Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(164)

Side by Side Diff: src/heap/incremental-marking.cc

Issue 2464393002: [heap] Invoke incremental marking step before allocation. (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/heap/incremental-marking.h ('k') | src/heap/spaces.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 14 matching lines...) Expand all
25 initial_old_generation_size_(0), 25 initial_old_generation_size_(0),
26 bytes_marked_ahead_of_schedule_(0), 26 bytes_marked_ahead_of_schedule_(0),
27 unscanned_bytes_of_large_object_(0), 27 unscanned_bytes_of_large_object_(0),
28 idle_marking_delay_counter_(0), 28 idle_marking_delay_counter_(0),
29 incremental_marking_finalization_rounds_(0), 29 incremental_marking_finalization_rounds_(0),
30 is_compacting_(false), 30 is_compacting_(false),
31 should_hurry_(false), 31 should_hurry_(false),
32 was_activated_(false), 32 was_activated_(false),
33 black_allocation_(false), 33 black_allocation_(false),
34 finalize_marking_completed_(false), 34 finalize_marking_completed_(false),
35 request_type_(NONE), 35 request_type_(NONE) {}
36 new_generation_observer_(*this, kAllocatedThreshold),
37 old_generation_observer_(*this, kAllocatedThreshold) {}
38 36
39 bool IncrementalMarking::BaseRecordWrite(HeapObject* obj, Object* value) { 37 bool IncrementalMarking::BaseRecordWrite(HeapObject* obj, Object* value) {
40 HeapObject* value_heap_obj = HeapObject::cast(value); 38 HeapObject* value_heap_obj = HeapObject::cast(value);
41 MarkBit value_bit = ObjectMarking::MarkBitFrom(value_heap_obj); 39 MarkBit value_bit = ObjectMarking::MarkBitFrom(value_heap_obj);
42 DCHECK(!Marking::IsImpossible(value_bit)); 40 DCHECK(!Marking::IsImpossible(value_bit));
43 41
44 MarkBit obj_bit = ObjectMarking::MarkBitFrom(obj); 42 MarkBit obj_bit = ObjectMarking::MarkBitFrom(obj);
45 DCHECK(!Marking::IsImpossible(obj_bit)); 43 DCHECK(!Marking::IsImpossible(obj_bit));
46 bool is_black = Marking::IsBlack(obj_bit); 44 bool is_black = Marking::IsBlack(obj_bit);
47 45
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 if (!heap_->mark_compact_collector()->sweeping_in_progress()) { 480 if (!heap_->mark_compact_collector()->sweeping_in_progress()) {
483 StartMarking(); 481 StartMarking();
484 } else { 482 } else {
485 if (FLAG_trace_incremental_marking) { 483 if (FLAG_trace_incremental_marking) {
486 heap()->isolate()->PrintWithTimestamp( 484 heap()->isolate()->PrintWithTimestamp(
487 "[IncrementalMarking] Start sweeping.\n"); 485 "[IncrementalMarking] Start sweeping.\n");
488 } 486 }
489 state_ = SWEEPING; 487 state_ = SWEEPING;
490 } 488 }
491 489
492 SpaceIterator it(heap_);
493 while (it.has_next()) {
494 Space* space = it.next();
495 if (space == heap_->new_space()) {
496 space->AddAllocationObserver(&new_generation_observer_);
497 } else {
498 space->AddAllocationObserver(&old_generation_observer_);
499 }
500 }
501
502 incremental_marking_job()->Start(heap_); 490 incremental_marking_job()->Start(heap_);
503 } 491 }
504 492
505 493
506 void IncrementalMarking::StartMarking() { 494 void IncrementalMarking::StartMarking() {
507 if (heap_->isolate()->serializer_enabled()) { 495 if (heap_->isolate()->serializer_enabled()) {
508 // Black allocation currently starts when we start incremental marking, 496 // Black allocation currently starts when we start incremental marking,
509 // but we cannot enable black allocation while deserializing. Hence, we 497 // but we cannot enable black allocation while deserializing. Hence, we
510 // have to delay the start of incremental marking in that case. 498 // have to delay the start of incremental marking in that case.
511 if (FLAG_trace_incremental_marking) { 499 if (FLAG_trace_incremental_marking) {
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after
950 static_cast<int>(heap()->PromotedSpaceSizeOfObjects() / MB); 938 static_cast<int>(heap()->PromotedSpaceSizeOfObjects() / MB);
951 int old_generation_limit_mb = 939 int old_generation_limit_mb =
952 static_cast<int>(heap()->old_generation_allocation_limit() / MB); 940 static_cast<int>(heap()->old_generation_allocation_limit() / MB);
953 heap()->isolate()->PrintWithTimestamp( 941 heap()->isolate()->PrintWithTimestamp(
954 "[IncrementalMarking] Stopping: old generation %dMB, limit %dMB, " 942 "[IncrementalMarking] Stopping: old generation %dMB, limit %dMB, "
955 "overshoot %dMB\n", 943 "overshoot %dMB\n",
956 old_generation_size_mb, old_generation_limit_mb, 944 old_generation_size_mb, old_generation_limit_mb,
957 Max(0, old_generation_size_mb - old_generation_limit_mb)); 945 Max(0, old_generation_size_mb - old_generation_limit_mb));
958 } 946 }
959 947
960 SpaceIterator it(heap_);
961 while (it.has_next()) {
962 Space* space = it.next();
963 if (space == heap_->new_space()) {
964 space->RemoveAllocationObserver(&new_generation_observer_);
965 } else {
966 space->RemoveAllocationObserver(&old_generation_observer_);
967 }
968 }
969
970 IncrementalMarking::set_should_hurry(false); 948 IncrementalMarking::set_should_hurry(false);
971 if (IsMarking()) { 949 if (IsMarking()) {
972 PatchIncrementalMarkingRecordWriteStubs(heap_, 950 PatchIncrementalMarkingRecordWriteStubs(heap_,
973 RecordWriteStub::STORE_BUFFER_ONLY); 951 RecordWriteStub::STORE_BUFFER_ONLY);
974 DeactivateIncrementalWriteBarrier(); 952 DeactivateIncrementalWriteBarrier();
975 } 953 }
976 heap_->isolate()->stack_guard()->ClearGC(); 954 heap_->isolate()->stack_guard()->ClearGC();
977 state_ = STOPPED; 955 state_ = STOPPED;
978 is_compacting_ = false; 956 is_compacting_ = false;
979 FinishBlackAllocation(); 957 FinishBlackAllocation();
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
1078 double factor = Min(time_passed_ms / kRampUpIntervalMs, 1.0); 1056 double factor = Min(time_passed_ms / kRampUpIntervalMs, 1.0);
1079 return static_cast<size_t>(factor * step_size); 1057 return static_cast<size_t>(factor * step_size);
1080 } 1058 }
1081 1059
1082 void IncrementalMarking::AdvanceIncrementalMarkingOnAllocation() { 1060 void IncrementalMarking::AdvanceIncrementalMarkingOnAllocation() {
1083 if (heap_->gc_state() != Heap::NOT_IN_GC || !FLAG_incremental_marking || 1061 if (heap_->gc_state() != Heap::NOT_IN_GC || !FLAG_incremental_marking ||
1084 (state_ != SWEEPING && state_ != MARKING)) { 1062 (state_ != SWEEPING && state_ != MARKING)) {
1085 return; 1063 return;
1086 } 1064 }
1087 1065
1088 size_t bytes_to_process = 1066 size_t bytes_to_process = StepSizeToKeepUpWithAllocations();
1089 StepSizeToKeepUpWithAllocations() + StepSizeToMakeProgress();
1090 1067
1091 if (bytes_to_process >= IncrementalMarking::kAllocatedThreshold) { 1068 if (bytes_to_process < IncrementalMarking::kAllocatedThreshold) {
1092 // The first step after Scavenge will see many allocated bytes. 1069 return;
1093 // Cap the step size to distribute the marking work more uniformly. 1070 }
1094 size_t max_step_size = GCIdleTimeHandler::EstimateMarkingStepSize(
1095 kMaxStepSizeInMs,
1096 heap()->tracer()->IncrementalMarkingSpeedInBytesPerMillisecond());
1097 bytes_to_process = Min(bytes_to_process, max_step_size);
1098 1071
1099 size_t bytes_processed = 0; 1072 bytes_to_process += StepSizeToMakeProgress();
1100 if (bytes_marked_ahead_of_schedule_ >= bytes_to_process) { 1073
1101 // Steps performed in tasks have put us ahead of schedule. 1074 // The first step after Scavenge will see many allocated bytes.
1102 // We skip processing of marking dequeue here and thus 1075 // Cap the step size to distribute the marking work more uniformly.
1103 // shift marking time from inside V8 to standalone tasks. 1076 size_t max_step_size = GCIdleTimeHandler::EstimateMarkingStepSize(
1104 bytes_marked_ahead_of_schedule_ -= bytes_to_process; 1077 kMaxStepSizeInMs,
1105 bytes_processed = bytes_to_process; 1078 heap()->tracer()->IncrementalMarkingSpeedInBytesPerMillisecond());
1106 } else { 1079 bytes_to_process = Min(bytes_to_process, max_step_size);
1107 bytes_processed = Step(bytes_to_process, GC_VIA_STACK_GUARD, 1080
1108 FORCE_COMPLETION, StepOrigin::kV8); 1081 size_t bytes_processed = 0;
1109 } 1082 if (bytes_marked_ahead_of_schedule_ >= bytes_to_process) {
1110 bytes_allocated_ -= Min(bytes_allocated_, bytes_processed); 1083 // Steps performed in tasks have put us ahead of schedule.
1084 // We skip processing of marking dequeue here and thus
1085 // shift marking time from inside V8 to standalone tasks.
1086 bytes_marked_ahead_of_schedule_ -= bytes_to_process;
1087 bytes_processed = bytes_to_process;
1088 } else {
1089 bytes_processed = Step(bytes_to_process, GC_VIA_STACK_GUARD,
1090 FORCE_COMPLETION, StepOrigin::kV8);
1111 } 1091 }
1092 bytes_allocated_ -= Min(bytes_allocated_, bytes_processed);
1112 } 1093 }
1113 1094
1114 size_t IncrementalMarking::Step(size_t bytes_to_process, 1095 size_t IncrementalMarking::Step(size_t bytes_to_process,
1115 CompletionAction action, 1096 CompletionAction action,
1116 ForceCompletionAction completion, 1097 ForceCompletionAction completion,
1117 StepOrigin step_origin) { 1098 StepOrigin step_origin) {
1118 HistogramTimerScope incremental_marking_scope( 1099 HistogramTimerScope incremental_marking_scope(
1119 heap_->isolate()->counters()->gc_incremental_marking()); 1100 heap_->isolate()->counters()->gc_incremental_marking());
1120 TRACE_EVENT0("v8", "V8.GCIncrementalMarking"); 1101 TRACE_EVENT0("v8", "V8.GCIncrementalMarking");
1121 TRACE_GC(heap_->tracer(), GCTracer::Scope::MC_INCREMENTAL); 1102 TRACE_GC(heap_->tracer(), GCTracer::Scope::MC_INCREMENTAL);
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
1192 idle_marking_delay_counter_++; 1173 idle_marking_delay_counter_++;
1193 } 1174 }
1194 1175
1195 1176
1196 void IncrementalMarking::ClearIdleMarkingDelayCounter() { 1177 void IncrementalMarking::ClearIdleMarkingDelayCounter() {
1197 idle_marking_delay_counter_ = 0; 1178 idle_marking_delay_counter_ = 0;
1198 } 1179 }
1199 1180
1200 } // namespace internal 1181 } // namespace internal
1201 } // namespace v8 1182 } // namespace v8
OLDNEW
« no previous file with comments | « src/heap/incremental-marking.h ('k') | src/heap/spaces.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698