| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 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 | 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 #ifndef V8_HEAP_GC_TRACER_H_ | 5 #ifndef V8_HEAP_GC_TRACER_H_ |
| 6 #define V8_HEAP_GC_TRACER_H_ | 6 #define V8_HEAP_GC_TRACER_H_ |
| 7 | 7 |
| 8 #include "src/base/compiler-specific.h" | 8 #include "src/base/compiler-specific.h" |
| 9 #include "src/base/platform/platform.h" | 9 #include "src/base/platform/platform.h" |
| 10 #include "src/counters.h" | 10 #include "src/counters.h" |
| 11 #include "src/globals.h" | 11 #include "src/globals.h" |
| 12 #include "testing/gtest/include/gtest/gtest_prod.h" |
| 12 | 13 |
| 13 namespace v8 { | 14 namespace v8 { |
| 14 namespace internal { | 15 namespace internal { |
| 15 | 16 |
| 16 template <typename T> | 17 template <typename T> |
| 17 class RingBuffer { | 18 class RingBuffer { |
| 18 public: | 19 public: |
| 19 RingBuffer() { Reset(); } | 20 RingBuffer() { Reset(); } |
| 20 static const int kSize = 10; | 21 static const int kSize = 10; |
| 21 void Push(const T& value) { | 22 void Push(const T& value) { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 52 }; | 53 }; |
| 53 | 54 |
| 54 typedef std::pair<uint64_t, double> BytesAndDuration; | 55 typedef std::pair<uint64_t, double> BytesAndDuration; |
| 55 | 56 |
| 56 inline BytesAndDuration MakeBytesAndDuration(uint64_t bytes, double duration) { | 57 inline BytesAndDuration MakeBytesAndDuration(uint64_t bytes, double duration) { |
| 57 return std::make_pair(bytes, duration); | 58 return std::make_pair(bytes, duration); |
| 58 } | 59 } |
| 59 | 60 |
| 60 enum ScavengeSpeedMode { kForAllObjects, kForSurvivedObjects }; | 61 enum ScavengeSpeedMode { kForAllObjects, kForSurvivedObjects }; |
| 61 | 62 |
| 62 #define TRACER_SCOPES(F) \ | 63 #define INCREMENTAL_SCOPES(F) \ |
| 63 F(EXTERNAL_WEAK_GLOBAL_HANDLES) \ | 64 F(MC_INCREMENTAL_WRAPPER_PROLOGUE) \ |
| 64 F(MC_CLEAR) \ | 65 F(MC_INCREMENTAL_WRAPPER_TRACING) \ |
| 65 F(MC_CLEAR_CODE_FLUSH) \ | 66 F(MC_INCREMENTAL_FINALIZE) \ |
| 66 F(MC_CLEAR_DEPENDENT_CODE) \ | 67 F(MC_INCREMENTAL_FINALIZE_OBJECT_GROUPING) \ |
| 67 F(MC_CLEAR_GLOBAL_HANDLES) \ | 68 F(MC_INCREMENTAL_EXTERNAL_EPILOGUE) \ |
| 68 F(MC_CLEAR_MAPS) \ | 69 F(MC_INCREMENTAL_EXTERNAL_PROLOGUE) |
| 69 F(MC_CLEAR_SLOTS_BUFFER) \ | 70 |
| 70 F(MC_CLEAR_STORE_BUFFER) \ | 71 #define TRACER_SCOPES(F) \ |
| 71 F(MC_CLEAR_STRING_TABLE) \ | 72 INCREMENTAL_SCOPES(F) \ |
| 72 F(MC_CLEAR_WEAK_CELLS) \ | 73 F(EXTERNAL_WEAK_GLOBAL_HANDLES) \ |
| 73 F(MC_CLEAR_WEAK_COLLECTIONS) \ | 74 F(MC_CLEAR) \ |
| 74 F(MC_CLEAR_WEAK_LISTS) \ | 75 F(MC_CLEAR_CODE_FLUSH) \ |
| 75 F(MC_EVACUATE) \ | 76 F(MC_CLEAR_DEPENDENT_CODE) \ |
| 76 F(MC_EVACUATE_CANDIDATES) \ | 77 F(MC_CLEAR_GLOBAL_HANDLES) \ |
| 77 F(MC_EVACUATE_CLEAN_UP) \ | 78 F(MC_CLEAR_MAPS) \ |
| 78 F(MC_EVACUATE_COPY) \ | 79 F(MC_CLEAR_SLOTS_BUFFER) \ |
| 79 F(MC_EVACUATE_UPDATE_POINTERS) \ | 80 F(MC_CLEAR_STORE_BUFFER) \ |
| 80 F(MC_EVACUATE_UPDATE_POINTERS_TO_EVACUATED) \ | 81 F(MC_CLEAR_STRING_TABLE) \ |
| 81 F(MC_EVACUATE_UPDATE_POINTERS_TO_NEW) \ | 82 F(MC_CLEAR_WEAK_CELLS) \ |
| 82 F(MC_EVACUATE_UPDATE_POINTERS_WEAK) \ | 83 F(MC_CLEAR_WEAK_COLLECTIONS) \ |
| 83 F(MC_EXTERNAL_EPILOGUE) \ | 84 F(MC_CLEAR_WEAK_LISTS) \ |
| 84 F(MC_EXTERNAL_PROLOGUE) \ | 85 F(MC_EVACUATE) \ |
| 85 F(MC_FINISH) \ | 86 F(MC_EVACUATE_CANDIDATES) \ |
| 86 F(MC_INCREMENTAL_FINALIZE) \ | 87 F(MC_EVACUATE_CLEAN_UP) \ |
| 87 F(MC_INCREMENTAL_EXTERNAL_EPILOGUE) \ | 88 F(MC_EVACUATE_COPY) \ |
| 88 F(MC_INCREMENTAL_EXTERNAL_PROLOGUE) \ | 89 F(MC_EVACUATE_UPDATE_POINTERS) \ |
| 89 F(MC_MARK) \ | 90 F(MC_EVACUATE_UPDATE_POINTERS_TO_EVACUATED) \ |
| 90 F(MC_MARK_FINISH_INCREMENTAL) \ | 91 F(MC_EVACUATE_UPDATE_POINTERS_TO_NEW) \ |
| 91 F(MC_MARK_PREPARE_CODE_FLUSH) \ | 92 F(MC_EVACUATE_UPDATE_POINTERS_WEAK) \ |
| 92 F(MC_MARK_ROOTS) \ | 93 F(MC_EXTERNAL_EPILOGUE) \ |
| 93 F(MC_MARK_WEAK_CLOSURE) \ | 94 F(MC_EXTERNAL_PROLOGUE) \ |
| 94 F(MC_MARK_WEAK_CLOSURE_EPHEMERAL) \ | 95 F(MC_FINISH) \ |
| 95 F(MC_MARK_WEAK_CLOSURE_WEAK_HANDLES) \ | 96 F(MC_MARK) \ |
| 96 F(MC_MARK_WEAK_CLOSURE_WEAK_ROOTS) \ | 97 F(MC_MARK_FINISH_INCREMENTAL) \ |
| 97 F(MC_MARK_WEAK_CLOSURE_HARMONY) \ | 98 F(MC_MARK_PREPARE_CODE_FLUSH) \ |
| 98 F(MC_SWEEP) \ | 99 F(MC_MARK_ROOTS) \ |
| 99 F(MC_SWEEP_CODE) \ | 100 F(MC_MARK_WEAK_CLOSURE) \ |
| 100 F(MC_SWEEP_MAP) \ | 101 F(MC_MARK_WEAK_CLOSURE_EPHEMERAL) \ |
| 101 F(MC_SWEEP_OLD) \ | 102 F(MC_MARK_WEAK_CLOSURE_WEAK_HANDLES) \ |
| 102 F(SCAVENGER_CODE_FLUSH_CANDIDATES) \ | 103 F(MC_MARK_WEAK_CLOSURE_WEAK_ROOTS) \ |
| 103 F(SCAVENGER_EXTERNAL_EPILOGUE) \ | 104 F(MC_MARK_WEAK_CLOSURE_HARMONY) \ |
| 104 F(SCAVENGER_EXTERNAL_PROLOGUE) \ | 105 F(MC_MARK_WRAPPER_EPILOGUE) \ |
| 105 F(SCAVENGER_OBJECT_GROUPS) \ | 106 F(MC_MARK_WRAPPER_PROLOGUE) \ |
| 106 F(SCAVENGER_OLD_TO_NEW_POINTERS) \ | 107 F(MC_MARK_WRAPPER_TRACING) \ |
| 107 F(SCAVENGER_ROOTS) \ | 108 F(MC_MARK_OBJECT_GROUPING) \ |
| 108 F(SCAVENGER_SCAVENGE) \ | 109 F(MC_SWEEP) \ |
| 109 F(SCAVENGER_SEMISPACE) \ | 110 F(MC_SWEEP_CODE) \ |
| 111 F(MC_SWEEP_MAP) \ |
| 112 F(MC_SWEEP_OLD) \ |
| 113 F(SCAVENGER_CODE_FLUSH_CANDIDATES) \ |
| 114 F(SCAVENGER_EXTERNAL_EPILOGUE) \ |
| 115 F(SCAVENGER_EXTERNAL_PROLOGUE) \ |
| 116 F(SCAVENGER_OBJECT_GROUPS) \ |
| 117 F(SCAVENGER_OLD_TO_NEW_POINTERS) \ |
| 118 F(SCAVENGER_ROOTS) \ |
| 119 F(SCAVENGER_SCAVENGE) \ |
| 120 F(SCAVENGER_SEMISPACE) \ |
| 110 F(SCAVENGER_WEAK) | 121 F(SCAVENGER_WEAK) |
| 111 | 122 |
| 112 #define TRACE_GC(tracer, scope_id) \ | 123 #define TRACE_GC(tracer, scope_id) \ |
| 113 GCTracer::Scope::ScopeId gc_tracer_scope_id(scope_id); \ | 124 GCTracer::Scope::ScopeId gc_tracer_scope_id(scope_id); \ |
| 114 GCTracer::Scope gc_tracer_scope(tracer, gc_tracer_scope_id); \ | 125 GCTracer::Scope gc_tracer_scope(tracer, gc_tracer_scope_id); \ |
| 115 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.gc"), \ | 126 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.gc"), \ |
| 116 GCTracer::Scope::Name(gc_tracer_scope_id)) | 127 GCTracer::Scope::Name(gc_tracer_scope_id)) |
| 117 | 128 |
| 118 // GCTracer collects and prints ONE line after each garbage collector | 129 // GCTracer collects and prints ONE line after each garbage collector |
| 119 // invocation IFF --trace_gc is used. | 130 // invocation IFF --trace_gc is used. |
| 120 // TODO(ernstm): Unit tests. | 131 // TODO(ernstm): Unit tests. |
| 121 class GCTracer { | 132 class GCTracer { |
| 122 public: | 133 public: |
| 123 class Scope { | 134 class Scope { |
| 124 public: | 135 public: |
| 125 enum ScopeId { | 136 enum ScopeId { |
| 126 #define DEFINE_SCOPE(scope) scope, | 137 #define DEFINE_SCOPE(scope) scope, |
| 127 TRACER_SCOPES(DEFINE_SCOPE) | 138 TRACER_SCOPES(DEFINE_SCOPE) |
| 128 #undef DEFINE_SCOPE | 139 #undef DEFINE_SCOPE |
| 129 NUMBER_OF_SCOPES | 140 NUMBER_OF_SCOPES, |
| 141 |
| 142 FIRST_INCREMENTAL_SCOPE = MC_INCREMENTAL_WRAPPER_PROLOGUE, |
| 143 LAST_INCREMENTAL_SCOPE = MC_INCREMENTAL_EXTERNAL_PROLOGUE, |
| 144 NUMBER_OF_INCREMENTAL_SCOPES = |
| 145 LAST_INCREMENTAL_SCOPE - FIRST_INCREMENTAL_SCOPE + 1 |
| 130 }; | 146 }; |
| 131 | 147 |
| 132 Scope(GCTracer* tracer, ScopeId scope); | 148 Scope(GCTracer* tracer, ScopeId scope); |
| 133 ~Scope(); | 149 ~Scope(); |
| 134 static const char* Name(ScopeId id); | 150 static const char* Name(ScopeId id); |
| 135 | 151 |
| 136 private: | 152 private: |
| 137 GCTracer* tracer_; | 153 GCTracer* tracer_; |
| 138 ScopeId scope_; | 154 ScopeId scope_; |
| 139 double start_time_; | 155 double start_time_; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 // Total amount of space either wasted or contained in one of free lists | 206 // Total amount of space either wasted or contained in one of free lists |
| 191 // before the current GC. | 207 // before the current GC. |
| 192 intptr_t start_holes_size; | 208 intptr_t start_holes_size; |
| 193 | 209 |
| 194 // Total amount of space either wasted or contained in one of free lists | 210 // Total amount of space either wasted or contained in one of free lists |
| 195 // after the current GC. | 211 // after the current GC. |
| 196 intptr_t end_holes_size; | 212 intptr_t end_holes_size; |
| 197 | 213 |
| 198 // Size of new space objects in constructor. | 214 // Size of new space objects in constructor. |
| 199 intptr_t new_space_object_size; | 215 intptr_t new_space_object_size; |
| 200 // Size of survived new space objects in desctructor. | 216 // Size of survived new space objects in destructor. |
| 201 intptr_t survived_new_space_object_size; | 217 intptr_t survived_new_space_object_size; |
| 202 | 218 |
| 203 // Number of incremental marking steps since creation of tracer. | 219 // Number of incremental marking steps since creation of tracer. |
| 204 // (value at start of event) | 220 // (value at start of event) |
| 205 int cumulative_incremental_marking_steps; | 221 int cumulative_incremental_marking_steps; |
| 206 | 222 |
| 207 // Incremental marking steps since | 223 // Incremental marking steps since |
| 208 // - last event for SCAVENGER events | 224 // - last event for SCAVENGER events |
| 209 // - last INCREMENTAL_MARK_COMPACTOR event for INCREMENTAL_MARK_COMPACTOR | 225 // - last INCREMENTAL_MARK_COMPACTOR event for INCREMENTAL_MARK_COMPACTOR |
| 210 // events | 226 // events |
| (...skipping 21 matching lines...) Expand all Loading... |
| 232 // Cumulative pure duration of incremental marking steps since creation of | 248 // Cumulative pure duration of incremental marking steps since creation of |
| 233 // tracer. (value at start of event) | 249 // tracer. (value at start of event) |
| 234 double cumulative_pure_incremental_marking_duration; | 250 double cumulative_pure_incremental_marking_duration; |
| 235 | 251 |
| 236 // Duration of pure incremental marking steps since | 252 // Duration of pure incremental marking steps since |
| 237 // - last event for SCAVENGER events | 253 // - last event for SCAVENGER events |
| 238 // - last INCREMENTAL_MARK_COMPACTOR event for INCREMENTAL_MARK_COMPACTOR | 254 // - last INCREMENTAL_MARK_COMPACTOR event for INCREMENTAL_MARK_COMPACTOR |
| 239 // events | 255 // events |
| 240 double pure_incremental_marking_duration; | 256 double pure_incremental_marking_duration; |
| 241 | 257 |
| 242 // Longest incremental marking step since start of marking. | 258 // Longest incremental marking step since start of marking (start of event). |
| 243 // (value at start of event) | |
| 244 double longest_incremental_marking_step; | 259 double longest_incremental_marking_step; |
| 245 | 260 |
| 261 // Number of incremental marking finalization steps since creation of |
| 262 // tracer. |
| 263 int cumulative_incremental_marking_finalization_steps; |
| 264 |
| 265 // Cumulative pure duration of incremental marking steps since creation of |
| 266 // tracer. (value at start of event) |
| 267 double cumulative_incremental_marking_finalizaton_duration; |
| 268 |
| 269 // Longest incremental marking finalization step since start of marking |
| 270 // (start of event). |
| 271 double longest_incremental_marking_finalization_step; |
| 272 |
| 273 // Incremental marking finalization steps since |
| 274 // - last event for SCAVENGER events |
| 275 // - last INCREMENTAL_MARK_COMPACTOR event for INCREMENTAL_MARK_COMPACTOR |
| 276 // events |
| 277 int incremental_marking_finalizaton_steps; |
| 278 |
| 279 // Duration of incremental marking finalization steps since |
| 280 // - last event for SCAVENGER events |
| 281 // - last INCREMENTAL_MARK_COMPACTOR event for INCREMENTAL_MARK_COMPACTOR |
| 282 // events |
| 283 double incremental_marking_finalization_duration; |
| 284 |
| 285 double cumulative_incremental_scopes[Scope::NUMBER_OF_INCREMENTAL_SCOPES]; |
| 286 |
| 246 // Amounts of time spent in different scopes during GC. | 287 // Amounts of time spent in different scopes during GC. |
| 247 double scopes[Scope::NUMBER_OF_SCOPES]; | 288 double scopes[Scope::NUMBER_OF_SCOPES]; |
| 248 }; | 289 }; |
| 249 | 290 |
| 250 static const int kThroughputTimeFrameMs = 5000; | 291 static const int kThroughputTimeFrameMs = 5000; |
| 251 | 292 |
| 252 explicit GCTracer(Heap* heap); | 293 explicit GCTracer(Heap* heap); |
| 253 | 294 |
| 254 // Start collecting data. | 295 // Start collecting data. |
| 255 void Start(GarbageCollector collector, const char* gc_reason, | 296 void Start(GarbageCollector collector, const char* gc_reason, |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 // events. | 399 // events. |
| 359 // Returns 0 if no events have been recorded. | 400 // Returns 0 if no events have been recorded. |
| 360 double AverageSurvivalRatio() const; | 401 double AverageSurvivalRatio() const; |
| 361 | 402 |
| 362 // Returns true if at least one survival event was recorded. | 403 // Returns true if at least one survival event was recorded. |
| 363 bool SurvivalEventsRecorded() const; | 404 bool SurvivalEventsRecorded() const; |
| 364 | 405 |
| 365 // Discard all recorded survival events. | 406 // Discard all recorded survival events. |
| 366 void ResetSurvivalEvents(); | 407 void ResetSurvivalEvents(); |
| 367 | 408 |
| 409 void AddScopeSample(Scope::ScopeId scope, double duration); |
| 410 |
| 411 private: |
| 412 FRIEND_TEST(GCTracer, AverageSpeed); |
| 413 FRIEND_TEST(GCTracerTest, AllocationThroughput); |
| 414 FRIEND_TEST(GCTracerTest, NewSpaceAllocationThroughput); |
| 415 FRIEND_TEST(GCTracerTest, NewSpaceAllocationThroughputWithProvidedTime); |
| 416 FRIEND_TEST(GCTracerTest, OldGenerationAllocationThroughputWithProvidedTime); |
| 417 FRIEND_TEST(GCTracerTest, RegularScope); |
| 418 FRIEND_TEST(GCTracerTest, IncrementalScope); |
| 419 |
| 368 // Returns the average speed of the events in the buffer. | 420 // Returns the average speed of the events in the buffer. |
| 369 // If the buffer is empty, the result is 0. | 421 // If the buffer is empty, the result is 0. |
| 370 // Otherwise, the result is between 1 byte/ms and 1 GB/ms. | 422 // Otherwise, the result is between 1 byte/ms and 1 GB/ms. |
| 371 static double AverageSpeed(const RingBuffer<BytesAndDuration>& buffer); | 423 static double AverageSpeed(const RingBuffer<BytesAndDuration>& buffer); |
| 372 static double AverageSpeed(const RingBuffer<BytesAndDuration>& buffer, | 424 static double AverageSpeed(const RingBuffer<BytesAndDuration>& buffer, |
| 373 const BytesAndDuration& initial, double time_ms); | 425 const BytesAndDuration& initial, double time_ms); |
| 374 | 426 |
| 375 void ResetForTesting(); | 427 void ResetForTesting(); |
| 376 | 428 |
| 377 private: | |
| 378 // Print one detailed trace line in name=value format. | 429 // Print one detailed trace line in name=value format. |
| 379 // TODO(ernstm): Move to Heap. | 430 // TODO(ernstm): Move to Heap. |
| 380 void PrintNVP() const; | 431 void PrintNVP() const; |
| 381 | 432 |
| 382 // Print one trace line. | 433 // Print one trace line. |
| 383 // TODO(ernstm): Move to Heap. | 434 // TODO(ernstm): Move to Heap. |
| 384 void Print() const; | 435 void Print() const; |
| 385 | 436 |
| 386 // Prints a line and also adds it to the heap's ring buffer so that | 437 // Prints a line and also adds it to the heap's ring buffer so that |
| 387 // it can be included in later crash dumps. | 438 // it can be included in later crash dumps. |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 // creation of tracer. | 499 // creation of tracer. |
| 449 double cumulative_incremental_marking_finalization_duration_; | 500 double cumulative_incremental_marking_finalization_duration_; |
| 450 | 501 |
| 451 // Longest incremental marking finalization step since start of marking. | 502 // Longest incremental marking finalization step since start of marking. |
| 452 double longest_incremental_marking_finalization_step_; | 503 double longest_incremental_marking_finalization_step_; |
| 453 | 504 |
| 454 // Total marking time. | 505 // Total marking time. |
| 455 // This timer is precise when run with --print-cumulative-gc-stat | 506 // This timer is precise when run with --print-cumulative-gc-stat |
| 456 double cumulative_marking_duration_; | 507 double cumulative_marking_duration_; |
| 457 | 508 |
| 509 // Cumulative duration of incremental marking scopes since the creation of |
| 510 // the tracer. |
| 511 double cumulative_incremental_scopes_[Scope::NUMBER_OF_INCREMENTAL_SCOPES]; |
| 512 |
| 458 // Total sweeping time on the main thread. | 513 // Total sweeping time on the main thread. |
| 459 // This timer is precise when run with --print-cumulative-gc-stat | 514 // This timer is precise when run with --print-cumulative-gc-stat |
| 460 // TODO(hpayer): Account for sweeping time on sweeper threads. Add a | 515 // TODO(hpayer): Account for sweeping time on sweeper threads. Add a |
| 461 // different field for that. | 516 // different field for that. |
| 462 // TODO(hpayer): This timer right now just holds the sweeping time | 517 // TODO(hpayer): This timer right now just holds the sweeping time |
| 463 // of the initial atomic sweeping pause. Make sure that it accumulates | 518 // of the initial atomic sweeping pause. Make sure that it accumulates |
| 464 // all sweeping operations performed on the main thread. | 519 // all sweeping operations performed on the main thread. |
| 465 double cumulative_sweeping_duration_; | 520 double cumulative_sweeping_duration_; |
| 466 | 521 |
| 467 // Timestamp and allocation counter at the last sampled allocation event. | 522 // Timestamp and allocation counter at the last sampled allocation event. |
| (...skipping 24 matching lines...) Expand all Loading... |
| 492 RingBuffer<BytesAndDuration> recorded_old_generation_allocations_; | 547 RingBuffer<BytesAndDuration> recorded_old_generation_allocations_; |
| 493 RingBuffer<double> recorded_context_disposal_times_; | 548 RingBuffer<double> recorded_context_disposal_times_; |
| 494 RingBuffer<double> recorded_survival_ratios_; | 549 RingBuffer<double> recorded_survival_ratios_; |
| 495 | 550 |
| 496 DISALLOW_COPY_AND_ASSIGN(GCTracer); | 551 DISALLOW_COPY_AND_ASSIGN(GCTracer); |
| 497 }; | 552 }; |
| 498 } // namespace internal | 553 } // namespace internal |
| 499 } // namespace v8 | 554 } // namespace v8 |
| 500 | 555 |
| 501 #endif // V8_HEAP_GC_TRACER_H_ | 556 #endif // V8_HEAP_GC_TRACER_H_ |
| OLD | NEW |