| Index: src/global-handles.cc
|
| diff --git a/src/global-handles.cc b/src/global-handles.cc
|
| index cb3115abfca7db7ce9baec4a29c9da134437c223..ce8fee442ee7c29085540e75102aa3b21660e2a4 100644
|
| --- a/src/global-handles.cc
|
| +++ b/src/global-handles.cc
|
| @@ -36,8 +36,7 @@ namespace v8 {
|
| namespace internal {
|
|
|
|
|
| -ObjectGroup::~ObjectGroup() {
|
| - if (info_ != NULL) info_->Dispose();
|
| +GroupRetainedObjectInfo::~GroupRetainedObjectInfo() {
|
| }
|
|
|
|
|
| @@ -578,45 +577,74 @@ void GlobalHandles::IterateNewSpaceWeakIndependentRoots(ObjectVisitor* v) {
|
|
|
| bool GlobalHandles::IterateObjectGroups(ObjectVisitor* v,
|
| WeakSlotCallbackWithHeap can_skip) {
|
| - int last = 0;
|
| + if (object_groups_.length() == 0)
|
| + return false;
|
| +
|
| + object_groups_.Sort();
|
| +
|
| + // During the iteration, some of the elements of object_groups are
|
| + // deleted. This is done by moving surviving elements at the front of the list
|
| + // and deleting from the end. This index tracks where the next surviving
|
| + // element should be moved.
|
| + int surviving_element_ix = 0;
|
| + int info_ix = 0; // For iterating retained_object_infos_.
|
| + int surviving_info_ix = 0;
|
| +
|
| + void* current_group_id = NULL;
|
| + size_t current_group_start = 0;
|
| bool any_group_was_visited = false;
|
| - for (int i = 0; i < object_groups_.length(); i++) {
|
| - ObjectGroup* entry = object_groups_.at(i);
|
| - ASSERT(entry != NULL);
|
| -
|
| - Object*** objects = entry->objects_;
|
| - bool group_should_be_visited = false;
|
| - for (size_t j = 0; j < entry->length_; j++) {
|
| - Object* object = *objects[j];
|
| - if (object->IsHeapObject()) {
|
| - if (!can_skip(isolate_->heap(), &object)) {
|
| - group_should_be_visited = true;
|
| - break;
|
| +
|
| + for (int i = 0; i <= object_groups_.length(); ++i) {
|
| + if (i == 0)
|
| + current_group_id = object_groups_[i].id;
|
| + if (i == object_groups_.length() ||
|
| + current_group_id != object_groups_[i].id) {
|
| + // Group detected: objects in indices [current_group_start, i[.
|
| + bool group_should_be_visited = false;
|
| + for (int j = current_group_start; j < i; ++j) {
|
| + Object* object = *(object_groups_[j].object);
|
| + if (object->IsHeapObject()) {
|
| + if (!can_skip(isolate_->heap(), &object)) {
|
| + group_should_be_visited = true;
|
| + break;
|
| + }
|
| }
|
| }
|
| - }
|
| -
|
| - if (!group_should_be_visited) {
|
| - object_groups_[last++] = entry;
|
| - continue;
|
| - }
|
| -
|
| - // An object in the group requires visiting, so iterate over all
|
| - // objects in the group.
|
| - for (size_t j = 0; j < entry->length_; ++j) {
|
| - Object* object = *objects[j];
|
| - if (object->IsHeapObject()) {
|
| - v->VisitPointer(&object);
|
| - any_group_was_visited = true;
|
| + if (!group_should_be_visited) {
|
| + for (int j = current_group_start; j < i; ++j)
|
| + object_groups_[surviving_element_ix++] = object_groups_[j];
|
| + } else {
|
| + // An object in the group requires visiting, so iterate over all
|
| + // objects in the group.
|
| + for (int j = current_group_start; j < i; ++j) {
|
| + Object* object = *(object_groups_[j].object);
|
| + if (object->IsHeapObject()) {
|
| + v->VisitPointer(&object);
|
| + any_group_was_visited = true;
|
| + }
|
| + }
|
| + }
|
| + if (info_ix < retained_object_infos_.length() &&
|
| + retained_object_infos_[info_ix].id ==
|
| + object_groups_[current_group_start].id) {
|
| + // This object group has an associated GroupRetainedObjectInfo.
|
| + if (!group_should_be_visited) {
|
| + retained_object_infos_[surviving_info_ix++] =
|
| + retained_object_infos_[info_ix];
|
| + } else if (retained_object_infos_[info_ix].info != NULL) {
|
| + retained_object_infos_[info_ix].info->Dispose();
|
| + retained_object_infos_[info_ix].info = NULL;
|
| + }
|
| + ++info_ix;
|
| + }
|
| + if (i < object_groups_.length()) {
|
| + current_group_id = object_groups_[i].id;
|
| + current_group_start = i;
|
| }
|
| }
|
| -
|
| - // Once the entire group has been iterated over, set the object
|
| - // group to NULL so it won't be processed again.
|
| - entry->Dispose();
|
| - object_groups_.at(i) = NULL;
|
| }
|
| - object_groups_.Rewind(last);
|
| + object_groups_.Rewind(surviving_element_ix);
|
| + retained_object_infos_.Rewind(surviving_info_ix);
|
| return any_group_was_visited;
|
| }
|
|
|
| @@ -824,7 +852,21 @@ void GlobalHandles::AddObjectGroup(Object*** handles,
|
| if (info != NULL) info->Dispose();
|
| return;
|
| }
|
| - object_groups_.Add(ObjectGroup::New(handles, length, info));
|
| + for (size_t i = 0; i < length; ++i)
|
| + object_groups_.Add(ObjectGroupConnection(handles[0], handles[i]));
|
| + retained_object_infos_.Add(GroupRetainedObjectInfo(handles[0], info));
|
| +}
|
| +
|
| +
|
| +void GlobalHandles::SetObjectGroupId(Object** handle,
|
| + void* id) {
|
| + object_groups_.Add(ObjectGroupConnection(id, handle));
|
| +}
|
| +
|
| +
|
| +void GlobalHandles::SetRetainedObjectInfo(void* id,
|
| + RetainedObjectInfo* info) {
|
| + retained_object_infos_.Add(GroupRetainedObjectInfo(id, info));
|
| }
|
|
|
|
|
| @@ -843,10 +885,12 @@ void GlobalHandles::AddImplicitReferences(HeapObject** parent,
|
|
|
|
|
| void GlobalHandles::RemoveObjectGroups() {
|
| - for (int i = 0; i < object_groups_.length(); i++) {
|
| - object_groups_.at(i)->Dispose();
|
| - }
|
| object_groups_.Clear();
|
| + for (int i = 0; i < retained_object_infos_.length(); ++i) {
|
| + if (retained_object_infos_[i].info != NULL)
|
| + retained_object_infos_[i].info->Dispose();
|
| + }
|
| + retained_object_infos_.Clear();
|
| }
|
|
|
|
|
|
|