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

Unified Diff: vm/gc_sweeper.cc

Issue 8898034: - Implement the old sweeper. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 9 years 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 side-by-side diff with in-line comments
Download patch
Index: vm/gc_sweeper.cc
===================================================================
--- vm/gc_sweeper.cc (revision 0)
+++ vm/gc_sweeper.cc (revision 0)
@@ -0,0 +1,68 @@
+// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+#include "vm/gc_sweeper.h"
+
+#include "vm/freelist.h"
+#include "vm/globals.h"
+#include "vm/pages.h"
+#include "vm/object.h"
siva 2011/12/14 16:20:13 list vm/object.h before vm/pages.h
Ivan Posva 2011/12/15 22:29:19 object.h was only needed for testing. Removed.
+
+namespace dart {
+
+intptr_t GCSweeper::SweepPage(HeapPage* page, FreeList* freelist) {
+ // Keep track of the discovered live object sizes to be able to finish
+ // sweeping early. Reset the per page in_use count for the next marking phase.
+ intptr_t in_use_swept = 0;
+ intptr_t in_use = page->used();
siva 2011/12/14 16:20:13 ASERT(in_use != 0); ?
Ivan Posva 2011/12/15 22:29:19 That would be an incorrect ASSERT for totally empt
+ page->set_used(0);
+
+ uword current = page->first_object_start();
+ uword top = page->top();
+
+ while (current < top) {
+ if (in_use_swept == in_use) {
+ // No more marked objects will be found on this page.
+ page->set_top(current);
+ break;
+ }
+ RawObject* raw_obj = RawObject::FromAddr(current);
+ intptr_t obj_size;
+ if (raw_obj->IsMarked()) {
+ // Found marked object. Clear the mark bit and update swept bytes.
+ raw_obj->ClearMarkBit();
+ obj_size = raw_obj->Size();
+ in_use_swept += obj_size;
+ } else {
+ uword free_end = current + raw_obj->Size();
cshapiro 2011/12/14 18:48:11 How does this interact with FreeList elements? Fr
Ivan Posva 2011/12/15 22:29:19 FreeListElements are coalesced and added to the co
+ while (free_end < top) {
+ RawObject* next_obj = RawObject::FromAddr(free_end);
+ if (next_obj->IsMarked()) {
+ // Reached the end of the free block.
+ break;
+ }
+ // Expand the free block by the size of this object.
+ free_end += next_obj->Size();
+ }
+ obj_size = free_end - current;
+ if ((current + obj_size) == top) {
+ page->set_top(current);
+ break;
+ } else {
+ freelist->Free(current, obj_size);
+ }
+ }
+ current += obj_size;
+ }
+
+ return in_use_swept;
+}
+
+
+intptr_t GCSweeper::SweepLargePage(HeapPage* page) {
+ UNIMPLEMENTED();
+ return 0;
+}
+
+} // namespace dart

Powered by Google App Engine
This is Rietveld 408576698