| 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 #include "vm/pages.h" | 5 #include "vm/pages.h" |
| 6 | 6 |
| 7 #include "platform/assert.h" | 7 #include "platform/assert.h" |
| 8 #include "vm/gc_marker.h" | 8 #include "vm/gc_marker.h" |
| 9 #include "vm/gc_sweeper.h" | 9 #include "vm/gc_sweeper.h" |
| 10 #include "vm/object.h" | 10 #include "vm/object.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 uword obj_addr = first_object_start(); | 42 uword obj_addr = first_object_start(); |
| 43 uword end_addr = top(); | 43 uword end_addr = top(); |
| 44 while (obj_addr < end_addr) { | 44 while (obj_addr < end_addr) { |
| 45 RawObject* raw_obj = RawObject::FromAddr(obj_addr); | 45 RawObject* raw_obj = RawObject::FromAddr(obj_addr); |
| 46 obj_addr += raw_obj->VisitPointers(visitor); | 46 obj_addr += raw_obj->VisitPointers(visitor); |
| 47 } | 47 } |
| 48 ASSERT(obj_addr == end_addr); | 48 ASSERT(obj_addr == end_addr); |
| 49 } | 49 } |
| 50 | 50 |
| 51 | 51 |
| 52 RawObject* HeapPage::FindObject(FindObjectVisitor* visitor) const { | |
| 53 uword obj_addr = first_object_start(); | |
| 54 uword end_addr = top(); | |
| 55 while (obj_addr < end_addr) { | |
| 56 RawObject* raw_obj = RawObject::FromAddr(obj_addr); | |
| 57 if (raw_obj->FindObject(visitor)) { | |
| 58 return raw_obj; // Found object, return it. | |
| 59 } | |
| 60 obj_addr += raw_obj->Size(); | |
| 61 } | |
| 62 ASSERT(obj_addr == end_addr); | |
| 63 return Object::null(); | |
| 64 } | |
| 65 | |
| 66 | |
| 67 PageSpace::PageSpace(Heap* heap, intptr_t max_capacity, bool is_executable) | 52 PageSpace::PageSpace(Heap* heap, intptr_t max_capacity, bool is_executable) |
| 68 : freelist_(), | 53 : freelist_(), |
| 69 heap_(heap), | 54 heap_(heap), |
| 70 pages_(NULL), | 55 pages_(NULL), |
| 71 pages_tail_(NULL), | 56 pages_tail_(NULL), |
| 72 large_pages_(NULL), | 57 large_pages_(NULL), |
| 73 max_capacity_(max_capacity), | 58 max_capacity_(max_capacity), |
| 74 capacity_(0), | 59 capacity_(0), |
| 75 in_use_(0), | 60 in_use_(0), |
| 76 count_(0), | 61 count_(0), |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 } | 199 } |
| 215 | 200 |
| 216 page = large_pages_; | 201 page = large_pages_; |
| 217 while (page != NULL) { | 202 while (page != NULL) { |
| 218 page->VisitObjectPointers(visitor); | 203 page->VisitObjectPointers(visitor); |
| 219 page = page->next(); | 204 page = page->next(); |
| 220 } | 205 } |
| 221 } | 206 } |
| 222 | 207 |
| 223 | 208 |
| 224 RawObject* PageSpace::FindObject(FindObjectVisitor* visitor) const { | |
| 225 ASSERT(Isolate::Current()->no_gc_scope_depth() != 0); | |
| 226 HeapPage* page = pages_; | |
| 227 while (page != NULL) { | |
| 228 RawObject* obj = page->FindObject(visitor); | |
| 229 if (obj != Object::null()) { | |
| 230 return obj; | |
| 231 } | |
| 232 page = page->next(); | |
| 233 } | |
| 234 | |
| 235 page = large_pages_; | |
| 236 while (page != NULL) { | |
| 237 RawObject* obj = page->FindObject(visitor); | |
| 238 if (obj != Object::null()) { | |
| 239 return obj; | |
| 240 } | |
| 241 page = page->next(); | |
| 242 } | |
| 243 return Object::null(); | |
| 244 } | |
| 245 | |
| 246 | |
| 247 void PageSpace::MarkSweep(bool invoke_api_callbacks) { | 209 void PageSpace::MarkSweep(bool invoke_api_callbacks) { |
| 248 // MarkSweep is not reentrant. Make sure that is the case. | 210 // MarkSweep is not reentrant. Make sure that is the case. |
| 249 ASSERT(!sweeping_); | 211 ASSERT(!sweeping_); |
| 250 sweeping_ = true; | 212 sweeping_ = true; |
| 251 Isolate* isolate = Isolate::Current(); | 213 Isolate* isolate = Isolate::Current(); |
| 252 NoHandleScope no_handles(isolate); | 214 NoHandleScope no_handles(isolate); |
| 253 | 215 |
| 254 if (FLAG_verify_before_gc) { | 216 if (FLAG_verify_before_gc) { |
| 255 OS::PrintErr("Verifying before MarkSweep... "); | 217 OS::PrintErr("Verifying before MarkSweep... "); |
| 256 heap_->Verify(); | 218 heap_->Verify(); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 OS::PrintErr(" done.\n"); | 273 OS::PrintErr(" done.\n"); |
| 312 } | 274 } |
| 313 | 275 |
| 314 count_++; | 276 count_++; |
| 315 // Done, reset the marker. | 277 // Done, reset the marker. |
| 316 ASSERT(sweeping_); | 278 ASSERT(sweeping_); |
| 317 sweeping_ = false; | 279 sweeping_ = false; |
| 318 } | 280 } |
| 319 | 281 |
| 320 } // namespace dart | 282 } // namespace dart |
| OLD | NEW |