Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1 | // Copyright 2014 the V8 project authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5 | #include "src/heap/gc-tracer.h" |
| 6 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7 | #include "src/counters.h" |
| 8 | #include "src/heap/heap-inl.h" |
| 9 | #include "src/isolate.h" |
| 10 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 11 | namespace v8 { |
| 12 | namespace internal { |
| 13 | |
| 14 | static intptr_t CountTotalHolesSize(Heap* heap) { |
| 15 | intptr_t holes_size = 0; |
| 16 | OldSpaces spaces(heap); |
| 17 | for (OldSpace* space = spaces.next(); space != NULL; space = spaces.next()) { |
| 18 | holes_size += space->Waste() + space->Available(); |
| 19 | } |
| 20 | return holes_size; |
| 21 | } |
| 22 | |
| 23 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 24 | GCTracer::Scope::Scope(GCTracer* tracer, ScopeId scope) |
| 25 | : tracer_(tracer), scope_(scope) { |
| 26 | start_time_ = tracer_->heap_->MonotonicallyIncreasingTimeInMs(); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 27 | // TODO(cbruni): remove once we fully moved to a trace-based system. |
| 28 | if (FLAG_runtime_call_stats) { |
| 29 | RuntimeCallStats* stats = |
| 30 | tracer_->heap_->isolate()->counters()->runtime_call_stats(); |
| 31 | timer_.Initialize(&stats->GC, stats->current_timer()); |
| 32 | stats->Enter(&timer_); |
| 33 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | |
| 37 | GCTracer::Scope::~Scope() { |
| 38 | DCHECK(scope_ < NUMBER_OF_SCOPES); // scope_ is unsigned. |
| 39 | tracer_->current_.scopes[scope_] += |
| 40 | tracer_->heap_->MonotonicallyIncreasingTimeInMs() - start_time_; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 41 | // TODO(cbruni): remove once we fully moved to a trace-based system. |
| 42 | if (FLAG_runtime_call_stats) { |
| 43 | tracer_->heap_->isolate()->counters()->runtime_call_stats()->Leave(&timer_); |
| 44 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 45 | } |
| 46 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 47 | const char* GCTracer::Scope::Name(ScopeId id) { |
| 48 | #define CASE(scope) \ |
| 49 | case Scope::scope: \ |
| 50 | return "V8.GC_" #scope; |
| 51 | switch (id) { |
| 52 | TRACER_SCOPES(CASE) |
| 53 | case Scope::NUMBER_OF_SCOPES: |
| 54 | break; |
| 55 | } |
| 56 | #undef CASE |
| 57 | return "(unknown)"; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 58 | } |
| 59 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 60 | GCTracer::Event::Event(Type type, const char* gc_reason, |
| 61 | const char* collector_reason) |
| 62 | : type(type), |
| 63 | gc_reason(gc_reason), |
| 64 | collector_reason(collector_reason), |
| 65 | start_time(0.0), |
| 66 | end_time(0.0), |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 67 | reduce_memory(false), |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 68 | start_object_size(0), |
| 69 | end_object_size(0), |
| 70 | start_memory_size(0), |
| 71 | end_memory_size(0), |
| 72 | start_holes_size(0), |
| 73 | end_holes_size(0), |
| 74 | cumulative_incremental_marking_steps(0), |
| 75 | incremental_marking_steps(0), |
| 76 | cumulative_incremental_marking_bytes(0), |
| 77 | incremental_marking_bytes(0), |
| 78 | cumulative_incremental_marking_duration(0.0), |
| 79 | incremental_marking_duration(0.0), |
| 80 | cumulative_pure_incremental_marking_duration(0.0), |
| 81 | pure_incremental_marking_duration(0.0), |
| 82 | longest_incremental_marking_step(0.0) { |
| 83 | for (int i = 0; i < Scope::NUMBER_OF_SCOPES; i++) { |
| 84 | scopes[i] = 0; |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | |
| 89 | const char* GCTracer::Event::TypeName(bool short_name) const { |
| 90 | switch (type) { |
| 91 | case SCAVENGER: |
| 92 | if (short_name) { |
| 93 | return "s"; |
| 94 | } else { |
| 95 | return "Scavenge"; |
| 96 | } |
| 97 | case MARK_COMPACTOR: |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 98 | case INCREMENTAL_MARK_COMPACTOR: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 99 | if (short_name) { |
| 100 | return "ms"; |
| 101 | } else { |
| 102 | return "Mark-sweep"; |
| 103 | } |
| 104 | case START: |
| 105 | if (short_name) { |
| 106 | return "st"; |
| 107 | } else { |
| 108 | return "Start"; |
| 109 | } |
| 110 | } |
| 111 | return "Unknown Event Type"; |
| 112 | } |
| 113 | |
| 114 | |
| 115 | GCTracer::GCTracer(Heap* heap) |
| 116 | : heap_(heap), |
| 117 | cumulative_incremental_marking_steps_(0), |
| 118 | cumulative_incremental_marking_bytes_(0), |
| 119 | cumulative_incremental_marking_duration_(0.0), |
| 120 | cumulative_pure_incremental_marking_duration_(0.0), |
| 121 | longest_incremental_marking_step_(0.0), |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 122 | cumulative_incremental_marking_finalization_steps_(0), |
| 123 | cumulative_incremental_marking_finalization_duration_(0.0), |
| 124 | longest_incremental_marking_finalization_step_(0.0), |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 125 | cumulative_marking_duration_(0.0), |
| 126 | cumulative_sweeping_duration_(0.0), |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 127 | allocation_time_ms_(0.0), |
| 128 | new_space_allocation_counter_bytes_(0), |
| 129 | old_generation_allocation_counter_bytes_(0), |
| 130 | allocation_duration_since_gc_(0.0), |
| 131 | new_space_allocation_in_bytes_since_gc_(0), |
| 132 | old_generation_allocation_in_bytes_since_gc_(0), |
| 133 | combined_mark_compact_speed_cache_(0.0), |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 134 | start_counter_(0) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 135 | current_ = Event(Event::START, NULL, NULL); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 136 | current_.end_time = heap_->MonotonicallyIncreasingTimeInMs(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 137 | previous_ = previous_incremental_mark_compactor_event_ = current_; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | |
| 141 | void GCTracer::Start(GarbageCollector collector, const char* gc_reason, |
| 142 | const char* collector_reason) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 143 | start_counter_++; |
| 144 | if (start_counter_ != 1) return; |
| 145 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 146 | previous_ = current_; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 147 | double start_time = heap_->MonotonicallyIncreasingTimeInMs(); |
| 148 | SampleAllocation(start_time, heap_->NewSpaceAllocationCounter(), |
| 149 | heap_->OldGenerationAllocationCounter()); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 150 | if (current_.type == Event::INCREMENTAL_MARK_COMPACTOR) |
| 151 | previous_incremental_mark_compactor_event_ = current_; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 152 | |
| 153 | if (collector == SCAVENGER) { |
| 154 | current_ = Event(Event::SCAVENGER, gc_reason, collector_reason); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 155 | } else if (collector == MARK_COMPACTOR) { |
| 156 | if (heap_->incremental_marking()->WasActivated()) { |
| 157 | current_ = |
| 158 | Event(Event::INCREMENTAL_MARK_COMPACTOR, gc_reason, collector_reason); |
| 159 | } else { |
| 160 | current_ = Event(Event::MARK_COMPACTOR, gc_reason, collector_reason); |
| 161 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 162 | } |
| 163 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 164 | current_.reduce_memory = heap_->ShouldReduceMemory(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 165 | current_.start_time = start_time; |
| 166 | current_.start_object_size = heap_->SizeOfObjects(); |
| 167 | current_.start_memory_size = heap_->isolate()->memory_allocator()->Size(); |
| 168 | current_.start_holes_size = CountTotalHolesSize(heap_); |
| 169 | current_.new_space_object_size = |
| 170 | heap_->new_space()->top() - heap_->new_space()->bottom(); |
| 171 | |
| 172 | current_.cumulative_incremental_marking_steps = |
| 173 | cumulative_incremental_marking_steps_; |
| 174 | current_.cumulative_incremental_marking_bytes = |
| 175 | cumulative_incremental_marking_bytes_; |
| 176 | current_.cumulative_incremental_marking_duration = |
| 177 | cumulative_incremental_marking_duration_; |
| 178 | current_.cumulative_pure_incremental_marking_duration = |
| 179 | cumulative_pure_incremental_marking_duration_; |
| 180 | current_.longest_incremental_marking_step = longest_incremental_marking_step_; |
| 181 | |
| 182 | for (int i = 0; i < Scope::NUMBER_OF_SCOPES; i++) { |
| 183 | current_.scopes[i] = 0; |
| 184 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 185 | int committed_memory = static_cast<int>(heap_->CommittedMemory() / KB); |
| 186 | int used_memory = static_cast<int>(current_.start_object_size / KB); |
| 187 | heap_->isolate()->counters()->aggregated_memory_heap_committed()->AddSample( |
| 188 | start_time, committed_memory); |
| 189 | heap_->isolate()->counters()->aggregated_memory_heap_used()->AddSample( |
| 190 | start_time, used_memory); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 191 | // TODO(cbruni): remove once we fully moved to a trace-based system. |
| 192 | if (FLAG_runtime_call_stats) { |
| 193 | RuntimeCallStats* stats = |
| 194 | heap_->isolate()->counters()->runtime_call_stats(); |
| 195 | timer_.Initialize(&stats->GC, stats->current_timer()); |
| 196 | stats->Enter(&timer_); |
| 197 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 198 | } |
| 199 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 200 | void GCTracer::Stop(GarbageCollector collector) { |
| 201 | start_counter_--; |
| 202 | if (start_counter_ != 0) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 203 | Output("[Finished reentrant %s during %s.]\n", |
| 204 | collector == SCAVENGER ? "Scavenge" : "Mark-sweep", |
| 205 | current_.TypeName(false)); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 206 | return; |
| 207 | } |
| 208 | |
| 209 | DCHECK(start_counter_ >= 0); |
| 210 | DCHECK((collector == SCAVENGER && current_.type == Event::SCAVENGER) || |
| 211 | (collector == MARK_COMPACTOR && |
| 212 | (current_.type == Event::MARK_COMPACTOR || |
| 213 | current_.type == Event::INCREMENTAL_MARK_COMPACTOR))); |
| 214 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 215 | current_.end_time = heap_->MonotonicallyIncreasingTimeInMs(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 216 | current_.end_object_size = heap_->SizeOfObjects(); |
| 217 | current_.end_memory_size = heap_->isolate()->memory_allocator()->Size(); |
| 218 | current_.end_holes_size = CountTotalHolesSize(heap_); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 219 | current_.survived_new_space_object_size = heap_->SurvivedNewSpaceObjectSize(); |
| 220 | |
| 221 | AddAllocation(current_.end_time); |
| 222 | |
| 223 | int committed_memory = static_cast<int>(heap_->CommittedMemory() / KB); |
| 224 | int used_memory = static_cast<int>(current_.end_object_size / KB); |
| 225 | heap_->isolate()->counters()->aggregated_memory_heap_committed()->AddSample( |
| 226 | current_.end_time, committed_memory); |
| 227 | heap_->isolate()->counters()->aggregated_memory_heap_used()->AddSample( |
| 228 | current_.end_time, used_memory); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 229 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 230 | double duration = current_.end_time - current_.start_time; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 231 | if (current_.type == Event::SCAVENGER) { |
| 232 | current_.incremental_marking_steps = |
| 233 | current_.cumulative_incremental_marking_steps - |
| 234 | previous_.cumulative_incremental_marking_steps; |
| 235 | current_.incremental_marking_bytes = |
| 236 | current_.cumulative_incremental_marking_bytes - |
| 237 | previous_.cumulative_incremental_marking_bytes; |
| 238 | current_.incremental_marking_duration = |
| 239 | current_.cumulative_incremental_marking_duration - |
| 240 | previous_.cumulative_incremental_marking_duration; |
| 241 | current_.pure_incremental_marking_duration = |
| 242 | current_.cumulative_pure_incremental_marking_duration - |
| 243 | previous_.cumulative_pure_incremental_marking_duration; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 244 | recorded_scavenges_total_.Push( |
| 245 | MakeBytesAndDuration(current_.new_space_object_size, duration)); |
| 246 | recorded_scavenges_survived_.Push(MakeBytesAndDuration( |
| 247 | current_.survived_new_space_object_size, duration)); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 248 | } else if (current_.type == Event::INCREMENTAL_MARK_COMPACTOR) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 249 | current_.incremental_marking_steps = |
| 250 | current_.cumulative_incremental_marking_steps - |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 251 | previous_incremental_mark_compactor_event_ |
| 252 | .cumulative_incremental_marking_steps; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 253 | current_.incremental_marking_bytes = |
| 254 | current_.cumulative_incremental_marking_bytes - |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 255 | previous_incremental_mark_compactor_event_ |
| 256 | .cumulative_incremental_marking_bytes; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 257 | current_.incremental_marking_duration = |
| 258 | current_.cumulative_incremental_marking_duration - |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 259 | previous_incremental_mark_compactor_event_ |
| 260 | .cumulative_incremental_marking_duration; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 261 | current_.pure_incremental_marking_duration = |
| 262 | current_.cumulative_pure_incremental_marking_duration - |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 263 | previous_incremental_mark_compactor_event_ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 264 | .cumulative_pure_incremental_marking_duration; |
| 265 | longest_incremental_marking_step_ = 0.0; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 266 | recorded_incremental_marking_steps_.Push( |
| 267 | MakeBytesAndDuration(current_.incremental_marking_bytes, |
| 268 | current_.pure_incremental_marking_duration)); |
| 269 | recorded_incremental_mark_compacts_.Push( |
| 270 | MakeBytesAndDuration(current_.start_object_size, duration)); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 271 | combined_mark_compact_speed_cache_ = 0.0; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 272 | } else { |
| 273 | DCHECK(current_.incremental_marking_bytes == 0); |
| 274 | DCHECK(current_.incremental_marking_duration == 0); |
| 275 | DCHECK(current_.pure_incremental_marking_duration == 0); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 276 | longest_incremental_marking_step_ = 0.0; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 277 | recorded_mark_compacts_.Push( |
| 278 | MakeBytesAndDuration(current_.start_object_size, duration)); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 279 | combined_mark_compact_speed_cache_ = 0.0; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | // TODO(ernstm): move the code below out of GCTracer. |
| 283 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 284 | double spent_in_mutator = Max(current_.start_time - previous_.end_time, 0.0); |
| 285 | |
| 286 | heap_->UpdateCumulativeGCStatistics(duration, spent_in_mutator, |
| 287 | current_.scopes[Scope::MC_MARK]); |
| 288 | |
| 289 | if (current_.type == Event::SCAVENGER && FLAG_trace_gc_ignore_scavenger) |
| 290 | return; |
| 291 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 292 | if (FLAG_trace_gc_nvp) |
| 293 | PrintNVP(); |
| 294 | else |
| 295 | Print(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 296 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 297 | if (FLAG_trace_gc) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 298 | heap_->PrintShortHeapStatistics(); |
| 299 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 300 | |
| 301 | longest_incremental_marking_finalization_step_ = 0.0; |
| 302 | cumulative_incremental_marking_finalization_steps_ = 0; |
| 303 | cumulative_incremental_marking_finalization_duration_ = 0.0; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 304 | // TODO(cbruni): remove once we fully moved to a trace-based system. |
| 305 | if (FLAG_runtime_call_stats) { |
| 306 | heap_->isolate()->counters()->runtime_call_stats()->Leave(&timer_); |
| 307 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 311 | void GCTracer::SampleAllocation(double current_ms, |
| 312 | size_t new_space_counter_bytes, |
| 313 | size_t old_generation_counter_bytes) { |
| 314 | if (allocation_time_ms_ == 0) { |
| 315 | // It is the first sample. |
| 316 | allocation_time_ms_ = current_ms; |
| 317 | new_space_allocation_counter_bytes_ = new_space_counter_bytes; |
| 318 | old_generation_allocation_counter_bytes_ = old_generation_counter_bytes; |
| 319 | return; |
| 320 | } |
| 321 | // This assumes that counters are unsigned integers so that the subtraction |
| 322 | // below works even if the new counter is less then the old counter. |
| 323 | size_t new_space_allocated_bytes = |
| 324 | new_space_counter_bytes - new_space_allocation_counter_bytes_; |
| 325 | size_t old_generation_allocated_bytes = |
| 326 | old_generation_counter_bytes - old_generation_allocation_counter_bytes_; |
| 327 | double duration = current_ms - allocation_time_ms_; |
| 328 | allocation_time_ms_ = current_ms; |
| 329 | new_space_allocation_counter_bytes_ = new_space_counter_bytes; |
| 330 | old_generation_allocation_counter_bytes_ = old_generation_counter_bytes; |
| 331 | allocation_duration_since_gc_ += duration; |
| 332 | new_space_allocation_in_bytes_since_gc_ += new_space_allocated_bytes; |
| 333 | old_generation_allocation_in_bytes_since_gc_ += |
| 334 | old_generation_allocated_bytes; |
| 335 | } |
| 336 | |
| 337 | |
| 338 | void GCTracer::AddAllocation(double current_ms) { |
| 339 | allocation_time_ms_ = current_ms; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 340 | if (allocation_duration_since_gc_ > 0) { |
| 341 | recorded_new_generation_allocations_.Push( |
| 342 | MakeBytesAndDuration(new_space_allocation_in_bytes_since_gc_, |
| 343 | allocation_duration_since_gc_)); |
| 344 | recorded_old_generation_allocations_.Push( |
| 345 | MakeBytesAndDuration(old_generation_allocation_in_bytes_since_gc_, |
| 346 | allocation_duration_since_gc_)); |
| 347 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 348 | allocation_duration_since_gc_ = 0; |
| 349 | new_space_allocation_in_bytes_since_gc_ = 0; |
| 350 | old_generation_allocation_in_bytes_since_gc_ = 0; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 354 | void GCTracer::AddContextDisposalTime(double time) { |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 355 | recorded_context_disposal_times_.Push(time); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 356 | } |
| 357 | |
| 358 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 359 | void GCTracer::AddCompactionEvent(double duration, |
| 360 | intptr_t live_bytes_compacted) { |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 361 | recorded_compactions_.Push( |
| 362 | MakeBytesAndDuration(live_bytes_compacted, duration)); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | |
| 366 | void GCTracer::AddSurvivalRatio(double promotion_ratio) { |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 367 | recorded_survival_ratios_.Push(promotion_ratio); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 371 | void GCTracer::AddIncrementalMarkingStep(double duration, intptr_t bytes) { |
| 372 | cumulative_incremental_marking_steps_++; |
| 373 | cumulative_incremental_marking_bytes_ += bytes; |
| 374 | cumulative_incremental_marking_duration_ += duration; |
| 375 | longest_incremental_marking_step_ = |
| 376 | Max(longest_incremental_marking_step_, duration); |
| 377 | cumulative_marking_duration_ += duration; |
| 378 | if (bytes > 0) { |
| 379 | cumulative_pure_incremental_marking_duration_ += duration; |
| 380 | } |
| 381 | } |
| 382 | |
| 383 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 384 | void GCTracer::AddIncrementalMarkingFinalizationStep(double duration) { |
| 385 | cumulative_incremental_marking_finalization_steps_++; |
| 386 | cumulative_incremental_marking_finalization_duration_ += duration; |
| 387 | longest_incremental_marking_finalization_step_ = |
| 388 | Max(longest_incremental_marking_finalization_step_, duration); |
| 389 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 390 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 391 | |
| 392 | void GCTracer::Output(const char* format, ...) const { |
| 393 | if (FLAG_trace_gc) { |
| 394 | va_list arguments; |
| 395 | va_start(arguments, format); |
| 396 | base::OS::VPrint(format, arguments); |
| 397 | va_end(arguments); |
| 398 | } |
| 399 | |
| 400 | const int kBufferSize = 256; |
| 401 | char raw_buffer[kBufferSize]; |
| 402 | Vector<char> buffer(raw_buffer, kBufferSize); |
| 403 | va_list arguments2; |
| 404 | va_start(arguments2, format); |
| 405 | VSNPrintF(buffer, format, arguments2); |
| 406 | va_end(arguments2); |
| 407 | |
| 408 | heap_->AddToRingBuffer(buffer.start()); |
| 409 | } |
| 410 | |
| 411 | |
| 412 | void GCTracer::Print() const { |
| 413 | if (FLAG_trace_gc) { |
| 414 | PrintIsolate(heap_->isolate(), ""); |
| 415 | } |
| 416 | Output("%8.0f ms: ", heap_->isolate()->time_millis_since_init()); |
| 417 | |
| 418 | Output("%s %.1f (%.1f) -> %.1f (%.1f) MB, ", current_.TypeName(false), |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 419 | static_cast<double>(current_.start_object_size) / MB, |
| 420 | static_cast<double>(current_.start_memory_size) / MB, |
| 421 | static_cast<double>(current_.end_object_size) / MB, |
| 422 | static_cast<double>(current_.end_memory_size) / MB); |
| 423 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 424 | double duration = current_.end_time - current_.start_time; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 425 | Output("%.1f / %.1f ms", duration, TotalExternalTime()); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 426 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 427 | if (current_.type == Event::SCAVENGER) { |
| 428 | if (current_.incremental_marking_steps > 0) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 429 | Output(" (+ %.1f ms in %d steps since last GC)", |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 430 | current_.incremental_marking_duration, |
| 431 | current_.incremental_marking_steps); |
| 432 | } |
| 433 | } else { |
| 434 | if (current_.incremental_marking_steps > 0) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 435 | Output( |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 436 | " (+ %.1f ms in %d steps since start of marking, " |
| 437 | "biggest step %.1f ms)", |
| 438 | current_.incremental_marking_duration, |
| 439 | current_.incremental_marking_steps, |
| 440 | current_.longest_incremental_marking_step); |
| 441 | } |
| 442 | } |
| 443 | |
| 444 | if (current_.gc_reason != NULL) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 445 | Output(" [%s]", current_.gc_reason); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 446 | } |
| 447 | |
| 448 | if (current_.collector_reason != NULL) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 449 | Output(" [%s]", current_.collector_reason); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 450 | } |
| 451 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 452 | Output(".\n"); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 453 | } |
| 454 | |
| 455 | |
| 456 | void GCTracer::PrintNVP() const { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 457 | double duration = current_.end_time - current_.start_time; |
| 458 | double spent_in_mutator = current_.start_time - previous_.end_time; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 459 | intptr_t allocated_since_last_gc = |
| 460 | current_.start_object_size - previous_.end_object_size; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 461 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 462 | switch (current_.type) { |
| 463 | case Event::SCAVENGER: |
| 464 | PrintIsolate(heap_->isolate(), |
| 465 | "%8.0f ms: " |
| 466 | "pause=%.1f " |
| 467 | "mutator=%.1f " |
| 468 | "gc=%s " |
| 469 | "reduce_memory=%d " |
| 470 | "scavenge=%.2f " |
| 471 | "old_new=%.2f " |
| 472 | "weak=%.2f " |
| 473 | "roots=%.2f " |
| 474 | "code=%.2f " |
| 475 | "semispace=%.2f " |
| 476 | "object_groups=%.2f " |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 477 | "external_prologue=%.2f " |
| 478 | "external_epilogue=%.2f " |
| 479 | "external_weak_global_handles=%.2f " |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 480 | "steps_count=%d " |
| 481 | "steps_took=%.1f " |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 482 | "scavenge_throughput=%.f " |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 483 | "total_size_before=%" V8_PTR_PREFIX |
| 484 | "d " |
| 485 | "total_size_after=%" V8_PTR_PREFIX |
| 486 | "d " |
| 487 | "holes_size_before=%" V8_PTR_PREFIX |
| 488 | "d " |
| 489 | "holes_size_after=%" V8_PTR_PREFIX |
| 490 | "d " |
| 491 | "allocated=%" V8_PTR_PREFIX |
| 492 | "d " |
| 493 | "promoted=%" V8_PTR_PREFIX |
| 494 | "d " |
| 495 | "semi_space_copied=%" V8_PTR_PREFIX |
| 496 | "d " |
| 497 | "nodes_died_in_new=%d " |
| 498 | "nodes_copied_in_new=%d " |
| 499 | "nodes_promoted=%d " |
| 500 | "promotion_ratio=%.1f%% " |
| 501 | "average_survival_ratio=%.1f%% " |
| 502 | "promotion_rate=%.1f%% " |
| 503 | "semi_space_copy_rate=%.1f%% " |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 504 | "new_space_allocation_throughput=%.1f " |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 505 | "context_disposal_rate=%.1f\n", |
| 506 | heap_->isolate()->time_millis_since_init(), duration, |
| 507 | spent_in_mutator, current_.TypeName(true), |
| 508 | current_.reduce_memory, |
| 509 | current_.scopes[Scope::SCAVENGER_SCAVENGE], |
| 510 | current_.scopes[Scope::SCAVENGER_OLD_TO_NEW_POINTERS], |
| 511 | current_.scopes[Scope::SCAVENGER_WEAK], |
| 512 | current_.scopes[Scope::SCAVENGER_ROOTS], |
| 513 | current_.scopes[Scope::SCAVENGER_CODE_FLUSH_CANDIDATES], |
| 514 | current_.scopes[Scope::SCAVENGER_SEMISPACE], |
| 515 | current_.scopes[Scope::SCAVENGER_OBJECT_GROUPS], |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 516 | current_.scopes[Scope::SCAVENGER_EXTERNAL_PROLOGUE], |
| 517 | current_.scopes[Scope::SCAVENGER_EXTERNAL_EPILOGUE], |
| 518 | current_.scopes[Scope::EXTERNAL_WEAK_GLOBAL_HANDLES], |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 519 | current_.incremental_marking_steps, |
| 520 | current_.incremental_marking_duration, |
| 521 | ScavengeSpeedInBytesPerMillisecond(), |
| 522 | current_.start_object_size, current_.end_object_size, |
| 523 | current_.start_holes_size, current_.end_holes_size, |
| 524 | allocated_since_last_gc, heap_->promoted_objects_size(), |
| 525 | heap_->semi_space_copied_object_size(), |
| 526 | heap_->nodes_died_in_new_space_, |
| 527 | heap_->nodes_copied_in_new_space_, heap_->nodes_promoted_, |
| 528 | heap_->promotion_ratio_, AverageSurvivalRatio(), |
| 529 | heap_->promotion_rate_, heap_->semi_space_copied_rate_, |
| 530 | NewSpaceAllocationThroughputInBytesPerMillisecond(), |
| 531 | ContextDisposalRateInMilliseconds()); |
| 532 | break; |
| 533 | case Event::MARK_COMPACTOR: |
| 534 | case Event::INCREMENTAL_MARK_COMPACTOR: |
| 535 | PrintIsolate( |
| 536 | heap_->isolate(), |
| 537 | "%8.0f ms: " |
| 538 | "pause=%.1f " |
| 539 | "mutator=%.1f " |
| 540 | "gc=%s " |
| 541 | "reduce_memory=%d " |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 542 | "clear=%1.f " |
| 543 | "clear.code_flush=%.1f " |
| 544 | "clear.dependent_code=%.1f " |
| 545 | "clear.global_handles=%.1f " |
| 546 | "clear.maps=%.1f " |
| 547 | "clear.slots_buffer=%.1f " |
| 548 | "clear.store_buffer=%.1f " |
| 549 | "clear.string_table=%.1f " |
| 550 | "clear.weak_cells=%.1f " |
| 551 | "clear.weak_collections=%.1f " |
| 552 | "clear.weak_lists=%.1f " |
| 553 | "evacuate=%.1f " |
| 554 | "evacuate.candidates=%.1f " |
| 555 | "evacuate.clean_up=%.1f " |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 556 | "evacuate.copy=%.1f " |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 557 | "evacuate.update_pointers=%.1f " |
| 558 | "evacuate.update_pointers.between_evacuated=%.1f " |
| 559 | "evacuate.update_pointers.to_evacuated=%.1f " |
| 560 | "evacuate.update_pointers.to_new=%.1f " |
| 561 | "evacuate.update_pointers.weak=%.1f " |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 562 | "external.mc_prologue=%.1f " |
| 563 | "external.mc_epilogue=%.1f " |
| 564 | "external.mc_incremental_prologue=%.1f " |
| 565 | "external.mc_incremental_epilogue=%.1f " |
| 566 | "external.weak_global_handles=%.1f " |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 567 | "finish=%.1f " |
| 568 | "mark=%.1f " |
| 569 | "mark.finish_incremental=%.1f " |
| 570 | "mark.prepare_code_flush=%.1f " |
| 571 | "mark.roots=%.1f " |
| 572 | "mark.weak_closure=%.1f " |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 573 | "mark.weak_closure.ephemeral=%.1f " |
| 574 | "mark.weak_closure.weak_handles=%.1f " |
| 575 | "mark.weak_closure.weak_roots=%.1f " |
| 576 | "mark.weak_closure.harmony=%.1f " |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 577 | "sweep=%.1f " |
| 578 | "sweep.code=%.1f " |
| 579 | "sweep.map=%.1f " |
| 580 | "sweep.old=%.1f " |
| 581 | "incremental_finalize=%.1f " |
| 582 | "steps_count=%d " |
| 583 | "steps_took=%.1f " |
| 584 | "longest_step=%.1f " |
| 585 | "finalization_steps_count=%d " |
| 586 | "finalization_steps_took=%.1f " |
| 587 | "finalization_longest_step=%.1f " |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 588 | "incremental_marking_throughput=%.f " |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 589 | "total_size_before=%" V8_PTR_PREFIX |
| 590 | "d " |
| 591 | "total_size_after=%" V8_PTR_PREFIX |
| 592 | "d " |
| 593 | "holes_size_before=%" V8_PTR_PREFIX |
| 594 | "d " |
| 595 | "holes_size_after=%" V8_PTR_PREFIX |
| 596 | "d " |
| 597 | "allocated=%" V8_PTR_PREFIX |
| 598 | "d " |
| 599 | "promoted=%" V8_PTR_PREFIX |
| 600 | "d " |
| 601 | "semi_space_copied=%" V8_PTR_PREFIX |
| 602 | "d " |
| 603 | "nodes_died_in_new=%d " |
| 604 | "nodes_copied_in_new=%d " |
| 605 | "nodes_promoted=%d " |
| 606 | "promotion_ratio=%.1f%% " |
| 607 | "average_survival_ratio=%.1f%% " |
| 608 | "promotion_rate=%.1f%% " |
| 609 | "semi_space_copy_rate=%.1f%% " |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 610 | "new_space_allocation_throughput=%.1f " |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 611 | "context_disposal_rate=%.1f " |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 612 | "compaction_speed=%.f\n", |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 613 | heap_->isolate()->time_millis_since_init(), duration, |
| 614 | spent_in_mutator, current_.TypeName(true), current_.reduce_memory, |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 615 | current_.scopes[Scope::MC_CLEAR], |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 616 | current_.scopes[Scope::MC_CLEAR_CODE_FLUSH], |
| 617 | current_.scopes[Scope::MC_CLEAR_DEPENDENT_CODE], |
| 618 | current_.scopes[Scope::MC_CLEAR_GLOBAL_HANDLES], |
| 619 | current_.scopes[Scope::MC_CLEAR_MAPS], |
| 620 | current_.scopes[Scope::MC_CLEAR_SLOTS_BUFFER], |
| 621 | current_.scopes[Scope::MC_CLEAR_STORE_BUFFER], |
| 622 | current_.scopes[Scope::MC_CLEAR_STRING_TABLE], |
| 623 | current_.scopes[Scope::MC_CLEAR_WEAK_CELLS], |
| 624 | current_.scopes[Scope::MC_CLEAR_WEAK_COLLECTIONS], |
| 625 | current_.scopes[Scope::MC_CLEAR_WEAK_LISTS], |
| 626 | current_.scopes[Scope::MC_EVACUATE], |
| 627 | current_.scopes[Scope::MC_EVACUATE_CANDIDATES], |
| 628 | current_.scopes[Scope::MC_EVACUATE_CLEAN_UP], |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 629 | current_.scopes[Scope::MC_EVACUATE_COPY], |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 630 | current_.scopes[Scope::MC_EVACUATE_UPDATE_POINTERS], |
| 631 | current_.scopes[Scope::MC_EVACUATE_UPDATE_POINTERS_BETWEEN_EVACUATED], |
| 632 | current_.scopes[Scope::MC_EVACUATE_UPDATE_POINTERS_TO_EVACUATED], |
| 633 | current_.scopes[Scope::MC_EVACUATE_UPDATE_POINTERS_TO_NEW], |
| 634 | current_.scopes[Scope::MC_EVACUATE_UPDATE_POINTERS_WEAK], |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 635 | current_.scopes[Scope::MC_EXTERNAL_PROLOGUE], |
| 636 | current_.scopes[Scope::MC_EXTERNAL_EPILOGUE], |
| 637 | current_.scopes[Scope::MC_INCREMENTAL_EXTERNAL_PROLOGUE], |
| 638 | current_.scopes[Scope::MC_INCREMENTAL_EXTERNAL_EPILOGUE], |
| 639 | current_.scopes[Scope::EXTERNAL_WEAK_GLOBAL_HANDLES], |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 640 | current_.scopes[Scope::MC_FINISH], current_.scopes[Scope::MC_MARK], |
| 641 | current_.scopes[Scope::MC_MARK_FINISH_INCREMENTAL], |
| 642 | current_.scopes[Scope::MC_MARK_PREPARE_CODE_FLUSH], |
| 643 | current_.scopes[Scope::MC_MARK_ROOTS], |
| 644 | current_.scopes[Scope::MC_MARK_WEAK_CLOSURE], |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 645 | current_.scopes[Scope::MC_MARK_WEAK_CLOSURE_EPHEMERAL], |
| 646 | current_.scopes[Scope::MC_MARK_WEAK_CLOSURE_WEAK_HANDLES], |
| 647 | current_.scopes[Scope::MC_MARK_WEAK_CLOSURE_WEAK_ROOTS], |
| 648 | current_.scopes[Scope::MC_MARK_WEAK_CLOSURE_HARMONY], |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 649 | current_.scopes[Scope::MC_SWEEP], |
| 650 | current_.scopes[Scope::MC_SWEEP_CODE], |
| 651 | current_.scopes[Scope::MC_SWEEP_MAP], |
| 652 | current_.scopes[Scope::MC_SWEEP_OLD], |
| 653 | current_.scopes[Scope::MC_INCREMENTAL_FINALIZE], |
| 654 | current_.incremental_marking_steps, |
| 655 | current_.incremental_marking_duration, |
| 656 | current_.longest_incremental_marking_step, |
| 657 | cumulative_incremental_marking_finalization_steps_, |
| 658 | cumulative_incremental_marking_finalization_duration_, |
| 659 | longest_incremental_marking_finalization_step_, |
| 660 | IncrementalMarkingSpeedInBytesPerMillisecond(), |
| 661 | current_.start_object_size, current_.end_object_size, |
| 662 | current_.start_holes_size, current_.end_holes_size, |
| 663 | allocated_since_last_gc, heap_->promoted_objects_size(), |
| 664 | heap_->semi_space_copied_object_size(), |
| 665 | heap_->nodes_died_in_new_space_, heap_->nodes_copied_in_new_space_, |
| 666 | heap_->nodes_promoted_, heap_->promotion_ratio_, |
| 667 | AverageSurvivalRatio(), heap_->promotion_rate_, |
| 668 | heap_->semi_space_copied_rate_, |
| 669 | NewSpaceAllocationThroughputInBytesPerMillisecond(), |
| 670 | ContextDisposalRateInMilliseconds(), |
| 671 | CompactionSpeedInBytesPerMillisecond()); |
| 672 | break; |
| 673 | case Event::START: |
| 674 | break; |
| 675 | default: |
| 676 | UNREACHABLE(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 677 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 678 | } |
| 679 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 680 | double GCTracer::AverageSpeed(const RingBuffer<BytesAndDuration>& buffer, |
| 681 | const BytesAndDuration& initial, double time_ms) { |
| 682 | BytesAndDuration sum = buffer.Sum( |
| 683 | [time_ms](BytesAndDuration a, BytesAndDuration b) { |
| 684 | if (time_ms != 0 && a.second >= time_ms) return a; |
| 685 | return std::make_pair(a.first + b.first, a.second + b.second); |
| 686 | }, |
| 687 | initial); |
| 688 | uint64_t bytes = sum.first; |
| 689 | double durations = sum.second; |
| 690 | if (durations == 0.0) return 0; |
| 691 | double speed = bytes / durations; |
| 692 | const int max_speed = 1024 * MB; |
| 693 | const int min_speed = 1; |
| 694 | if (speed >= max_speed) return max_speed; |
| 695 | if (speed <= min_speed) return min_speed; |
| 696 | return speed; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 697 | } |
| 698 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 699 | double GCTracer::AverageSpeed(const RingBuffer<BytesAndDuration>& buffer) { |
| 700 | return AverageSpeed(buffer, MakeBytesAndDuration(0, 0), 0); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 701 | } |
| 702 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 703 | double GCTracer::IncrementalMarkingSpeedInBytesPerMillisecond() const { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 704 | if (cumulative_incremental_marking_duration_ == 0.0) return 0; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 705 | // We haven't completed an entire round of incremental marking, yet. |
| 706 | // Use data from GCTracer instead of data from event buffers. |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 707 | if (recorded_incremental_marking_steps_.Count() == 0) { |
| 708 | return cumulative_incremental_marking_bytes_ / |
| 709 | cumulative_pure_incremental_marking_duration_; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 710 | } |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 711 | return AverageSpeed(recorded_incremental_marking_steps_); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 712 | } |
| 713 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 714 | double GCTracer::ScavengeSpeedInBytesPerMillisecond( |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 715 | ScavengeSpeedMode mode) const { |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 716 | if (mode == kForAllObjects) { |
| 717 | return AverageSpeed(recorded_scavenges_total_); |
| 718 | } else { |
| 719 | return AverageSpeed(recorded_scavenges_survived_); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 720 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 721 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 722 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 723 | double GCTracer::CompactionSpeedInBytesPerMillisecond() const { |
| 724 | return AverageSpeed(recorded_compactions_); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 725 | } |
| 726 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 727 | double GCTracer::MarkCompactSpeedInBytesPerMillisecond() const { |
| 728 | return AverageSpeed(recorded_mark_compacts_); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 729 | } |
| 730 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 731 | double GCTracer::FinalIncrementalMarkCompactSpeedInBytesPerMillisecond() const { |
| 732 | return AverageSpeed(recorded_incremental_mark_compacts_); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 733 | } |
| 734 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 735 | double GCTracer::CombinedMarkCompactSpeedInBytesPerMillisecond() { |
| 736 | if (combined_mark_compact_speed_cache_ > 0) |
| 737 | return combined_mark_compact_speed_cache_; |
| 738 | const double kMinimumMarkingSpeed = 0.5; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 739 | double speed1 = IncrementalMarkingSpeedInBytesPerMillisecond(); |
| 740 | double speed2 = FinalIncrementalMarkCompactSpeedInBytesPerMillisecond(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 741 | if (speed1 < kMinimumMarkingSpeed || speed2 < kMinimumMarkingSpeed) { |
| 742 | // No data for the incremental marking speed. |
| 743 | // Return the non-incremental mark-compact speed. |
| 744 | combined_mark_compact_speed_cache_ = |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 745 | MarkCompactSpeedInBytesPerMillisecond(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 746 | } else { |
| 747 | // Combine the speed of incremental step and the speed of the final step. |
| 748 | // 1 / (1 / speed1 + 1 / speed2) = speed1 * speed2 / (speed1 + speed2). |
| 749 | combined_mark_compact_speed_cache_ = speed1 * speed2 / (speed1 + speed2); |
| 750 | } |
| 751 | return combined_mark_compact_speed_cache_; |
| 752 | } |
| 753 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 754 | double GCTracer::NewSpaceAllocationThroughputInBytesPerMillisecond( |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 755 | double time_ms) const { |
| 756 | size_t bytes = new_space_allocation_in_bytes_since_gc_; |
| 757 | double durations = allocation_duration_since_gc_; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 758 | return AverageSpeed(recorded_new_generation_allocations_, |
| 759 | MakeBytesAndDuration(bytes, durations), time_ms); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 760 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 761 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 762 | double GCTracer::OldGenerationAllocationThroughputInBytesPerMillisecond( |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 763 | double time_ms) const { |
| 764 | size_t bytes = old_generation_allocation_in_bytes_since_gc_; |
| 765 | double durations = allocation_duration_since_gc_; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 766 | return AverageSpeed(recorded_old_generation_allocations_, |
| 767 | MakeBytesAndDuration(bytes, durations), time_ms); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 768 | } |
| 769 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 770 | double GCTracer::AllocationThroughputInBytesPerMillisecond( |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 771 | double time_ms) const { |
| 772 | return NewSpaceAllocationThroughputInBytesPerMillisecond(time_ms) + |
| 773 | OldGenerationAllocationThroughputInBytesPerMillisecond(time_ms); |
| 774 | } |
| 775 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 776 | double GCTracer::CurrentAllocationThroughputInBytesPerMillisecond() const { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 777 | return AllocationThroughputInBytesPerMillisecond(kThroughputTimeFrameMs); |
| 778 | } |
| 779 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 780 | double GCTracer::CurrentOldGenerationAllocationThroughputInBytesPerMillisecond() |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 781 | const { |
| 782 | return OldGenerationAllocationThroughputInBytesPerMillisecond( |
| 783 | kThroughputTimeFrameMs); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 784 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 785 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 786 | double GCTracer::ContextDisposalRateInMilliseconds() const { |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 787 | if (recorded_context_disposal_times_.Count() < |
| 788 | recorded_context_disposal_times_.kSize) |
| 789 | return 0.0; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 790 | double begin = heap_->MonotonicallyIncreasingTimeInMs(); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 791 | double end = recorded_context_disposal_times_.Sum( |
| 792 | [](double a, double b) { return b; }, 0.0); |
| 793 | return (begin - end) / recorded_context_disposal_times_.Count(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 794 | } |
| 795 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 796 | double GCTracer::AverageSurvivalRatio() const { |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 797 | if (recorded_survival_ratios_.Count() == 0) return 0.0; |
| 798 | double sum = recorded_survival_ratios_.Sum( |
| 799 | [](double a, double b) { return a + b; }, 0.0); |
| 800 | return sum / recorded_survival_ratios_.Count(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 801 | } |
| 802 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 803 | bool GCTracer::SurvivalEventsRecorded() const { |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 804 | return recorded_survival_ratios_.Count() > 0; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 805 | } |
| 806 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 807 | void GCTracer::ResetSurvivalEvents() { recorded_survival_ratios_.Reset(); } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 808 | } // namespace internal |
| 809 | } // namespace v8 |