Commit 7b1b9643 authored by yangguo's avatar yangguo Committed by Commit bot

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}
parent f68e24ad
......@@ -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();
......
......@@ -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;
......
......@@ -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();
......
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