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