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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 | 64 |
65 // Statistics for a particular scavenge. | 65 // Statistics for a particular scavenge. |
66 class ScavengeStats { | 66 class ScavengeStats { |
67 public: | 67 public: |
68 ScavengeStats() {} | 68 ScavengeStats() {} |
69 ScavengeStats(int64_t start_micros, | 69 ScavengeStats(int64_t start_micros, |
70 int64_t end_micros, | 70 int64_t end_micros, |
71 SpaceUsage before, | 71 SpaceUsage before, |
72 SpaceUsage after, | 72 SpaceUsage after, |
73 intptr_t promo_candidates_in_words, | 73 intptr_t promo_candidates_in_words, |
74 intptr_t promoted_in_words) : | 74 intptr_t promoted_in_words) |
75 start_micros_(start_micros), | 75 : start_micros_(start_micros), |
76 end_micros_(end_micros), | 76 end_micros_(end_micros), |
77 before_(before), | 77 before_(before), |
78 after_(after), | 78 after_(after), |
79 promo_candidates_in_words_(promo_candidates_in_words), | 79 promo_candidates_in_words_(promo_candidates_in_words), |
80 promoted_in_words_(promoted_in_words) {} | 80 promoted_in_words_(promoted_in_words) {} |
81 | 81 |
82 // Of all data before scavenge, what fraction was found to be garbage? | 82 // Of all data before scavenge, what fraction was found to be garbage? |
83 double GarbageFraction() const { | 83 double GarbageFraction() const { |
84 intptr_t survived = after_.used_in_words + promoted_in_words_; | 84 intptr_t survived = after_.used_in_words + promoted_in_words_; |
85 return 1.0 - (survived / static_cast<double>(before_.used_in_words)); | 85 return 1.0 - (survived / static_cast<double>(before_.used_in_words)); |
86 } | 86 } |
87 | 87 |
88 // Fraction of promotion candidates that survived and was thereby promoted. | 88 // Fraction of promotion candidates that survived and was thereby promoted. |
89 // Returns zero if there were no promotion candidates. | 89 // Returns zero if there were no promotion candidates. |
90 double PromoCandidatesSuccessFraction() const { | 90 double PromoCandidatesSuccessFraction() const { |
91 return promo_candidates_in_words_ > 0 ? | 91 return promo_candidates_in_words_ > 0 |
92 promoted_in_words_ / static_cast<double>(promo_candidates_in_words_) : | 92 ? promoted_in_words_ / |
93 0.0; | 93 static_cast<double>(promo_candidates_in_words_) |
| 94 : 0.0; |
94 } | 95 } |
95 | 96 |
96 int64_t DurationMicros() const { | 97 int64_t DurationMicros() const { return end_micros_ - start_micros_; } |
97 return end_micros_ - start_micros_; | |
98 } | |
99 | 98 |
100 private: | 99 private: |
101 int64_t start_micros_; | 100 int64_t start_micros_; |
102 int64_t end_micros_; | 101 int64_t end_micros_; |
103 SpaceUsage before_; | 102 SpaceUsage before_; |
104 SpaceUsage after_; | 103 SpaceUsage after_; |
105 intptr_t promo_candidates_in_words_; | 104 intptr_t promo_candidates_in_words_; |
106 intptr_t promoted_in_words_; | 105 intptr_t promoted_in_words_; |
107 }; | 106 }; |
108 | 107 |
109 | 108 |
110 class Scavenger { | 109 class Scavenger { |
111 public: | 110 public: |
112 Scavenger(Heap* heap, | 111 Scavenger(Heap* heap, |
113 intptr_t max_semi_capacity_in_words, | 112 intptr_t max_semi_capacity_in_words, |
114 uword object_alignment); | 113 uword object_alignment); |
115 ~Scavenger(); | 114 ~Scavenger(); |
116 | 115 |
117 // Check whether this Scavenger contains this address. | 116 // Check whether this Scavenger contains this address. |
118 // During scavenging both the to and from spaces contain "legal" objects. | 117 // During scavenging both the to and from spaces contain "legal" objects. |
119 // During a scavenge this function only returns true for addresses that will | 118 // During a scavenge this function only returns true for addresses that will |
120 // be part of the surviving objects. | 119 // be part of the surviving objects. |
121 bool Contains(uword addr) const { | 120 bool Contains(uword addr) const { return to_->Contains(addr); } |
122 return to_->Contains(addr); | |
123 } | |
124 | 121 |
125 RawObject* FindObject(FindObjectVisitor* visitor) const; | 122 RawObject* FindObject(FindObjectVisitor* visitor) const; |
126 | 123 |
127 uword TryAllocate(intptr_t size) { | 124 uword TryAllocate(intptr_t size) { |
128 ASSERT(Utils::IsAligned(size, kObjectAlignment)); | 125 ASSERT(Utils::IsAligned(size, kObjectAlignment)); |
129 ASSERT(heap_ != Dart::vm_isolate()->heap()); | 126 ASSERT(heap_ != Dart::vm_isolate()->heap()); |
130 #if defined(DEBUG) | 127 #if defined(DEBUG) |
131 if (FLAG_gc_at_alloc && !scavenging_) { | 128 if (FLAG_gc_at_alloc && !scavenging_) { |
132 Scavenge(); | 129 Scavenge(); |
133 } | 130 } |
(...skipping 24 matching lines...) Expand all Loading... |
158 | 155 |
159 // Accessors to generate code for inlined allocation. | 156 // Accessors to generate code for inlined allocation. |
160 uword* TopAddress() { return &top_; } | 157 uword* TopAddress() { return &top_; } |
161 uword* EndAddress() { return &end_; } | 158 uword* EndAddress() { return &end_; } |
162 static intptr_t top_offset() { return OFFSET_OF(Scavenger, top_); } | 159 static intptr_t top_offset() { return OFFSET_OF(Scavenger, top_); } |
163 static intptr_t end_offset() { return OFFSET_OF(Scavenger, end_); } | 160 static intptr_t end_offset() { return OFFSET_OF(Scavenger, end_); } |
164 | 161 |
165 int64_t UsedInWords() const { | 162 int64_t UsedInWords() const { |
166 return (top_ - FirstObjectStart()) >> kWordSizeLog2; | 163 return (top_ - FirstObjectStart()) >> kWordSizeLog2; |
167 } | 164 } |
168 int64_t CapacityInWords() const { | 165 int64_t CapacityInWords() const { return to_->size_in_words(); } |
169 return to_->size_in_words(); | 166 int64_t ExternalInWords() const { return external_size_ >> kWordSizeLog2; } |
170 } | |
171 int64_t ExternalInWords() const { | |
172 return external_size_ >> kWordSizeLog2; | |
173 } | |
174 SpaceUsage GetCurrentUsage() const { | 167 SpaceUsage GetCurrentUsage() const { |
175 SpaceUsage usage; | 168 SpaceUsage usage; |
176 usage.used_in_words = UsedInWords(); | 169 usage.used_in_words = UsedInWords(); |
177 usage.capacity_in_words = CapacityInWords(); | 170 usage.capacity_in_words = CapacityInWords(); |
178 usage.external_in_words = ExternalInWords(); | 171 usage.external_in_words = ExternalInWords(); |
179 return usage; | 172 return usage; |
180 } | 173 } |
181 | 174 |
182 void VisitObjects(ObjectVisitor* visitor) const; | 175 void VisitObjects(ObjectVisitor* visitor) const; |
183 void VisitObjectPointers(ObjectPointerVisitor* visitor) const; | 176 void VisitObjectPointers(ObjectPointerVisitor* visitor) const; |
184 | 177 |
185 void AddRegionsToObjectSet(ObjectSet* set) const; | 178 void AddRegionsToObjectSet(ObjectSet* set) const; |
186 | 179 |
187 void WriteProtect(bool read_only); | 180 void WriteProtect(bool read_only); |
188 | 181 |
189 void AddGCTime(int64_t micros) { | 182 void AddGCTime(int64_t micros) { gc_time_micros_ += micros; } |
190 gc_time_micros_ += micros; | |
191 } | |
192 | 183 |
193 int64_t gc_time_micros() const { | 184 int64_t gc_time_micros() const { return gc_time_micros_; } |
194 return gc_time_micros_; | |
195 } | |
196 | 185 |
197 void IncrementCollections() { | 186 void IncrementCollections() { collections_++; } |
198 collections_++; | |
199 } | |
200 | 187 |
201 intptr_t collections() const { | 188 intptr_t collections() const { return collections_; } |
202 return collections_; | |
203 } | |
204 | 189 |
205 #ifndef PRODUCT | 190 #ifndef PRODUCT |
206 void PrintToJSONObject(JSONObject* object) const; | 191 void PrintToJSONObject(JSONObject* object) const; |
207 #endif // !PRODUCT | 192 #endif // !PRODUCT |
208 | 193 |
209 void AllocateExternal(intptr_t size); | 194 void AllocateExternal(intptr_t size); |
210 void FreeExternal(intptr_t size); | 195 void FreeExternal(intptr_t size); |
211 | 196 |
212 private: | 197 private: |
213 // Ids for time and data records in Heap::GCStats. | 198 // Ids for time and data records in Heap::GCStats. |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 | 291 |
307 friend class ScavengerVisitor; | 292 friend class ScavengerVisitor; |
308 friend class ScavengerWeakVisitor; | 293 friend class ScavengerWeakVisitor; |
309 | 294 |
310 DISALLOW_COPY_AND_ASSIGN(Scavenger); | 295 DISALLOW_COPY_AND_ASSIGN(Scavenger); |
311 }; | 296 }; |
312 | 297 |
313 } // namespace dart | 298 } // namespace dart |
314 | 299 |
315 #endif // RUNTIME_VM_SCAVENGER_H_ | 300 #endif // RUNTIME_VM_SCAVENGER_H_ |
OLD | NEW |