5#ifndef V8_SNAPSHOT_SERIALIZER_H_
6#define V8_SNAPSHOT_SERIALIZER_H_
28 CHECK(isolate->logger()->AddListener(
this));
67 if (entry->
value ==
nullptr) {
74 return (entry !=
nullptr) ?
static_cast<const char*
>(entry->
value)
80 if (entry !=
nullptr) {
87 if (from == to)
return;
90 void* value = from_entry->
value;
98 static char*
CopyName(
const char* name,
size_t name_size) {
100 for (
size_t i = 0;
i < name_size; ++
i) {
102 if (c ==
'\0') c =
' ';
115 return impl_.
Lookup(
reinterpret_cast<void*
>(code_address),
128 const char* name,
size_t length)
override {
133#if V8_ENABLE_WEBASSEMBLY
135 size_t length)
override {
153 auto find_result =
map_.FindOrInsert(obj);
154 if (!find_result.already_exists) {
157 *index_out = *find_result.entry;
158 return find_result.already_exists;
165 int* index =
map_.Find(obj);
166 if (index ==
nullptr) {
200#if V8_COMPRESS_POINTERS
216 serializer_->recursion_depth_++;
220 return serializer_->recursion_depth_ > kMaxRecursionDepth;
223 return serializer_->recursion_depth_ - kMaxRecursionDepth;
227 static const int kMaxRecursionDepth = 32;
288 void Pad(
int padding_offset = 0);
317 void PrintStack(std::ostream&);
371 DCHECK(!AllowGarbageCollection::IsAllowed());
395#if V8_COMPRESS_POINTERS
441#define VERBOSE_SERIALIZATION_STATISTICS
443#ifdef VERBOSE_SERIALIZATION_STATISTICS
444 static constexpr int kInstanceTypes =
LAST_TYPE + 1;
#define DISALLOW_GARBAGE_COLLECTION(name)
Entry * Next(Entry *entry) const
Entry * LookupOrInsert(const Key &key, uint32_t hash)
Value Remove(const Key &key, uint32_t hash)
Entry * Lookup(const Key &key, uint32_t hash) const
base::HashMap::Entry * FindOrCreateEntry(Address code_address)
base::HashMap::Entry * FindEntry(Address code_address)
NameMap(const NameMap &)=delete
void Move(Address from, Address to)
static char * CopyName(const char *name, size_t name_size)
void Insert(Address code_address, const char *name, size_t name_size)
NameMap & operator=(const NameMap &)=delete
void RemoveEntry(base::HashMap::Entry *entry)
void Remove(Address code_address)
const char * Lookup(Address code_address)
~CodeAddressMap() override
void LogRecordedBuffer(Tagged< AbstractCode > code, MaybeDirectHandle< SharedFunctionInfo >, const char *name, size_t length) override
NameMap address_to_name_map_
void CodeDisableOptEvent(DirectHandle< AbstractCode > code, DirectHandle< SharedFunctionInfo > shared) override
void CodeMoveEvent(Tagged< InstructionStream > from, Tagged< InstructionStream > to) override
const char * Lookup(Address address)
void BytecodeMoveEvent(Tagged< BytecodeArray > from, Tagged< BytecodeArray > to) override
CodeAddressMap(Isolate *isolate)
Maybe< Value > TryEncode(Address key) const
bool RemoveListener(LogEventListener *listener)
ObjectCacheIndexMap & operator=(const ObjectCacheIndexMap &)=delete
DirectHandle< FixedArray > Values(Isolate *isolate)
ObjectCacheIndexMap(Heap *heap)
bool LookupOrInsert(Tagged< HeapObject > obj, int *index_out)
ObjectCacheIndexMap(const ObjectCacheIndexMap &)=delete
IdentityMap< int, base::DefaultAllocationPolicy > map_
bool LookupOrInsert(DirectHandle< HeapObject > obj, int *index_out)
bool Lookup(Tagged< HeapObject > obj, int *index_out) const
static const int kHotObjectCount
const SerializerReference * LookupReference(Tagged< HeapObject > object) const
static const int kSizeMask
StrongRootsEntry * strong_roots_entry_
static const int kNotFound
HotObjectsList & operator=(const HotObjectsList &)=delete
int Find(Tagged< HeapObject > object)
HotObjectsList(const HotObjectsList &)=delete
HotObjectsList(Heap *heap)
void Add(Tagged< HeapObject > object)
Address circular_queue_[kSize]
void VisitInstructionStreamPointer(Tagged< Code > host, InstructionStreamSlot slot) override
void SerializeContent(Tagged< Map > map, int size)
void SerializeJSArrayBuffer()
ObjectSerializer(Serializer *serializer, Handle< HeapObject > obj, SnapshotByteSink *sink)
void OutputRawData(Address up_to)
void VisitExternalReference(Tagged< InstructionStream > host, RelocInfo *rinfo) override
void VisitJSDispatchTableEntry(Tagged< HeapObject > host, JSDispatchHandle handle) override
void VisitPointers(Tagged< HeapObject > host, ObjectSlot start, ObjectSlot end) override
uint32_t SerializeBackingStore(void *backing_store, uint32_t byte_length, Maybe< uint32_t > max_byte_length)
void VisitProtectedPointer(Tagged< TrustedObject > host, ProtectedPointerSlot slot) override
int bytes_processed_so_far_
void SerializeExternalString()
~ObjectSerializer() override
void VisitEmbeddedPointer(Tagged< InstructionStream > host, RelocInfo *target) override
void VisitTrustedPointerTableEntry(Tagged< HeapObject > host, IndirectPointerSlot slot) override
void VisitExternalPointer(Tagged< HeapObject > host, ExternalPointerSlot slot) override
Handle< HeapObject > object_
void VisitIndirectPointer(Tagged< HeapObject > host, IndirectPointerSlot slot, IndirectPointerMode mode) override
void VisitOffHeapTarget(Tagged< InstructionStream > host, RelocInfo *target) override
void OutputExternalReference(Address target, int target_size, bool sandboxify, ExternalPointerTag tag)
void Serialize(SlotType slot_type)
void VisitCodeTarget(Tagged< InstructionStream > host, RelocInfo *target) override
void VisitInternalReference(Tagged< InstructionStream > host, RelocInfo *rinfo) override
void VisitCppHeapPointer(Tagged< HeapObject > host, CppHeapPointerSlot slot) override
void SerializeExternalStringAsSequentialString()
void SerializeJSTypedArray()
void SerializePrologue(SnapshotSpace space, int size, Tagged< Map > map)
int ExceedsMaximumBy() const
bool ExceedsMaximum() const
RecursionScope(Serializer *serializer)
bool ReferenceMapContains(DirectHandle< HeapObject > o)
void InitializeCodeAddressMap()
bool allow_unknown_external_references_for_testing() const
HotObjectsList hot_objects_
bool SerializePendingObject(Tagged< HeapObject > obj)
PtrComprCageBase cage_base() const
Serializer & operator=(const Serializer &)=delete
ExternalReferenceEncoder::Value EncodeExternalReference(Address addr)
virtual bool MustBeDeferred(Tagged< HeapObject > object)
Tagged< InstructionStream > CopyCode(Tagged< InstructionStream > istream)
std::unique_ptr< CodeAddressMap > code_address_map_
void ResolvePendingObject(Tagged< HeapObject > obj)
bool ObjectIsBytecodeHandler(Tagged< HeapObject > obj) const
Isolate * isolate() const
void PutSmiRoot(FullObjectSlot slot)
void RegisterObjectIsPending(Tagged< HeapObject > obj)
void VisitRootPointers(Root root, const char *description, FullObjectSlot start, FullObjectSlot end) override
bool reconstruct_read_only_and_shared_object_caches_for_testing() const
SerializerReferenceMap reference_map_
RootIndexMap root_index_map_
bool serializer_tracks_serialization_statistics() const
const std::vector< uint8_t > * Payload() const
const RootIndexMap * root_index_map() const
void set_serializer_tracks_serialization_statistics(bool v)
void PutBackReference(Tagged< HeapObject > object, SerializerReference reference)
void QueueDeferredObject(Tagged< HeapObject > obj)
void CountAllocation(Tagged< Map > map, int size, SnapshotSpace space)
void PutPendingForwardReference(PendingObjectReferences &ref)
ExternalReferenceEncoder external_reference_encoder_
int unresolved_forward_refs_
virtual void SerializeObjectImpl(Handle< HeapObject > o, SlotType slot_type)=0
void SerializeRootObject(FullObjectSlot slot)
void PutRepeatRoot(int repeat_count, RootIndex root_index)
void SerializeDeferredObjects()
Serializer(const Serializer &)=delete
void PutRoot(RootIndex root_index)
bool SerializeRoot(Tagged< HeapObject > obj)
bool SerializeReadOnlyObjectReference(Tagged< HeapObject > obj, SnapshotByteSink *sink)
void OutputStatistics(const char *name)
bool serializer_tracks_serialization_statistics_
IdentityMap< PendingObjectReferences, base::DefaultAllocationPolicy > forward_refs_per_pending_object_
void ResolvePendingForwardReference(int obj)
void PutAttachedReference(SerializerReference reference)
Serializer(Isolate *isolate, Snapshot::SerializerFlags flags)
void Pad(int padding_offset=0)
uint32_t seen_backing_stores_index_
bool deferred_objects_empty()
int TotalAllocationSize() const
std::vector< uint8_t > code_buffer_
void PutNextChunk(SnapshotSpace space)
std::unordered_map< JSDispatchHandle, uint32_t > dispatch_handle_map_
void SerializeObject(Handle< HeapObject > o, SlotType slot_type)
bool allow_active_isolate_for_testing() const
Maybe< ExternalReferenceEncoder::Value > TryEncodeExternalReference(Address addr)
std::vector< int > * PendingObjectReferences
SerializerReferenceMap * reference_map()
bool SerializeHotObject(Tagged< HeapObject > obj)
V8_INLINE bool IsNotMappedSymbol(Tagged< HeapObject > obj) const
size_t allocation_size_[kNumberOfSnapshotSpaces]
GlobalHandleVector< HeapObject > deferred_objects_
bool SerializeBackReference(Tagged< HeapObject > obj)
const Snapshot::SerializerFlags flags_
const std::vector< uint8_t > * data() const
@ kReconstructReadOnlyAndSharedObjectCachesForTesting
@ kAllowActiveIsolateForTesting
@ kAllowUnknownExternalReferencesForTesting
DisallowGarbageCollection no_gc_
ZoneVector< RpoNumber > & result
constexpr bool IsPowerOfTwo(T value)
void DeleteArray(T *array)
V8_INLINE IndirectHandle< T > handle(Tagged< T > object, Isolate *isolate)
static constexpr int kNumberOfSnapshotSpaces
static constexpr Address kNullAddress
T * NewArray(size_t size)
uint32_t ComputeAddressHash(Address address)
#define DCHECK_NOT_NULL(val)
#define DCHECK(condition)
#define DCHECK_EQ(v1, v2)