5 #ifndef V8_SNAPSHOT_SERIALIZER_COMMON_H_ 6 #define V8_SNAPSHOT_SERIALIZER_COMMON_H_ 8 #include "src/address-map.h" 9 #include "src/base/bits.h" 10 #include "src/external-reference-table.h" 11 #include "src/globals.h" 13 #include "src/snapshot/references.h" 14 #include "src/v8memory.h" 15 #include "src/visitors.h" 20 class CallHandlerInfo;
28 Value() : value_(0) {}
30 return Index::encode(index) | IsFromAPI::encode(is_from_api);
33 bool is_from_api()
const {
return IsFromAPI::decode(value_); }
34 uint32_t index()
const {
return Index::decode(value_); }
37 class Index :
public BitField<uint32_t, 0, 31> {};
38 class IsFromAPI :
public BitField<bool, 31, 1> {};
48 const char* NameOfAddress(
Isolate* isolate,
Address address)
const;
54 std::vector<int> count_;
55 const intptr_t* api_references_;
64 for (
int i = 0;
i < kSize;
i++) circular_queue_[
i] =
nullptr;
68 DCHECK(!AllowHeapAllocation::IsAllowed());
69 circular_queue_[index_] = object;
70 index_ = (index_ + 1) & kSizeMask;
74 DCHECK(!AllowHeapAllocation::IsAllowed());
75 DCHECK_NOT_NULL(circular_queue_[index]);
76 return circular_queue_[index];
79 static const int kNotFound = -1;
82 DCHECK(!AllowHeapAllocation::IsAllowed());
83 for (
int i = 0;
i < kSize;
i++) {
84 if (circular_queue_[
i] ==
object)
return i;
89 static const int kSize = 8;
92 static_assert(base::bits::IsPowerOfTwo(kSize),
"kSize must be power of two");
93 static const int kSizeMask = kSize - 1;
109 STATIC_ASSERT(MAP_SPACE == CODE_SPACE + 1);
112 STATIC_ASSERT(LAST_SPACE == NEW_LO_SPACE);
113 STATIC_ASSERT(LAST_SPACE - 2 == LO_SPACE);
114 static const int kNumberOfPreallocatedSpaces = CODE_SPACE + 1;
118 static const int kNumberOfSpaces = LO_SPACE + 1;
123 void RestoreExternalReferenceRedirectors(
124 const std::vector<AccessorInfo*>& accessor_infos);
125 void RestoreExternalReferenceRedirectors(
126 const std::vector<CallHandlerInfo*>& call_handler_infos);
128 #define UNUSED_SERIALIZER_BYTE_CODES(V) \ 155 STATIC_ASSERT(6 == kNumberOfSpaces);
162 kBackrefWithSkip = 0x10,
165 kPartialSnapshotCache = 0x06,
167 kExternalReference = 0x07,
172 kAttachedReference = 0x17,
174 kReadOnlyObjectCache = 0x18,
180 static const int kWhereMask = 0x1f;
181 static const int kSpaceMask = 7;
182 STATIC_ASSERT(kNumberOfSpaces <= kSpaceMask + 1);
192 static const int kHowToCodeMask = 0x20;
202 static const int kWhereToPointMask = 0x40;
206 static const int kSkip = 0x0f;
208 static const int kNop = 0x2f;
210 static const int kNextChunk = 0x4f;
212 static const int kDeferred = 0x6f;
214 static const int kAlignmentPrefix = 0x19;
220 static const int kSynchronize = 0x1c;
222 static const int kVariableRepeat = 0x1d;
226 static const int kOffHeapBackingStore = 0x1e;
229 static const int kEmbedderFieldsData = 0x1f;
231 static const int kVariableRawCode = 0x39;
232 static const int kVariableRawData = 0x3a;
234 static const int kInternalReference = 0x3b;
235 static const int kInternalReferenceEncoded = 0x3c;
238 static const int kApiReference = 0x3d;
241 static const int kClearedWeakReference = 0x7d;
242 static const int kWeakPrefix = 0x7e;
245 static const int kOffHeapTarget = 0x7f;
249 static const int kNumberOfRootArrayConstants = 0x20;
251 static const int kRootArrayConstants = 0x80;
253 static const int kRootArrayConstantsWithSkip = 0xa0;
254 static const int kRootArrayConstantsMask = 0x1f;
257 static const int kNumberOfFixedRawData = 0x20;
259 static const int kFixedRawData = 0xc0;
260 static const int kOnePointerRawData = kFixedRawData;
261 static const int kFixedRawDataStart = kFixedRawData - 1;
264 static const int kNumberOfFixedRepeat = 0x10;
266 static const int kFixedRepeat = 0xe0;
267 static const int kFixedRepeatStart = kFixedRepeat - 1;
270 static const int kNumberOfHotObjects = 8;
271 STATIC_ASSERT(kNumberOfHotObjects == HotObjectsList::kSize);
273 static const int kHotObject = 0xf0;
275 static const int kHotObjectWithSkip = 0xf8;
276 static const int kHotObjectMask = 0x07;
279 static const int kAnyOldSpace = -1;
282 static const int kDoubleAlignmentSentinel = 0;
294 : reservation_(ChunkSizeBits::encode(size)) {}
296 uint32_t chunk_size()
const {
return ChunkSizeBits::decode(reservation_); }
297 bool is_last()
const {
return IsLastChunkBits::decode(reservation_); }
299 void mark_as_last() { reservation_ |= IsLastChunkBits::encode(
true); }
306 : data_(data), size_(size), owns_data_(false) {}
308 SerializedData(SerializedData&& other) V8_NOEXCEPT
309 : data_(other.data_),
311 owns_data_(other.owns_data_) {
313 other.owns_data_ =
false;
316 virtual ~SerializedData() {
317 if (owns_data_) DeleteArray<byte>(data_);
320 uint32_t GetMagicNumber()
const {
return GetHeaderValue(kMagicNumberOffset); }
326 uint32_t external_refs = table->size();
327 return 0xC0DE0000 ^ external_refs;
330 static const uint32_t kMagicNumberOffset = 0;
334 WriteLittleEndianValue(reinterpret_cast<Address>(data_) + offset, value);
338 return ReadLittleEndianValue<uint32_t>(
reinterpret_cast<Address
>(data_) +
344 static uint32_t ComputeMagicNumber(Isolate* isolate);
346 void SetMagicNumber(Isolate* isolate) {
347 SetHeaderValue(kMagicNumberOffset, ComputeMagicNumber(isolate));
355 DISALLOW_COPY_AND_ASSIGN(SerializedData);
361 #ifdef MEMORY_SANITIZER 364 MSAN_MEMORY_IS_INITIALIZED(payload.start(), payload.length());
365 #endif // MEMORY_SANITIZER 370 DCHECK(IsAligned(payload.length(), kIntptrSize));
371 const uintptr_t* end = cur + payload.length() / kIntptrSize;
377 #if V8_HOST_ARCH_64_BIT 380 #endif // V8_HOST_ARCH_64_BIT 400 #endif // V8_SNAPSHOT_SERIALIZER_COMMON_H_