Commit 5c4b8056 authored by Jakob Gruber's avatar Jakob Gruber Committed by Commit Bot

[snapshot] Extract more files

This moves:

- ExternalReferenceEncoder to codegen/external-reference-encoder.h
- SerializerDeserializer to snapshot/serializer-deserializer.h
- Checksum() to snapshot/snapshot-utils.h

serializer-common.h and .cc are removed.

Tbr: clemensb@chromium.org,ulan@chromium.org
Bug: v8:10416
Change-Id: I36a242dcc1ad8833374aa567f73e0d4a75632c58
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2144118
Commit-Queue: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Reviewed-by: 's avatarClemens Backes <clemensb@chromium.org>
Reviewed-by: 's avatarDan Elphick <delphick@chromium.org>
Cr-Commit-Position: refs/heads/master@{#67281}
parent d2f8c9e4
......@@ -2189,6 +2189,8 @@ v8_source_set("v8_base_without_compiler") {
"src/codegen/constant-pool.h",
"src/codegen/constants-arch.h",
"src/codegen/cpu-features.h",
"src/codegen/external-reference-encoder.cc",
"src/codegen/external-reference-encoder.h",
"src/codegen/external-reference-table.cc",
"src/codegen/external-reference-table.h",
"src/codegen/external-reference.cc",
......@@ -2956,8 +2958,8 @@ v8_source_set("v8_base_without_compiler") {
"src/snapshot/roots-serializer.h",
"src/snapshot/serializer-allocator.cc",
"src/snapshot/serializer-allocator.h",
"src/snapshot/serializer-common.cc",
"src/snapshot/serializer-common.h",
"src/snapshot/serializer-deserializer.cc",
"src/snapshot/serializer-deserializer.h",
"src/snapshot/serializer.cc",
"src/snapshot/serializer.h",
"src/snapshot/snapshot-compression.cc",
......@@ -2966,6 +2968,8 @@ v8_source_set("v8_base_without_compiler") {
"src/snapshot/snapshot-data.h",
"src/snapshot/snapshot-source-sink.cc",
"src/snapshot/snapshot-source-sink.h",
"src/snapshot/snapshot-utils.cc",
"src/snapshot/snapshot-utils.h",
"src/snapshot/snapshot.cc",
"src/snapshot/snapshot.h",
"src/snapshot/startup-deserializer.cc",
......
......@@ -41,7 +41,6 @@
#include "src/execution/isolate.h"
#include "src/heap/heap-inl.h" // For MemoryAllocator. TODO(jkummerow): Drop.
#include "src/snapshot/embedded/embedded-data.h"
#include "src/snapshot/serializer-common.h"
#include "src/snapshot/snapshot.h"
#include "src/utils/ostreams.h"
#include "src/utils/vector.h"
......
// Copyright 2016 the V8 project authors. All rights reserved.
// Copyright 2020 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.
#include "src/snapshot/serializer-common.h"
#include "src/codegen/external-reference-encoder.h"
#include "src/codegen/external-reference-table.h"
#include "src/objects/foreign-inl.h"
#include "src/objects/objects-inl.h"
#include "src/objects/slots.h"
#include "third_party/zlib/zlib.h"
#include "src/execution/isolate.h"
namespace v8 {
namespace internal {
......@@ -45,8 +42,8 @@ ExternalReferenceEncoder::ExternalReferenceEncoder(Isolate* isolate) {
}
}
ExternalReferenceEncoder::~ExternalReferenceEncoder() {
#ifdef DEBUG
ExternalReferenceEncoder::~ExternalReferenceEncoder() {
if (!i::FLAG_external_reference_stats) return;
if (api_references_ == nullptr) return;
for (uint32_t i = 0; api_references_[i] != 0; ++i) {
......@@ -56,8 +53,8 @@ ExternalReferenceEncoder::~ExternalReferenceEncoder() {
"index=%5d count=%5d %-60s\n", i, count_[i],
ExternalReferenceTable::ResolveSymbol(reinterpret_cast<void*>(addr)));
}
#endif // DEBUG
}
#endif // DEBUG
Maybe<ExternalReferenceEncoder::Value> ExternalReferenceEncoder::TryEncode(
Address address) {
......@@ -96,63 +93,5 @@ const char* ExternalReferenceEncoder::NameOfAddress(Isolate* isolate,
return isolate->external_reference_table()->name(value.index());
}
// The partial snapshot cache is terminated by undefined. We visit the
// partial snapshot...
// - during deserialization to populate it.
// - during normal GC to keep its content alive.
// - not during serialization. The partial serializer adds to it explicitly.
DISABLE_CFI_PERF
void SerializerDeserializer::Iterate(Isolate* isolate, RootVisitor* visitor) {
std::vector<Object>* cache = isolate->partial_snapshot_cache();
for (size_t i = 0;; ++i) {
// Extend the array ready to get a value when deserializing.
if (cache->size() <= i) cache->push_back(Smi::zero());
// During deserialization, the visitor populates the partial snapshot cache
// and eventually terminates the cache with undefined.
visitor->VisitRootPointer(Root::kPartialSnapshotCache, nullptr,
FullObjectSlot(&cache->at(i)));
if (cache->at(i).IsUndefined(isolate)) break;
}
}
bool SerializerDeserializer::CanBeDeferred(HeapObject o) {
// ArrayBuffer instances are serialized by first re-assigning a index
// to the backing store field, then serializing the object, and then
// storing the actual backing store address again (and the same for the
// ArrayBufferExtension). If serialization of the object itself is deferred,
// the real backing store address is written into the snapshot, which cannot
// be processed when deserializing.
return !o.IsString() && !o.IsScript() && !o.IsJSTypedArray() &&
!o.IsJSArrayBuffer();
}
void SerializerDeserializer::RestoreExternalReferenceRedirectors(
const std::vector<AccessorInfo>& accessor_infos) {
// Restore wiped accessor infos.
for (AccessorInfo info : accessor_infos) {
Foreign::cast(info.js_getter())
.set_foreign_address(info.redirected_getter());
}
}
void SerializerDeserializer::RestoreExternalReferenceRedirectors(
const std::vector<CallHandlerInfo>& call_handler_infos) {
for (CallHandlerInfo info : call_handler_infos) {
Foreign::cast(info.js_callback())
.set_foreign_address(info.redirected_callback());
}
}
uint32_t Checksum(Vector<const byte> payload) {
#ifdef MEMORY_SANITIZER
// Computing the checksum includes padding bytes for objects like strings.
// Mark every object as initialized in the code serializer.
MSAN_MEMORY_IS_INITIALIZED(payload.begin(), payload.length());
#endif // MEMORY_SANITIZER
// Priming the adler32 call so it can see what CPU features are available.
adler32(0, NULL, 0);
return static_cast<uint32_t>(adler32(0, payload.begin(), payload.length()));
}
} // namespace internal
} // namespace v8
// Copyright 2020 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_CODEGEN_EXTERNAL_REFERENCE_ENCODER_H_
#define V8_CODEGEN_EXTERNAL_REFERENCE_ENCODER_H_
#include "src/base/bit-field.h"
#include "src/common/globals.h"
#include "src/utils/address-map.h"
namespace v8 {
namespace internal {
class Isolate;
class ExternalReferenceEncoder {
public:
class Value {
public:
explicit Value(uint32_t raw) : value_(raw) {}
Value() : value_(0) {}
static uint32_t Encode(uint32_t index, bool is_from_api) {
return Index::encode(index) | IsFromAPI::encode(is_from_api);
}
bool is_from_api() const { return IsFromAPI::decode(value_); }
uint32_t index() const { return Index::decode(value_); }
private:
using Index = base::BitField<uint32_t, 0, 31>;
using IsFromAPI = base::BitField<bool, 31, 1>;
uint32_t value_;
};
explicit ExternalReferenceEncoder(Isolate* isolate);
#ifdef DEBUG
~ExternalReferenceEncoder();
#endif // DEBUG
Value Encode(Address key);
Maybe<Value> TryEncode(Address key);
const char* NameOfAddress(Isolate* isolate, Address address) const;
private:
AddressToIndexHashMap* map_;
#ifdef DEBUG
std::vector<int> count_;
const intptr_t* api_references_;
#endif // DEBUG
DISALLOW_COPY_AND_ASSIGN(ExternalReferenceEncoder);
};
} // namespace internal
} // namespace v8
#endif // V8_CODEGEN_EXTERNAL_REFERENCE_ENCODER_H_
......@@ -6,12 +6,12 @@
#include "src/codegen/assembler-inl.h"
#include "src/codegen/code-reference.h"
#include "src/codegen/external-reference-encoder.h"
#include "src/deoptimizer/deoptimize-reason.h"
#include "src/deoptimizer/deoptimizer.h"
#include "src/heap/heap-write-barrier-inl.h"
#include "src/objects/code-inl.h"
#include "src/snapshot/embedded/embedded-data.h"
#include "src/snapshot/serializer-common.h" // For ExternalReferenceEncoder.
namespace v8 {
namespace internal {
......
......@@ -6,9 +6,9 @@
#include "src/builtins/builtins.h"
#include "src/builtins/constants-table-builder.h"
#include "src/codegen/external-reference-encoder.h"
#include "src/execution/isolate-data.h"
#include "src/execution/isolate-inl.h"
#include "src/snapshot/serializer-common.h"
namespace v8 {
namespace internal {
......
......@@ -12,6 +12,7 @@
#include "src/codegen/assembler-inl.h"
#include "src/codegen/code-comments.h"
#include "src/codegen/code-reference.h"
#include "src/codegen/external-reference-encoder.h"
#include "src/codegen/macro-assembler.h"
#include "src/debug/debug.h"
#include "src/deoptimizer/deoptimizer.h"
......@@ -20,7 +21,6 @@
#include "src/ic/ic.h"
#include "src/objects/objects-inl.h"
#include "src/snapshot/embedded/embedded-data.h"
#include "src/snapshot/serializer-common.h"
#include "src/strings/string-stream.h"
#include "src/utils/vector.h"
#include "src/wasm/wasm-code-manager.h"
......
......@@ -80,6 +80,7 @@
#include "src/tasks/cancelable-task.h"
#include "src/tracing/tracing-category-observer.h"
#include "src/trap-handler/trap-handler.h"
#include "src/utils/address-map.h"
#include "src/utils/ostreams.h"
#include "src/utils/version.h"
#include "src/wasm/wasm-code-manager.h"
......
......@@ -71,7 +71,7 @@
#include "src/objects/slots-inl.h"
#include "src/regexp/regexp.h"
#include "src/snapshot/embedded/embedded-data.h"
#include "src/snapshot/serializer-common.h"
#include "src/snapshot/serializer-deserializer.h"
#include "src/snapshot/snapshot.h"
#include "src/strings/string-stream.h"
#include "src/strings/unicode-decoder.h"
......
......@@ -5,7 +5,7 @@ specific_include_rules = {
"snapshot-compression.cc": [
"+third_party/zlib",
],
"serializer-common.cc": [
"snapshot-utils.cc": [
"+third_party/zlib",
],
}
......@@ -13,6 +13,7 @@
#include "src/objects/slots.h"
#include "src/objects/visitors.h"
#include "src/snapshot/object-deserializer.h"
#include "src/snapshot/snapshot-utils.h"
#include "src/snapshot/snapshot.h"
#include "src/utils/version.h"
......
......@@ -8,7 +8,7 @@
#include "src/common/globals.h"
#include "src/heap/heap.h"
#include "src/objects/heap-object.h"
#include "src/snapshot/serializer-common.h"
#include "src/snapshot/references.h"
#include "src/snapshot/snapshot-data.h"
namespace v8 {
......
......@@ -16,7 +16,7 @@
#include "src/objects/map.h"
#include "src/objects/string.h"
#include "src/snapshot/deserializer-allocator.h"
#include "src/snapshot/serializer-common.h"
#include "src/snapshot/serializer-deserializer.h"
#include "src/snapshot/snapshot-source-sink.h"
namespace v8 {
......
......@@ -5,7 +5,7 @@
#ifndef V8_SNAPSHOT_SERIALIZER_ALLOCATOR_H_
#define V8_SNAPSHOT_SERIALIZER_ALLOCATOR_H_
#include "src/snapshot/serializer-common.h"
#include "src/snapshot/references.h"
#include "src/snapshot/snapshot-data.h"
namespace v8 {
......
// Copyright 2020 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.
#include "src/snapshot/serializer-deserializer.h"
#include "src/objects/foreign-inl.h"
#include "src/objects/objects-inl.h"
namespace v8 {
namespace internal {
// The partial snapshot cache is terminated by undefined. We visit the
// partial snapshot...
// - during deserialization to populate it.
// - during normal GC to keep its content alive.
// - not during serialization. The partial serializer adds to it explicitly.
DISABLE_CFI_PERF
void SerializerDeserializer::Iterate(Isolate* isolate, RootVisitor* visitor) {
std::vector<Object>* cache = isolate->partial_snapshot_cache();
for (size_t i = 0;; ++i) {
// Extend the array ready to get a value when deserializing.
if (cache->size() <= i) cache->push_back(Smi::zero());
// During deserialization, the visitor populates the partial snapshot cache
// and eventually terminates the cache with undefined.
visitor->VisitRootPointer(Root::kPartialSnapshotCache, nullptr,
FullObjectSlot(&cache->at(i)));
if (cache->at(i).IsUndefined(isolate)) break;
}
}
bool SerializerDeserializer::CanBeDeferred(HeapObject o) {
// ArrayBuffer instances are serialized by first re-assigning a index
// to the backing store field, then serializing the object, and then
// storing the actual backing store address again (and the same for the
// ArrayBufferExtension). If serialization of the object itself is deferred,
// the real backing store address is written into the snapshot, which cannot
// be processed when deserializing.
return !o.IsString() && !o.IsScript() && !o.IsJSTypedArray() &&
!o.IsJSArrayBuffer();
}
void SerializerDeserializer::RestoreExternalReferenceRedirectors(
const std::vector<AccessorInfo>& accessor_infos) {
// Restore wiped accessor infos.
for (AccessorInfo info : accessor_infos) {
Foreign::cast(info.js_getter())
.set_foreign_address(info.redirected_getter());
}
}
void SerializerDeserializer::RestoreExternalReferenceRedirectors(
const std::vector<CallHandlerInfo>& call_handler_infos) {
for (CallHandlerInfo info : call_handler_infos) {
Foreign::cast(info.js_callback())
.set_foreign_address(info.redirected_callback());
}
}
} // namespace internal
} // namespace v8
// Copyright 2016 the V8 project authors. All rights reserved.
// Copyright 2020 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_SERIALIZER_COMMON_H_
#define V8_SNAPSHOT_SERIALIZER_COMMON_H_
#ifndef V8_SNAPSHOT_SERIALIZER_DESERIALIZER_H_
#define V8_SNAPSHOT_SERIALIZER_DESERIALIZER_H_
#include "src/base/bits.h"
#include "src/base/memory.h"
#include "src/codegen/external-reference-table.h"
#include "src/common/globals.h"
#include "src/objects/visitors.h"
#include "src/sanitizer/msan.h"
#include "src/snapshot/references.h"
#include "src/utils/address-map.h"
namespace v8 {
namespace internal {
......@@ -20,89 +14,51 @@ namespace internal {
class CallHandlerInfo;
class Isolate;
class ExternalReferenceEncoder {
// The Serializer/Deserializer class is a common superclass for Serializer and
// Deserializer which is used to store common constants and methods used by
// both.
class SerializerDeserializer : public RootVisitor {
public:
class Value {
public:
explicit Value(uint32_t raw) : value_(raw) {}
Value() : value_(0) {}
static uint32_t Encode(uint32_t index, bool is_from_api) {
return Index::encode(index) | IsFromAPI::encode(is_from_api);
}
bool is_from_api() const { return IsFromAPI::decode(value_); }
uint32_t index() const { return Index::decode(value_); }
private:
using Index = base::BitField<uint32_t, 0, 31>;
using IsFromAPI = base::BitField<bool, 31, 1>;
uint32_t value_;
};
explicit ExternalReferenceEncoder(Isolate* isolate);
~ExternalReferenceEncoder(); // NOLINT (modernize-use-equals-default)
Value Encode(Address key);
Maybe<Value> TryEncode(Address key);
const char* NameOfAddress(Isolate* isolate, Address address) const;
private:
AddressToIndexHashMap* map_;
#ifdef DEBUG
std::vector<int> count_;
const intptr_t* api_references_;
#endif // DEBUG
DISALLOW_COPY_AND_ASSIGN(ExternalReferenceEncoder);
};
static void Iterate(Isolate* isolate, RootVisitor* visitor);
class HotObjectsList {
public:
HotObjectsList() : index_(0) {}
protected:
class HotObjectsList {
public:
HotObjectsList() = default;
void Add(HeapObject object) {
DCHECK(!AllowHeapAllocation::IsAllowed());
circular_queue_[index_] = object;
index_ = (index_ + 1) & kSizeMask;
}
void Add(HeapObject object) {
DCHECK(!AllowHeapAllocation::IsAllowed());
circular_queue_[index_] = object;
index_ = (index_ + 1) & kSizeMask;
}
HeapObject Get(int index) {
DCHECK(!AllowHeapAllocation::IsAllowed());
DCHECK(!circular_queue_[index].is_null());
return circular_queue_[index];
}
HeapObject Get(int index) {
DCHECK(!AllowHeapAllocation::IsAllowed());
DCHECK(!circular_queue_[index].is_null());
return circular_queue_[index];
}
static const int kNotFound = -1;
static const int kNotFound = -1;
int Find(HeapObject object) {
DCHECK(!AllowHeapAllocation::IsAllowed());
for (int i = 0; i < kSize; i++) {
if (circular_queue_[i] == object) return i;
int Find(HeapObject object) {
DCHECK(!AllowHeapAllocation::IsAllowed());
for (int i = 0; i < kSize; i++) {
if (circular_queue_[i] == object) return i;
}
return kNotFound;
}
return kNotFound;
}
static const int kSize = 8;
private:
static_assert(base::bits::IsPowerOfTwo(kSize), "kSize must be power of two");
static const int kSizeMask = kSize - 1;
HeapObject circular_queue_[kSize];
int index_;
static const int kSize = 8;
DISALLOW_COPY_AND_ASSIGN(HotObjectsList);
};
private:
STATIC_ASSERT(base::bits::IsPowerOfTwo(kSize));
static const int kSizeMask = kSize - 1;
HeapObject circular_queue_[kSize];
int index_ = 0;
// The Serializer/Deserializer class is a common superclass for Serializer and
// Deserializer which is used to store common constants and methods used by
// both.
class SerializerDeserializer : public RootVisitor {
public:
static void Iterate(Isolate* isolate, RootVisitor* visitor);
DISALLOW_COPY_AND_ASSIGN(HotObjectsList);
};
protected:
static bool CanBeDeferred(HeapObject o);
void RestoreExternalReferenceRedirectors(
......@@ -293,9 +249,7 @@ class SerializerDeserializer : public RootVisitor {
HotObjectsList hot_objects_;
};
V8_EXPORT_PRIVATE uint32_t Checksum(Vector<const byte> payload);
} // namespace internal
} // namespace v8
#endif // V8_SNAPSHOT_SERIALIZER_COMMON_H_
#endif // V8_SNAPSHOT_SERIALIZER_DESERIALIZER_H_
......@@ -7,12 +7,13 @@
#include <map>
#include "src/codegen/external-reference-encoder.h"
#include "src/execution/isolate.h"
#include "src/logging/log.h"
#include "src/objects/objects.h"
#include "src/snapshot/embedded/embedded-data.h"
#include "src/snapshot/serializer-allocator.h"
#include "src/snapshot/serializer-common.h"
#include "src/snapshot/serializer-deserializer.h"
#include "src/snapshot/snapshot-source-sink.h"
namespace v8 {
......
......@@ -4,7 +4,9 @@
#include "src/snapshot/snapshot-compression.h"
#include "src/base/platform/elapsed-timer.h"
#include "src/utils/memcopy.h"
#include "src/utils/utils.h"
#include "third_party/zlib/google/compression_utils_portable.h"
namespace v8 {
......
......@@ -5,9 +5,7 @@
#ifndef V8_SNAPSHOT_SNAPSHOT_COMPRESSION_H_
#define V8_SNAPSHOT_SNAPSHOT_COMPRESSION_H_
#include "src/snapshot/serializer-common.h"
#include "src/snapshot/serializer.h"
#include "src/snapshot/snapshot.h"
#include "src/snapshot/snapshot-data.h"
#include "src/utils/vector.h"
namespace v8 {
......
......@@ -8,7 +8,7 @@
#include <utility>
#include "src/base/logging.h"
#include "src/snapshot/serializer-common.h"
#include "src/snapshot/snapshot-utils.h"
#include "src/utils/utils.h"
namespace v8 {
......
// Copyright 2020 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.
#include "src/snapshot/snapshot-utils.h"
#include "third_party/zlib/zlib.h"
namespace v8 {
namespace internal {
uint32_t Checksum(Vector<const byte> payload) {
#ifdef MEMORY_SANITIZER
// Computing the checksum includes padding bytes for objects like strings.
// Mark every object as initialized in the code serializer.
MSAN_MEMORY_IS_INITIALIZED(payload.begin(), payload.length());
#endif // MEMORY_SANITIZER
// Priming the adler32 call so it can see what CPU features are available.
adler32(0, NULL, 0);
return static_cast<uint32_t>(adler32(0, payload.begin(), payload.length()));
}
} // namespace internal
} // namespace v8
// Copyright 2020 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_SNAPSHOT_UTILS_H_
#define V8_SNAPSHOT_SNAPSHOT_UTILS_H_
#include "src/utils/vector.h"
namespace v8 {
namespace internal {
V8_EXPORT_PRIVATE uint32_t Checksum(Vector<const byte> payload);
} // namespace internal
} // namespace v8
#endif // V8_SNAPSHOT_SNAPSHOT_UTILS_H_
......@@ -10,6 +10,7 @@
#include "src/logging/counters.h"
#include "src/snapshot/partial-deserializer.h"
#include "src/snapshot/read-only-deserializer.h"
#include "src/snapshot/snapshot-utils.h"
#include "src/snapshot/startup-deserializer.h"
#include "src/utils/memcopy.h"
#include "src/utils/version.h"
......
......@@ -10,7 +10,6 @@
#include "src/objects/objects.h"
#include "src/runtime/runtime.h"
#include "src/snapshot/code-serializer.h"
#include "src/snapshot/serializer-common.h"
#include "src/utils/ostreams.h"
#include "src/utils/utils.h"
#include "src/utils/version.h"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment