| 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" |
| 11 #include "src/base/utils/random-number-generator.h" | 11 #include "src/base/utils/random-number-generator.h" |
| 12 #include "src/bootstrapper.h" | 12 #include "src/bootstrapper.h" |
| 13 #include "src/codegen.h" | 13 #include "src/codegen.h" |
| 14 #include "src/compilation-cache.h" | 14 #include "src/compilation-cache.h" |
| 15 #include "src/conversions.h" | 15 #include "src/conversions.h" |
| 16 #include "src/cpu-profiler.h" | 16 #include "src/cpu-profiler.h" |
| 17 #include "src/debug/debug.h" | 17 #include "src/debug/debug.h" |
| 18 #include "src/deoptimizer.h" | 18 #include "src/deoptimizer.h" |
| 19 #include "src/global-handles.h" | 19 #include "src/global-handles.h" |
| 20 #include "src/heap/array-buffer-tracker.h" | 20 #include "src/heap/array-buffer-tracker.h" |
| 21 #include "src/heap/gc-idle-time-handler.h" | 21 #include "src/heap/gc-idle-time-handler.h" |
| 22 #include "src/heap/gc-tracer.h" | 22 #include "src/heap/gc-tracer.h" |
| 23 #include "src/heap/incremental-marking.h" | 23 #include "src/heap/incremental-marking.h" |
| 24 #include "src/heap/mark-compact-inl.h" | 24 #include "src/heap/mark-compact-inl.h" |
| 25 #include "src/heap/mark-compact.h" | 25 #include "src/heap/mark-compact.h" |
| 26 #include "src/heap/memory-reducer.h" | 26 #include "src/heap/memory-reducer.h" |
| 27 #include "src/heap/object-stats.h" | 27 #include "src/heap/object-stats.h" |
| 28 #include "src/heap/objects-visiting-inl.h" | 28 #include "src/heap/objects-visiting-inl.h" |
| 29 #include "src/heap/objects-visiting.h" | 29 #include "src/heap/objects-visiting.h" |
| 30 #include "src/heap/scavenge-job.h" |
| 30 #include "src/heap/scavenger-inl.h" | 31 #include "src/heap/scavenger-inl.h" |
| 31 #include "src/heap/store-buffer.h" | 32 #include "src/heap/store-buffer.h" |
| 32 #include "src/heap-profiler.h" | 33 #include "src/heap-profiler.h" |
| 33 #include "src/interpreter/interpreter.h" | 34 #include "src/interpreter/interpreter.h" |
| 34 #include "src/runtime-profiler.h" | 35 #include "src/runtime-profiler.h" |
| 35 #include "src/scopeinfo.h" | 36 #include "src/scopeinfo.h" |
| 36 #include "src/snapshot/natives.h" | 37 #include "src/snapshot/natives.h" |
| 37 #include "src/snapshot/serialize.h" | 38 #include "src/snapshot/serialize.h" |
| 38 #include "src/snapshot/snapshot.h" | 39 #include "src/snapshot/snapshot.h" |
| 39 #include "src/type-feedback-vector.h" | 40 #include "src/type-feedback-vector.h" |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 sweeping_time_(0.0), | 122 sweeping_time_(0.0), |
| 122 last_idle_notification_time_(0.0), | 123 last_idle_notification_time_(0.0), |
| 123 last_gc_time_(0.0), | 124 last_gc_time_(0.0), |
| 124 scavenge_collector_(nullptr), | 125 scavenge_collector_(nullptr), |
| 125 mark_compact_collector_(this), | 126 mark_compact_collector_(this), |
| 126 store_buffer_(this), | 127 store_buffer_(this), |
| 127 incremental_marking_(this), | 128 incremental_marking_(this), |
| 128 gc_idle_time_handler_(nullptr), | 129 gc_idle_time_handler_(nullptr), |
| 129 memory_reducer_(nullptr), | 130 memory_reducer_(nullptr), |
| 130 object_stats_(nullptr), | 131 object_stats_(nullptr), |
| 132 scavenge_job_(nullptr), |
| 131 full_codegen_bytes_generated_(0), | 133 full_codegen_bytes_generated_(0), |
| 132 crankshaft_codegen_bytes_generated_(0), | 134 crankshaft_codegen_bytes_generated_(0), |
| 133 new_space_allocation_counter_(0), | 135 new_space_allocation_counter_(0), |
| 134 old_generation_allocation_counter_(0), | 136 old_generation_allocation_counter_(0), |
| 135 old_generation_size_at_last_gc_(0), | 137 old_generation_size_at_last_gc_(0), |
| 136 gcs_since_last_deopt_(0), | 138 gcs_since_last_deopt_(0), |
| 137 allocation_sites_scratchpad_length_(0), | 139 allocation_sites_scratchpad_length_(0), |
| 138 ring_buffer_full_(false), | 140 ring_buffer_full_(false), |
| 139 ring_buffer_end_(0), | 141 ring_buffer_end_(0), |
| 140 promotion_queue_(this), | 142 promotion_queue_(this), |
| (...skipping 632 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 773 current_gc_callback_flags_); | 775 current_gc_callback_flags_); |
| 774 return; | 776 return; |
| 775 } | 777 } |
| 776 DCHECK(FLAG_overapproximate_weak_closure); | 778 DCHECK(FLAG_overapproximate_weak_closure); |
| 777 if (!incremental_marking()->weak_closure_was_overapproximated()) { | 779 if (!incremental_marking()->weak_closure_was_overapproximated()) { |
| 778 OverApproximateWeakClosure("GC interrupt"); | 780 OverApproximateWeakClosure("GC interrupt"); |
| 779 } | 781 } |
| 780 } | 782 } |
| 781 | 783 |
| 782 | 784 |
| 785 void Heap::ScheduleIdleScavengeIfNeeded(int bytes_allocated) { |
| 786 scavenge_job_->ScheduleIdleTaskIfNeeded(this, bytes_allocated); |
| 787 } |
| 788 |
| 789 |
| 783 void Heap::OverApproximateWeakClosure(const char* gc_reason) { | 790 void Heap::OverApproximateWeakClosure(const char* gc_reason) { |
| 784 if (FLAG_trace_incremental_marking) { | 791 if (FLAG_trace_incremental_marking) { |
| 785 PrintF("[IncrementalMarking] Overapproximate weak closure (%s).\n", | 792 PrintF("[IncrementalMarking] Overapproximate weak closure (%s).\n", |
| 786 gc_reason); | 793 gc_reason); |
| 787 } | 794 } |
| 788 | 795 |
| 789 GCTracer::Scope gc_scope(tracer(), | 796 GCTracer::Scope gc_scope(tracer(), |
| 790 GCTracer::Scope::MC_INCREMENTAL_WEAKCLOSURE); | 797 GCTracer::Scope::MC_INCREMENTAL_WEAKCLOSURE); |
| 791 | 798 |
| 792 { | 799 { |
| (...skipping 3298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4091 | 4098 |
| 4092 | 4099 |
| 4093 GCIdleTimeHeapState Heap::ComputeHeapState() { | 4100 GCIdleTimeHeapState Heap::ComputeHeapState() { |
| 4094 GCIdleTimeHeapState heap_state; | 4101 GCIdleTimeHeapState heap_state; |
| 4095 heap_state.contexts_disposed = contexts_disposed_; | 4102 heap_state.contexts_disposed = contexts_disposed_; |
| 4096 heap_state.contexts_disposal_rate = | 4103 heap_state.contexts_disposal_rate = |
| 4097 tracer()->ContextDisposalRateInMilliseconds(); | 4104 tracer()->ContextDisposalRateInMilliseconds(); |
| 4098 heap_state.incremental_marking_stopped = incremental_marking()->IsStopped(); | 4105 heap_state.incremental_marking_stopped = incremental_marking()->IsStopped(); |
| 4099 heap_state.mark_compact_speed_in_bytes_per_ms = | 4106 heap_state.mark_compact_speed_in_bytes_per_ms = |
| 4100 static_cast<size_t>(tracer()->MarkCompactSpeedInBytesPerMillisecond()); | 4107 static_cast<size_t>(tracer()->MarkCompactSpeedInBytesPerMillisecond()); |
| 4101 heap_state.scavenge_speed_in_bytes_per_ms = | |
| 4102 static_cast<size_t>(tracer()->ScavengeSpeedInBytesPerMillisecond()); | |
| 4103 heap_state.used_new_space_size = new_space_.Size(); | |
| 4104 heap_state.new_space_capacity = new_space_.Capacity(); | |
| 4105 heap_state.new_space_allocation_throughput_in_bytes_per_ms = | |
| 4106 tracer()->NewSpaceAllocationThroughputInBytesPerMillisecond(); | |
| 4107 return heap_state; | 4108 return heap_state; |
| 4108 } | 4109 } |
| 4109 | 4110 |
| 4110 | 4111 |
| 4111 double Heap::AdvanceIncrementalMarking( | 4112 double Heap::AdvanceIncrementalMarking( |
| 4112 intptr_t step_size_in_bytes, double deadline_in_ms, | 4113 intptr_t step_size_in_bytes, double deadline_in_ms, |
| 4113 IncrementalMarking::StepActions step_actions) { | 4114 IncrementalMarking::StepActions step_actions) { |
| 4114 DCHECK(!incremental_marking()->IsStopped()); | 4115 DCHECK(!incremental_marking()->IsStopped()); |
| 4115 | 4116 |
| 4116 if (step_size_in_bytes == 0) { | 4117 if (step_size_in_bytes == 0) { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4153 IncrementalMarkingJob::IdleTask::kDone; | 4154 IncrementalMarkingJob::IdleTask::kDone; |
| 4154 } | 4155 } |
| 4155 break; | 4156 break; |
| 4156 } | 4157 } |
| 4157 case DO_FULL_GC: { | 4158 case DO_FULL_GC: { |
| 4158 DCHECK(contexts_disposed_ > 0); | 4159 DCHECK(contexts_disposed_ > 0); |
| 4159 HistogramTimerScope scope(isolate_->counters()->gc_context()); | 4160 HistogramTimerScope scope(isolate_->counters()->gc_context()); |
| 4160 CollectAllGarbage(kNoGCFlags, "idle notification: contexts disposed"); | 4161 CollectAllGarbage(kNoGCFlags, "idle notification: contexts disposed"); |
| 4161 break; | 4162 break; |
| 4162 } | 4163 } |
| 4163 case DO_SCAVENGE: | |
| 4164 CollectGarbage(NEW_SPACE, "idle notification: scavenge"); | |
| 4165 break; | |
| 4166 case DO_NOTHING: | 4164 case DO_NOTHING: |
| 4167 break; | 4165 break; |
| 4168 } | 4166 } |
| 4169 | 4167 |
| 4170 return result; | 4168 return result; |
| 4171 } | 4169 } |
| 4172 | 4170 |
| 4173 | 4171 |
| 4174 void Heap::IdleNotificationEpilogue(GCIdleTimeAction action, | 4172 void Heap::IdleNotificationEpilogue(GCIdleTimeAction action, |
| 4175 GCIdleTimeHeapState heap_state, | 4173 GCIdleTimeHeapState heap_state, |
| (...skipping 806 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4982 | 4980 |
| 4983 // Update inline allocation limit for old spaces. | 4981 // Update inline allocation limit for old spaces. |
| 4984 PagedSpaces spaces(this); | 4982 PagedSpaces spaces(this); |
| 4985 for (PagedSpace* space = spaces.next(); space != NULL; | 4983 for (PagedSpace* space = spaces.next(); space != NULL; |
| 4986 space = spaces.next()) { | 4984 space = spaces.next()) { |
| 4987 space->EmptyAllocationInfo(); | 4985 space->EmptyAllocationInfo(); |
| 4988 } | 4986 } |
| 4989 } | 4987 } |
| 4990 | 4988 |
| 4991 | 4989 |
| 4990 void Heap::LowerInlineAllocationLimit(intptr_t step) { |
| 4991 new_space()->LowerInlineAllocationLimit(step); |
| 4992 } |
| 4993 |
| 4994 |
| 4995 void Heap::ResetInlineAllocationLimit() { |
| 4996 new_space()->LowerInlineAllocationLimit( |
| 4997 ScavengeJob::kBytesAllocatedBeforeNextIdleTask); |
| 4998 } |
| 4999 |
| 5000 |
| 4992 V8_DECLARE_ONCE(initialize_gc_once); | 5001 V8_DECLARE_ONCE(initialize_gc_once); |
| 4993 | 5002 |
| 4994 static void InitializeGCOnce() { | 5003 static void InitializeGCOnce() { |
| 4995 Scavenger::Initialize(); | 5004 Scavenger::Initialize(); |
| 4996 StaticScavengeVisitor::Initialize(); | 5005 StaticScavengeVisitor::Initialize(); |
| 4997 MarkCompactCollector::Initialize(); | 5006 MarkCompactCollector::Initialize(); |
| 4998 } | 5007 } |
| 4999 | 5008 |
| 5000 | 5009 |
| 5001 bool Heap::SetUp() { | 5010 bool Heap::SetUp() { |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5074 | 5083 |
| 5075 scavenge_collector_ = new Scavenger(this); | 5084 scavenge_collector_ = new Scavenger(this); |
| 5076 | 5085 |
| 5077 gc_idle_time_handler_ = new GCIdleTimeHandler(); | 5086 gc_idle_time_handler_ = new GCIdleTimeHandler(); |
| 5078 | 5087 |
| 5079 memory_reducer_ = new MemoryReducer(this); | 5088 memory_reducer_ = new MemoryReducer(this); |
| 5080 | 5089 |
| 5081 object_stats_ = new ObjectStats(this); | 5090 object_stats_ = new ObjectStats(this); |
| 5082 object_stats_->ClearObjectStats(true); | 5091 object_stats_->ClearObjectStats(true); |
| 5083 | 5092 |
| 5093 scavenge_job_ = new ScavengeJob(); |
| 5094 |
| 5084 array_buffer_tracker_ = new ArrayBufferTracker(this); | 5095 array_buffer_tracker_ = new ArrayBufferTracker(this); |
| 5085 | 5096 |
| 5086 LOG(isolate_, IntPtrTEvent("heap-capacity", Capacity())); | 5097 LOG(isolate_, IntPtrTEvent("heap-capacity", Capacity())); |
| 5087 LOG(isolate_, IntPtrTEvent("heap-available", Available())); | 5098 LOG(isolate_, IntPtrTEvent("heap-available", Available())); |
| 5088 | 5099 |
| 5089 store_buffer()->SetUp(); | 5100 store_buffer()->SetUp(); |
| 5090 | 5101 |
| 5091 mark_compact_collector()->SetUp(); | 5102 mark_compact_collector()->SetUp(); |
| 5092 | 5103 |
| 5104 ResetInlineAllocationLimit(); |
| 5105 |
| 5093 return true; | 5106 return true; |
| 5094 } | 5107 } |
| 5095 | 5108 |
| 5096 | 5109 |
| 5097 bool Heap::CreateHeapObjects() { | 5110 bool Heap::CreateHeapObjects() { |
| 5098 // Create initial maps. | 5111 // Create initial maps. |
| 5099 if (!CreateInitialMaps()) return false; | 5112 if (!CreateInitialMaps()) return false; |
| 5100 CreateApiObjects(); | 5113 CreateApiObjects(); |
| 5101 | 5114 |
| 5102 // Create initial objects | 5115 // Create initial objects |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5195 | 5208 |
| 5196 if (memory_reducer_ != nullptr) { | 5209 if (memory_reducer_ != nullptr) { |
| 5197 memory_reducer_->TearDown(); | 5210 memory_reducer_->TearDown(); |
| 5198 delete memory_reducer_; | 5211 delete memory_reducer_; |
| 5199 memory_reducer_ = nullptr; | 5212 memory_reducer_ = nullptr; |
| 5200 } | 5213 } |
| 5201 | 5214 |
| 5202 delete object_stats_; | 5215 delete object_stats_; |
| 5203 object_stats_ = nullptr; | 5216 object_stats_ = nullptr; |
| 5204 | 5217 |
| 5218 delete scavenge_job_; |
| 5219 scavenge_job_ = nullptr; |
| 5220 |
| 5205 WaitUntilUnmappingOfFreeChunksCompleted(); | 5221 WaitUntilUnmappingOfFreeChunksCompleted(); |
| 5206 | 5222 |
| 5207 delete array_buffer_tracker_; | 5223 delete array_buffer_tracker_; |
| 5208 array_buffer_tracker_ = nullptr; | 5224 array_buffer_tracker_ = nullptr; |
| 5209 | 5225 |
| 5210 isolate_->global_handles()->TearDown(); | 5226 isolate_->global_handles()->TearDown(); |
| 5211 | 5227 |
| 5212 external_string_table_.TearDown(); | 5228 external_string_table_.TearDown(); |
| 5213 | 5229 |
| 5214 mark_compact_collector()->TearDown(); | 5230 mark_compact_collector()->TearDown(); |
| (...skipping 893 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6108 } | 6124 } |
| 6109 | 6125 |
| 6110 | 6126 |
| 6111 // static | 6127 // static |
| 6112 int Heap::GetStaticVisitorIdForMap(Map* map) { | 6128 int Heap::GetStaticVisitorIdForMap(Map* map) { |
| 6113 return StaticVisitorBase::GetVisitorId(map); | 6129 return StaticVisitorBase::GetVisitorId(map); |
| 6114 } | 6130 } |
| 6115 | 6131 |
| 6116 } // namespace internal | 6132 } // namespace internal |
| 6117 } // namespace v8 | 6133 } // namespace v8 |
| OLD | NEW |