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

          Line data    Source code
       1             : // Copyright 2006-2008 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_SNAPSHOT_H_
       6             : #define V8_SNAPSHOT_SNAPSHOT_H_
       7             : 
       8             : #include "src/snapshot/partial-serializer.h"
       9             : #include "src/snapshot/startup-serializer.h"
      10             : 
      11             : namespace v8 {
      12             : namespace internal {
      13             : 
      14             : // Forward declarations.
      15             : class Isolate;
      16             : class PartialSerializer;
      17             : class StartupSerializer;
      18             : 
      19             : // Wrapper around reservation sizes and the serialization payload.
      20             : class SnapshotData : public SerializedData {
      21             :  public:
      22             :   // Used when producing.
      23             :   explicit SnapshotData(const Serializer* serializer);
      24             : 
      25             :   // Used when consuming.
      26      167545 :   explicit SnapshotData(const Vector<const byte> snapshot)
      27      167545 :       : SerializedData(const_cast<byte*>(snapshot.begin()), snapshot.length()) {
      28      167545 :     CHECK(IsSane());
      29      167545 :   }
      30             : 
      31             :   Vector<const Reservation> Reservations() const;
      32             :   Vector<const byte> Payload() const;
      33             : 
      34             :   Vector<const byte> RawData() const {
      35             :     return Vector<const byte>(data_, size_);
      36             :   }
      37             : 
      38             :  private:
      39             :   bool IsSane();
      40             : 
      41             :   // The data header consists of uint32_t-sized entries:
      42             :   // [0] magic number and (internal) external reference count
      43             :   // [1] API-provided external reference count
      44             :   // [2] version hash
      45             :   // [3] number of reservation size entries
      46             :   // [4] payload length
      47             :   // ... reservations
      48             :   // ... serialized payload
      49             :   static const int kNumReservationsOffset = kVersionHashOffset + kInt32Size;
      50             :   static const int kPayloadLengthOffset = kNumReservationsOffset + kInt32Size;
      51             :   static const int kHeaderSize = kPayloadLengthOffset + kInt32Size;
      52             : };
      53             : 
      54             : class Snapshot : public AllStatic {
      55             :  public:
      56             :   // Initialize the Isolate from the internal snapshot. Returns false if no
      57             :   // snapshot could be found.
      58             :   static bool Initialize(Isolate* isolate);
      59             :   // Create a new context using the internal partial snapshot.
      60             :   static MaybeHandle<Context> NewContextFromSnapshot(
      61             :       Isolate* isolate, Handle<JSGlobalProxy> global_proxy,
      62             :       size_t context_index,
      63             :       v8::DeserializeEmbedderFieldsCallback embedder_fields_deserializer);
      64             : 
      65             :   static bool HasContextSnapshot(Isolate* isolate, size_t index);
      66             : 
      67             :   static bool EmbedsScript(Isolate* isolate);
      68             : 
      69             :   // To be implemented by the snapshot source.
      70             :   static const v8::StartupData* DefaultSnapshotBlob();
      71             : 
      72             :   static v8::StartupData CreateSnapshotBlob(
      73             :       const SnapshotData* startup_snapshot,
      74             :       const List<SnapshotData*>* context_snapshots);
      75             : 
      76             : #ifdef DEBUG
      77             :   static bool SnapshotIsValid(v8::StartupData* snapshot_blob);
      78             : #endif  // DEBUG
      79             : 
      80             :  private:
      81             :   static int ExtractNumContexts(const v8::StartupData* data);
      82             :   static Vector<const byte> ExtractStartupData(const v8::StartupData* data);
      83             :   static Vector<const byte> ExtractContextData(const v8::StartupData* data,
      84             :                                                int index);
      85             : 
      86             :   // Snapshot blob layout:
      87             :   // [0] number of contexts N
      88             :   // [1] offset to context 0
      89             :   // [2] offset to context 1
      90             :   // ...
      91             :   // ... offset to context N - 1
      92             :   // ... startup snapshot data
      93             :   // ... context 0 snapshot data
      94             :   // ... context 1 snapshot data
      95             : 
      96             :   static const int kNumberOfContextsOffset = 0;
      97             :   static const int kFirstContextOffsetOffset =
      98             :       kNumberOfContextsOffset + kInt32Size;
      99             : 
     100             :   static int StartupSnapshotOffset(int num_contexts) {
     101       60794 :     return kFirstContextOffsetOffset + num_contexts * kInt32Size;
     102             :   }
     103             : 
     104             :   static int ContextSnapshotOffsetOffset(int index) {
     105      106987 :     return kFirstContextOffsetOffset + index * kInt32Size;
     106             :   }
     107             : 
     108             :   DISALLOW_IMPLICIT_CONSTRUCTORS(Snapshot);
     109             : };
     110             : 
     111             : #ifdef V8_USE_EXTERNAL_STARTUP_DATA
     112             : void SetSnapshotFromFile(StartupData* snapshot_blob);
     113             : #endif
     114             : 
     115             : }  // namespace internal
     116             : }  // namespace v8
     117             : 
     118             : #endif  // V8_SNAPSHOT_SNAPSHOT_H_

Generated by: LCOV version 1.10