LCOV - code coverage report
Current view: top level - src/snapshot - deserializer.h (source / functions) Hit Total Coverage
Test: app.info Lines: 5 7 71.4 %
Date: 2017-04-26 Functions: 2 2 100.0 %

          Line data    Source code
       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             : // Used for platforms with embedded constant pools to trigger deserialization
      17             : // of objects found in code.
      18             : #if defined(V8_TARGET_ARCH_MIPS) || defined(V8_TARGET_ARCH_MIPS64) || \
      19             :     defined(V8_TARGET_ARCH_PPC) || defined(V8_TARGET_ARCH_S390) ||    \
      20             :     V8_EMBEDDED_CONSTANT_POOL
      21             : #define V8_CODE_EMBEDS_OBJECT_POINTER 1
      22             : #else
      23             : #define V8_CODE_EMBEDS_OBJECT_POINTER 0
      24             : #endif
      25             : 
      26             : class Heap;
      27             : 
      28             : // A Deserializer reads a snapshot and reconstructs the Object graph it defines.
      29             : class Deserializer : public SerializerDeserializer {
      30             :  public:
      31             :   // Create a deserializer from a snapshot byte source.
      32             :   template <class Data>
      33      167930 :   explicit Deserializer(Data* data, bool deserializing_user_code = false)
      34             :       : isolate_(NULL),
      35             :         source_(data->Payload()),
      36             :         magic_number_(data->GetMagicNumber()),
      37             :         num_extra_references_(data->GetExtraReferences()),
      38             :         next_map_index_(0),
      39             :         external_reference_table_(NULL),
      40             :         deserialized_large_objects_(0),
      41             :         deserializing_user_code_(deserializing_user_code),
      42     1679300 :         next_alignment_(kWordAligned) {
      43      167930 :     DecodeReservation(data->Reservations());
      44      167930 :   }
      45             : 
      46             :   ~Deserializer() override;
      47             : 
      48             :   // Deserialize the snapshot into an empty heap.
      49             :   void Deserialize(Isolate* isolate);
      50             : 
      51             :   // Deserialize a single object and the objects reachable from it.
      52             :   MaybeHandle<Object> DeserializePartial(
      53             :       Isolate* isolate, Handle<JSGlobalProxy> global_proxy,
      54             :       v8::DeserializeEmbedderFieldsCallback embedder_fields_deserializer);
      55             : 
      56             :   // Deserialize an object graph. Fail gracefully.
      57             :   MaybeHandle<HeapObject> DeserializeObject(Isolate* isolate);
      58             : 
      59             :   // Add an object to back an attached reference. The order to add objects must
      60             :   // mirror the order they are added in the serializer.
      61             :   void AddAttachedObject(Handle<HeapObject> attached_object) {
      62      107656 :     attached_objects_.Add(attached_object);
      63             :   }
      64             : 
      65             :  private:
      66             :   void VisitRootPointers(Root root, Object** start, Object** end) override;
      67             : 
      68             :   void Synchronize(VisitorSynchronization::SyncTag tag) override;
      69             : 
      70             :   void Initialize(Isolate* isolate);
      71             : 
      72             :   bool deserializing_user_code() { return deserializing_user_code_; }
      73             : 
      74             :   void DecodeReservation(Vector<const SerializedData::Reservation> res);
      75             : 
      76             :   bool ReserveSpace();
      77             : 
      78             :   void UnalignedCopy(Object** dest, Object** src) {
      79             :     memcpy(dest, src, sizeof(*src));
      80             :   }
      81             : 
      82             :   void SetAlignment(byte data) {
      83             :     DCHECK_EQ(kWordAligned, next_alignment_);
      84           0 :     int alignment = data - (kAlignmentPrefix - 1);
      85             :     DCHECK_LE(kWordAligned, alignment);
      86             :     DCHECK_LE(alignment, kDoubleUnaligned);
      87           0 :     next_alignment_ = static_cast<AllocationAlignment>(alignment);
      88             :   }
      89             : 
      90             :   void DeserializeDeferredObjects();
      91             :   void DeserializeEmbedderFields(
      92             :       v8::DeserializeEmbedderFieldsCallback embedder_fields_deserializer);
      93             : 
      94             :   void FlushICacheForNewIsolate();
      95             :   void FlushICacheForNewCodeObjectsAndRecordEmbeddedObjects();
      96             : 
      97             :   void CommitPostProcessedObjects(Isolate* isolate);
      98             : 
      99             :   void PrintDisassembledCodeObjects();
     100             : 
     101             :   // Fills in some heap data in an area from start to end (non-inclusive).  The
     102             :   // space id is used for the write barrier.  The object_address is the address
     103             :   // of the object we are writing into, or NULL if we are not writing into an
     104             :   // object, i.e. if we are writing a series of tagged values that are not on
     105             :   // the heap. Return false if the object content has been deferred.
     106             :   bool ReadData(Object** start, Object** end, int space,
     107             :                 Address object_address);
     108             :   void ReadObject(int space_number, Object** write_back);
     109             :   Address Allocate(int space_index, int size);
     110             : 
     111             :   // Special handling for serialized code like hooking up internalized strings.
     112             :   HeapObject* PostProcessNewObject(HeapObject* obj, int space);
     113             : 
     114             :   // This returns the address of an object that has been described in the
     115             :   // snapshot by chunk index and offset.
     116             :   HeapObject* GetBackReferencedObject(int space);
     117             : 
     118             :   // Cached current isolate.
     119             :   Isolate* isolate_;
     120             : 
     121             :   // Objects from the attached object descriptions in the serialized user code.
     122             :   List<Handle<HeapObject> > attached_objects_;
     123             : 
     124             :   SnapshotByteSource source_;
     125             :   uint32_t magic_number_;
     126             :   uint32_t num_extra_references_;
     127             : 
     128             :   // The address of the next object that will be allocated in each space.
     129             :   // Each space has a number of chunks reserved by the GC, with each chunk
     130             :   // fitting into a page. Deserialized objects are allocated into the
     131             :   // current chunk of the target space by bumping up high water mark.
     132             :   Heap::Reservation reservations_[kNumberOfSpaces];
     133             :   uint32_t current_chunk_[kNumberOfPreallocatedSpaces];
     134             :   Address high_water_[kNumberOfPreallocatedSpaces];
     135             :   int next_map_index_;
     136             :   List<Address> allocated_maps_;
     137             : 
     138             :   ExternalReferenceTable* external_reference_table_;
     139             : 
     140             :   List<HeapObject*> deserialized_large_objects_;
     141             :   List<Code*> new_code_objects_;
     142             :   List<AccessorInfo*> accessor_infos_;
     143             :   List<Handle<String> > new_internalized_strings_;
     144             :   List<Handle<Script> > new_scripts_;
     145             : 
     146             :   bool deserializing_user_code_;
     147             : 
     148             :   AllocationAlignment next_alignment_;
     149             : 
     150             :   DISALLOW_COPY_AND_ASSIGN(Deserializer);
     151             : };
     152             : 
     153             : }  // namespace internal
     154             : }  // namespace v8
     155             : 
     156             : #endif  // V8_SNAPSHOT_DESERIALIZER_H_

Generated by: LCOV version 1.10