| 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 namespace v8 { | 45 namespace v8 { |
| 46 namespace internal { | 46 namespace internal { |
| 47 | 47 |
| 48 | 48 |
| 49 struct Heap::StrongRootsList { | 49 struct Heap::StrongRootsList { |
| 50 Object** start; | 50 Object** start; |
| 51 Object** end; | 51 Object** end; |
| 52 StrongRootsList* next; | 52 StrongRootsList* next; |
| 53 }; | 53 }; |
| 54 | 54 |
| 55 class IdleScavengeObserver : public InlineAllocationObserver { |
| 56 public: |
| 57 IdleScavengeObserver(Heap& heap, intptr_t step_size) |
| 58 : InlineAllocationObserver(step_size), heap_(heap) {} |
| 59 |
| 60 virtual void Step(int bytes_allocated) { |
| 61 heap_.ScheduleIdleScavengeIfNeeded(bytes_allocated); |
| 62 } |
| 63 |
| 64 private: |
| 65 Heap& heap_; |
| 66 }; |
| 67 |
| 55 | 68 |
| 56 Heap::Heap() | 69 Heap::Heap() |
| 57 : amount_of_external_allocated_memory_(0), | 70 : amount_of_external_allocated_memory_(0), |
| 58 amount_of_external_allocated_memory_at_last_global_gc_(0), | 71 amount_of_external_allocated_memory_at_last_global_gc_(0), |
| 59 isolate_(NULL), | 72 isolate_(NULL), |
| 60 code_range_size_(0), | 73 code_range_size_(0), |
| 61 // semispace_size_ should be a power of 2 and old_generation_size_ should | 74 // semispace_size_ should be a power of 2 and old_generation_size_ should |
| 62 // be a multiple of Page::kPageSize. | 75 // be a multiple of Page::kPageSize. |
| 63 reserved_semispace_size_(8 * (kPointerSize / 4) * MB), | 76 reserved_semispace_size_(8 * (kPointerSize / 4) * MB), |
| 64 max_semi_space_size_(8 * (kPointerSize / 4) * MB), | 77 max_semi_space_size_(8 * (kPointerSize / 4) * MB), |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 last_idle_notification_time_(0.0), | 135 last_idle_notification_time_(0.0), |
| 123 last_gc_time_(0.0), | 136 last_gc_time_(0.0), |
| 124 scavenge_collector_(nullptr), | 137 scavenge_collector_(nullptr), |
| 125 mark_compact_collector_(nullptr), | 138 mark_compact_collector_(nullptr), |
| 126 store_buffer_(this), | 139 store_buffer_(this), |
| 127 incremental_marking_(nullptr), | 140 incremental_marking_(nullptr), |
| 128 gc_idle_time_handler_(nullptr), | 141 gc_idle_time_handler_(nullptr), |
| 129 memory_reducer_(nullptr), | 142 memory_reducer_(nullptr), |
| 130 object_stats_(nullptr), | 143 object_stats_(nullptr), |
| 131 scavenge_job_(nullptr), | 144 scavenge_job_(nullptr), |
| 145 idle_scavenge_observer_(nullptr), |
| 132 full_codegen_bytes_generated_(0), | 146 full_codegen_bytes_generated_(0), |
| 133 crankshaft_codegen_bytes_generated_(0), | 147 crankshaft_codegen_bytes_generated_(0), |
| 134 new_space_allocation_counter_(0), | 148 new_space_allocation_counter_(0), |
| 135 old_generation_allocation_counter_(0), | 149 old_generation_allocation_counter_(0), |
| 136 old_generation_size_at_last_gc_(0), | 150 old_generation_size_at_last_gc_(0), |
| 137 gcs_since_last_deopt_(0), | 151 gcs_since_last_deopt_(0), |
| 138 allocation_sites_scratchpad_length_(0), | 152 allocation_sites_scratchpad_length_(0), |
| 139 ring_buffer_full_(false), | 153 ring_buffer_full_(false), |
| 140 ring_buffer_end_(0), | 154 ring_buffer_end_(0), |
| 141 promotion_queue_(this), | 155 promotion_queue_(this), |
| (...skipping 4822 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4964 | 4978 |
| 4965 // Update inline allocation limit for old spaces. | 4979 // Update inline allocation limit for old spaces. |
| 4966 PagedSpaces spaces(this); | 4980 PagedSpaces spaces(this); |
| 4967 for (PagedSpace* space = spaces.next(); space != NULL; | 4981 for (PagedSpace* space = spaces.next(); space != NULL; |
| 4968 space = spaces.next()) { | 4982 space = spaces.next()) { |
| 4969 space->EmptyAllocationInfo(); | 4983 space->EmptyAllocationInfo(); |
| 4970 } | 4984 } |
| 4971 } | 4985 } |
| 4972 | 4986 |
| 4973 | 4987 |
| 4974 void Heap::LowerInlineAllocationLimit(intptr_t step) { | |
| 4975 new_space()->LowerInlineAllocationLimit(step); | |
| 4976 } | |
| 4977 | |
| 4978 | |
| 4979 void Heap::ResetInlineAllocationLimit() { | |
| 4980 new_space()->LowerInlineAllocationLimit( | |
| 4981 ScavengeJob::kBytesAllocatedBeforeNextIdleTask); | |
| 4982 } | |
| 4983 | |
| 4984 | |
| 4985 V8_DECLARE_ONCE(initialize_gc_once); | 4988 V8_DECLARE_ONCE(initialize_gc_once); |
| 4986 | 4989 |
| 4987 static void InitializeGCOnce() { | 4990 static void InitializeGCOnce() { |
| 4988 Scavenger::Initialize(); | 4991 Scavenger::Initialize(); |
| 4989 StaticScavengeVisitor::Initialize(); | 4992 StaticScavengeVisitor::Initialize(); |
| 4990 MarkCompactCollector::Initialize(); | 4993 MarkCompactCollector::Initialize(); |
| 4991 } | 4994 } |
| 4992 | 4995 |
| 4993 | 4996 |
| 4994 bool Heap::SetUp() { | 4997 bool Heap::SetUp() { |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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())); |
| 5087 LOG(isolate_, IntPtrTEvent("heap-available", Available())); | 5090 LOG(isolate_, IntPtrTEvent("heap-available", Available())); |
| 5088 | 5091 |
| 5089 store_buffer()->SetUp(); | 5092 store_buffer()->SetUp(); |
| 5090 | 5093 |
| 5091 mark_compact_collector()->SetUp(); | 5094 mark_compact_collector()->SetUp(); |
| 5092 | 5095 |
| 5093 ResetInlineAllocationLimit(); | 5096 idle_scavenge_observer_ = new IdleScavengeObserver( |
| 5097 *this, ScavengeJob::kBytesAllocatedBeforeNextIdleTask); |
| 5098 new_space()->AddInlineAllocationObserver(idle_scavenge_observer_); |
| 5094 | 5099 |
| 5095 return true; | 5100 return true; |
| 5096 } | 5101 } |
| 5097 | 5102 |
| 5098 | 5103 |
| 5099 bool Heap::CreateHeapObjects() { | 5104 bool Heap::CreateHeapObjects() { |
| 5100 // Create initial maps. | 5105 // Create initial maps. |
| 5101 if (!CreateInitialMaps()) return false; | 5106 if (!CreateInitialMaps()) return false; |
| 5102 CreateApiObjects(); | 5107 CreateApiObjects(); |
| 5103 | 5108 |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5182 map_space_->MaximumCommittedMemory()); | 5187 map_space_->MaximumCommittedMemory()); |
| 5183 PrintF("maximum_committed_by_lo_space=%" V8_PTR_PREFIX "d ", | 5188 PrintF("maximum_committed_by_lo_space=%" V8_PTR_PREFIX "d ", |
| 5184 lo_space_->MaximumCommittedMemory()); | 5189 lo_space_->MaximumCommittedMemory()); |
| 5185 PrintF("\n\n"); | 5190 PrintF("\n\n"); |
| 5186 } | 5191 } |
| 5187 | 5192 |
| 5188 if (FLAG_verify_predictable) { | 5193 if (FLAG_verify_predictable) { |
| 5189 PrintAlloctionsHash(); | 5194 PrintAlloctionsHash(); |
| 5190 } | 5195 } |
| 5191 | 5196 |
| 5197 new_space()->RemoveInlineAllocationObserver(idle_scavenge_observer_); |
| 5198 delete idle_scavenge_observer_; |
| 5199 idle_scavenge_observer_ = nullptr; |
| 5200 |
| 5192 delete scavenge_collector_; | 5201 delete scavenge_collector_; |
| 5193 scavenge_collector_ = nullptr; | 5202 scavenge_collector_ = nullptr; |
| 5194 | 5203 |
| 5195 if (mark_compact_collector_ != nullptr) { | 5204 if (mark_compact_collector_ != nullptr) { |
| 5196 mark_compact_collector_->TearDown(); | 5205 mark_compact_collector_->TearDown(); |
| 5197 delete mark_compact_collector_; | 5206 delete mark_compact_collector_; |
| 5198 mark_compact_collector_ = nullptr; | 5207 mark_compact_collector_ = nullptr; |
| 5199 } | 5208 } |
| 5200 | 5209 |
| 5201 delete incremental_marking_; | 5210 delete incremental_marking_; |
| (...skipping 918 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6120 } | 6129 } |
| 6121 | 6130 |
| 6122 | 6131 |
| 6123 // static | 6132 // static |
| 6124 int Heap::GetStaticVisitorIdForMap(Map* map) { | 6133 int Heap::GetStaticVisitorIdForMap(Map* map) { |
| 6125 return StaticVisitorBase::GetVisitorId(map); | 6134 return StaticVisitorBase::GetVisitorId(map); |
| 6126 } | 6135 } |
| 6127 | 6136 |
| 6128 } // namespace internal | 6137 } // namespace internal |
| 6129 } // namespace v8 | 6138 } // namespace v8 |
| OLD | NEW |