| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 #include "vm/gc_sweeper.h" |
| 6 |
| 7 #include "vm/freelist.h" |
| 8 #include "vm/globals.h" |
| 9 #include "vm/pages.h" |
| 10 |
| 11 namespace dart { |
| 12 |
| 13 intptr_t GCSweeper::SweepPage(HeapPage* page, FreeList* freelist) { |
| 14 // Keep track of the discovered live object sizes to be able to finish |
| 15 // sweeping early. Reset the per page in_use count for the next marking phase. |
| 16 intptr_t in_use_swept = 0; |
| 17 intptr_t in_use = page->used(); |
| 18 page->set_used(0); |
| 19 |
| 20 uword current = page->first_object_start(); |
| 21 uword top = page->top(); |
| 22 |
| 23 while (current < top) { |
| 24 if (in_use_swept == in_use) { |
| 25 // No more marked objects will be found on this page. |
| 26 page->set_top(current); |
| 27 break; |
| 28 } |
| 29 RawObject* raw_obj = RawObject::FromAddr(current); |
| 30 intptr_t obj_size; |
| 31 if (raw_obj->IsMarked()) { |
| 32 // Found marked object. Clear the mark bit and update swept bytes. |
| 33 raw_obj->ClearMarkBit(); |
| 34 obj_size = raw_obj->Size(); |
| 35 in_use_swept += obj_size; |
| 36 } else { |
| 37 uword free_end = current + raw_obj->Size(); |
| 38 while (free_end < top) { |
| 39 RawObject* next_obj = RawObject::FromAddr(free_end); |
| 40 if (next_obj->IsMarked()) { |
| 41 // Reached the end of the free block. |
| 42 break; |
| 43 } |
| 44 // Expand the free block by the size of this object. |
| 45 free_end += next_obj->Size(); |
| 46 } |
| 47 obj_size = free_end - current; |
| 48 if ((current + obj_size) == top) { |
| 49 page->set_top(current); |
| 50 break; |
| 51 } else { |
| 52 freelist->Free(current, obj_size); |
| 53 } |
| 54 } |
| 55 current += obj_size; |
| 56 } |
| 57 |
| 58 return in_use_swept; |
| 59 } |
| 60 |
| 61 |
| 62 intptr_t GCSweeper::SweepLargePage(HeapPage* page) { |
| 63 UNIMPLEMENTED(); |
| 64 return 0; |
| 65 } |
| 66 |
| 67 } // namespace dart |
| OLD | NEW |