Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(173)

Side by Side Diff: runtime/vm/gc_sweeper.cc

Issue 2993383002: [vm] Compute per-HeapPage usage during sweeping. (Closed)
Patch Set: Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | runtime/vm/pages.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "vm/pages.h" 11 #include "vm/pages.h"
12 #include "vm/safepoint.h" 12 #include "vm/safepoint.h"
13 #include "vm/thread_pool.h" 13 #include "vm/thread_pool.h"
14 #include "vm/timeline.h" 14 #include "vm/timeline.h"
15 15
16 namespace dart { 16 namespace dart {
17 17
18 bool GCSweeper::SweepPage(HeapPage* page, FreeList* freelist, bool locked) { 18 bool GCSweeper::SweepPage(HeapPage* page, FreeList* freelist, bool locked) {
19 if (page->is_image_page()) { 19 if (page->is_image_page()) {
20 // Don't clear mark bits. 20 // Don't clear mark bits.
21 return true; 21 return true;
22 } 22 }
23 23
24 // Keep track whether this page is still in use. 24 // Keep track whether this page is still in use.
25 bool in_use = false; 25 intptr_t used_in_bytes = 0;
26 26
27 bool is_executable = (page->type() == HeapPage::kExecutable); 27 bool is_executable = (page->type() == HeapPage::kExecutable);
28 uword start = page->object_start(); 28 uword start = page->object_start();
29 uword end = page->object_end(); 29 uword end = page->object_end();
30 uword current = start; 30 uword current = start;
31 31
32 while (current < end) { 32 while (current < end) {
33 intptr_t obj_size; 33 intptr_t obj_size;
34 RawObject* raw_obj = RawObject::FromAddr(current); 34 RawObject* raw_obj = RawObject::FromAddr(current);
35 if (raw_obj->IsMarked()) { 35 if (raw_obj->IsMarked()) {
36 // Found marked object. Clear the mark bit and update swept bytes. 36 // Found marked object. Clear the mark bit and update swept bytes.
37 raw_obj->ClearMarkBit(); 37 raw_obj->ClearMarkBit();
38 obj_size = raw_obj->Size(); 38 obj_size = raw_obj->Size();
39 in_use = true; 39 used_in_bytes += obj_size;
40 } else { 40 } else {
41 uword free_end = current + raw_obj->Size(); 41 uword free_end = current + raw_obj->Size();
42 while (free_end < end) { 42 while (free_end < end) {
43 RawObject* next_obj = RawObject::FromAddr(free_end); 43 RawObject* next_obj = RawObject::FromAddr(free_end);
44 if (next_obj->IsMarked()) { 44 if (next_obj->IsMarked()) {
45 // Reached the end of the free block. 45 // Reached the end of the free block.
46 break; 46 break;
47 } 47 }
48 // Expand the free block by the size of this object. 48 // Expand the free block by the size of this object.
49 free_end += next_obj->Size(); 49 free_end += next_obj->Size();
(...skipping 12 matching lines...) Expand all
62 freelist->FreeLocked(current, obj_size); 62 freelist->FreeLocked(current, obj_size);
63 } else { 63 } else {
64 freelist->Free(current, obj_size); 64 freelist->Free(current, obj_size);
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 page->set_used_in_bytes(used_in_bytes);
73 return used_in_bytes != 0; // In use.
73 } 74 }
74 75
75 intptr_t GCSweeper::SweepLargePage(HeapPage* page) { 76 intptr_t GCSweeper::SweepLargePage(HeapPage* page) {
76 intptr_t words_to_end = 0; 77 intptr_t words_to_end = 0;
77 RawObject* raw_obj = RawObject::FromAddr(page->object_start()); 78 RawObject* raw_obj = RawObject::FromAddr(page->object_start());
78 if (raw_obj->IsMarked()) { 79 if (raw_obj->IsMarked()) {
79 raw_obj->ClearMarkBit(); 80 raw_obj->ClearMarkBit();
80 words_to_end = (raw_obj->Size() >> kWordSizeLog2); 81 words_to_end = (raw_obj->Size() >> kWordSizeLog2);
81 } 82 }
82 #ifdef DEBUG 83 #ifdef DEBUG
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 HeapPage* first, 171 HeapPage* first,
171 HeapPage* last, 172 HeapPage* last,
172 FreeList* freelist) { 173 FreeList* freelist) {
173 SweeperTask* task = new SweeperTask(isolate, isolate->heap()->old_space(), 174 SweeperTask* task = new SweeperTask(isolate, isolate->heap()->old_space(),
174 first, last, freelist); 175 first, last, freelist);
175 ThreadPool* pool = Dart::thread_pool(); 176 ThreadPool* pool = Dart::thread_pool();
176 pool->Run(task); 177 pool->Run(task);
177 } 178 }
178 179
179 } // namespace dart 180 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/pages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698