| 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/gc_marker.h" | 5 #include "vm/gc_marker.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 return &skipped_code_functions_; | 151 return &skipped_code_functions_; |
| 152 } | 152 } |
| 153 | 153 |
| 154 void DelayWeakProperty(RawWeakProperty* raw_weak) { | 154 void DelayWeakProperty(RawWeakProperty* raw_weak) { |
| 155 RawObject* raw_key = raw_weak->ptr()->key_; | 155 RawObject* raw_key = raw_weak->ptr()->key_; |
| 156 DelaySet::iterator it = delay_set_.find(raw_key); | 156 DelaySet::iterator it = delay_set_.find(raw_key); |
| 157 if (it != delay_set_.end()) { | 157 if (it != delay_set_.end()) { |
| 158 ASSERT(raw_key->IsWatched()); | 158 ASSERT(raw_key->IsWatched()); |
| 159 } else { | 159 } else { |
| 160 ASSERT(!raw_key->IsWatched()); | 160 ASSERT(!raw_key->IsWatched()); |
| 161 raw_key->SetWatchedBit(); | 161 raw_key->SetWatchedBitUnsynchronized(); |
| 162 } | 162 } |
| 163 delay_set_.insert(std::make_pair(raw_key, raw_weak)); | 163 delay_set_.insert(std::make_pair(raw_key, raw_weak)); |
| 164 } | 164 } |
| 165 | 165 |
| 166 void Finalize() { | 166 void Finalize() { |
| 167 DelaySet::iterator it = delay_set_.begin(); | 167 DelaySet::iterator it = delay_set_.begin(); |
| 168 for (; it != delay_set_.end(); ++it) { | 168 for (; it != delay_set_.end(); ++it) { |
| 169 WeakProperty::Clear(it->second); | 169 WeakProperty::Clear(it->second); |
| 170 } | 170 } |
| 171 if (!visit_function_code_) { | 171 if (!visit_function_code_) { |
| 172 DetachCode(); | 172 DetachCode(); |
| 173 } | 173 } |
| 174 } | 174 } |
| 175 | 175 |
| 176 void VisitingOldObject(RawObject* obj) { | 176 void VisitingOldObject(RawObject* obj) { |
| 177 ASSERT((obj == NULL) || obj->IsOldObject()); | 177 ASSERT((obj == NULL) || obj->IsOldObject()); |
| 178 visiting_old_object_ = obj; | 178 visiting_old_object_ = obj; |
| 179 } | 179 } |
| 180 | 180 |
| 181 private: | 181 private: |
| 182 void MarkAndPush(RawObject* raw_obj) { | 182 void MarkAndPush(RawObject* raw_obj) { |
| 183 ASSERT(raw_obj->IsHeapObject()); | 183 ASSERT(raw_obj->IsHeapObject()); |
| 184 ASSERT((FLAG_verify_before_gc || FLAG_verify_before_gc) ? | 184 ASSERT((FLAG_verify_before_gc || FLAG_verify_before_gc) ? |
| 185 page_space_->Contains(RawObject::ToAddr(raw_obj)) : | 185 page_space_->Contains(RawObject::ToAddr(raw_obj)) : |
| 186 true); | 186 true); |
| 187 | 187 |
| 188 // Mark the object and push it on the marking stack. | 188 // Mark the object and push it on the marking stack. |
| 189 ASSERT(!raw_obj->IsMarked()); | 189 ASSERT(!raw_obj->IsMarked()); |
| 190 raw_obj->SetMarkBit(); | 190 const bool is_watched = raw_obj->IsWatched(); |
| 191 raw_obj->ClearRememberedBit(); | 191 raw_obj->SetMarkBitUnsynchronized(); |
| 192 if (raw_obj->IsWatched()) { | 192 raw_obj->ClearRememberedBitUnsynchronized(); |
| 193 raw_obj->ClearWatchedBitUnsynchronized(); |
| 194 if (is_watched) { |
| 193 std::pair<DelaySet::iterator, DelaySet::iterator> ret; | 195 std::pair<DelaySet::iterator, DelaySet::iterator> ret; |
| 194 // Visit all elements with a key equal to raw_obj. | 196 // Visit all elements with a key equal to raw_obj. |
| 195 ret = delay_set_.equal_range(raw_obj); | 197 ret = delay_set_.equal_range(raw_obj); |
| 196 // Create a copy of the range in a temporary vector to iterate over it | 198 // Create a copy of the range in a temporary vector to iterate over it |
| 197 // while delay_set_ may be modified. | 199 // while delay_set_ may be modified. |
| 198 std::vector<DelaySetEntry> temp_copy(ret.first, ret.second); | 200 std::vector<DelaySetEntry> temp_copy(ret.first, ret.second); |
| 199 delay_set_.erase(ret.first, ret.second); | 201 delay_set_.erase(ret.first, ret.second); |
| 200 for (std::vector<DelaySetEntry>::iterator it = temp_copy.begin(); | 202 for (std::vector<DelaySetEntry>::iterator it = temp_copy.begin(); |
| 201 it != temp_copy.end(); ++it) { | 203 it != temp_copy.end(); ++it) { |
| 202 it->second->VisitPointers(this); | 204 it->second->VisitPointers(this); |
| 203 } | 205 } |
| 204 raw_obj->ClearWatchedBit(); | |
| 205 } | 206 } |
| 206 marking_stack_->Push(raw_obj); | 207 marking_stack_->Push(raw_obj); |
| 207 } | 208 } |
| 208 | 209 |
| 209 void MarkObject(RawObject* raw_obj, RawObject** p) { | 210 void MarkObject(RawObject* raw_obj, RawObject** p) { |
| 210 // Fast exit if the raw object is a Smi. | 211 // Fast exit if the raw object is a Smi. |
| 211 if (!raw_obj->IsHeapObject()) { | 212 if (!raw_obj->IsHeapObject()) { |
| 212 return; | 213 return; |
| 213 } | 214 } |
| 214 | 215 |
| 215 // Fast exit if the raw object is marked. | 216 // Fast exit if the raw object is marked. |
| 216 if (raw_obj->IsMarked()) { | 217 if (raw_obj->IsMarked()) { |
| 217 return; | 218 return; |
| 218 } | 219 } |
| 219 | 220 |
| 220 // Skip over new objects, but verify consistency of heap while at it. | 221 // Skip over new objects, but verify consistency of heap while at it. |
| 221 if (raw_obj->IsNewObject()) { | 222 if (raw_obj->IsNewObject()) { |
| 222 // TODO(iposva): Add consistency check. | 223 // TODO(iposva): Add consistency check. |
| 223 if ((visiting_old_object_ != NULL) && | 224 if ((visiting_old_object_ != NULL) && |
| 224 !visiting_old_object_->IsRemembered()) { | 225 !visiting_old_object_->IsRemembered()) { |
| 225 ASSERT(p != NULL); | 226 ASSERT(p != NULL); |
| 226 visiting_old_object_->SetRememberedBit(); | 227 visiting_old_object_->SetRememberedBitUnsynchronized(); |
| 227 isolate()->store_buffer()->AddObjectGC(visiting_old_object_); | 228 isolate()->store_buffer()->AddObjectGC(visiting_old_object_); |
| 228 } | 229 } |
| 229 return; | 230 return; |
| 230 } | 231 } |
| 231 if (RawObject::IsVariableSizeClassId(raw_obj->GetClassId())) { | 232 if (RawObject::IsVariableSizeClassId(raw_obj->GetClassId())) { |
| 232 class_table_->UpdateLiveOld(raw_obj->GetClassId(), raw_obj->Size()); | 233 class_table_->UpdateLiveOld(raw_obj->GetClassId(), raw_obj->Size()); |
| 233 } else { | 234 } else { |
| 234 class_table_->UpdateLiveOld(raw_obj->GetClassId(), 0); | 235 class_table_->UpdateLiveOld(raw_obj->GetClassId(), 0); |
| 235 } | 236 } |
| 236 | 237 |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 510 MarkingWeakVisitor mark_weak; | 511 MarkingWeakVisitor mark_weak; |
| 511 IterateWeakRoots(isolate, &mark_weak, invoke_api_callbacks); | 512 IterateWeakRoots(isolate, &mark_weak, invoke_api_callbacks); |
| 512 mark.Finalize(); | 513 mark.Finalize(); |
| 513 ProcessWeakTables(page_space); | 514 ProcessWeakTables(page_space); |
| 514 ProcessObjectIdTable(isolate); | 515 ProcessObjectIdTable(isolate); |
| 515 | 516 |
| 516 Epilogue(isolate, invoke_api_callbacks); | 517 Epilogue(isolate, invoke_api_callbacks); |
| 517 } | 518 } |
| 518 | 519 |
| 519 } // namespace dart | 520 } // namespace dart |
| OLD | NEW |