Some cleanup of the mark-sweep/compact collector following the symbol

table debacle.

Review URL: http://codereview.chromium.org/109012

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@1856 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 4973c842
...@@ -258,7 +258,7 @@ void GlobalHandles::IterateWeakRoots(ObjectVisitor* v) { ...@@ -258,7 +258,7 @@ void GlobalHandles::IterateWeakRoots(ObjectVisitor* v) {
} }
void GlobalHandles::MarkWeakRoots(WeakSlotCallback f) { void GlobalHandles::IdentifyWeakHandles(WeakSlotCallback f) {
for (Node* current = head_; current != NULL; current = current->next()) { for (Node* current = head_; current != NULL; current = current->next()) {
if (current->state_ == Node::WEAK) { if (current->state_ == Node::WEAK) {
if (f(&current->object_)) { if (f(&current->object_)) {
......
...@@ -98,8 +98,9 @@ class GlobalHandles : public AllStatic { ...@@ -98,8 +98,9 @@ class GlobalHandles : public AllStatic {
// Iterates over all weak roots in heap. // Iterates over all weak roots in heap.
static void IterateWeakRoots(ObjectVisitor* v); static void IterateWeakRoots(ObjectVisitor* v);
// Mark the weak pointers based on the callback. // Find all weak handles satisfying the callback predicate, mark
static void MarkWeakRoots(WeakSlotCallback f); // them as pending.
static void IdentifyWeakHandles(WeakSlotCallback f);
// Add an object group. // Add an object group.
// Should only used in GC callback function before a collection. // Should only used in GC callback function before a collection.
......
...@@ -555,10 +555,8 @@ static void ScanOverflowedObjects(T* it) { ...@@ -555,10 +555,8 @@ static void ScanOverflowedObjects(T* it) {
} }
bool MarkCompactCollector::MustBeMarked(Object** p) { bool MarkCompactCollector::IsUnmarkedHeapObject(Object** p) {
// Check whether *p is a HeapObject pointer. return (*p)->IsHeapObject() && !HeapObject::cast(*p)->IsMarked();
if (!(*p)->IsHeapObject()) return false;
return !HeapObject::cast(*p)->IsMarked();
} }
...@@ -756,19 +754,20 @@ void MarkCompactCollector::MarkLiveObjects() { ...@@ -756,19 +754,20 @@ void MarkCompactCollector::MarkLiveObjects() {
RootMarkingVisitor root_visitor; RootMarkingVisitor root_visitor;
MarkRoots(&root_visitor); MarkRoots(&root_visitor);
// The objects reachable from the roots are marked black, unreachable // The objects reachable from the roots are marked, yet unreachable
// objects are white. Mark objects reachable from object groups with at // objects are unmarked. Mark objects reachable from object groups
// least one marked object, and continue until no new objects are // containing at least one marked object, and continue until no new
// reachable from the object groups. // objects are reachable from the object groups.
ProcessObjectGroups(root_visitor.stack_visitor()); ProcessObjectGroups(root_visitor.stack_visitor());
// The objects reachable from the roots or object groups are marked black, // The objects reachable from the roots or object groups are marked,
// unreachable objects are white. Process objects reachable only from // yet unreachable objects are unmarked. Mark objects reachable
// weak global handles. // only from weak global handles.
// //
// First we mark weak pointers not yet reachable. // First we identify nonlive weak handles and mark them as pending
GlobalHandles::MarkWeakRoots(&MustBeMarked); // destruction.
// Then we process weak pointers and process the transitive closure. GlobalHandles::IdentifyWeakHandles(&IsUnmarkedHeapObject);
// Then we mark the objects and process the transitive closure.
GlobalHandles::IterateWeakRoots(&root_visitor); GlobalHandles::IterateWeakRoots(&root_visitor);
while (marking_stack.overflowed()) { while (marking_stack.overflowed()) {
RefillMarkingStack(); RefillMarkingStack();
...@@ -801,22 +800,21 @@ static int CountMarkedCallback(HeapObject* obj) { ...@@ -801,22 +800,21 @@ static int CountMarkedCallback(HeapObject* obj) {
#ifdef DEBUG #ifdef DEBUG
void MarkCompactCollector::UpdateLiveObjectCount(HeapObject* obj, int scale) { void MarkCompactCollector::UpdateLiveObjectCount(HeapObject* obj) {
ASSERT(scale == -1 || scale == 1); live_bytes_ += obj->Size();
live_bytes_ += obj->Size() * scale;
if (Heap::new_space()->Contains(obj)) { if (Heap::new_space()->Contains(obj)) {
live_young_objects_ += scale; live_young_objects_++;
} else if (Heap::map_space()->Contains(obj)) { } else if (Heap::map_space()->Contains(obj)) {
ASSERT(obj->IsMap()); ASSERT(obj->IsMap());
live_map_objects_ += scale; live_map_objects_ ++;
} else if (Heap::old_pointer_space()->Contains(obj)) { } else if (Heap::old_pointer_space()->Contains(obj)) {
live_old_pointer_objects_ += scale; live_old_pointer_objects_++;
} else if (Heap::old_data_space()->Contains(obj)) { } else if (Heap::old_data_space()->Contains(obj)) {
live_old_data_objects_ += scale; live_old_data_objects_++;
} else if (Heap::code_space()->Contains(obj)) { } else if (Heap::code_space()->Contains(obj)) {
live_code_objects_ += scale; live_code_objects_++;
} else if (Heap::lo_space()->Contains(obj)) { } else if (Heap::lo_space()->Contains(obj)) {
live_lo_objects_ +=scale; live_lo_objects_++;
} else { } else {
UNREACHABLE(); UNREACHABLE();
} }
......
...@@ -142,7 +142,6 @@ class MarkCompactCollector: public AllStatic { ...@@ -142,7 +142,6 @@ class MarkCompactCollector: public AllStatic {
friend class RootMarkingVisitor; friend class RootMarkingVisitor;
friend class MarkingVisitor; friend class MarkingVisitor;
friend class UnmarkingVisitor;
// Marking operations for objects reachable from roots. // Marking operations for objects reachable from roots.
static void MarkLiveObjects(); static void MarkLiveObjects();
...@@ -156,7 +155,7 @@ class MarkCompactCollector: public AllStatic { ...@@ -156,7 +155,7 @@ class MarkCompactCollector: public AllStatic {
static inline void SetMark(HeapObject* obj) { static inline void SetMark(HeapObject* obj) {
tracer_->increment_marked_count(); tracer_->increment_marked_count();
#ifdef DEBUG #ifdef DEBUG
UpdateLiveObjectCount(obj, 1); UpdateLiveObjectCount(obj);
#endif #endif
obj->SetMark(); obj->SetMark();
} }
...@@ -203,14 +202,12 @@ class MarkCompactCollector: public AllStatic { ...@@ -203,14 +202,12 @@ class MarkCompactCollector: public AllStatic {
// flag on the marking stack. // flag on the marking stack.
static void RefillMarkingStack(); static void RefillMarkingStack();
// Callback function for telling whether the object *p must be marked. // Callback function for telling whether the object *p is an unmarked
static bool MustBeMarked(Object** p); // heap object.
static bool IsUnmarkedHeapObject(Object** p);
#ifdef DEBUG #ifdef DEBUG
// The scale argument is positive 1 if we are marking an object and static void UpdateLiveObjectCount(HeapObject* obj);
// -1 if we are clearing the mark bit of an object that we didn't
// actually want marked.
static void UpdateLiveObjectCount(HeapObject* obj, int scale);
#endif #endif
// We sweep the large object space in the same way whether we are // We sweep the large object space in the same way whether we are
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment