| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef RUNTIME_VM_SCAVENGER_H_ | 5 #ifndef RUNTIME_VM_SCAVENGER_H_ |
| 6 #define RUNTIME_VM_SCAVENGER_H_ | 6 #define RUNTIME_VM_SCAVENGER_H_ |
| 7 | 7 |
| 8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
| 9 #include "platform/utils.h" | 9 #include "platform/utils.h" |
| 10 #include "vm/dart.h" | 10 #include "vm/dart.h" |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 // Returns zero if there were no promotion candidates. | 91 // Returns zero if there were no promotion candidates. |
| 92 double PromoCandidatesSuccessFraction() const { | 92 double PromoCandidatesSuccessFraction() const { |
| 93 return promo_candidates_in_words_ > 0 | 93 return promo_candidates_in_words_ > 0 |
| 94 ? promoted_in_words_ / | 94 ? promoted_in_words_ / |
| 95 static_cast<double>(promo_candidates_in_words_) | 95 static_cast<double>(promo_candidates_in_words_) |
| 96 : 0.0; | 96 : 0.0; |
| 97 } | 97 } |
| 98 | 98 |
| 99 int64_t DurationMicros() const { return end_micros_ - start_micros_; } | 99 int64_t DurationMicros() const { return end_micros_ - start_micros_; } |
| 100 | 100 |
| 101 intptr_t UsedBefore() const { return before_.used_in_words * kWordSize; } |
| 102 |
| 101 private: | 103 private: |
| 102 int64_t start_micros_; | 104 int64_t start_micros_; |
| 103 int64_t end_micros_; | 105 int64_t end_micros_; |
| 104 SpaceUsage before_; | 106 SpaceUsage before_; |
| 105 SpaceUsage after_; | 107 SpaceUsage after_; |
| 106 intptr_t promo_candidates_in_words_; | 108 intptr_t promo_candidates_in_words_; |
| 107 intptr_t promoted_in_words_; | 109 intptr_t promoted_in_words_; |
| 108 }; | 110 }; |
| 109 | 111 |
| 110 class Scavenger { | 112 class Scavenger { |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 int64_t CapacityInWords() const { return to_->size_in_words(); } | 209 int64_t CapacityInWords() const { return to_->size_in_words(); } |
| 208 int64_t ExternalInWords() const { return external_size_ >> kWordSizeLog2; } | 210 int64_t ExternalInWords() const { return external_size_ >> kWordSizeLog2; } |
| 209 SpaceUsage GetCurrentUsage() const { | 211 SpaceUsage GetCurrentUsage() const { |
| 210 SpaceUsage usage; | 212 SpaceUsage usage; |
| 211 usage.used_in_words = UsedInWords(); | 213 usage.used_in_words = UsedInWords(); |
| 212 usage.capacity_in_words = CapacityInWords(); | 214 usage.capacity_in_words = CapacityInWords(); |
| 213 usage.external_in_words = ExternalInWords(); | 215 usage.external_in_words = ExternalInWords(); |
| 214 return usage; | 216 return usage; |
| 215 } | 217 } |
| 216 | 218 |
| 219 intptr_t ScavengeRateInBytesPerMicro() const { |
| 220 intptr_t total_used = 0; |
| 221 intptr_t total_micros = 0; |
| 222 for (intptr_t i = 0; i < stats_history_.Size(); i++) { |
| 223 total_used += stats_history_.Get(i).UsedBefore(); |
| 224 total_micros += stats_history_.Get(i).DurationMicros(); |
| 225 } |
| 226 intptr_t scavenge_rate; |
| 227 if (total_micros != 0) { |
| 228 scavenge_rate = total_used / total_micros; |
| 229 } else { |
| 230 scavenge_rate = 400; // Conservative initial guess. |
| 231 } |
| 232 if (scavenge_rate == 0) { |
| 233 scavenge_rate = 1; |
| 234 } |
| 235 return scavenge_rate; |
| 236 } |
| 237 |
| 238 intptr_t EstimatedScavengeTime() const { |
| 239 return UsedInWords() * kWordSize / ScavengeRateInBytesPerMicro(); |
| 240 } |
| 241 |
| 217 void VisitObjects(ObjectVisitor* visitor) const; | 242 void VisitObjects(ObjectVisitor* visitor) const; |
| 218 void VisitObjectPointers(ObjectPointerVisitor* visitor) const; | 243 void VisitObjectPointers(ObjectPointerVisitor* visitor) const; |
| 219 | 244 |
| 220 void AddRegionsToObjectSet(ObjectSet* set) const; | 245 void AddRegionsToObjectSet(ObjectSet* set) const; |
| 221 | 246 |
| 222 void WriteProtect(bool read_only); | 247 void WriteProtect(bool read_only); |
| 223 | 248 |
| 224 void AddGCTime(int64_t micros) { gc_time_micros_ += micros; } | 249 void AddGCTime(int64_t micros) { gc_time_micros_ += micros; } |
| 225 | 250 |
| 226 int64_t gc_time_micros() const { return gc_time_micros_; } | 251 int64_t gc_time_micros() const { return gc_time_micros_; } |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 uword object_alignment_; | 348 uword object_alignment_; |
| 324 | 349 |
| 325 // Keep track whether a scavenge is currently running. | 350 // Keep track whether a scavenge is currently running. |
| 326 bool scavenging_; | 351 bool scavenging_; |
| 327 | 352 |
| 328 // Keep track of pending weak properties discovered while scagenging. | 353 // Keep track of pending weak properties discovered while scagenging. |
| 329 RawWeakProperty* delayed_weak_properties_; | 354 RawWeakProperty* delayed_weak_properties_; |
| 330 | 355 |
| 331 int64_t gc_time_micros_; | 356 int64_t gc_time_micros_; |
| 332 intptr_t collections_; | 357 intptr_t collections_; |
| 333 static const int kStatsHistoryCapacity = 2; | 358 static const int kStatsHistoryCapacity = 8; |
| 334 RingBuffer<ScavengeStats, kStatsHistoryCapacity> stats_history_; | 359 RingBuffer<ScavengeStats, kStatsHistoryCapacity> stats_history_; |
| 335 | 360 |
| 336 // The total size of external data associated with objects in this scavenger. | 361 // The total size of external data associated with objects in this scavenger. |
| 337 intptr_t external_size_; | 362 intptr_t external_size_; |
| 338 | 363 |
| 339 bool failed_to_promote_; | 364 bool failed_to_promote_; |
| 340 | 365 |
| 341 // Protects new space during the allocation of new TLABs | 366 // Protects new space during the allocation of new TLABs |
| 342 Mutex* space_lock_; | 367 Mutex* space_lock_; |
| 343 friend class ScavengerVisitor; | 368 friend class ScavengerVisitor; |
| 344 friend class ScavengerWeakVisitor; | 369 friend class ScavengerWeakVisitor; |
| 345 | 370 |
| 346 DISALLOW_COPY_AND_ASSIGN(Scavenger); | 371 DISALLOW_COPY_AND_ASSIGN(Scavenger); |
| 347 }; | 372 }; |
| 348 | 373 |
| 349 } // namespace dart | 374 } // namespace dart |
| 350 | 375 |
| 351 #endif // RUNTIME_VM_SCAVENGER_H_ | 376 #endif // RUNTIME_VM_SCAVENGER_H_ |
| OLD | NEW |