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