// Copyright 2016 the V8 project authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef V8_SNAPSHOT_CODE_SERIALIZER_H_ #define V8_SNAPSHOT_CODE_SERIALIZER_H_ #include "src/base/macros.h" #include "src/snapshot/serializer.h" #include "src/snapshot/snapshot-data.h" namespace v8 { namespace internal { class PersistentHandles; class BackgroundMergeTask; class V8_EXPORT_PRIVATE AlignedCachedData { public: AlignedCachedData(const uint8_t* data, int length); ~AlignedCachedData() { if (owns_data_) DeleteArray(data_); } AlignedCachedData(const AlignedCachedData&) = delete; AlignedCachedData& operator=(const AlignedCachedData&) = delete; const uint8_t* data() const { return data_; } int length() const { return length_; } bool rejected() const { return rejected_; } void Reject() { rejected_ = true; } bool HasDataOwnership() const { return owns_data_; } void AcquireDataOwnership() { DCHECK(!owns_data_); owns_data_ = true; } void ReleaseDataOwnership() { DCHECK(owns_data_); owns_data_ = false; } private: bool owns_data_ : 1; bool rejected_ : 1; const uint8_t* data_; int length_; }; enum class SerializedCodeSanityCheckResult { // Don't change order/existing values of this enum since it keys into the // `code_cache_reject_reason` histogram. Append-only! kSuccess = 0, kMagicNumberMismatch = 1, kVersionMismatch = 2, kSourceMismatch = 3, kFlagsMismatch = 5, kChecksumMismatch = 6, kInvalidHeader = 7, kLengthMismatch = 8, kReadOnlySnapshotChecksumMismatch = 9, // This should always point at the last real enum value. kLast = kReadOnlySnapshotChecksumMismatch }; // If this fails, update the static_assert AND the code_cache_reject_reason // histogram definition. static_assert(static_cast(SerializedCodeSanityCheckResult::kLast) == 9); class CodeSerializer : public Serializer { public: struct OffThreadDeserializeData { public: bool HasResult() const { return !maybe_result.is_null(); } Handle