v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
snapshot-data.h
Go to the documentation of this file.
1// Copyright 2020 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_DATA_H_
6#define V8_SNAPSHOT_SNAPSHOT_DATA_H_
7
9#include "src/base/memory.h"
10#include "src/base/vector.h"
12#include "src/utils/memcopy.h"
13
14namespace v8 {
15namespace internal {
16
17// Forward declarations.
18class Isolate;
19class Serializer;
20
22 public:
23 SerializedData(uint8_t* data, int size)
24 : data_(data), size_(size), owns_data_(false) {}
25 SerializedData() : data_(nullptr), size_(0), owns_data_(false) {}
27 : data_(other.data_),
28 size_(other.size_),
29 owns_data_(other.owns_data_) {
30 // Ensure |other| will not attempt to destroy our data in destructor.
31 other.owns_data_ = false;
32 }
35
39
40 uint32_t GetMagicNumber() const { return GetHeaderValue(kMagicNumberOffset); }
41
44
45 static constexpr uint32_t kMagicNumberOffset = 0;
46 static constexpr uint32_t kMagicNumber =
48
49 protected:
50 void SetHeaderValue(uint32_t offset, uint32_t value) {
52 value);
53 }
54
55 uint32_t GetHeaderValue(uint32_t offset) const {
57 reinterpret_cast<Address>(data_) + offset);
58 }
59
60 void AllocateData(uint32_t size);
61
63
64 uint8_t* data_;
65 uint32_t size_;
67};
68
69// Wrapper around reservation sizes and the serialization payload.
71 public:
72 // Used when producing.
73 explicit SnapshotData(const Serializer* serializer);
74
75 // Used when consuming.
77 : SerializedData(const_cast<uint8_t*>(snapshot.begin()),
78 snapshot.length()) {}
79
80 virtual base::Vector<const uint8_t> Payload() const;
81
85
86 protected:
87 // Empty constructor used by SnapshotCompression so it can manually allocate
88 // memory.
90 friend class SnapshotCompression;
91
92 // Resize used by SnapshotCompression so it can shrink the compressed
93 // SnapshotData.
94 void Resize(uint32_t size) { size_ = size; }
95
96 // The data header consists of uint32_t-sized entries:
97 // [0] magic number and (internal) external reference count
98 // [1] payload length
99 // ... serialized payload
100 static const uint32_t kPayloadLengthOffset = kMagicNumberOffset + kUInt32Size;
101 static const uint32_t kHeaderSize = kPayloadLengthOffset + kUInt32Size;
102};
103
104} // namespace internal
105} // namespace v8
106
107#endif // V8_SNAPSHOT_SNAPSHOT_DATA_H_
uint8_t data_[MAX_STACK_LENGTH]
SerializedData(uint8_t *data, int size)
void SetHeaderValue(uint32_t offset, uint32_t value)
SerializedData & operator=(const SerializedData &)=delete
static constexpr uint32_t kMagicNumber
static constexpr uint32_t kMagicNumberOffset
SerializedData(const SerializedData &)=delete
SerializedData(SerializedData &&other) V8_NOEXCEPT
uint32_t GetMagicNumber() const
void AllocateData(uint32_t size)
uint32_t GetHeaderValue(uint32_t offset) const
void Resize(uint32_t size)
SnapshotData(const base::Vector< const uint8_t > snapshot)
base::Vector< const uint8_t > RawData() const
const int size_
Definition assembler.cc:132
int32_t offset
static void WriteLittleEndianValue(Address p, V value)
Definition memory.h:67
static V ReadLittleEndianValue(Address p)
Definition memory.h:52
void DeleteArray(T *array)
Definition allocation.h:63
constexpr int kUInt32Size
Definition globals.h:403
#define V8_NOEXCEPT
#define V8_EXPORT_PRIVATE
Definition macros.h:460