snapshot.h 2.83 KB
Newer Older
1
// Copyright 2006-2008 the V8 project authors. All rights reserved.
2 3
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
4

5 6
#ifndef V8_SNAPSHOT_SNAPSHOT_H_
#define V8_SNAPSHOT_SNAPSHOT_H_
7

8 9
#include "src/snapshot/serialize.h"

10 11
namespace v8 {
namespace internal {
12

13 14 15 16 17
// Forward declarations.
class Isolate;
class PartialSerializer;
class StartupSerializer;

18
class Snapshot : public AllStatic {
19
 public:
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
  class Metadata {
   public:
    explicit Metadata(uint32_t data = 0) : data_(data) {}
    bool embeds_script() { return EmbedsScriptBits::decode(data_); }
    void set_embeds_script(bool v) {
      data_ = EmbedsScriptBits::update(data_, v);
    }

    uint32_t& RawValue() { return data_; }

   private:
    class EmbedsScriptBits : public BitField<bool, 0, 1> {};
    uint32_t data_;
  };

35 36 37
  // Initialize the Isolate from the internal snapshot. Returns false if no
  // snapshot could be found.
  static bool Initialize(Isolate* isolate);
38
  // Create a new context using the internal partial snapshot.
39
  static MaybeHandle<Context> NewContextFromSnapshot(
40 41
      Isolate* isolate, Handle<JSGlobalProxy> global_proxy,
      Handle<FixedArray>* outdated_contexts_out);
42

43
  static bool HaveASnapshotToStartFrom(Isolate* isolate);
44

45 46 47
  static bool EmbedsScript(Isolate* isolate);

  static uint32_t SizeOfFirstPage(Isolate* isolate, AllocationSpace space);
48

49

50
  // To be implemented by the snapshot source.
51
  static const v8::StartupData* DefaultSnapshotBlob();
52

53
  static v8::StartupData CreateSnapshotBlob(
54 55
      const StartupSerializer& startup_ser,
      const PartialSerializer& context_ser, Snapshot::Metadata metadata);
56 57 58 59

#ifdef DEBUG
  static bool SnapshotIsValid(v8::StartupData* snapshot_blob);
#endif  // DEBUG
60

61
 private:
62 63
  static Vector<const byte> ExtractStartupData(const v8::StartupData* data);
  static Vector<const byte> ExtractContextData(const v8::StartupData* data);
64 65
  static Metadata ExtractMetadata(const v8::StartupData* data);

66 67 68 69 70 71 72 73 74
  // Snapshot blob layout:
  // [0] metadata
  // [1 - 6] pre-calculated first page sizes for paged spaces
  // [7] serialized start up data length
  // ... serialized start up data
  // ... serialized context data

  static const int kNumPagedSpaces = LAST_PAGED_SPACE - FIRST_PAGED_SPACE + 1;

75
  static const int kMetadataOffset = 0;
76 77 78
  static const int kFirstPageSizesOffset = kMetadataOffset + kInt32Size;
  static const int kStartupLengthOffset =
      kFirstPageSizesOffset + kNumPagedSpaces * kInt32Size;
79 80 81 82 83
  static const int kStartupDataOffset = kStartupLengthOffset + kInt32Size;

  static int ContextOffset(int startup_length) {
    return kStartupDataOffset + startup_length;
  }
84

85 86 87
  DISALLOW_IMPLICIT_CONSTRUCTORS(Snapshot);
};

88 89 90 91
#ifdef V8_USE_EXTERNAL_STARTUP_DATA
void SetSnapshotFromFile(StartupData* snapshot_blob);
#endif

92 93
} }  // namespace v8::internal

94
#endif  // V8_SNAPSHOT_SNAPSHOT_H_