| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 #include "vm/scavenger.h" | 5 #include "vm/scavenger.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <map> | 8 #include <map> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 | 67 |
| 68 class ScavengerVisitor : public ObjectPointerVisitor { | 68 class ScavengerVisitor : public ObjectPointerVisitor { |
| 69 public: | 69 public: |
| 70 explicit ScavengerVisitor(Isolate* isolate, Scavenger* scavenger) | 70 explicit ScavengerVisitor(Isolate* isolate, Scavenger* scavenger) |
| 71 : ObjectPointerVisitor(isolate), | 71 : ObjectPointerVisitor(isolate), |
| 72 scavenger_(scavenger), | 72 scavenger_(scavenger), |
| 73 heap_(scavenger->heap_), | 73 heap_(scavenger->heap_), |
| 74 vm_heap_(Dart::vm_isolate()->heap()), | 74 vm_heap_(Dart::vm_isolate()->heap()), |
| 75 delayed_weak_stack_(), | 75 delayed_weak_stack_(), |
| 76 growth_policy_(PageSpace::kControlGrowth), | 76 growth_policy_(PageSpace::kControlGrowth), |
| 77 bytes_promoted_(0), |
| 77 visiting_old_pointers_(false), | 78 visiting_old_pointers_(false), |
| 78 in_scavenge_pointer_(false) {} | 79 in_scavenge_pointer_(false) {} |
| 79 | 80 |
| 80 void VisitPointers(RawObject** first, RawObject** last) { | 81 void VisitPointers(RawObject** first, RawObject** last) { |
| 81 for (RawObject** current = first; current <= last; current++) { | 82 for (RawObject** current = first; current <= last; current++) { |
| 82 ScavengePointer(current); | 83 ScavengePointer(current); |
| 83 } | 84 } |
| 84 } | 85 } |
| 85 | 86 |
| 86 GrowableArray<RawObject*>* DelayedWeakStack() { | 87 GrowableArray<RawObject*>* DelayedWeakStack() { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 101 delay_set_.insert(std::make_pair(raw_key, raw_weak)); | 102 delay_set_.insert(std::make_pair(raw_key, raw_weak)); |
| 102 } | 103 } |
| 103 | 104 |
| 104 void Finalize() { | 105 void Finalize() { |
| 105 DelaySet::iterator it = delay_set_.begin(); | 106 DelaySet::iterator it = delay_set_.begin(); |
| 106 for (; it != delay_set_.end(); ++it) { | 107 for (; it != delay_set_.end(); ++it) { |
| 107 WeakProperty::Clear(it->second); | 108 WeakProperty::Clear(it->second); |
| 108 } | 109 } |
| 109 } | 110 } |
| 110 | 111 |
| 112 intptr_t bytes_promoted() const { return bytes_promoted_; } |
| 113 |
| 111 private: | 114 private: |
| 112 void UpdateStoreBuffer(RawObject** p, RawObject* obj) { | 115 void UpdateStoreBuffer(RawObject** p, RawObject* obj) { |
| 113 uword ptr = reinterpret_cast<uword>(p); | 116 uword ptr = reinterpret_cast<uword>(p); |
| 114 ASSERT(obj->IsHeapObject()); | 117 ASSERT(obj->IsHeapObject()); |
| 115 ASSERT(!scavenger_->Contains(ptr)); | 118 ASSERT(!scavenger_->Contains(ptr)); |
| 116 ASSERT(!heap_->CodeContains(ptr)); | 119 ASSERT(!heap_->CodeContains(ptr)); |
| 117 ASSERT(heap_->Contains(ptr)); | 120 ASSERT(heap_->Contains(ptr)); |
| 118 // If the newly written object is not a new object, drop it immediately. | 121 // If the newly written object is not a new object, drop it immediately. |
| 119 if (!obj->IsNewObject()) return; | 122 if (!obj->IsNewObject()) return; |
| 120 isolate()->store_buffer()->AddPointer(ptr); | 123 isolate()->store_buffer()->AddPointer(ptr); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 // a coin toss determines if an object is promoted or whether it should | 180 // a coin toss determines if an object is promoted or whether it should |
| 178 // survive in this generation. | 181 // survive in this generation. |
| 179 // | 182 // |
| 180 // This object is a survivor of a previous scavenge. Attempt to promote | 183 // This object is a survivor of a previous scavenge. Attempt to promote |
| 181 // the object. | 184 // the object. |
| 182 new_addr = heap_->TryAllocate(size, Heap::kOld, growth_policy_); | 185 new_addr = heap_->TryAllocate(size, Heap::kOld, growth_policy_); |
| 183 if (new_addr != 0) { | 186 if (new_addr != 0) { |
| 184 // If promotion succeeded then we need to remember it so that it can | 187 // If promotion succeeded then we need to remember it so that it can |
| 185 // be traversed later. | 188 // be traversed later. |
| 186 scavenger_->PushToPromotedStack(new_addr); | 189 scavenger_->PushToPromotedStack(new_addr); |
| 190 bytes_promoted_ += size; |
| 187 if (HeapTrace::is_enabled()) { | 191 if (HeapTrace::is_enabled()) { |
| 188 heap_->trace()->TracePromotion(raw_addr, new_addr); | 192 heap_->trace()->TracePromotion(raw_addr, new_addr); |
| 189 } | 193 } |
| 190 } else if (!scavenger_->had_promotion_failure_) { | 194 } else if (!scavenger_->had_promotion_failure_) { |
| 191 // Signal a promotion failure and set the growth policy for | 195 // Signal a promotion failure and set the growth policy for |
| 192 // this, and all subsequent promotion allocations, to force | 196 // this, and all subsequent promotion allocations, to force |
| 193 // growth. | 197 // growth. |
| 194 scavenger_->had_promotion_failure_ = true; | 198 scavenger_->had_promotion_failure_ = true; |
| 195 growth_policy_ = PageSpace::kForceGrowth; | 199 growth_policy_ = PageSpace::kForceGrowth; |
| 196 new_addr = heap_->TryAllocate(size, Heap::kOld, growth_policy_); | 200 new_addr = heap_->TryAllocate(size, Heap::kOld, growth_policy_); |
| 197 if (new_addr != 0) { | 201 if (new_addr != 0) { |
| 198 scavenger_->PushToPromotedStack(new_addr); | 202 scavenger_->PushToPromotedStack(new_addr); |
| 203 bytes_promoted_ += size; |
| 199 if (HeapTrace::is_enabled()) { | 204 if (HeapTrace::is_enabled()) { |
| 200 heap_->trace()->TracePromotion(raw_addr, new_addr); | 205 heap_->trace()->TracePromotion(raw_addr, new_addr); |
| 201 } | 206 } |
| 202 } else { | 207 } else { |
| 203 // Promotion did not succeed. Copy into the to space | 208 // Promotion did not succeed. Copy into the to space |
| 204 // instead. | 209 // instead. |
| 205 new_addr = scavenger_->TryAllocate(size); | 210 new_addr = scavenger_->TryAllocate(size); |
| 206 if (HeapTrace::is_enabled()) { | 211 if (HeapTrace::is_enabled()) { |
| 207 heap_->trace()->TraceCopy(raw_addr, new_addr); | 212 heap_->trace()->TraceCopy(raw_addr, new_addr); |
| 208 } | 213 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 235 } | 240 } |
| 236 } | 241 } |
| 237 | 242 |
| 238 Scavenger* scavenger_; | 243 Scavenger* scavenger_; |
| 239 Heap* heap_; | 244 Heap* heap_; |
| 240 Heap* vm_heap_; | 245 Heap* vm_heap_; |
| 241 typedef std::multimap<RawObject*, RawWeakProperty*> DelaySet; | 246 typedef std::multimap<RawObject*, RawWeakProperty*> DelaySet; |
| 242 DelaySet delay_set_; | 247 DelaySet delay_set_; |
| 243 GrowableArray<RawObject*> delayed_weak_stack_; | 248 GrowableArray<RawObject*> delayed_weak_stack_; |
| 244 PageSpace::GrowthPolicy growth_policy_; | 249 PageSpace::GrowthPolicy growth_policy_; |
| 250 // TODO(cshapiro): use this value to compute survival statistics for |
| 251 // new space growth policy. |
| 252 intptr_t bytes_promoted_; |
| 245 | 253 |
| 246 bool visiting_old_pointers_; | 254 bool visiting_old_pointers_; |
| 247 bool in_scavenge_pointer_; | 255 bool in_scavenge_pointer_; |
| 248 | 256 |
| 249 DISALLOW_COPY_AND_ASSIGN(ScavengerVisitor); | 257 DISALLOW_COPY_AND_ASSIGN(ScavengerVisitor); |
| 250 }; | 258 }; |
| 251 | 259 |
| 252 | 260 |
| 253 class ScavengerWeakVisitor : public HandleVisitor { | 261 class ScavengerWeakVisitor : public HandleVisitor { |
| 254 public: | 262 public: |
| (...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 696 PeerTable::iterator it = peer_table_.find(raw_obj); | 704 PeerTable::iterator it = peer_table_.find(raw_obj); |
| 697 return (it == peer_table_.end()) ? NULL : it->second; | 705 return (it == peer_table_.end()) ? NULL : it->second; |
| 698 } | 706 } |
| 699 | 707 |
| 700 | 708 |
| 701 int64_t Scavenger::PeerCount() const { | 709 int64_t Scavenger::PeerCount() const { |
| 702 return static_cast<int64_t>(peer_table_.size()); | 710 return static_cast<int64_t>(peer_table_.size()); |
| 703 } | 711 } |
| 704 | 712 |
| 705 } // namespace dart | 713 } // namespace dart |
| OLD | NEW |