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