diff options
Diffstat (limited to 'deps/v8/src/snapshot')
-rw-r--r-- | deps/v8/src/snapshot/code-serializer.cc | 3 | ||||
-rw-r--r-- | deps/v8/src/snapshot/deserializer.cc | 90 | ||||
-rw-r--r-- | deps/v8/src/snapshot/deserializer.h | 22 | ||||
-rw-r--r-- | deps/v8/src/snapshot/partial-serializer.cc | 39 | ||||
-rw-r--r-- | deps/v8/src/snapshot/partial-serializer.h | 8 | ||||
-rw-r--r-- | deps/v8/src/snapshot/serializer-common.cc | 4 | ||||
-rw-r--r-- | deps/v8/src/snapshot/serializer-common.h | 5 | ||||
-rw-r--r-- | deps/v8/src/snapshot/serializer.cc | 30 | ||||
-rw-r--r-- | deps/v8/src/snapshot/serializer.h | 20 | ||||
-rw-r--r-- | deps/v8/src/snapshot/snapshot-common.cc | 13 | ||||
-rw-r--r-- | deps/v8/src/snapshot/snapshot.h | 14 | ||||
-rw-r--r-- | deps/v8/src/snapshot/startup-serializer.cc | 30 | ||||
-rw-r--r-- | deps/v8/src/snapshot/startup-serializer.h | 10 |
13 files changed, 77 insertions, 211 deletions
diff --git a/deps/v8/src/snapshot/code-serializer.cc b/deps/v8/src/snapshot/code-serializer.cc index 48813f5c61..cd8b1f1a0e 100644 --- a/deps/v8/src/snapshot/code-serializer.cc +++ b/deps/v8/src/snapshot/code-serializer.cc @@ -14,6 +14,7 @@ #include "src/snapshot/deserializer.h" #include "src/snapshot/snapshot.h" #include "src/version.h" +#include "src/visitors.h" #include "src/wasm/wasm-module.h" #include "src/wasm/wasm-objects.h" @@ -50,7 +51,7 @@ ScriptData* CodeSerializer::Serialize(Isolate* isolate, ScriptData* CodeSerializer::Serialize(Handle<HeapObject> obj) { DisallowHeapAllocation no_gc; - VisitPointer(Handle<Object>::cast(obj).location()); + VisitRootPointer(Root::kHandleScope, Handle<Object>::cast(obj).location()); SerializeDeferredObjects(); Pad(); diff --git a/deps/v8/src/snapshot/deserializer.cc b/deps/v8/src/snapshot/deserializer.cc index 4b1bd45ecb..c76e4eca54 100644 --- a/deps/v8/src/snapshot/deserializer.cc +++ b/deps/v8/src/snapshot/deserializer.cc @@ -22,11 +22,11 @@ namespace internal { void Deserializer::DecodeReservation( Vector<const SerializedData::Reservation> res) { - DCHECK_EQ(0, reservations_[NEW_SPACE].length()); + DCHECK_EQ(0, reservations_[NEW_SPACE].size()); STATIC_ASSERT(NEW_SPACE == 0); int current_space = NEW_SPACE; for (auto& r : res) { - reservations_[current_space].Add({r.chunk_size(), NULL, NULL}); + reservations_[current_space].push_back({r.chunk_size(), NULL, NULL}); if (r.is_last()) current_space++; } DCHECK_EQ(kNumberOfSpaces, current_space); @@ -57,7 +57,7 @@ void Deserializer::FlushICacheForNewCodeObjectsAndRecordEmbeddedObjects() { bool Deserializer::ReserveSpace() { #ifdef DEBUG for (int i = NEW_SPACE; i < kNumberOfSpaces; ++i) { - CHECK(reservations_[i].length() > 0); + CHECK(reservations_[i].size() > 0); } #endif // DEBUG DCHECK(allocated_maps_.is_empty()); @@ -92,6 +92,8 @@ void Deserializer::Deserialize(Isolate* isolate) { DCHECK(isolate_->handle_scope_implementer()->blocks()->is_empty()); // Partial snapshot cache is not yet populated. DCHECK(isolate_->partial_snapshot_cache()->is_empty()); + // Builtins are not yet created. + DCHECK(!isolate_->builtins()->is_initialized()); { DisallowHeapAllocation no_gc; @@ -122,7 +124,7 @@ void Deserializer::Deserialize(Isolate* isolate) { LOG_CODE_EVENT(isolate_, LogBytecodeHandlers()); LOG_CODE_EVENT(isolate_, LogCompiledFunctions()); - if (FLAG_rehash_snapshot && can_rehash_) Rehash(); + isolate_->builtins()->MarkInitialized(); } MaybeHandle<Object> Deserializer::DeserializePartial( @@ -142,7 +144,7 @@ MaybeHandle<Object> Deserializer::DeserializePartial( OldSpace* code_space = isolate_->heap()->code_space(); Address start_address = code_space->top(); Object* root; - VisitPointer(&root); + VisitRootPointer(Root::kPartialSnapshotCache, &root); DeserializeDeferredObjects(); DeserializeEmbedderFields(embedder_fields_deserializer); @@ -153,9 +155,6 @@ MaybeHandle<Object> Deserializer::DeserializePartial( // changed and logging should be added to notify the profiler et al of the // new code, which also has to be flushed from instruction cache. CHECK_EQ(start_address, code_space->top()); - - if (FLAG_rehash_snapshot && can_rehash_) RehashContext(Context::cast(root)); - return Handle<Object>(root, isolate); } @@ -170,7 +169,7 @@ MaybeHandle<HeapObject> Deserializer::DeserializeObject(Isolate* isolate) { { DisallowHeapAllocation no_gc; Object* root; - VisitPointer(&root); + VisitRootPointer(Root::kPartialSnapshotCache, &root); DeserializeDeferredObjects(); FlushICacheForNewCodeObjectsAndRecordEmbeddedObjects(); result = Handle<HeapObject>(HeapObject::cast(root)); @@ -182,63 +181,6 @@ MaybeHandle<HeapObject> Deserializer::DeserializeObject(Isolate* isolate) { } } -// We only really just need HashForObject here. -class StringRehashKey : public HashTableKey { - public: - uint32_t HashForObject(Object* other) override { - return String::cast(other)->Hash(); - } - - static uint32_t StringHash(Object* obj) { - UNREACHABLE(); - return String::cast(obj)->Hash(); - } - - bool IsMatch(Object* string) override { - UNREACHABLE(); - return false; - } - - uint32_t Hash() override { - UNREACHABLE(); - return 0; - } - - Handle<Object> AsHandle(Isolate* isolate) override { - UNREACHABLE(); - return isolate->factory()->empty_string(); - } -}; - -void Deserializer::Rehash() { - DCHECK(can_rehash_); - isolate_->heap()->InitializeHashSeed(); - if (FLAG_profile_deserialization) { - PrintF("Re-initializing hash seed to %x\n", - isolate_->heap()->hash_seed()->value()); - } - StringRehashKey string_rehash_key; - isolate_->heap()->string_table()->Rehash(&string_rehash_key); - SortMapDescriptors(); -} - -void Deserializer::RehashContext(Context* context) { - DCHECK(can_rehash_); - for (const auto& array : transition_arrays_) array->Sort(); - Handle<Name> dummy = isolate_->factory()->empty_string(); - context->global_object()->global_dictionary()->Rehash(dummy); - SortMapDescriptors(); -} - -void Deserializer::SortMapDescriptors() { - for (const auto& address : allocated_maps_) { - Map* map = Map::cast(HeapObject::FromAddress(address)); - if (map->instance_descriptors()->number_of_descriptors() > 1) { - map->instance_descriptors()->Sort(); - } - } -} - Deserializer::~Deserializer() { #ifdef DEBUG // Do not perform checks if we aborted deserialization. @@ -247,7 +189,7 @@ Deserializer::~Deserializer() { while (source_.HasMore()) CHECK_EQ(kNop, source_.Get()); for (int space = 0; space < kNumberOfPreallocatedSpaces; space++) { int chunk_index = current_chunk_[space]; - CHECK_EQ(reservations_[space].length(), chunk_index + 1); + CHECK_EQ(reservations_[space].size(), chunk_index + 1); CHECK_EQ(reservations_[space][chunk_index].end, high_water_[space]); } CHECK_EQ(allocated_maps_.length(), next_map_index_); @@ -256,7 +198,7 @@ Deserializer::~Deserializer() { // This is called on the roots. It is the driver of the deserialization // process. It is also called on the body of each function. -void Deserializer::VisitPointers(Object** start, Object** end) { +void Deserializer::VisitRootPointers(Root root, Object** start, Object** end) { // The space must be new space. Any other space would cause ReadChunk to try // to update the remembered using NULL as the address. ReadData(start, end, NEW_SPACE, NULL); @@ -429,16 +371,6 @@ HeapObject* Deserializer::PostProcessNewObject(HeapObject* obj, int space) { string->resource())); isolate_->heap()->RegisterExternalString(string); } - if (FLAG_rehash_snapshot && can_rehash_ && !deserializing_user_code()) { - if (obj->IsString()) { - // Uninitialize hash field as we are going to reinitialize the hash seed. - String* string = String::cast(obj); - string->set_hash_field(String::kEmptyHashField); - } else if (obj->IsTransitionArray() && - TransitionArray::cast(obj)->number_of_entries() > 1) { - transition_arrays_.Add(TransitionArray::cast(obj)); - } - } // Check alignment. DCHECK_EQ(0, Heap::GetFillToAlign(obj->address(), obj->RequiredAlignment())); return obj; @@ -863,7 +795,7 @@ bool Deserializer::ReadData(Object** current, Object** limit, int source_space, CHECK_EQ(reservation[chunk_index].end, high_water_[space]); // Move to next reserved chunk. chunk_index = ++current_chunk_[space]; - CHECK_LT(chunk_index, reservation.length()); + CHECK_LT(chunk_index, reservation.size()); high_water_[space] = reservation[chunk_index].start; break; } diff --git a/deps/v8/src/snapshot/deserializer.h b/deps/v8/src/snapshot/deserializer.h index f3a60b89c3..a56adb67d4 100644 --- a/deps/v8/src/snapshot/deserializer.h +++ b/deps/v8/src/snapshot/deserializer.h @@ -39,8 +39,7 @@ class Deserializer : public SerializerDeserializer { external_reference_table_(NULL), deserialized_large_objects_(0), deserializing_user_code_(deserializing_user_code), - next_alignment_(kWordAligned), - can_rehash_(false) { + next_alignment_(kWordAligned) { DecodeReservation(data->Reservations()); } @@ -63,15 +62,11 @@ class Deserializer : public SerializerDeserializer { attached_objects_.Add(attached_object); } - void SetRehashability(bool v) { can_rehash_ = v; } - private: - void VisitPointers(Object** start, Object** end) override; + void VisitRootPointers(Root root, Object** start, Object** end) override; void Synchronize(VisitorSynchronization::SyncTag tag) override; - void VisitRuntimeEntry(RelocInfo* rinfo) override { UNREACHABLE(); } - void Initialize(Isolate* isolate); bool deserializing_user_code() { return deserializing_user_code_; } @@ -120,15 +115,6 @@ class Deserializer : public SerializerDeserializer { // snapshot by chunk index and offset. HeapObject* GetBackReferencedObject(int space); - // Rehash after deserializing an isolate. - void Rehash(); - - // Rehash after deserializing a context. - void RehashContext(Context* context); - - // Sort descriptors of deserialized maps using new string hashes. - void SortMapDescriptors(); - // Cached current isolate. Isolate* isolate_; @@ -156,15 +142,11 @@ class Deserializer : public SerializerDeserializer { List<AccessorInfo*> accessor_infos_; List<Handle<String> > new_internalized_strings_; List<Handle<Script> > new_scripts_; - List<TransitionArray*> transition_arrays_; bool deserializing_user_code_; AllocationAlignment next_alignment_; - // TODO(6593): generalize rehashing, and remove this flag. - bool can_rehash_; - DISALLOW_COPY_AND_ASSIGN(Deserializer); }; diff --git a/deps/v8/src/snapshot/partial-serializer.cc b/deps/v8/src/snapshot/partial-serializer.cc index 894fea7dba..d3e60e0e4e 100644 --- a/deps/v8/src/snapshot/partial-serializer.cc +++ b/deps/v8/src/snapshot/partial-serializer.cc @@ -15,9 +15,7 @@ PartialSerializer::PartialSerializer( v8::SerializeEmbedderFieldsCallback callback) : Serializer(isolate), startup_serializer_(startup_serializer), - serialize_embedder_fields_(callback), - rehashable_global_dictionary_(nullptr), - can_be_rehashed_(true) { + serialize_embedder_fields_(callback) { InitializeCodeAddressMap(); } @@ -26,7 +24,7 @@ PartialSerializer::~PartialSerializer() { } void PartialSerializer::Serialize(Object** o, bool include_global_proxy) { - if ((*o)->IsNativeContext()) { + if ((*o)->IsContext()) { Context* context = Context::cast(*o); reference_map()->AddAttachedReference(context->global_proxy()); // The bootstrap snapshot has a code-stub context. When serializing the @@ -34,20 +32,16 @@ void PartialSerializer::Serialize(Object** o, bool include_global_proxy) { // and it's next context pointer may point to the code-stub context. Clear // it before serializing, it will get re-added to the context list // explicitly when it's loaded. - context->set(Context::NEXT_CONTEXT_LINK, - isolate_->heap()->undefined_value()); - DCHECK(!context->global_object()->IsUndefined(context->GetIsolate())); - // Reset math random cache to get fresh random numbers. - context->set_math_random_index(Smi::kZero); - context->set_math_random_cache(isolate_->heap()->undefined_value()); - DCHECK_NULL(rehashable_global_dictionary_); - rehashable_global_dictionary_ = - context->global_object()->global_dictionary(); - } else { - // We only do rehashing for native contexts. - can_be_rehashed_ = false; + if (context->IsNativeContext()) { + context->set(Context::NEXT_CONTEXT_LINK, + isolate_->heap()->undefined_value()); + DCHECK(!context->global_object()->IsUndefined(context->GetIsolate())); + // Reset math random cache to get fresh random numbers. + context->set_math_random_index(Smi::kZero); + context->set_math_random_cache(isolate_->heap()->undefined_value()); + } } - VisitPointer(o); + VisitRootPointer(Root::kPartialSnapshotCache, o); SerializeDeferredObjects(); SerializeEmbedderFields(); Pad(); @@ -110,8 +104,6 @@ void PartialSerializer::SerializeObject(HeapObject* obj, HowToCode how_to_code, } } - if (obj->IsHashTable()) CheckRehashability(obj); - // Object has not yet been serialized. Serialize it here. ObjectSerializer serializer(this, obj, &sink_, how_to_code, where_to_point); serializer.Serialize(); @@ -160,14 +152,5 @@ void PartialSerializer::SerializeEmbedderFields() { sink_.Put(kSynchronize, "Finished with embedder fields data"); } -void PartialSerializer::CheckRehashability(HeapObject* table) { - DCHECK(table->IsHashTable()); - if (!can_be_rehashed_) return; - // We can only correctly rehash if the global dictionary is the only hash - // table that we deserialize. - if (table == rehashable_global_dictionary_) return; - can_be_rehashed_ = false; -} - } // namespace internal } // namespace v8 diff --git a/deps/v8/src/snapshot/partial-serializer.h b/deps/v8/src/snapshot/partial-serializer.h index 4b3035f9e5..313a800042 100644 --- a/deps/v8/src/snapshot/partial-serializer.h +++ b/deps/v8/src/snapshot/partial-serializer.h @@ -23,8 +23,6 @@ class PartialSerializer : public Serializer { // Serialize the objects reachable from a single object pointer. void Serialize(Object** o, bool include_global_proxy); - bool can_be_rehashed() const { return can_be_rehashed_; } - private: void SerializeObject(HeapObject* o, HowToCode how_to_code, WhereToPoint where_to_point, int skip) override; @@ -33,15 +31,9 @@ class PartialSerializer : public Serializer { void SerializeEmbedderFields(); - void CheckRehashability(HeapObject* table); - StartupSerializer* startup_serializer_; List<JSObject*> embedder_field_holders_; v8::SerializeEmbedderFieldsCallback serialize_embedder_fields_; - GlobalDictionary* rehashable_global_dictionary_; - // Indicates whether we only serialized hash tables that we can rehash. - // TODO(yangguo): generalize rehashing, and remove this flag. - bool can_be_rehashed_; DISALLOW_COPY_AND_ASSIGN(PartialSerializer); }; diff --git a/deps/v8/src/snapshot/serializer-common.cc b/deps/v8/src/snapshot/serializer-common.cc index 89aabdf263..05a18ab727 100644 --- a/deps/v8/src/snapshot/serializer-common.cc +++ b/deps/v8/src/snapshot/serializer-common.cc @@ -67,14 +67,14 @@ void SerializedData::AllocateData(int size) { // - during normal GC to keep its content alive. // - not during serialization. The partial serializer adds to it explicitly. DISABLE_CFI_PERF -void SerializerDeserializer::Iterate(Isolate* isolate, ObjectVisitor* visitor) { +void SerializerDeserializer::Iterate(Isolate* isolate, RootVisitor* visitor) { List<Object*>* cache = isolate->partial_snapshot_cache(); for (int i = 0;; ++i) { // Extend the array ready to get a value when deserializing. if (cache->length() <= i) cache->Add(Smi::kZero); // During deserialization, the visitor populates the partial snapshot cache // and eventually terminates the cache with undefined. - visitor->VisitPointer(&cache->at(i)); + visitor->VisitRootPointer(Root::kPartialSnapshotCache, &cache->at(i)); if (cache->at(i)->IsUndefined(isolate)) break; } } diff --git a/deps/v8/src/snapshot/serializer-common.h b/deps/v8/src/snapshot/serializer-common.h index 8605c43f3b..d445cb95c9 100644 --- a/deps/v8/src/snapshot/serializer-common.h +++ b/deps/v8/src/snapshot/serializer-common.h @@ -8,6 +8,7 @@ #include "src/address-map.h" #include "src/external-reference-table.h" #include "src/globals.h" +#include "src/visitors.h" namespace v8 { namespace internal { @@ -73,9 +74,9 @@ class HotObjectsList { // The Serializer/Deserializer class is a common superclass for Serializer and // Deserializer which is used to store common constants and methods used by // both. -class SerializerDeserializer : public ObjectVisitor { +class SerializerDeserializer : public RootVisitor { public: - static void Iterate(Isolate* isolate, ObjectVisitor* visitor); + static void Iterate(Isolate* isolate, RootVisitor* visitor); // No reservation for large object space necessary. // We also handle map space differenly. diff --git a/deps/v8/src/snapshot/serializer.cc b/deps/v8/src/snapshot/serializer.cc index 625958812f..a63d888d11 100644 --- a/deps/v8/src/snapshot/serializer.cc +++ b/deps/v8/src/snapshot/serializer.cc @@ -76,6 +76,7 @@ void Serializer::OutputStatistics(const char* name) { for (uint32_t chunk_size : completed_chunks_[space]) s += chunk_size; PrintF("%16" PRIuS, s); } + PrintF("%16d", num_maps_ * Map::kSize); PrintF("%16d\n", large_objects_total_size_); #ifdef OBJECT_PRINT PrintF(" Instance types (count and bytes):\n"); @@ -99,7 +100,7 @@ void Serializer::SerializeDeferredObjects() { sink_.Put(kSynchronize, "Finished with deferred objects"); } -void Serializer::VisitPointers(Object** start, Object** end) { +void Serializer::VisitRootPointers(Root root, Object** start, Object** end) { for (Object** current = start; current < end; current++) { if ((*current)->IsSmi()) { PutSmi(Smi::cast(*current)); @@ -598,7 +599,8 @@ void Serializer::ObjectSerializer::SerializeDeferred() { OutputRawData(object_->address() + size); } -void Serializer::ObjectSerializer::VisitPointers(Object** start, Object** end) { +void Serializer::ObjectSerializer::VisitPointers(HeapObject* host, + Object** start, Object** end) { Object** current = start; while (current < end) { while (current < end && (*current)->IsSmi()) current++; @@ -636,7 +638,8 @@ void Serializer::ObjectSerializer::VisitPointers(Object** start, Object** end) { } } -void Serializer::ObjectSerializer::VisitEmbeddedPointer(RelocInfo* rinfo) { +void Serializer::ObjectSerializer::VisitEmbeddedPointer(Code* host, + RelocInfo* rinfo) { int skip = OutputRawData(rinfo->target_address_address(), kCanReturnSkipInsteadOfSkipping); HowToCode how_to_code = rinfo->IsCodedSpecially() ? kFromCode : kPlain; @@ -646,7 +649,8 @@ void Serializer::ObjectSerializer::VisitEmbeddedPointer(RelocInfo* rinfo) { bytes_processed_so_far_ += rinfo->target_address_size(); } -void Serializer::ObjectSerializer::VisitExternalReference(Address* p) { +void Serializer::ObjectSerializer::VisitExternalReference(Foreign* host, + Address* p) { int skip = OutputRawData(reinterpret_cast<Address>(p), kCanReturnSkipInsteadOfSkipping); Address target = *p; @@ -658,7 +662,8 @@ void Serializer::ObjectSerializer::VisitExternalReference(Address* p) { bytes_processed_so_far_ += kPointerSize; } -void Serializer::ObjectSerializer::VisitExternalReference(RelocInfo* rinfo) { +void Serializer::ObjectSerializer::VisitExternalReference(Code* host, + RelocInfo* rinfo) { int skip = OutputRawData(rinfo->target_address_address(), kCanReturnSkipInsteadOfSkipping); HowToCode how_to_code = rinfo->IsCodedSpecially() ? kFromCode : kPlain; @@ -673,7 +678,8 @@ void Serializer::ObjectSerializer::VisitExternalReference(RelocInfo* rinfo) { bytes_processed_so_far_ += rinfo->target_address_size(); } -void Serializer::ObjectSerializer::VisitInternalReference(RelocInfo* rinfo) { +void Serializer::ObjectSerializer::VisitInternalReference(Code* host, + RelocInfo* rinfo) { // We can only reference to internal references of code that has been output. DCHECK(object_->IsCode() && code_has_been_output_); // We do not use skip from last patched pc to find the pc to patch, since @@ -697,7 +703,8 @@ void Serializer::ObjectSerializer::VisitInternalReference(RelocInfo* rinfo) { sink_->PutInt(static_cast<uintptr_t>(target_offset), "internal ref value"); } -void Serializer::ObjectSerializer::VisitRuntimeEntry(RelocInfo* rinfo) { +void Serializer::ObjectSerializer::VisitRuntimeEntry(Code* host, + RelocInfo* rinfo) { int skip = OutputRawData(rinfo->target_address_address(), kCanReturnSkipInsteadOfSkipping); HowToCode how_to_code = rinfo->IsCodedSpecially() ? kFromCode : kPlain; @@ -711,7 +718,8 @@ void Serializer::ObjectSerializer::VisitRuntimeEntry(RelocInfo* rinfo) { bytes_processed_so_far_ += rinfo->target_address_size(); } -void Serializer::ObjectSerializer::VisitCodeTarget(RelocInfo* rinfo) { +void Serializer::ObjectSerializer::VisitCodeTarget(Code* host, + RelocInfo* rinfo) { int skip = OutputRawData(rinfo->target_address_address(), kCanReturnSkipInsteadOfSkipping); Code* object = Code::GetCodeFromTargetAddress(rinfo->target_address()); @@ -719,14 +727,16 @@ void Serializer::ObjectSerializer::VisitCodeTarget(RelocInfo* rinfo) { bytes_processed_so_far_ += rinfo->target_address_size(); } -void Serializer::ObjectSerializer::VisitCodeEntry(Address entry_address) { +void Serializer::ObjectSerializer::VisitCodeEntry(JSFunction* host, + Address entry_address) { int skip = OutputRawData(entry_address, kCanReturnSkipInsteadOfSkipping); Code* object = Code::cast(Code::GetObjectFromEntryAddress(entry_address)); serializer_->SerializeObject(object, kPlain, kInnerPointer, skip); bytes_processed_so_far_ += kPointerSize; } -void Serializer::ObjectSerializer::VisitCell(RelocInfo* rinfo) { +void Serializer::ObjectSerializer::VisitCellPointer(Code* host, + RelocInfo* rinfo) { int skip = OutputRawData(rinfo->pc(), kCanReturnSkipInsteadOfSkipping); Cell* object = Cell::cast(rinfo->target_cell()); serializer_->SerializeObject(object, kPlain, kInnerPointer, skip); diff --git a/deps/v8/src/snapshot/serializer.h b/deps/v8/src/snapshot/serializer.h index 1af259db57..cc4d30bfc5 100644 --- a/deps/v8/src/snapshot/serializer.h +++ b/deps/v8/src/snapshot/serializer.h @@ -156,7 +156,7 @@ class Serializer : public SerializerDeserializer { virtual void SerializeObject(HeapObject* o, HowToCode how_to_code, WhereToPoint where_to_point, int skip) = 0; - void VisitPointers(Object** start, Object** end) override; + void VisitRootPointers(Root root, Object** start, Object** end) override; void PutRoot(int index, HeapObject* object, HowToCode how, WhereToPoint where, int skip); @@ -282,15 +282,15 @@ class Serializer::ObjectSerializer : public ObjectVisitor { void Serialize(); void SerializeContent(); void SerializeDeferred(); - void VisitPointers(Object** start, Object** end) override; - void VisitEmbeddedPointer(RelocInfo* target) override; - void VisitExternalReference(Address* p) override; - void VisitExternalReference(RelocInfo* rinfo) override; - void VisitInternalReference(RelocInfo* rinfo) override; - void VisitCodeTarget(RelocInfo* target) override; - void VisitCodeEntry(Address entry_address) override; - void VisitCell(RelocInfo* rinfo) override; - void VisitRuntimeEntry(RelocInfo* reloc) override; + void VisitPointers(HeapObject* host, Object** start, Object** end) override; + void VisitEmbeddedPointer(Code* host, RelocInfo* target) override; + void VisitExternalReference(Foreign* host, Address* p) override; + void VisitExternalReference(Code* host, RelocInfo* rinfo) override; + void VisitInternalReference(Code* host, RelocInfo* rinfo) override; + void VisitCodeTarget(Code* host, RelocInfo* target) override; + void VisitCodeEntry(JSFunction* host, Address entry_address) override; + void VisitCellPointer(Code* host, RelocInfo* rinfo) override; + void VisitRuntimeEntry(Code* host, RelocInfo* reloc) override; private: bool TryEncodeDeoptimizationEntry(HowToCode how_to_code, Address target, diff --git a/deps/v8/src/snapshot/snapshot-common.cc b/deps/v8/src/snapshot/snapshot-common.cc index 9f299e697e..9350ec6b54 100644 --- a/deps/v8/src/snapshot/snapshot-common.cc +++ b/deps/v8/src/snapshot/snapshot-common.cc @@ -41,7 +41,6 @@ bool Snapshot::Initialize(Isolate* isolate) { Vector<const byte> startup_data = ExtractStartupData(blob); SnapshotData snapshot_data(startup_data); Deserializer deserializer(&snapshot_data); - deserializer.SetRehashability(ExtractRehashability(blob)); bool success = isolate->Init(&deserializer); if (FLAG_profile_deserialization) { double ms = timer.Elapsed().InMillisecondsF(); @@ -63,7 +62,6 @@ MaybeHandle<Context> Snapshot::NewContextFromSnapshot( ExtractContextData(blob, static_cast<int>(context_index)); SnapshotData snapshot_data(context_data); Deserializer deserializer(&snapshot_data); - deserializer.SetRehashability(ExtractRehashability(blob)); MaybeHandle<Object> maybe_context = deserializer.DeserializePartial( isolate, global_proxy, embedder_fields_deserializer); @@ -100,7 +98,7 @@ void ProfileDeserialization(const SnapshotData* startup_snapshot, v8::StartupData Snapshot::CreateSnapshotBlob( const SnapshotData* startup_snapshot, - const List<SnapshotData*>* context_snapshots, bool can_be_rehashed) { + const List<SnapshotData*>* context_snapshots) { int num_contexts = context_snapshots->length(); int startup_snapshot_offset = StartupSnapshotOffset(num_contexts); int total_length = startup_snapshot_offset; @@ -113,8 +111,6 @@ v8::StartupData Snapshot::CreateSnapshotBlob( char* data = new char[total_length]; memcpy(data + kNumberOfContextsOffset, &num_contexts, kInt32Size); - int rehashability = can_be_rehashed ? 1 : 0; - memcpy(data + kRehashabilityOffset, &rehashability, kInt32Size); int payload_offset = StartupSnapshotOffset(num_contexts); int payload_length = startup_snapshot->RawData().length(); memcpy(data + payload_offset, startup_snapshot->RawData().start(), @@ -147,13 +143,6 @@ int Snapshot::ExtractNumContexts(const v8::StartupData* data) { return num_contexts; } -bool Snapshot::ExtractRehashability(const v8::StartupData* data) { - CHECK_LT(kRehashabilityOffset, data->raw_size); - int rehashability; - memcpy(&rehashability, data->data + kRehashabilityOffset, kInt32Size); - return rehashability != 0; -} - Vector<const byte> Snapshot::ExtractStartupData(const v8::StartupData* data) { int num_contexts = ExtractNumContexts(data); int startup_offset = StartupSnapshotOffset(num_contexts); diff --git a/deps/v8/src/snapshot/snapshot.h b/deps/v8/src/snapshot/snapshot.h index e0fd226e62..7d9082e6d2 100644 --- a/deps/v8/src/snapshot/snapshot.h +++ b/deps/v8/src/snapshot/snapshot.h @@ -62,8 +62,6 @@ class Snapshot : public AllStatic { size_t context_index, v8::DeserializeEmbedderFieldsCallback embedder_fields_deserializer); - static bool HaveASnapshotToStartFrom(Isolate* isolate); - static bool HasContextSnapshot(Isolate* isolate, size_t index); static bool EmbedsScript(Isolate* isolate); @@ -73,7 +71,7 @@ class Snapshot : public AllStatic { static v8::StartupData CreateSnapshotBlob( const SnapshotData* startup_snapshot, - const List<SnapshotData*>* context_snapshots, bool can_be_rehashed); + const List<SnapshotData*>* context_snapshots); #ifdef DEBUG static bool SnapshotIsValid(v8::StartupData* snapshot_blob); @@ -81,16 +79,14 @@ class Snapshot : public AllStatic { private: static int ExtractNumContexts(const v8::StartupData* data); - static bool ExtractRehashability(const v8::StartupData* data); static Vector<const byte> ExtractStartupData(const v8::StartupData* data); static Vector<const byte> ExtractContextData(const v8::StartupData* data, int index); // Snapshot blob layout: // [0] number of contexts N - // [1] rehashability - // [2] offset to context 0 - // [3] offset to context 1 + // [1] offset to context 0 + // [2] offset to context 1 // ... // ... offset to context N - 1 // ... startup snapshot data @@ -98,10 +94,8 @@ class Snapshot : public AllStatic { // ... context 1 snapshot data static const int kNumberOfContextsOffset = 0; - // TODO(yangguo): generalize rehashing, and remove this flag. - static const int kRehashabilityOffset = kNumberOfContextsOffset + kInt32Size; static const int kFirstContextOffsetOffset = - kRehashabilityOffset + kInt32Size; + kNumberOfContextsOffset + kInt32Size; static int StartupSnapshotOffset(int num_contexts) { return kFirstContextOffsetOffset + num_contexts * kInt32Size; diff --git a/deps/v8/src/snapshot/startup-serializer.cc b/deps/v8/src/snapshot/startup-serializer.cc index b63474ec75..dfc02036d8 100644 --- a/deps/v8/src/snapshot/startup-serializer.cc +++ b/deps/v8/src/snapshot/startup-serializer.cc @@ -16,8 +16,7 @@ StartupSerializer::StartupSerializer( : Serializer(isolate), clear_function_code_(function_code_handling == v8::SnapshotCreator::FunctionCodeHandling::kClear), - serializing_builtins_(false), - can_be_rehashed_(true) { + serializing_builtins_(false) { InitializeCodeAddressMap(); } @@ -74,10 +73,11 @@ void StartupSerializer::SerializeObject(HeapObject* obj, HowToCode how_to_code, Address original_address = Foreign::cast(info->getter())->foreign_address(); Foreign::cast(info->js_getter())->set_foreign_address(original_address); accessor_infos_.Add(info); + } else if (obj->IsScript() && Script::cast(obj)->IsUserJavaScript()) { + Script::cast(obj)->set_context_data( + isolate_->heap()->uninitialized_symbol()); } - if (obj->IsHashTable()) CheckRehashability(obj); - // Object has not yet been serialized. Serialize it here. ObjectSerializer object_serializer(this, obj, &sink_, how_to_code, where_to_point); @@ -98,7 +98,7 @@ void StartupSerializer::SerializeWeakReferencesAndDeferred() { // add entries to the partial snapshot cache of the startup snapshot. Add // one entry with 'undefined' to terminate the partial snapshot cache. Object* undefined = isolate()->heap()->undefined_value(); - VisitPointer(&undefined); + VisitRootPointer(Root::kPartialSnapshotCache, &undefined); isolate()->heap()->IterateWeakRoots(this, VISIT_ALL); SerializeDeferredObjects(); Pad(); @@ -110,7 +110,8 @@ int StartupSerializer::PartialSnapshotCacheIndex(HeapObject* heap_object) { // This object is not part of the partial snapshot cache yet. Add it to the // startup snapshot so we can refer to it via partial snapshot index from // the partial snapshot. - VisitPointer(reinterpret_cast<Object**>(&heap_object)); + VisitRootPointer(Root::kPartialSnapshotCache, + reinterpret_cast<Object**>(&heap_object)); } return index; } @@ -147,7 +148,8 @@ void StartupSerializer::SerializeStrongReferences() { VISIT_ONLY_STRONG_FOR_SERIALIZATION); } -void StartupSerializer::VisitPointers(Object** start, Object** end) { +void StartupSerializer::VisitRootPointers(Root root, Object** start, + Object** end) { if (start == isolate()->heap()->roots_array_start()) { // Serializing the root list needs special handling: // - The first pass over the root list only serializes immortal immovables. @@ -174,7 +176,7 @@ void StartupSerializer::VisitPointers(Object** start, Object** end) { } FlushSkip(skip); } else { - Serializer::VisitPointers(start, end); + Serializer::VisitRootPointers(root, start, end); } } @@ -187,17 +189,5 @@ bool StartupSerializer::RootShouldBeSkipped(int root_index) { serializing_immortal_immovables_roots_; } -void StartupSerializer::CheckRehashability(HeapObject* table) { - DCHECK(table->IsHashTable()); - if (!can_be_rehashed_) return; - // We can only correctly rehash if the four hash tables below are the only - // ones that we deserialize. - if (table == isolate_->heap()->empty_slow_element_dictionary()) return; - if (table == isolate_->heap()->empty_properties_dictionary()) return; - if (table == isolate_->heap()->weak_object_to_code_table()) return; - if (table == isolate_->heap()->string_table()) return; - can_be_rehashed_ = false; -} - } // namespace internal } // namespace v8 diff --git a/deps/v8/src/snapshot/startup-serializer.h b/deps/v8/src/snapshot/startup-serializer.h index 5f76808cd0..223e1c7bff 100644 --- a/deps/v8/src/snapshot/startup-serializer.h +++ b/deps/v8/src/snapshot/startup-serializer.h @@ -29,8 +29,6 @@ class StartupSerializer : public Serializer { int PartialSnapshotCacheIndex(HeapObject* o); - bool can_be_rehashed() const { return can_be_rehashed_; } - private: class PartialCacheIndexMap { public: @@ -59,7 +57,7 @@ class StartupSerializer : public Serializer { // The StartupSerializer has to serialize the root array, which is slightly // different. - void VisitPointers(Object** start, Object** end) override; + void VisitRootPointers(Root root, Object** start, Object** end) override; void SerializeObject(HeapObject* o, HowToCode how_to_code, WhereToPoint where_to_point, int skip) override; void Synchronize(VisitorSynchronization::SyncTag tag) override; @@ -70,18 +68,12 @@ class StartupSerializer : public Serializer { // roots. In the second pass, we serialize the rest. bool RootShouldBeSkipped(int root_index); - void CheckRehashability(HeapObject* hashtable); - bool clear_function_code_; bool serializing_builtins_; bool serializing_immortal_immovables_roots_; std::bitset<Heap::kStrongRootListLength> root_has_been_serialized_; PartialCacheIndexMap partial_cache_index_map_; List<AccessorInfo*> accessor_infos_; - // Indicates whether we only serialized hash tables that we can rehash. - // TODO(yangguo): generalize rehashing, and remove this flag. - bool can_be_rehashed_; - DISALLOW_COPY_AND_ASSIGN(StartupSerializer); }; |