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();
+ // We do not insert cleared weak cells into the list, so the value
+ // cannot be a Smi here.
+ HeapObject* value = HeapObject::cast(weak_cell->value());
if (!MarkCompactCollector::IsMarked(value)) {
- weak_cell->clear(undefined);
+ weak_cell->clear();
} else {
Object** slot = HeapObject::RawField(weak_cell, WeakCell::kValueOffset);
heap()->mark_compact_collector()->RecordSlot(slot, slot, value);
WeakCell* weak_cell = reinterpret_cast<WeakCell*>(object);
Object* undefined = heap->undefined_value();
// Enqueue weak cell in linked list of encountered weak collections.
- // We can ignore weak cells with cleared values because they will always point
- // to the undefined_value.
- if (weak_cell->next() == undefined && weak_cell->value() != undefined) {
+ // We can ignore weak cells with cleared values because they will always
+ // contain smi zero.
+ if (weak_cell->next() == undefined && !weak_cell->cleared()) {
weak_cell->set_next(heap->encountered_weak_cells());
heap->set_encountered_weak_cells(weak_cell);
}
}
-HeapObject* WeakCell::value() const {
+Object* WeakCell::value() const {
return HeapObject::cast(READ_FIELD(this, kValueOffset));
}
-void WeakCell::clear(HeapObject* undefined) {
- WRITE_FIELD(this, kValueOffset, undefined);
+void WeakCell::clear() {
+ DCHECK(GetHeap()->gc_state() == Heap::MARK_COMPACT);
+ WRITE_FIELD(this, kValueOffset, Smi::FromInt(0));
}
}
+bool WeakCell::cleared() const { return value() == Smi::FromInt(0); }
+
+
Object* WeakCell::next() const { return READ_FIELD(this, kNextOffset); }
Isolate* isolate = script->GetIsolate();
if (!script->wrapper()->IsUndefined()) {
Handle<WeakCell> cell(WeakCell::cast(script->wrapper()));
- if (!cell->value()->IsUndefined()) {
+ if (!cell->cleared()) {
// Return a handle for the existing script wrapper from the cache.
return handle(JSObject::cast(cell->value()));
}
class WeakCell : public HeapObject {
public:
- inline HeapObject* value() const;
+ inline Object* value() const;
// This should not be called by anyone except GC.
- inline void clear(HeapObject* undefined);
+ inline void clear();
// This should not be called by anyone except allocator.
inline void initialize(HeapObject* value);
+ inline bool cleared() const;
+
DECL_ACCESSORS(next, Object)
DECLARE_CAST(WeakCell)
CHECK(weak_cell1->value()->IsFixedArray());
CHECK_EQ(*survivor, weak_cell2->value());
heap->CollectAllAvailableGarbage();
+ CHECK(weak_cell1->cleared());
CHECK_EQ(*survivor, weak_cell2->value());
- CHECK(weak_cell2->value()->IsFixedArray());
}
heap->CollectAllGarbage(Heap::kNoGCFlags);
CHECK_EQ(*survivor, weak_cells[0]->value());
for (int i = 1; i < N; i++) {
- CHECK(weak_cells[i]->value()->IsUndefined());
+ CHECK(weak_cells[i]->cleared());
}
}