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

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

Issue 14190014: - Disassociate old page size from new allocatable size. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « runtime/vm/gc_marker.cc ('k') | runtime/vm/heap.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/pages.h" 10 #include "vm/pages.h"
11 11
12 namespace dart { 12 namespace dart {
13 13
14 intptr_t GCSweeper::SweepPage(HeapPage* page, FreeList* freelist) { 14 intptr_t GCSweeper::SweepPage(HeapPage* page, FreeList* freelist) {
15 // 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
16 // 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.
17 intptr_t in_use_swept = 0; 17 intptr_t in_use = 0;
18 intptr_t in_use = page->used();
19 page->set_used(0);
20
21 // Whole page is empty. Do not enter anything into the freelist.
22 if (in_use == 0) {
23 return 0;
24 }
25 18
26 bool is_executable = (page->type() == HeapPage::kExecutable); 19 bool is_executable = (page->type() == HeapPage::kExecutable);
27 uword current = page->object_start(); 20 uword start = page->object_start();
28 uword end = page->object_end(); 21 uword end = page->object_end();
22 uword current = start;
29 23
30 while (current < end) { 24 while (current < end) {
31 intptr_t obj_size; 25 intptr_t obj_size;
32 if (in_use_swept == in_use) {
33 // No more marked objects will be found on this page.
34 obj_size = end - current;
35 freelist->Free(current, obj_size);
36 break;
37 }
38 RawObject* raw_obj = RawObject::FromAddr(current); 26 RawObject* raw_obj = RawObject::FromAddr(current);
39 if (raw_obj->IsMarked()) { 27 if (raw_obj->IsMarked()) {
40 // Found marked object. Clear the mark bit and update swept bytes. 28 // Found marked object. Clear the mark bit and update swept bytes.
41 raw_obj->ClearMarkBit(); 29 raw_obj->ClearMarkBit();
42 obj_size = raw_obj->Size(); 30 obj_size = raw_obj->Size();
43 in_use_swept += obj_size; 31 in_use += obj_size;
44 } else { 32 } else {
45 uword free_end = current + raw_obj->Size(); 33 uword free_end = current + raw_obj->Size();
46 while (free_end < end) { 34 while (free_end < end) {
47 RawObject* next_obj = RawObject::FromAddr(free_end); 35 RawObject* next_obj = RawObject::FromAddr(free_end);
48 if (next_obj->IsMarked()) { 36 if (next_obj->IsMarked()) {
49 // Reached the end of the free block. 37 // Reached the end of the free block.
50 break; 38 break;
51 } 39 }
52 // Expand the free block by the size of this object. 40 // Expand the free block by the size of this object.
53 free_end += next_obj->Size(); 41 free_end += next_obj->Size();
54 } 42 }
55 obj_size = free_end - current; 43 obj_size = free_end - current;
56 if (is_executable) { 44 if (is_executable) {
57 memset(reinterpret_cast<void*>(current), 0xcc, obj_size); 45 memset(reinterpret_cast<void*>(current), 0xcc, obj_size);
58 } 46 }
59 freelist->Free(current, obj_size); 47 if ((current != start) || (free_end != end)) {
48 // Only add to the free list if not covering the whole page.
49 freelist->Free(current, obj_size);
50 }
60 } 51 }
61 current += obj_size; 52 current += obj_size;
62 } 53 }
54 ASSERT(current == end);
63 55
64 return in_use_swept; 56 return in_use;
65 } 57 }
66 58
67 59
68 intptr_t GCSweeper::SweepLargePage(HeapPage* page) { 60 intptr_t GCSweeper::SweepLargePage(HeapPage* page) {
69 RawObject* raw_obj = RawObject::FromAddr(page->object_start()); 61 RawObject* raw_obj = RawObject::FromAddr(page->object_start());
70 if (!raw_obj->IsMarked()) { 62 if (!raw_obj->IsMarked()) {
71 // The large object was not marked. Used size is zero, which also tells the 63 // The large object was not marked. Used size is zero, which also tells the
72 // calling code that the large object page can be recycled. 64 // calling code that the large object page can be recycled.
73 return 0; 65 return 0;
74 } 66 }
75 raw_obj->ClearMarkBit(); 67 raw_obj->ClearMarkBit();
76 return raw_obj->Size(); 68 return raw_obj->Size();
77 } 69 }
78 70
79 } // namespace dart 71 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/gc_marker.cc ('k') | runtime/vm/heap.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698