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

Side by Side Diff: src/heap/heap.cc

Issue 1366183003: [heap] No leakage of mark-compact.h outside of heap. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 2 months 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/heap.h ('k') | src/heap/incremental-marking.h » ('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/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
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_(this), 127 incremental_marking_(this),
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 full_codegen_bytes_generated_(0), 131 full_codegen_bytes_generated_(0),
132 crankshaft_codegen_bytes_generated_(0), 132 crankshaft_codegen_bytes_generated_(0),
133 new_space_allocation_counter_(0), 133 new_space_allocation_counter_(0),
134 old_generation_allocation_counter_(0), 134 old_generation_allocation_counter_(0),
135 old_generation_size_at_last_gc_(0), 135 old_generation_size_at_last_gc_(0),
(...skipping 766 matching lines...) Expand 10 before | Expand all | Expand 10 after
902 } 902 }
903 903
904 if (collector == MARK_COMPACTOR && !ShouldFinalizeIncrementalMarking() && 904 if (collector == MARK_COMPACTOR && !ShouldFinalizeIncrementalMarking() &&
905 !ShouldAbortIncrementalMarking() && !incremental_marking()->IsStopped() && 905 !ShouldAbortIncrementalMarking() && !incremental_marking()->IsStopped() &&
906 !incremental_marking()->should_hurry() && FLAG_incremental_marking) { 906 !incremental_marking()->should_hurry() && FLAG_incremental_marking) {
907 // Make progress in incremental marking. 907 // Make progress in incremental marking.
908 const intptr_t kStepSizeWhenDelayedByScavenge = 1 * MB; 908 const intptr_t kStepSizeWhenDelayedByScavenge = 1 * MB;
909 incremental_marking()->Step(kStepSizeWhenDelayedByScavenge, 909 incremental_marking()->Step(kStepSizeWhenDelayedByScavenge,
910 IncrementalMarking::NO_GC_VIA_STACK_GUARD); 910 IncrementalMarking::NO_GC_VIA_STACK_GUARD);
911 if (!incremental_marking()->IsComplete() && 911 if (!incremental_marking()->IsComplete() &&
912 !mark_compact_collector_.marking_deque_.IsEmpty() && !FLAG_gc_global) { 912 !mark_compact_collector()->marking_deque_.IsEmpty() &&
913 !FLAG_gc_global) {
913 if (FLAG_trace_incremental_marking) { 914 if (FLAG_trace_incremental_marking) {
914 PrintF("[IncrementalMarking] Delaying MarkSweep.\n"); 915 PrintF("[IncrementalMarking] Delaying MarkSweep.\n");
915 } 916 }
916 collector = SCAVENGER; 917 collector = SCAVENGER;
917 collector_reason = "incremental marking delaying mark-sweep"; 918 collector_reason = "incremental marking delaying mark-sweep";
918 } 919 }
919 } 920 }
920 921
921 bool next_gc_likely_to_collect_more = false; 922 bool next_gc_likely_to_collect_more = false;
922 intptr_t committed_memory_before = 0; 923 intptr_t committed_memory_before = 0;
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
1243 1244
1244 isolate_->counters()->objs_since_last_young()->Set(0); 1245 isolate_->counters()->objs_since_last_young()->Set(0);
1245 1246
1246 if (collector != SCAVENGER) { 1247 if (collector != SCAVENGER) {
1247 // Callbacks that fire after this point might trigger nested GCs and 1248 // Callbacks that fire after this point might trigger nested GCs and
1248 // restart incremental marking, the assertion can't be moved down. 1249 // restart incremental marking, the assertion can't be moved down.
1249 DCHECK(incremental_marking()->IsStopped()); 1250 DCHECK(incremental_marking()->IsStopped());
1250 1251
1251 // We finished a marking cycle. We can uncommit the marking deque until 1252 // We finished a marking cycle. We can uncommit the marking deque until
1252 // we start marking again. 1253 // we start marking again.
1253 mark_compact_collector_.marking_deque()->Uninitialize(); 1254 mark_compact_collector()->marking_deque()->Uninitialize();
1254 mark_compact_collector_.EnsureMarkingDequeIsCommitted( 1255 mark_compact_collector()->EnsureMarkingDequeIsCommitted(
1255 MarkCompactCollector::kMinMarkingDequeSize); 1256 MarkCompactCollector::kMinMarkingDequeSize);
1256 } 1257 }
1257 1258
1258 gc_post_processing_depth_++; 1259 gc_post_processing_depth_++;
1259 { 1260 {
1260 AllowHeapAllocation allow_allocation; 1261 AllowHeapAllocation allow_allocation;
1261 GCTracer::Scope scope(tracer(), GCTracer::Scope::EXTERNAL); 1262 GCTracer::Scope scope(tracer(), GCTracer::Scope::EXTERNAL);
1262 freed_global_handles = 1263 freed_global_handles =
1263 isolate_->global_handles()->PostGarbageCollectionProcessing( 1264 isolate_->global_handles()->PostGarbageCollectionProcessing(
1264 collector, gc_callback_flags); 1265 collector, gc_callback_flags);
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
1338 } 1339 }
1339 } 1340 }
1340 1341
1341 1342
1342 void Heap::MarkCompact() { 1343 void Heap::MarkCompact() {
1343 gc_state_ = MARK_COMPACT; 1344 gc_state_ = MARK_COMPACT;
1344 LOG(isolate_, ResourceEvent("markcompact", "begin")); 1345 LOG(isolate_, ResourceEvent("markcompact", "begin"));
1345 1346
1346 uint64_t size_of_objects_before_gc = SizeOfObjects(); 1347 uint64_t size_of_objects_before_gc = SizeOfObjects();
1347 1348
1348 mark_compact_collector_.Prepare(); 1349 mark_compact_collector()->Prepare();
1349 1350
1350 ms_count_++; 1351 ms_count_++;
1351 1352
1352 MarkCompactPrologue(); 1353 MarkCompactPrologue();
1353 1354
1354 mark_compact_collector_.CollectGarbage(); 1355 mark_compact_collector()->CollectGarbage();
1355 1356
1356 LOG(isolate_, ResourceEvent("markcompact", "end")); 1357 LOG(isolate_, ResourceEvent("markcompact", "end"));
1357 1358
1358 MarkCompactEpilogue(); 1359 MarkCompactEpilogue();
1359 1360
1360 if (FLAG_allocation_site_pretenuring) { 1361 if (FLAG_allocation_site_pretenuring) {
1361 EvaluateOldSpaceLocalPretenuring(size_of_objects_before_gc); 1362 EvaluateOldSpaceLocalPretenuring(size_of_objects_before_gc);
1362 } 1363 }
1363 } 1364 }
1364 1365
(...skipping 2682 matching lines...) Expand 10 before | Expand all | Expand 10 after
4047 new_space_.Shrink(); 4048 new_space_.Shrink();
4048 UncommitFromSpace(); 4049 UncommitFromSpace();
4049 } 4050 }
4050 } 4051 }
4051 4052
4052 4053
4053 void Heap::FinalizeIncrementalMarkingIfComplete(const char* comment) { 4054 void Heap::FinalizeIncrementalMarkingIfComplete(const char* comment) {
4054 if (FLAG_overapproximate_weak_closure && incremental_marking()->IsMarking() && 4055 if (FLAG_overapproximate_weak_closure && incremental_marking()->IsMarking() &&
4055 (incremental_marking()->IsReadyToOverApproximateWeakClosure() || 4056 (incremental_marking()->IsReadyToOverApproximateWeakClosure() ||
4056 (!incremental_marking()->weak_closure_was_overapproximated() && 4057 (!incremental_marking()->weak_closure_was_overapproximated() &&
4057 mark_compact_collector_.marking_deque()->IsEmpty()))) { 4058 mark_compact_collector()->marking_deque()->IsEmpty()))) {
4058 OverApproximateWeakClosure(comment); 4059 OverApproximateWeakClosure(comment);
4059 } else if (incremental_marking()->IsComplete() || 4060 } else if (incremental_marking()->IsComplete() ||
4060 (mark_compact_collector_.marking_deque()->IsEmpty())) { 4061 (mark_compact_collector()->marking_deque()->IsEmpty())) {
4061 CollectAllGarbage(current_gc_flags_, comment); 4062 CollectAllGarbage(current_gc_flags_, comment);
4062 } 4063 }
4063 } 4064 }
4064 4065
4065 4066
4066 bool Heap::TryFinalizeIdleIncrementalMarking(double idle_time_in_ms) { 4067 bool Heap::TryFinalizeIdleIncrementalMarking(double idle_time_in_ms) {
4067 size_t size_of_objects = static_cast<size_t>(SizeOfObjects()); 4068 size_t size_of_objects = static_cast<size_t>(SizeOfObjects());
4068 size_t final_incremental_mark_compact_speed_in_bytes_per_ms = 4069 size_t final_incremental_mark_compact_speed_in_bytes_per_ms =
4069 static_cast<size_t>( 4070 static_cast<size_t>(
4070 tracer()->FinalIncrementalMarkCompactSpeedInBytesPerMillisecond()); 4071 tracer()->FinalIncrementalMarkCompactSpeedInBytesPerMillisecond());
4071 if (FLAG_overapproximate_weak_closure && 4072 if (FLAG_overapproximate_weak_closure &&
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 gc_idle_time_handler_->ShouldDoOverApproximateWeakClosure( 4076 gc_idle_time_handler_->ShouldDoOverApproximateWeakClosure(
4076 static_cast<size_t>(idle_time_in_ms))))) { 4077 static_cast<size_t>(idle_time_in_ms))))) {
4077 OverApproximateWeakClosure( 4078 OverApproximateWeakClosure(
4078 "Idle notification: overapproximate weak closure"); 4079 "Idle notification: overapproximate weak closure");
4079 return true; 4080 return true;
4080 } else if (incremental_marking()->IsComplete() || 4081 } else if (incremental_marking()->IsComplete() ||
4081 (mark_compact_collector_.marking_deque()->IsEmpty() && 4082 (mark_compact_collector()->marking_deque()->IsEmpty() &&
4082 gc_idle_time_handler_->ShouldDoFinalIncrementalMarkCompact( 4083 gc_idle_time_handler_->ShouldDoFinalIncrementalMarkCompact(
4083 static_cast<size_t>(idle_time_in_ms), size_of_objects, 4084 static_cast<size_t>(idle_time_in_ms), size_of_objects,
4084 final_incremental_mark_compact_speed_in_bytes_per_ms))) { 4085 final_incremental_mark_compact_speed_in_bytes_per_ms))) {
4085 CollectAllGarbage(current_gc_flags_, 4086 CollectAllGarbage(current_gc_flags_,
4086 "idle notification: finalize incremental"); 4087 "idle notification: finalize incremental");
4087 return true; 4088 return true;
4088 } 4089 }
4089 return false; 4090 return false;
4090 } 4091 }
4091 4092
(...skipping 30 matching lines...) Expand all
4122 4123
4123 double remaining_time_in_ms = 0.0; 4124 double remaining_time_in_ms = 0.0;
4124 do { 4125 do {
4125 incremental_marking()->Step( 4126 incremental_marking()->Step(
4126 step_size_in_bytes, step_actions.completion_action, 4127 step_size_in_bytes, step_actions.completion_action,
4127 step_actions.force_marking, step_actions.force_completion); 4128 step_actions.force_marking, step_actions.force_completion);
4128 remaining_time_in_ms = deadline_in_ms - MonotonicallyIncreasingTimeInMs(); 4129 remaining_time_in_ms = deadline_in_ms - MonotonicallyIncreasingTimeInMs();
4129 } while (remaining_time_in_ms >= 4130 } while (remaining_time_in_ms >=
4130 2.0 * GCIdleTimeHandler::kIncrementalMarkingStepTimeInMs && 4131 2.0 * GCIdleTimeHandler::kIncrementalMarkingStepTimeInMs &&
4131 !incremental_marking()->IsComplete() && 4132 !incremental_marking()->IsComplete() &&
4132 !mark_compact_collector_.marking_deque()->IsEmpty()); 4133 !mark_compact_collector()->marking_deque()->IsEmpty());
4133 return remaining_time_in_ms; 4134 return remaining_time_in_ms;
4134 } 4135 }
4135 4136
4136 4137
4137 bool Heap::PerformIdleTimeAction(GCIdleTimeAction action, 4138 bool Heap::PerformIdleTimeAction(GCIdleTimeAction action,
4138 GCIdleTimeHeapState heap_state, 4139 GCIdleTimeHeapState heap_state,
4139 double deadline_in_ms) { 4140 double deadline_in_ms) {
4140 bool result = false; 4141 bool result = false;
4141 switch (action.type) { 4142 switch (action.type) {
4142 case DONE: 4143 case DONE:
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
4429 new_space_.Verify(); 4430 new_space_.Verify();
4430 4431
4431 old_space_->Verify(&visitor); 4432 old_space_->Verify(&visitor);
4432 map_space_->Verify(&visitor); 4433 map_space_->Verify(&visitor);
4433 4434
4434 VerifyPointersVisitor no_dirty_regions_visitor; 4435 VerifyPointersVisitor no_dirty_regions_visitor;
4435 code_space_->Verify(&no_dirty_regions_visitor); 4436 code_space_->Verify(&no_dirty_regions_visitor);
4436 4437
4437 lo_space_->Verify(); 4438 lo_space_->Verify();
4438 4439
4439 mark_compact_collector_.VerifyWeakEmbeddedObjectsInCode(); 4440 mark_compact_collector()->VerifyWeakEmbeddedObjectsInCode();
4440 if (FLAG_omit_map_checks_for_leaf_maps) { 4441 if (FLAG_omit_map_checks_for_leaf_maps) {
4441 mark_compact_collector_.VerifyOmittedMapChecks(); 4442 mark_compact_collector()->VerifyOmittedMapChecks();
4442 } 4443 }
4443 } 4444 }
4444 #endif 4445 #endif
4445 4446
4446 4447
4447 void Heap::ZapFromSpace() { 4448 void Heap::ZapFromSpace() {
4448 if (!new_space_.IsFromSpaceCommitted()) return; 4449 if (!new_space_.IsFromSpaceCommitted()) return;
4449 NewSpacePageIterator it(new_space_.FromSpaceStart(), 4450 NewSpacePageIterator it(new_space_.FromSpaceStart(),
4450 new_space_.FromSpaceEnd()); 4451 new_space_.FromSpaceEnd());
4451 while (it.has_next()) { 4452 while (it.has_next()) {
(...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after
5067 5068
5068 for (int i = 0; i < static_cast<int>(v8::Isolate::kUseCounterFeatureCount); 5069 for (int i = 0; i < static_cast<int>(v8::Isolate::kUseCounterFeatureCount);
5069 i++) { 5070 i++) {
5070 deferred_counters_[i] = 0; 5071 deferred_counters_[i] = 0;
5071 } 5072 }
5072 5073
5073 tracer_ = new GCTracer(this); 5074 tracer_ = new GCTracer(this);
5074 5075
5075 scavenge_collector_ = new Scavenger(this); 5076 scavenge_collector_ = new Scavenger(this);
5076 5077
5078 mark_compact_collector_ = new MarkCompactCollector(this);
5079
5077 gc_idle_time_handler_ = new GCIdleTimeHandler(); 5080 gc_idle_time_handler_ = new GCIdleTimeHandler();
5078 5081
5079 memory_reducer_ = new MemoryReducer(this); 5082 memory_reducer_ = new MemoryReducer(this);
5080 5083
5081 object_stats_ = new ObjectStats(this); 5084 object_stats_ = new ObjectStats(this);
5082 object_stats_->ClearObjectStats(true); 5085 object_stats_->ClearObjectStats(true);
5083 5086
5084 array_buffer_tracker_ = new ArrayBufferTracker(this); 5087 array_buffer_tracker_ = new ArrayBufferTracker(this);
5085 5088
5086 LOG(isolate_, IntPtrTEvent("heap-capacity", Capacity())); 5089 LOG(isolate_, IntPtrTEvent("heap-capacity", Capacity()));
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
5183 PrintF("\n\n"); 5186 PrintF("\n\n");
5184 } 5187 }
5185 5188
5186 if (FLAG_verify_predictable) { 5189 if (FLAG_verify_predictable) {
5187 PrintAlloctionsHash(); 5190 PrintAlloctionsHash();
5188 } 5191 }
5189 5192
5190 delete scavenge_collector_; 5193 delete scavenge_collector_;
5191 scavenge_collector_ = nullptr; 5194 scavenge_collector_ = nullptr;
5192 5195
5196 if (mark_compact_collector_ != nullptr) {
5197 mark_compact_collector_->TearDown();
5198 delete mark_compact_collector_;
5199 mark_compact_collector_ = nullptr;
5200 }
5201
5193 delete gc_idle_time_handler_; 5202 delete gc_idle_time_handler_;
5194 gc_idle_time_handler_ = nullptr; 5203 gc_idle_time_handler_ = nullptr;
5195 5204
5196 if (memory_reducer_ != nullptr) { 5205 if (memory_reducer_ != nullptr) {
5197 memory_reducer_->TearDown(); 5206 memory_reducer_->TearDown();
5198 delete memory_reducer_; 5207 delete memory_reducer_;
5199 memory_reducer_ = nullptr; 5208 memory_reducer_ = nullptr;
5200 } 5209 }
5201 5210
5202 delete object_stats_; 5211 delete object_stats_;
5203 object_stats_ = nullptr; 5212 object_stats_ = nullptr;
5204 5213
5205 WaitUntilUnmappingOfFreeChunksCompleted(); 5214 WaitUntilUnmappingOfFreeChunksCompleted();
5206 5215
5207 delete array_buffer_tracker_; 5216 delete array_buffer_tracker_;
5208 array_buffer_tracker_ = nullptr; 5217 array_buffer_tracker_ = nullptr;
5209 5218
5210 isolate_->global_handles()->TearDown(); 5219 isolate_->global_handles()->TearDown();
5211 5220
5212 external_string_table_.TearDown(); 5221 external_string_table_.TearDown();
5213 5222
5214 mark_compact_collector()->TearDown();
5215
5216 delete tracer_; 5223 delete tracer_;
5217 tracer_ = nullptr; 5224 tracer_ = nullptr;
5218 5225
5219 new_space_.TearDown(); 5226 new_space_.TearDown();
5220 5227
5221 if (old_space_ != NULL) { 5228 if (old_space_ != NULL) {
5222 delete old_space_; 5229 delete old_space_;
5223 old_space_ = NULL; 5230 old_space_ = NULL;
5224 } 5231 }
5225 5232
(...skipping 882 matching lines...) Expand 10 before | Expand all | Expand 10 after
6108 } 6115 }
6109 6116
6110 6117
6111 // static 6118 // static
6112 int Heap::GetStaticVisitorIdForMap(Map* map) { 6119 int Heap::GetStaticVisitorIdForMap(Map* map) {
6113 return StaticVisitorBase::GetVisitorId(map); 6120 return StaticVisitorBase::GetVisitorId(map);
6114 } 6121 }
6115 6122
6116 } // namespace internal 6123 } // namespace internal
6117 } // namespace v8 6124 } // namespace v8
OLDNEW
« no previous file with comments | « src/heap/heap.h ('k') | src/heap/incremental-marking.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698