[snapshot] no longer iterate strong roots twice.

Previously, in order to get immortal immovable objects onto
the first page, the serializer would iterate the root list
twice. The first time it would prioritize immortal immovables.
The second time it would serialize the rest.

This does not guarantee that immortal immovable objects
actually end up on the first page, and by now this is not
necessary anymore, since we mark all pages created during
heap init as immortal immovable pages.

R=mlippautz@chromium.org

Change-Id: Ie95fcd779377a75337621ba862bc1a745ed5cbaa
Reviewed-on: https://chromium-review.googlesource.com/768731
Commit-Queue: Yang Guo <yangguo@chromium.org>
Reviewed-by: Michael Lippautz <mlippautz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#49468}
This commit is contained in:
Yang Guo 2017-11-19 09:07:00 +01:00 committed by Commit Bot
parent ec1ad5f337
commit 678f910375
8 changed files with 102 additions and 148 deletions

View File

@ -627,7 +627,6 @@ enum VisitMode {
VISIT_ALL_IN_SWEEP_NEWSPACE,
VISIT_ONLY_STRONG,
VISIT_ONLY_STRONG_FOR_SERIALIZATION,
VISIT_ONLY_STRONG_ROOT_LIST,
};
// Flag indicating whether code is built into the VM (one of the natives files).

View File

@ -4877,10 +4877,6 @@ void Heap::IterateStrongRoots(RootVisitor* v, VisitMode mode) {
v->VisitRootPointers(Root::kStrongRootList, &roots_[0],
&roots_[kStrongRootListLength]);
v->Synchronize(VisitorSynchronization::kStrongRootList);
// The serializer/deserializer iterates the root list twice, first to pick
// off immortal immovable roots to make sure they end up on the first page,
// and then again for the rest.
if (mode == VISIT_ONLY_STRONG_ROOT_LIST) return;
isolate_->bootstrapper()->Iterate(v);
v->Synchronize(VisitorSynchronization::kBootstrapper);
@ -4913,11 +4909,7 @@ void Heap::IterateStrongRoots(RootVisitor* v, VisitMode mode) {
// Iterate over global handles.
switch (mode) {
case VISIT_ONLY_STRONG_ROOT_LIST:
UNREACHABLE();
break;
case VISIT_ONLY_STRONG_FOR_SERIALIZATION:
break;
case VISIT_ONLY_STRONG:
isolate_->global_handles()->IterateStrongRoots(v);
break;

View File

@ -80,13 +80,6 @@ bool DefaultSerializerAllocator::BackReferenceIsAlreadyAllocated(
}
}
}
bool DefaultSerializerAllocator::HasNotExceededFirstPageOfEachSpace() const {
for (int i = 0; i < kNumberOfPreallocatedSpaces; i++) {
if (!completed_chunks_[i].empty()) return false;
}
return true;
}
#endif
std::vector<SerializedData::Reservation>

View File

@ -26,7 +26,6 @@ class DefaultSerializerAllocator final {
#ifdef DEBUG
bool BackReferenceIsAlreadyAllocated(
SerializerReference back_reference) const;
bool HasNotExceededFirstPageOfEachSpace() const;
#endif
std::vector<SerializedData::Reservation> EncodeReservations() const;

View File

@ -34,8 +34,6 @@ void StartupDeserializer::DeserializeInto(Isolate* isolate) {
{
DisallowHeapAllocation no_gc;
isolate->heap()->IterateStrongRoots(this, VISIT_ONLY_STRONG_ROOT_LIST);
isolate->heap()->IterateSmiRoots(this);
isolate->heap()->IterateStrongRoots(this, VISIT_ONLY_STRONG);
isolate->heap()->RepairFreeListsAfterDeserialization();

View File

@ -124,19 +124,13 @@ void StartupSerializer::SerializeStrongReferences() {
CHECK(isolate->handle_scope_implementer()->blocks()->empty());
CHECK_EQ(0, isolate->global_handles()->global_handles_count());
CHECK_EQ(0, isolate->eternal_handles()->NumberOfHandles());
// First visit immortal immovables to make sure they end up in the first page.
serializing_immortal_immovables_roots_ = true;
isolate->heap()->IterateStrongRoots(this, VISIT_ONLY_STRONG_ROOT_LIST);
// Check that immortal immovable roots are allocated on the first page.
DCHECK(allocator()->HasNotExceededFirstPageOfEachSpace());
serializing_immortal_immovables_roots_ = false;
// Visit the rest of the strong roots.
// Visit smi roots.
// Clear the stack limits to make the snapshot reproducible.
// Reset it again afterwards.
isolate->heap()->ClearStackLimits();
isolate->heap()->IterateSmiRoots(this);
isolate->heap()->SetStackLimits();
// First visit immortal immovables to make sure they end up in the first page.
isolate->heap()->IterateStrongRoots(this,
VISIT_ONLY_STRONG_FOR_SERIALIZATION);
}
@ -152,20 +146,15 @@ void StartupSerializer::VisitRootPointers(Root root, Object** start,
int skip = 0;
for (Object** current = start; current < end; current++) {
int root_index = static_cast<int>(current - start);
if (RootShouldBeSkipped(root_index)) {
skip += kPointerSize;
continue;
if ((*current)->IsSmi()) {
FlushSkip(skip);
PutSmi(Smi::cast(*current));
} else {
if ((*current)->IsSmi()) {
FlushSkip(skip);
PutSmi(Smi::cast(*current));
} else {
SerializeObject(HeapObject::cast(*current), kPlain, kStartOfObject,
skip);
}
root_has_been_serialized_.set(root_index);
skip = 0;
SerializeObject(HeapObject::cast(*current), kPlain, kStartOfObject,
skip);
}
root_has_been_serialized_.set(root_index);
skip = 0;
}
FlushSkip(skip);
} else {
@ -173,15 +162,6 @@ void StartupSerializer::VisitRootPointers(Root root, Object** start,
}
}
bool StartupSerializer::RootShouldBeSkipped(int root_index) {
if (root_index == Heap::kStackLimitRootIndex ||
root_index == Heap::kRealStackLimitRootIndex) {
return true;
}
return Heap::RootIsImmortalImmovable(root_index) !=
serializing_immortal_immovables_roots_;
}
void StartupSerializer::CheckRehashability(HeapObject* obj) {
if (!can_be_rehashed_) return;
if (!obj->NeedsRehashing()) return;

View File

@ -69,16 +69,9 @@ class StartupSerializer : public Serializer<> {
void Synchronize(VisitorSynchronization::SyncTag tag) override;
bool MustBeDeferred(HeapObject* object) override;
// Some roots should not be serialized, because their actual value depends on
// absolute addresses and they are reset after deserialization, anyway.
// In the first pass over the root list, we only serialize immortal immovable
// roots. In the second pass, we serialize the rest.
bool RootShouldBeSkipped(int root_index);
void CheckRehashability(HeapObject* obj);
const bool clear_function_code_;
bool serializing_immortal_immovables_roots_;
std::bitset<Heap::kStrongRootListLength> root_has_been_serialized_;
PartialCacheIndexMap partial_cache_index_map_;
std::vector<AccessorInfo*> accessor_infos_;

View File

@ -187,73 +187,73 @@ KNOWN_MAPS = {
0x02931: (179, "GlobalPropertyCellMap"),
0x02981: (135, "ForeignMap"),
0x029d1: (174, "TransitionArrayMap"),
0x02a21: (131, "ArgumentsMarkerMap"),
0x02a71: (131, "ExceptionMap"),
0x02ac1: (131, "TerminationExceptionMap"),
0x02b11: (131, "OptimizedOutMap"),
0x02b61: (131, "StaleRegisterMap"),
0x02bb1: (171, "NativeContextMap"),
0x02c01: (171, "ModuleContextMap"),
0x02c51: (171, "EvalContextMap"),
0x02ca1: (171, "ScriptContextMap"),
0x02cf1: (171, "BlockContextMap"),
0x02d41: (171, "CatchContextMap"),
0x02d91: (171, "WithContextMap"),
0x02de1: (171, "DescriptorArrayMap"),
0x02e31: (148, "FixedDoubleArrayMap"),
0x02e81: (134, "MutableHeapNumberMap"),
0x02ed1: (172, "OrderedHashTableMap"),
0x02f21: (172, "NameDictionaryMap"),
0x02f71: (172, "GlobalDictionaryMap"),
0x02fc1: (172, "NumberDictionaryMap"),
0x03011: (171, "SloppyArgumentsElementsMap"),
0x03061: (180, "SmallOrderedHashMapMap"),
0x030b1: (181, "SmallOrderedHashSetMap"),
0x03101: (189, "JSMessageObjectMap"),
0x03151: (137, "BytecodeArrayMap"),
0x031a1: (171, "ModuleInfoMap"),
0x031f1: (177, "NoClosuresCellMap"),
0x03241: (177, "OneClosureCellMap"),
0x03291: (177, "ManyClosuresCellMap"),
0x032e1: (175, "PropertyArrayMap"),
0x03331: (130, "BigIntMap"),
0x03381: (64, "StringMap"),
0x033d1: (73, "ConsOneByteStringMap"),
0x03421: (65, "ConsStringMap"),
0x03471: (77, "ThinOneByteStringMap"),
0x034c1: (69, "ThinStringMap"),
0x03511: (67, "SlicedStringMap"),
0x03561: (75, "SlicedOneByteStringMap"),
0x035b1: (66, "ExternalStringMap"),
0x03601: (82, "ExternalStringWithOneByteDataMap"),
0x03651: (74, "ExternalOneByteStringMap"),
0x036a1: (98, "ShortExternalStringMap"),
0x036f1: (114, "ShortExternalStringWithOneByteDataMap"),
0x03741: (0, "InternalizedStringMap"),
0x03791: (2, "ExternalInternalizedStringMap"),
0x037e1: (18, "ExternalInternalizedStringWithOneByteDataMap"),
0x03831: (10, "ExternalOneByteInternalizedStringMap"),
0x03881: (34, "ShortExternalInternalizedStringMap"),
0x038d1: (50, "ShortExternalInternalizedStringWithOneByteDataMap"),
0x03921: (42, "ShortExternalOneByteInternalizedStringMap"),
0x03971: (106, "ShortExternalOneByteStringMap"),
0x039c1: (140, "FixedUint8ArrayMap"),
0x03a11: (139, "FixedInt8ArrayMap"),
0x03a61: (142, "FixedUint16ArrayMap"),
0x03ab1: (141, "FixedInt16ArrayMap"),
0x03b01: (144, "FixedUint32ArrayMap"),
0x03b51: (143, "FixedInt32ArrayMap"),
0x03ba1: (145, "FixedFloat32ArrayMap"),
0x03bf1: (146, "FixedFloat64ArrayMap"),
0x03c41: (147, "FixedUint8ClampedArrayMap"),
0x03c91: (158, "ScriptMap"),
0x03ce1: (182, "CodeDataContainerMap"),
0x03d31: (173, "FeedbackVectorMap"),
0x03d81: (171, "DebugEvaluateContextMap"),
0x03dd1: (171, "ScriptContextTableMap"),
0x03e21: (192, "ExternalMap"),
0x03e71: (106, "NativeSourceStringMap"),
0x03ec1: (165, "Tuple2Map"),
0x02a21: (173, "FeedbackVectorMap"),
0x02a71: (131, "ArgumentsMarkerMap"),
0x02ac1: (131, "ExceptionMap"),
0x02b11: (131, "TerminationExceptionMap"),
0x02b61: (131, "OptimizedOutMap"),
0x02bb1: (131, "StaleRegisterMap"),
0x02c01: (171, "NativeContextMap"),
0x02c51: (171, "ModuleContextMap"),
0x02ca1: (171, "EvalContextMap"),
0x02cf1: (171, "ScriptContextMap"),
0x02d41: (171, "BlockContextMap"),
0x02d91: (171, "CatchContextMap"),
0x02de1: (171, "WithContextMap"),
0x02e31: (171, "DebugEvaluateContextMap"),
0x02e81: (171, "ScriptContextTableMap"),
0x02ed1: (171, "DescriptorArrayMap"),
0x02f21: (148, "FixedDoubleArrayMap"),
0x02f71: (134, "MutableHeapNumberMap"),
0x02fc1: (172, "OrderedHashTableMap"),
0x03011: (172, "NameDictionaryMap"),
0x03061: (172, "GlobalDictionaryMap"),
0x030b1: (172, "NumberDictionaryMap"),
0x03101: (171, "SloppyArgumentsElementsMap"),
0x03151: (180, "SmallOrderedHashMapMap"),
0x031a1: (181, "SmallOrderedHashSetMap"),
0x031f1: (182, "CodeDataContainerMap"),
0x03241: (189, "JSMessageObjectMap"),
0x03291: (192, "ExternalMap"),
0x032e1: (137, "BytecodeArrayMap"),
0x03331: (171, "ModuleInfoMap"),
0x03381: (177, "NoClosuresCellMap"),
0x033d1: (177, "OneClosureCellMap"),
0x03421: (177, "ManyClosuresCellMap"),
0x03471: (175, "PropertyArrayMap"),
0x034c1: (130, "BigIntMap"),
0x03511: (106, "NativeSourceStringMap"),
0x03561: (64, "StringMap"),
0x035b1: (73, "ConsOneByteStringMap"),
0x03601: (65, "ConsStringMap"),
0x03651: (77, "ThinOneByteStringMap"),
0x036a1: (69, "ThinStringMap"),
0x036f1: (67, "SlicedStringMap"),
0x03741: (75, "SlicedOneByteStringMap"),
0x03791: (66, "ExternalStringMap"),
0x037e1: (82, "ExternalStringWithOneByteDataMap"),
0x03831: (74, "ExternalOneByteStringMap"),
0x03881: (98, "ShortExternalStringMap"),
0x038d1: (114, "ShortExternalStringWithOneByteDataMap"),
0x03921: (0, "InternalizedStringMap"),
0x03971: (2, "ExternalInternalizedStringMap"),
0x039c1: (18, "ExternalInternalizedStringWithOneByteDataMap"),
0x03a11: (10, "ExternalOneByteInternalizedStringMap"),
0x03a61: (34, "ShortExternalInternalizedStringMap"),
0x03ab1: (50, "ShortExternalInternalizedStringWithOneByteDataMap"),
0x03b01: (42, "ShortExternalOneByteInternalizedStringMap"),
0x03b51: (106, "ShortExternalOneByteStringMap"),
0x03ba1: (140, "FixedUint8ArrayMap"),
0x03bf1: (139, "FixedInt8ArrayMap"),
0x03c41: (142, "FixedUint16ArrayMap"),
0x03c91: (141, "FixedInt16ArrayMap"),
0x03ce1: (144, "FixedUint32ArrayMap"),
0x03d31: (143, "FixedInt32ArrayMap"),
0x03d81: (145, "FixedFloat32ArrayMap"),
0x03dd1: (146, "FixedFloat64ArrayMap"),
0x03e21: (147, "FixedUint8ClampedArrayMap"),
0x03e71: (165, "Tuple2Map"),
0x03ec1: (158, "ScriptMap"),
0x03f11: (153, "InterceptorInfoMap"),
0x03f61: (150, "AccessorInfoMap"),
0x03fb1: (151, "AccessorPairMap"),
@ -294,32 +294,32 @@ KNOWN_OBJECTS = {
("OLD_SPACE", 0x02519): "TerminationException",
("OLD_SPACE", 0x02579): "OptimizedOut",
("OLD_SPACE", 0x025d1): "StaleRegister",
("OLD_SPACE", 0x02629): "EmptyByteArray",
("OLD_SPACE", 0x02639): "EmptyFixedUint8Array",
("OLD_SPACE", 0x02659): "EmptyFixedInt8Array",
("OLD_SPACE", 0x02679): "EmptyFixedUint16Array",
("OLD_SPACE", 0x02699): "EmptyFixedInt16Array",
("OLD_SPACE", 0x026b9): "EmptyFixedUint32Array",
("OLD_SPACE", 0x026d9): "EmptyFixedInt32Array",
("OLD_SPACE", 0x026f9): "EmptyFixedFloat32Array",
("OLD_SPACE", 0x02719): "EmptyFixedFloat64Array",
("OLD_SPACE", 0x02739): "EmptyFixedUint8ClampedArray",
("OLD_SPACE", 0x02759): "EmptyScript",
("OLD_SPACE", 0x027e1): "UndefinedCell",
("OLD_SPACE", 0x027f1): "EmptySloppyArgumentsElements",
("OLD_SPACE", 0x02811): "EmptySlowElementDictionary",
("OLD_SPACE", 0x02859): "EmptyPropertyCell",
("OLD_SPACE", 0x02881): "EmptyWeakCell",
("OLD_SPACE", 0x02891): "ArrayProtector",
("OLD_SPACE", 0x028b9): "IsConcatSpreadableProtector",
("OLD_SPACE", 0x028c9): "SpeciesProtector",
("OLD_SPACE", 0x028f1): "StringLengthProtector",
("OLD_SPACE", 0x02901): "FastArrayIterationProtector",
("OLD_SPACE", 0x02911): "ArrayIteratorProtector",
("OLD_SPACE", 0x02939): "ArrayBufferNeuteringProtector",
("OLD_SPACE", 0x02961): "InfinityValue",
("OLD_SPACE", 0x02971): "MinusZeroValue",
("OLD_SPACE", 0x02981): "MinusInfinityValue",
("OLD_SPACE", 0x02651): "EmptyByteArray",
("OLD_SPACE", 0x02661): "EmptyFixedUint8Array",
("OLD_SPACE", 0x02681): "EmptyFixedInt8Array",
("OLD_SPACE", 0x026a1): "EmptyFixedUint16Array",
("OLD_SPACE", 0x026c1): "EmptyFixedInt16Array",
("OLD_SPACE", 0x026e1): "EmptyFixedUint32Array",
("OLD_SPACE", 0x02701): "EmptyFixedInt32Array",
("OLD_SPACE", 0x02721): "EmptyFixedFloat32Array",
("OLD_SPACE", 0x02741): "EmptyFixedFloat64Array",
("OLD_SPACE", 0x02761): "EmptyFixedUint8ClampedArray",
("OLD_SPACE", 0x02781): "EmptyScript",
("OLD_SPACE", 0x02809): "UndefinedCell",
("OLD_SPACE", 0x02819): "EmptySloppyArgumentsElements",
("OLD_SPACE", 0x02839): "EmptySlowElementDictionary",
("OLD_SPACE", 0x028a9): "EmptyPropertyCell",
("OLD_SPACE", 0x028d1): "EmptyWeakCell",
("OLD_SPACE", 0x02941): "ArrayProtector",
("OLD_SPACE", 0x02969): "IsConcatSpreadableProtector",
("OLD_SPACE", 0x02979): "SpeciesProtector",
("OLD_SPACE", 0x029a1): "StringLengthProtector",
("OLD_SPACE", 0x029b1): "FastArrayIterationProtector",
("OLD_SPACE", 0x029c1): "ArrayIteratorProtector",
("OLD_SPACE", 0x029e9): "ArrayBufferNeuteringProtector",
("OLD_SPACE", 0x02a11): "InfinityValue",
("OLD_SPACE", 0x02a21): "MinusZeroValue",
("OLD_SPACE", 0x02a31): "MinusInfinityValue",
}
# List of known V8 Frame Markers.