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/lockers.h" | 10 #include "vm/lockers.h" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 } | 65 } |
66 } | 66 } |
67 } | 67 } |
68 current += obj_size; | 68 current += obj_size; |
69 } | 69 } |
70 ASSERT(current == end); | 70 ASSERT(current == end); |
71 | 71 |
72 return in_use; | 72 return in_use; |
73 } | 73 } |
74 | 74 |
75 | |
76 intptr_t GCSweeper::SweepLargePage(HeapPage* page) { | 75 intptr_t GCSweeper::SweepLargePage(HeapPage* page) { |
77 intptr_t words_to_end = 0; | 76 intptr_t words_to_end = 0; |
78 RawObject* raw_obj = RawObject::FromAddr(page->object_start()); | 77 RawObject* raw_obj = RawObject::FromAddr(page->object_start()); |
79 if (raw_obj->IsMarked()) { | 78 if (raw_obj->IsMarked()) { |
80 raw_obj->ClearMarkBit(); | 79 raw_obj->ClearMarkBit(); |
81 words_to_end = (raw_obj->Size() >> kWordSizeLog2); | 80 words_to_end = (raw_obj->Size() >> kWordSizeLog2); |
82 } | 81 } |
83 #ifdef DEBUG | 82 #ifdef DEBUG |
84 // String::MakeExternal and Array::MakeFixedLength create trailing filler | 83 // String::MakeExternal and Array::MakeFixedLength create trailing filler |
85 // objects, but they are always unreachable. Verify that they are not marked. | 84 // objects, but they are always unreachable. Verify that they are not marked. |
86 uword current = RawObject::ToAddr(raw_obj) + raw_obj->Size(); | 85 uword current = RawObject::ToAddr(raw_obj) + raw_obj->Size(); |
87 uword end = page->object_end(); | 86 uword end = page->object_end(); |
88 while (current < end) { | 87 while (current < end) { |
89 RawObject* cur_obj = RawObject::FromAddr(current); | 88 RawObject* cur_obj = RawObject::FromAddr(current); |
90 ASSERT(!cur_obj->IsMarked()); | 89 ASSERT(!cur_obj->IsMarked()); |
91 intptr_t obj_size = cur_obj->Size(); | 90 intptr_t obj_size = cur_obj->Size(); |
92 memset(reinterpret_cast<void*>(current), Heap::kZapByte, obj_size); | 91 memset(reinterpret_cast<void*>(current), Heap::kZapByte, obj_size); |
93 current += obj_size; | 92 current += obj_size; |
94 } | 93 } |
95 #endif // DEBUG | 94 #endif // DEBUG |
96 return words_to_end; | 95 return words_to_end; |
97 } | 96 } |
98 | 97 |
99 | |
100 class SweeperTask : public ThreadPool::Task { | 98 class SweeperTask : public ThreadPool::Task { |
101 public: | 99 public: |
102 SweeperTask(Isolate* isolate, | 100 SweeperTask(Isolate* isolate, |
103 PageSpace* old_space, | 101 PageSpace* old_space, |
104 HeapPage* first, | 102 HeapPage* first, |
105 HeapPage* last, | 103 HeapPage* last, |
106 FreeList* freelist) | 104 FreeList* freelist) |
107 : task_isolate_(isolate), | 105 : task_isolate_(isolate), |
108 old_space_(old_space), | 106 old_space_(old_space), |
109 first_(first), | 107 first_(first), |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 } | 159 } |
162 | 160 |
163 private: | 161 private: |
164 Isolate* task_isolate_; | 162 Isolate* task_isolate_; |
165 PageSpace* old_space_; | 163 PageSpace* old_space_; |
166 HeapPage* first_; | 164 HeapPage* first_; |
167 HeapPage* last_; | 165 HeapPage* last_; |
168 FreeList* freelist_; | 166 FreeList* freelist_; |
169 }; | 167 }; |
170 | 168 |
171 | |
172 void GCSweeper::SweepConcurrent(Isolate* isolate, | 169 void GCSweeper::SweepConcurrent(Isolate* isolate, |
173 HeapPage* first, | 170 HeapPage* first, |
174 HeapPage* last, | 171 HeapPage* last, |
175 FreeList* freelist) { | 172 FreeList* freelist) { |
176 SweeperTask* task = new SweeperTask(isolate, isolate->heap()->old_space(), | 173 SweeperTask* task = new SweeperTask(isolate, isolate->heap()->old_space(), |
177 first, last, freelist); | 174 first, last, freelist); |
178 ThreadPool* pool = Dart::thread_pool(); | 175 ThreadPool* pool = Dart::thread_pool(); |
179 pool->Run(task); | 176 pool->Run(task); |
180 } | 177 } |
181 | 178 |
182 } // namespace dart | 179 } // namespace dart |
OLD | NEW |