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

Unified Diff: src/heap/mark-compact.cc

Issue 640303006: Weak Cells (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Skip cleared weak cells Created 6 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/heap/mark-compact.h ('k') | src/heap/objects-visiting.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/heap/mark-compact.cc
diff --git a/src/heap/mark-compact.cc b/src/heap/mark-compact.cc
index e2504bfaa3c24f480e72616bc1dea104ad246b8f..f53fb6c177c675e4e74c685f9633d011398220f6 100644
--- a/src/heap/mark-compact.cc
+++ b/src/heap/mark-compact.cc
@@ -298,8 +298,12 @@ void MarkCompactCollector::CollectGarbage() {
if (FLAG_collect_maps) ClearNonLiveReferences();
+ ProcessAndClearWeakCells();
+
ClearWeakCollections();
+ heap_->set_encountered_weak_cells(Smi::FromInt(0));
+
#ifdef VERIFY_HEAP
if (FLAG_verify_heap) {
VerifyMarking(heap_);
@@ -822,6 +826,7 @@ void MarkCompactCollector::Prepare() {
heap()->incremental_marking()->Abort();
ClearMarkbits();
AbortWeakCollections();
+ AbortWeakCells();
AbortCompaction();
was_marked_incrementally_ = false;
}
@@ -2734,6 +2739,37 @@ void MarkCompactCollector::AbortWeakCollections() {
}
+void MarkCompactCollector::ProcessAndClearWeakCells() {
+ HeapObject* undefined = heap()->undefined_value();
+ Object* weak_cell_obj = heap()->encountered_weak_cells();
+ while (weak_cell_obj != Smi::FromInt(0)) {
+ WeakCell* weak_cell = reinterpret_cast<WeakCell*>(weak_cell_obj);
+ HeapObject* value = weak_cell->value();
+ if (!MarkCompactCollector::IsMarked(value)) {
+ weak_cell->clear(undefined);
+ } else {
+ Object** slot = HeapObject::RawField(weak_cell, WeakCell::kValueOffset);
+ heap()->mark_compact_collector()->RecordSlot(slot, slot, value);
+ }
+ weak_cell_obj = weak_cell->next();
+ weak_cell->set_next(undefined, SKIP_WRITE_BARRIER);
+ }
+ heap()->set_encountered_weak_cells(Smi::FromInt(0));
+}
+
+
+void MarkCompactCollector::AbortWeakCells() {
+ Object* undefined = heap()->undefined_value();
+ Object* weak_cell_obj = heap()->encountered_weak_cells();
+ while (weak_cell_obj != Smi::FromInt(0)) {
+ WeakCell* weak_cell = reinterpret_cast<WeakCell*>(weak_cell_obj);
+ weak_cell_obj = weak_cell->next();
+ weak_cell->set_next(undefined, SKIP_WRITE_BARRIER);
+ }
+ heap()->set_encountered_weak_cells(Smi::FromInt(0));
+}
+
+
void MarkCompactCollector::RecordMigratedSlot(Object* value, Address slot) {
if (heap_->InNewSpace(value)) {
heap_->store_buffer()->Mark(slot);
@@ -2745,7 +2781,7 @@ void MarkCompactCollector::RecordMigratedSlot(Object* value, Address slot) {
}
-// We scavange new space simultaneously with sweeping. This is done in two
+// We scavenge new space simultaneously with sweeping. This is done in two
// passes.
//
// The first pass migrates all alive objects from one semispace to another or
« no previous file with comments | « src/heap/mark-compact.h ('k') | src/heap/objects-visiting.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698