OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef V8_SNAPSHOT_DESERIALIZER_H_ |
| 6 #define V8_SNAPSHOT_DESERIALIZER_H_ |
| 7 |
| 8 #include "src/heap/heap.h" |
| 9 #include "src/objects.h" |
| 10 #include "src/snapshot/serializer-common.h" |
| 11 #include "src/snapshot/snapshot-source-sink.h" |
| 12 |
| 13 namespace v8 { |
| 14 namespace internal { |
| 15 |
| 16 class Heap; |
| 17 |
| 18 // A Deserializer reads a snapshot and reconstructs the Object graph it defines. |
| 19 class Deserializer : public SerializerDeserializer { |
| 20 public: |
| 21 // Create a deserializer from a snapshot byte source. |
| 22 template <class Data> |
| 23 explicit Deserializer(Data* data) |
| 24 : isolate_(NULL), |
| 25 source_(data->Payload()), |
| 26 magic_number_(data->GetMagicNumber()), |
| 27 external_reference_table_(NULL), |
| 28 deserialized_large_objects_(0), |
| 29 deserializing_user_code_(false), |
| 30 next_alignment_(kWordAligned) { |
| 31 DecodeReservation(data->Reservations()); |
| 32 } |
| 33 |
| 34 ~Deserializer() override; |
| 35 |
| 36 // Deserialize the snapshot into an empty heap. |
| 37 void Deserialize(Isolate* isolate); |
| 38 |
| 39 // Deserialize a single object and the objects reachable from it. |
| 40 MaybeHandle<Object> DeserializePartial(Isolate* isolate, |
| 41 Handle<JSGlobalProxy> global_proxy); |
| 42 |
| 43 // Deserialize a shared function info. Fail gracefully. |
| 44 MaybeHandle<SharedFunctionInfo> DeserializeCode(Isolate* isolate); |
| 45 |
| 46 // Pass a vector of externally-provided objects referenced by the snapshot. |
| 47 // The ownership to its backing store is handed over as well. |
| 48 void SetAttachedObjects(Vector<Handle<Object> > attached_objects) { |
| 49 attached_objects_ = attached_objects; |
| 50 } |
| 51 |
| 52 private: |
| 53 void VisitPointers(Object** start, Object** end) override; |
| 54 |
| 55 void Synchronize(VisitorSynchronization::SyncTag tag) override; |
| 56 |
| 57 void VisitRuntimeEntry(RelocInfo* rinfo) override { UNREACHABLE(); } |
| 58 |
| 59 void Initialize(Isolate* isolate); |
| 60 |
| 61 bool deserializing_user_code() { return deserializing_user_code_; } |
| 62 |
| 63 void DecodeReservation(Vector<const SerializedData::Reservation> res); |
| 64 |
| 65 bool ReserveSpace(); |
| 66 |
| 67 void UnalignedCopy(Object** dest, Object** src) { |
| 68 memcpy(dest, src, sizeof(*src)); |
| 69 } |
| 70 |
| 71 void SetAlignment(byte data) { |
| 72 DCHECK_EQ(kWordAligned, next_alignment_); |
| 73 int alignment = data - (kAlignmentPrefix - 1); |
| 74 DCHECK_LE(kWordAligned, alignment); |
| 75 DCHECK_LE(alignment, kSimd128Unaligned); |
| 76 next_alignment_ = static_cast<AllocationAlignment>(alignment); |
| 77 } |
| 78 |
| 79 void DeserializeDeferredObjects(); |
| 80 |
| 81 void FlushICacheForNewIsolate(); |
| 82 void FlushICacheForNewCodeObjects(); |
| 83 |
| 84 void CommitPostProcessedObjects(Isolate* isolate); |
| 85 |
| 86 // Fills in some heap data in an area from start to end (non-inclusive). The |
| 87 // space id is used for the write barrier. The object_address is the address |
| 88 // of the object we are writing into, or NULL if we are not writing into an |
| 89 // object, i.e. if we are writing a series of tagged values that are not on |
| 90 // the heap. Return false if the object content has been deferred. |
| 91 bool ReadData(Object** start, Object** end, int space, |
| 92 Address object_address); |
| 93 void ReadObject(int space_number, Object** write_back); |
| 94 Address Allocate(int space_index, int size); |
| 95 |
| 96 // Special handling for serialized code like hooking up internalized strings. |
| 97 HeapObject* PostProcessNewObject(HeapObject* obj, int space); |
| 98 |
| 99 // This returns the address of an object that has been described in the |
| 100 // snapshot by chunk index and offset. |
| 101 HeapObject* GetBackReferencedObject(int space); |
| 102 |
| 103 Object** CopyInNativesSource(Vector<const char> source_vector, |
| 104 Object** current); |
| 105 |
| 106 // Cached current isolate. |
| 107 Isolate* isolate_; |
| 108 |
| 109 // Objects from the attached object descriptions in the serialized user code. |
| 110 Vector<Handle<Object> > attached_objects_; |
| 111 |
| 112 SnapshotByteSource source_; |
| 113 uint32_t magic_number_; |
| 114 |
| 115 // The address of the next object that will be allocated in each space. |
| 116 // Each space has a number of chunks reserved by the GC, with each chunk |
| 117 // fitting into a page. Deserialized objects are allocated into the |
| 118 // current chunk of the target space by bumping up high water mark. |
| 119 Heap::Reservation reservations_[kNumberOfSpaces]; |
| 120 uint32_t current_chunk_[kNumberOfPreallocatedSpaces]; |
| 121 Address high_water_[kNumberOfPreallocatedSpaces]; |
| 122 |
| 123 ExternalReferenceTable* external_reference_table_; |
| 124 |
| 125 List<HeapObject*> deserialized_large_objects_; |
| 126 List<Code*> new_code_objects_; |
| 127 List<Handle<String> > new_internalized_strings_; |
| 128 List<Handle<Script> > new_scripts_; |
| 129 |
| 130 bool deserializing_user_code_; |
| 131 |
| 132 AllocationAlignment next_alignment_; |
| 133 |
| 134 DISALLOW_COPY_AND_ASSIGN(Deserializer); |
| 135 }; |
| 136 |
| 137 } // namespace internal |
| 138 } // namespace v8 |
| 139 |
| 140 #endif // V8_SNAPSHOT_DESERIALIZER_H_ |
OLD | NEW |