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