Commit 75aada42 authored by yangguo's avatar yangguo Committed by Commit bot

[snapshot] pass arguments as pointers, not references.

R=vogelheim@chromium.org

Review-Url: https://codereview.chromium.org/2051043003
Cr-Commit-Position: refs/heads/master@{#36887}
parent b4274ce3
...@@ -469,14 +469,12 @@ StartupData SnapshotCreator::CreateBlob( ...@@ -469,14 +469,12 @@ StartupData SnapshotCreator::CreateBlob(
i::SnapshotByteSink context_sink; i::SnapshotByteSink context_sink;
i::PartialSerializer context_serializer(isolate, &startup_serializer, i::PartialSerializer context_serializer(isolate, &startup_serializer,
&context_sink); &context_sink);
// TODO(yangguo): support multiple contexts in the snapshot.
DCHECK_EQ(1, contexts.length());
context_serializer.Serialize(&contexts[0]); context_serializer.Serialize(&contexts[0]);
startup_serializer.SerializeWeakReferencesAndDeferred(); startup_serializer.SerializeWeakReferencesAndDeferred();
data->created_ = true; data->created_ = true;
return i::Snapshot::CreateSnapshotBlob(startup_serializer, return i::Snapshot::CreateSnapshotBlob(&startup_serializer,
context_serializer); &context_serializer);
} }
StartupData V8::CreateSnapshotDataBlob(const char* embedded_source) { StartupData V8::CreateSnapshotDataBlob(const char* embedded_source) {
......
...@@ -34,7 +34,7 @@ ScriptData* CodeSerializer::Serialize(Isolate* isolate, ...@@ -34,7 +34,7 @@ ScriptData* CodeSerializer::Serialize(Isolate* isolate,
cs.SerializeDeferredObjects(); cs.SerializeDeferredObjects();
cs.Pad(); cs.Pad();
SerializedCodeData data(sink.data(), cs); SerializedCodeData data(sink.data(), &cs);
ScriptData* script_data = data.GetScriptData(); ScriptData* script_data = data.GetScriptData();
if (FLAG_profile_deserialization) { if (FLAG_profile_deserialization) {
...@@ -235,13 +235,13 @@ class Checksum { ...@@ -235,13 +235,13 @@ class Checksum {
DISALLOW_COPY_AND_ASSIGN(Checksum); DISALLOW_COPY_AND_ASSIGN(Checksum);
}; };
SerializedCodeData::SerializedCodeData(const List<byte>& payload, SerializedCodeData::SerializedCodeData(const List<byte>* payload,
const CodeSerializer& cs) { const CodeSerializer* cs) {
DisallowHeapAllocation no_gc; DisallowHeapAllocation no_gc;
const List<uint32_t>* stub_keys = cs.stub_keys(); const List<uint32_t>* stub_keys = cs->stub_keys();
List<Reservation> reservations; List<Reservation> reservations;
cs.EncodeReservations(&reservations); cs->EncodeReservations(&reservations);
// Calculate sizes. // Calculate sizes.
int reservation_size = reservations.length() * kInt32Size; int reservation_size = reservations.length() * kInt32Size;
...@@ -249,23 +249,23 @@ SerializedCodeData::SerializedCodeData(const List<byte>& payload, ...@@ -249,23 +249,23 @@ SerializedCodeData::SerializedCodeData(const List<byte>& payload,
int stub_keys_size = stub_keys->length() * kInt32Size; int stub_keys_size = stub_keys->length() * kInt32Size;
int payload_offset = kHeaderSize + reservation_size + stub_keys_size; int payload_offset = kHeaderSize + reservation_size + stub_keys_size;
int padded_payload_offset = POINTER_SIZE_ALIGN(payload_offset); int padded_payload_offset = POINTER_SIZE_ALIGN(payload_offset);
int size = padded_payload_offset + payload.length(); int size = padded_payload_offset + payload->length();
// Allocate backing store and create result data. // Allocate backing store and create result data.
AllocateData(size); AllocateData(size);
// Set header values. // Set header values.
SetMagicNumber(cs.isolate()); SetMagicNumber(cs->isolate());
SetHeaderValue(kVersionHashOffset, Version::Hash()); SetHeaderValue(kVersionHashOffset, Version::Hash());
SetHeaderValue(kSourceHashOffset, SourceHash(cs.source())); SetHeaderValue(kSourceHashOffset, SourceHash(cs->source()));
SetHeaderValue(kCpuFeaturesOffset, SetHeaderValue(kCpuFeaturesOffset,
static_cast<uint32_t>(CpuFeatures::SupportedFeatures())); static_cast<uint32_t>(CpuFeatures::SupportedFeatures()));
SetHeaderValue(kFlagHashOffset, FlagList::Hash()); SetHeaderValue(kFlagHashOffset, FlagList::Hash());
SetHeaderValue(kNumReservationsOffset, reservations.length()); SetHeaderValue(kNumReservationsOffset, reservations.length());
SetHeaderValue(kNumCodeStubKeysOffset, num_stub_keys); SetHeaderValue(kNumCodeStubKeysOffset, num_stub_keys);
SetHeaderValue(kPayloadLengthOffset, payload.length()); SetHeaderValue(kPayloadLengthOffset, payload->length());
Checksum checksum(payload.ToConstVector()); Checksum checksum(payload->ToConstVector());
SetHeaderValue(kChecksum1Offset, checksum.a()); SetHeaderValue(kChecksum1Offset, checksum.a());
SetHeaderValue(kChecksum2Offset, checksum.b()); SetHeaderValue(kChecksum2Offset, checksum.b());
...@@ -280,8 +280,8 @@ SerializedCodeData::SerializedCodeData(const List<byte>& payload, ...@@ -280,8 +280,8 @@ SerializedCodeData::SerializedCodeData(const List<byte>& payload,
memset(data_ + payload_offset, 0, padded_payload_offset - payload_offset); memset(data_ + payload_offset, 0, padded_payload_offset - payload_offset);
// Copy serialized data. // Copy serialized data.
CopyBytes(data_ + padded_payload_offset, payload.begin(), CopyBytes(data_ + padded_payload_offset, payload->begin(),
static_cast<size_t>(payload.length())); static_cast<size_t>(payload->length()));
} }
SerializedCodeData::SanityCheckResult SerializedCodeData::SanityCheck( SerializedCodeData::SanityCheckResult SerializedCodeData::SanityCheck(
......
...@@ -60,7 +60,7 @@ class SerializedCodeData : public SerializedData { ...@@ -60,7 +60,7 @@ class SerializedCodeData : public SerializedData {
String* source); String* source);
// Used when producing. // Used when producing.
SerializedCodeData(const List<byte>& payload, const CodeSerializer& cs); SerializedCodeData(const List<byte>* payload, const CodeSerializer* cs);
// Return ScriptData object and relinquish ownership over it to the caller. // Return ScriptData object and relinquish ownership over it to the caller.
ScriptData* GetScriptData(); ScriptData* GetScriptData();
......
...@@ -86,23 +86,23 @@ MaybeHandle<Context> Snapshot::NewContextFromSnapshot( ...@@ -86,23 +86,23 @@ MaybeHandle<Context> Snapshot::NewContextFromSnapshot(
return Handle<Context>::cast(result); return Handle<Context>::cast(result);
} }
void CalculateFirstPageSizes(const SnapshotData& startup_snapshot, void CalculateFirstPageSizes(const SnapshotData* startup_snapshot,
const SnapshotData& context_snapshot, const SnapshotData* context_snapshot,
uint32_t* sizes_out) { uint32_t* sizes_out) {
Vector<const SerializedData::Reservation> startup_reservations = Vector<const SerializedData::Reservation> startup_reservations =
startup_snapshot.Reservations(); startup_snapshot->Reservations();
Vector<const SerializedData::Reservation> context_reservations = Vector<const SerializedData::Reservation> context_reservations =
context_snapshot.Reservations(); context_snapshot->Reservations();
int startup_index = 0; int startup_index = 0;
int context_index = 0; int context_index = 0;
if (FLAG_profile_deserialization) { if (FLAG_profile_deserialization) {
int startup_total = 0; int startup_total = 0;
int context_total = 0; int context_total = 0;
for (auto& reservation : startup_reservations) { for (const auto& reservation : startup_reservations) {
startup_total += reservation.chunk_size(); startup_total += reservation.chunk_size();
} }
for (auto& reservation : context_reservations) { for (const auto& reservation : context_reservations) {
context_total += reservation.chunk_size(); context_total += reservation.chunk_size();
} }
PrintF( PrintF(
...@@ -152,16 +152,17 @@ void CalculateFirstPageSizes(const SnapshotData& startup_snapshot, ...@@ -152,16 +152,17 @@ void CalculateFirstPageSizes(const SnapshotData& startup_snapshot,
} }
v8::StartupData Snapshot::CreateSnapshotBlob( v8::StartupData Snapshot::CreateSnapshotBlob(
const i::StartupSerializer& startup_ser, const StartupSerializer* startup_serializer,
const i::PartialSerializer& context_ser) { const PartialSerializer* context_serializer) {
SnapshotData startup_snapshot(startup_ser); SnapshotData startup_snapshot(startup_serializer);
SnapshotData context_snapshot(context_ser); SnapshotData context_snapshot(context_serializer);
Vector<const byte> startup_data = startup_snapshot.RawData(); Vector<const byte> startup_data = startup_snapshot.RawData();
Vector<const byte> context_data = context_snapshot.RawData(); Vector<const byte> context_data = context_snapshot.RawData();
uint32_t first_page_sizes[kNumPagedSpaces]; uint32_t first_page_sizes[kNumPagedSpaces];
CalculateFirstPageSizes(startup_snapshot, context_snapshot, first_page_sizes); CalculateFirstPageSizes(&startup_snapshot, &context_snapshot,
first_page_sizes);
int startup_length = startup_data.length(); int startup_length = startup_data.length();
int context_length = context_data.length(); int context_length = context_data.length();
...@@ -210,32 +211,32 @@ Vector<const byte> Snapshot::ExtractContextData(const v8::StartupData* data) { ...@@ -210,32 +211,32 @@ Vector<const byte> Snapshot::ExtractContextData(const v8::StartupData* data) {
return Vector<const byte>(context_data, context_length); return Vector<const byte>(context_data, context_length);
} }
SnapshotData::SnapshotData(const Serializer& ser) { SnapshotData::SnapshotData(const Serializer* serializer) {
DisallowHeapAllocation no_gc; DisallowHeapAllocation no_gc;
List<Reservation> reservations; List<Reservation> reservations;
ser.EncodeReservations(&reservations); serializer->EncodeReservations(&reservations);
const List<byte>& payload = ser.sink()->data(); const List<byte>* payload = serializer->sink()->data();
// Calculate sizes. // Calculate sizes.
int reservation_size = reservations.length() * kInt32Size; int reservation_size = reservations.length() * kInt32Size;
int size = kHeaderSize + reservation_size + payload.length(); int size = kHeaderSize + reservation_size + payload->length();
// Allocate backing store and create result data. // Allocate backing store and create result data.
AllocateData(size); AllocateData(size);
// Set header values. // Set header values.
SetMagicNumber(ser.isolate()); SetMagicNumber(serializer->isolate());
SetHeaderValue(kCheckSumOffset, Version::Hash()); SetHeaderValue(kCheckSumOffset, Version::Hash());
SetHeaderValue(kNumReservationsOffset, reservations.length()); SetHeaderValue(kNumReservationsOffset, reservations.length());
SetHeaderValue(kPayloadLengthOffset, payload.length()); SetHeaderValue(kPayloadLengthOffset, payload->length());
// Copy reservation chunk sizes. // Copy reservation chunk sizes.
CopyBytes(data_ + kHeaderSize, reinterpret_cast<byte*>(reservations.begin()), CopyBytes(data_ + kHeaderSize, reinterpret_cast<byte*>(reservations.begin()),
reservation_size); reservation_size);
// Copy serialized data. // Copy serialized data.
CopyBytes(data_ + kHeaderSize + reservation_size, payload.begin(), CopyBytes(data_ + kHeaderSize + reservation_size, payload->begin(),
static_cast<size_t>(payload.length())); static_cast<size_t>(payload->length()));
} }
bool SnapshotData::IsSane() { bool SnapshotData::IsSane() {
......
...@@ -94,7 +94,7 @@ class SnapshotByteSink { ...@@ -94,7 +94,7 @@ class SnapshotByteSink {
void PutRaw(const byte* data, int number_of_bytes, const char* description); void PutRaw(const byte* data, int number_of_bytes, const char* description);
int Position() { return data_.length(); } int Position() { return data_.length(); }
const List<byte>& data() const { return data_; } const List<byte>* data() const { return &data_; }
private: private:
List<byte> data_; List<byte> data_;
......
...@@ -36,8 +36,8 @@ class Snapshot : public AllStatic { ...@@ -36,8 +36,8 @@ class Snapshot : public AllStatic {
static const v8::StartupData* DefaultSnapshotBlob(); static const v8::StartupData* DefaultSnapshotBlob();
static v8::StartupData CreateSnapshotBlob( static v8::StartupData CreateSnapshotBlob(
const StartupSerializer& startup_ser, const StartupSerializer* startup_serializer,
const PartialSerializer& context_ser); const PartialSerializer* context_serializer);
#ifdef DEBUG #ifdef DEBUG
static bool SnapshotIsValid(v8::StartupData* snapshot_blob); static bool SnapshotIsValid(v8::StartupData* snapshot_blob);
...@@ -75,7 +75,7 @@ void SetSnapshotFromFile(StartupData* snapshot_blob); ...@@ -75,7 +75,7 @@ void SetSnapshotFromFile(StartupData* snapshot_blob);
class SnapshotData : public SerializedData { class SnapshotData : public SerializedData {
public: public:
// Used when producing. // Used when producing.
explicit SnapshotData(const Serializer& ser); explicit SnapshotData(const Serializer* serializer);
// Used when consuming. // Used when consuming.
explicit SnapshotData(const Vector<const byte> snapshot) explicit SnapshotData(const Vector<const byte> snapshot)
......
...@@ -97,7 +97,7 @@ static Vector<const byte> Serialize(v8::Isolate* isolate) { ...@@ -97,7 +97,7 @@ static Vector<const byte> Serialize(v8::Isolate* isolate) {
v8::SnapshotCreator::FunctionCodeHandling::kClear); v8::SnapshotCreator::FunctionCodeHandling::kClear);
ser.SerializeStrongReferences(); ser.SerializeStrongReferences();
ser.SerializeWeakReferencesAndDeferred(); ser.SerializeWeakReferencesAndDeferred();
SnapshotData snapshot_data(ser); SnapshotData snapshot_data(&ser);
return WritePayload(snapshot_data.RawData()); return WritePayload(snapshot_data.RawData());
} }
...@@ -295,8 +295,8 @@ static void PartiallySerializeObject(Vector<const byte>* startup_blob_out, ...@@ -295,8 +295,8 @@ static void PartiallySerializeObject(Vector<const byte>* startup_blob_out,
startup_serializer.SerializeWeakReferencesAndDeferred(); startup_serializer.SerializeWeakReferencesAndDeferred();
SnapshotData startup_snapshot(startup_serializer); SnapshotData startup_snapshot(&startup_serializer);
SnapshotData partial_snapshot(partial_serializer); SnapshotData partial_snapshot(&partial_serializer);
*partial_blob_out = WritePayload(partial_snapshot.RawData()); *partial_blob_out = WritePayload(partial_snapshot.RawData());
*startup_blob_out = WritePayload(startup_snapshot.RawData()); *startup_blob_out = WritePayload(startup_snapshot.RawData());
...@@ -395,8 +395,8 @@ static void PartiallySerializeContext(Vector<const byte>* startup_blob_out, ...@@ -395,8 +395,8 @@ static void PartiallySerializeContext(Vector<const byte>* startup_blob_out,
partial_serializer.Serialize(&raw_context); partial_serializer.Serialize(&raw_context);
startup_serializer.SerializeWeakReferencesAndDeferred(); startup_serializer.SerializeWeakReferencesAndDeferred();
SnapshotData startup_snapshot(startup_serializer); SnapshotData startup_snapshot(&startup_serializer);
SnapshotData partial_snapshot(partial_serializer); SnapshotData partial_snapshot(&partial_serializer);
*partial_blob_out = WritePayload(partial_snapshot.RawData()); *partial_blob_out = WritePayload(partial_snapshot.RawData());
*startup_blob_out = WritePayload(startup_snapshot.RawData()); *startup_blob_out = WritePayload(startup_snapshot.RawData());
...@@ -515,8 +515,8 @@ static void PartiallySerializeCustomContext( ...@@ -515,8 +515,8 @@ static void PartiallySerializeCustomContext(
partial_serializer.Serialize(&raw_context); partial_serializer.Serialize(&raw_context);
startup_serializer.SerializeWeakReferencesAndDeferred(); startup_serializer.SerializeWeakReferencesAndDeferred();
SnapshotData startup_snapshot(startup_serializer); SnapshotData startup_snapshot(&startup_serializer);
SnapshotData partial_snapshot(partial_serializer); SnapshotData partial_snapshot(&partial_serializer);
*partial_blob_out = WritePayload(partial_snapshot.RawData()); *partial_blob_out = WritePayload(partial_snapshot.RawData());
*startup_blob_out = WritePayload(startup_snapshot.RawData()); *startup_blob_out = WritePayload(startup_snapshot.RawData());
......
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