Compact weak fixed arrays before serializing.

R=ulan@chromium.org
BUG=v8:4050
LOG=N

Review URL: https://codereview.chromium.org/1099103003

Cr-Commit-Position: refs/heads/master@{#27988}
This commit is contained in:
yangguo 2015-04-22 00:40:05 -07:00 committed by Commit bot
parent f68e24ad46
commit 7b1b964362
3 changed files with 23 additions and 0 deletions

View File

@ -8295,6 +8295,20 @@ Handle<WeakFixedArray> WeakFixedArray::Add(
}
void WeakFixedArray::Compact() {
FixedArray* array = FixedArray::cast(this);
int new_length = kFirstIndex;
for (int i = kFirstIndex; i < array->length(); i++) {
Object* element = array->get(i);
if (element->IsSmi()) continue;
if (WeakCell::cast(element)->cleared()) continue;
array->set(new_length++, element);
}
array->Shrink(new_length);
set_last_used_index(0);
}
void WeakFixedArray::Remove(Handle<HeapObject> value) {
// Optimize for the most recently added element to be removed again.
int first_index = last_used_index();

View File

@ -2625,6 +2625,8 @@ class WeakFixedArray : public FixedArray {
void Remove(Handle<HeapObject> value);
void Compact();
inline Object* Get(int index) const;
inline int Length() const;

View File

@ -1779,6 +1779,13 @@ void Serializer::ObjectSerializer::Serialize() {
// We cannot serialize typed array objects correctly.
DCHECK(!object_->IsJSTypedArray());
if (object_->IsPrototypeInfo()) {
Object* prototype_users = PrototypeInfo::cast(object_)->prototype_users();
if (prototype_users->IsWeakFixedArray()) {
WeakFixedArray::cast(prototype_users)->Compact();
}
}
if (object_->IsScript()) {
// Clear cached line ends.
Object* undefined = serializer_->isolate()->heap()->undefined_value();