Commit ccf68a7b authored by machenbach's avatar machenbach Committed by Commit bot

Revert of Encode reservation meta data in the snapshot blob. (patchset #3...

Revert of Encode reservation meta data in the snapshot blob. (patchset #3 id:40001 of https://codereview.chromium.org/781443002/)

Reason for revert:
[sheriff] Breaks http://build.chromium.org/p/client.v8/builders/V8-Blink%20Linux%2064/builds/1540

Original issue's description:
> Encode reservation meta data in the snapshot blob.
>
> This also makes reserving multiple chunks per object space possible.
>
> R=vogelheim@chromium.org

TBR=vogelheim@chromium.org,baixo@chromium.org,yangguo@chromium.org
NOTREECHECKS=true
NOTRY=true

Review URL: https://codereview.chromium.org/780833002

Cr-Commit-Position: refs/heads/master@{#25654}
parent a8fbf3ac
......@@ -20,13 +20,24 @@
using namespace v8;
class Compressor {
public:
virtual ~Compressor() {}
virtual bool Compress(i::Vector<i::byte> input) = 0;
virtual i::Vector<i::byte>* output() = 0;
};
class SnapshotWriter {
public:
explicit SnapshotWriter(const char* snapshot_file)
: fp_(GetFileDescriptorOrDie(snapshot_file)),
raw_file_(NULL),
raw_context_file_(NULL),
startup_blob_file_(NULL) {}
: fp_(GetFileDescriptorOrDie(snapshot_file))
, raw_file_(NULL)
, raw_context_file_(NULL)
, startup_blob_file_(NULL)
, compressor_(NULL) {
}
~SnapshotWriter() {
fclose(fp_);
......@@ -35,6 +46,10 @@ class SnapshotWriter {
if (startup_blob_file_) fclose(startup_blob_file_);
}
void SetCompressor(Compressor* compressor) {
compressor_ = compressor;
}
void SetRawFiles(const char* raw_file, const char* raw_context_file) {
raw_file_ = GetFileDescriptorOrDie(raw_file);
raw_context_file_ = GetFileDescriptorOrDie(raw_context_file);
......@@ -45,21 +60,51 @@ class SnapshotWriter {
startup_blob_file_ = GetFileDescriptorOrDie(startup_blob_file);
}
void WriteSnapshot(const i::SnapshotData& sd,
const i::SnapshotData& csd) const {
WriteSnapshotFile(sd, csd);
MaybeWriteStartupBlob(sd, csd);
void WriteSnapshot(const i::List<i::byte>& snapshot_data,
const i::Serializer& serializer,
const i::List<i::byte>& context_snapshot_data,
const i::Serializer& context_serializer) const {
WriteSnapshotFile(snapshot_data, serializer,
context_snapshot_data, context_serializer);
MaybeWriteStartupBlob(snapshot_data, serializer,
context_snapshot_data, context_serializer);
}
private:
void MaybeWriteStartupBlob(const i::SnapshotData& sd,
const i::SnapshotData& csd) const {
void MaybeWriteStartupBlob(const i::List<i::byte>& snapshot_data,
const i::Serializer& serializer,
const i::List<i::byte>& context_snapshot_data,
const i::Serializer& context_serializer) const {
if (!startup_blob_file_) return;
i::SnapshotByteSink sink;
sink.PutBlob(sd.RawData(), "snapshot");
sink.PutBlob(csd.RawData(), "context");
int spaces[] = {i::NEW_SPACE, i::OLD_POINTER_SPACE,
i::OLD_DATA_SPACE, i::CODE_SPACE,
i::MAP_SPACE, i::CELL_SPACE,
i::PROPERTY_CELL_SPACE, i::LO_SPACE};
i::byte* snapshot_bytes = snapshot_data.begin();
sink.PutBlob(snapshot_bytes, snapshot_data.length(), "snapshot");
for (size_t i = 0; i < arraysize(spaces); ++i) {
i::Vector<const uint32_t> chunks =
serializer.FinalAllocationChunks(spaces[i]);
// For the start-up snapshot, none of the reservations has more than
// one chunk (reservation for each space fits onto a single page).
CHECK_EQ(1, chunks.length());
sink.PutInt(chunks[0], "spaces");
}
i::byte* context_bytes = context_snapshot_data.begin();
sink.PutBlob(context_bytes, context_snapshot_data.length(), "context");
for (size_t i = 0; i < arraysize(spaces); ++i) {
i::Vector<const uint32_t> chunks =
context_serializer.FinalAllocationChunks(spaces[i]);
// For the context snapshot, none of the reservations has more than
// one chunk (reservation for each space fits onto a single page).
CHECK_EQ(1, chunks.length());
sink.PutInt(chunks[0], "spaces");
}
const i::List<i::byte>& startup_blob = sink.data();
size_t written = fwrite(startup_blob.begin(), 1, startup_blob.length(),
......@@ -70,11 +115,15 @@ class SnapshotWriter {
}
}
void WriteSnapshotFile(const i::SnapshotData& snapshot_data,
const i::SnapshotData& context_snapshot_data) const {
void WriteSnapshotFile(const i::List<i::byte>& snapshot_data,
const i::Serializer& serializer,
const i::List<i::byte>& context_snapshot_data,
const i::Serializer& context_serializer) const {
WriteFilePrefix();
WriteData("", snapshot_data.RawData(), raw_file_);
WriteData("context_", context_snapshot_data.RawData(), raw_context_file_);
WriteData("", snapshot_data, raw_file_);
WriteData("context_", context_snapshot_data, raw_context_file_);
WriteMeta("context_", context_serializer);
WriteMeta("", serializer);
WriteFileSuffix();
}
......@@ -92,43 +141,90 @@ class SnapshotWriter {
fprintf(fp_, "} // namespace v8\n");
}
void WriteData(const char* prefix,
const i::Vector<const i::byte>& source_data,
void WriteData(const char* prefix, const i::List<i::byte>& source_data,
FILE* raw_file) const {
MaybeWriteRawFile(&source_data, raw_file);
WriteData(prefix, source_data);
const i::List<i::byte>* data_to_be_written = NULL;
i::List<i::byte> compressed_data;
if (!compressor_) {
data_to_be_written = &source_data;
} else if (compressor_->Compress(source_data.ToVector())) {
compressed_data.AddAll(*compressor_->output());
data_to_be_written = &compressed_data;
} else {
i::PrintF("Compression failed. Aborting.\n");
exit(1);
}
DCHECK(data_to_be_written);
MaybeWriteRawFile(data_to_be_written, raw_file);
WriteData(prefix, source_data, data_to_be_written);
}
void MaybeWriteRawFile(const i::Vector<const i::byte>* data,
FILE* raw_file) const {
if (!data || !raw_file) return;
void MaybeWriteRawFile(const i::List<i::byte>* data, FILE* raw_file) const {
if (!data || !raw_file)
return;
// Sanity check, whether i::List iterators truly return pointers to an
// internal array.
DCHECK(data->end() - data->begin() == data->length());
size_t written = fwrite(data->begin(), 1, data->length(), raw_file);
if (written != static_cast<size_t>(data->length())) {
if (written != (size_t)data->length()) {
i::PrintF("Writing raw file failed.. Aborting.\n");
exit(1);
}
}
void WriteData(const char* prefix,
const i::Vector<const i::byte>& source_data) const {
void WriteData(const char* prefix, const i::List<i::byte>& source_data,
const i::List<i::byte>* data_to_be_written) const {
fprintf(fp_, "const byte Snapshot::%sdata_[] = {\n", prefix);
WriteSnapshotData(source_data);
WriteSnapshotData(data_to_be_written);
fprintf(fp_, "};\n");
fprintf(fp_, "const int Snapshot::%ssize_ = %d;\n", prefix,
source_data.length());
data_to_be_written->length());
if (data_to_be_written == &source_data) {
fprintf(fp_, "const byte* Snapshot::%sraw_data_ = Snapshot::%sdata_;\n",
prefix, prefix);
fprintf(fp_, "const int Snapshot::%sraw_size_ = Snapshot::%ssize_;\n",
prefix, prefix);
} else {
fprintf(fp_, "const byte* Snapshot::%sraw_data_ = NULL;\n", prefix);
fprintf(fp_, "const int Snapshot::%sraw_size_ = %d;\n",
prefix, source_data.length());
}
fprintf(fp_, "\n");
}
void WriteMeta(const char* prefix, const i::Serializer& ser) const {
WriteSizeVar(ser, prefix, "new", i::NEW_SPACE);
WriteSizeVar(ser, prefix, "pointer", i::OLD_POINTER_SPACE);
WriteSizeVar(ser, prefix, "data", i::OLD_DATA_SPACE);
WriteSizeVar(ser, prefix, "code", i::CODE_SPACE);
WriteSizeVar(ser, prefix, "map", i::MAP_SPACE);
WriteSizeVar(ser, prefix, "cell", i::CELL_SPACE);
WriteSizeVar(ser, prefix, "property_cell", i::PROPERTY_CELL_SPACE);
WriteSizeVar(ser, prefix, "lo", i::LO_SPACE);
fprintf(fp_, "\n");
}
void WriteSnapshotData(const i::Vector<const i::byte>& data) const {
for (int i = 0; i < data.length(); i++) {
if ((i & 0x1f) == 0x1f) fprintf(fp_, "\n");
if (i > 0) fprintf(fp_, ",");
fprintf(fp_, "%u", static_cast<unsigned char>(data.at(i)));
void WriteSizeVar(const i::Serializer& ser, const char* prefix,
const char* name, int space) const {
i::Vector<const uint32_t> chunks = ser.FinalAllocationChunks(space);
// For the start-up snapshot, none of the reservations has more than
// one chunk (total reservation fits into a single page).
CHECK_EQ(1, chunks.length());
fprintf(fp_, "const int Snapshot::%s%s_space_used_ = %d;\n", prefix, name,
chunks[0]);
}
void WriteSnapshotData(const i::List<i::byte>* data) const {
for (int i = 0; i < data->length(); i++) {
if ((i & 0x1f) == 0x1f)
fprintf(fp_, "\n");
if (i > 0)
fprintf(fp_, ",");
fprintf(fp_, "%u", static_cast<unsigned char>(data->at(i)));
}
fprintf(fp_, "\n");
}
......@@ -146,6 +242,7 @@ class SnapshotWriter {
FILE* raw_file_;
FILE* raw_context_file_;
FILE* startup_blob_file_;
Compressor* compressor_;
};
......@@ -268,15 +365,17 @@ int main(int argc, char** argv) {
context_ser.Serialize(&raw_context);
ser.SerializeWeakReferences();
context_ser.FinalizeAllocation();
ser.FinalizeAllocation();
{
SnapshotWriter writer(argv[1]);
if (i::FLAG_raw_file && i::FLAG_raw_context_file)
writer.SetRawFiles(i::FLAG_raw_file, i::FLAG_raw_context_file);
if (i::FLAG_startup_blob)
writer.SetStartupBlobFile(i::FLAG_startup_blob);
i::SnapshotData sd(snapshot_sink, ser);
i::SnapshotData csd(context_sink, context_ser);
writer.WriteSnapshot(sd, csd);
writer.WriteSnapshot(snapshot_sink.data(), ser, context_sink.data(),
context_ser);
}
}
......
......@@ -147,8 +147,9 @@ void SetNativesFromFile(StartupData* natives_blob) {
DCHECK(natives_blob->data);
DCHECK(natives_blob->raw_size > 0);
SnapshotByteSource bytes(reinterpret_cast<const byte*>(natives_blob->data),
natives_blob->raw_size);
SnapshotByteSource bytes(
reinterpret_cast<const byte*>(natives_blob->data),
natives_blob->raw_size);
NativesHolder<CORE>::set(NativesStore::MakeFromScriptsSource(&bytes));
NativesHolder<EXPERIMENTAL>::set(NativesStore::MakeFromScriptsSource(&bytes));
DCHECK(!bytes.HasMore());
......
This diff is collapsed.
......@@ -453,63 +453,11 @@ class SerializerDeserializer: public ObjectVisitor {
};
class SerializedData {
public:
class Reservation {
public:
explicit Reservation(uint32_t size)
: reservation_(ChunkSizeBits::encode(size)) {}
uint32_t chunk_size() const { return ChunkSizeBits::decode(reservation_); }
bool is_last() const { return IsLastChunkBits::decode(reservation_); }
void mark_as_last() { reservation_ |= IsLastChunkBits::encode(true); }
private:
uint32_t reservation_;
};
SerializedData(byte* data, int size)
: data_(data), size_(size), owns_data_(false) {}
SerializedData() : data_(NULL), size_(0), owns_data_(false) {}
~SerializedData() {
if (owns_data_) DeleteArray<byte>(data_);
}
class ChunkSizeBits : public BitField<uint32_t, 0, 31> {};
class IsLastChunkBits : public BitField<bool, 31, 1> {};
protected:
void SetHeaderValue(int offset, int value) {
reinterpret_cast<int*>(data_)[offset] = value;
}
int GetHeaderValue(int offset) const {
return reinterpret_cast<const int*>(data_)[offset];
}
void AllocateData(int size);
byte* data_;
int size_;
bool owns_data_;
};
// A Deserializer reads a snapshot and reconstructs the Object graph it defines.
class Deserializer: public SerializerDeserializer {
public:
// Create a deserializer from a snapshot byte source.
template <class Data>
explicit Deserializer(Data* data)
: isolate_(NULL),
attached_objects_(NULL),
source_(data->Payload()),
external_reference_decoder_(NULL),
deserialized_large_objects_(0) {
DecodeReservation(data->Reservations());
}
explicit Deserializer(SnapshotByteSource* source);
virtual ~Deserializer();
......@@ -523,6 +471,12 @@ class Deserializer: public SerializerDeserializer {
void DeserializePartial(Isolate* isolate, Object** root,
OnOOM on_oom = FATAL_ON_OOM);
void AddReservation(int space, uint32_t chunk) {
DCHECK(space >= 0);
DCHECK(space < kNumberOfSpaces);
reservations_[space].Add({chunk, NULL, NULL});
}
void FlushICacheForNewCodeObjects();
// Serialized user code reference certain objects that are provided in a list
......@@ -540,8 +494,6 @@ class Deserializer: public SerializerDeserializer {
UNREACHABLE();
}
void DecodeReservation(Vector<const SerializedData::Reservation> res);
bool ReserveSpace();
// Allocation sites are present in the snapshot, and must be linked into
......@@ -571,7 +523,7 @@ class Deserializer: public SerializerDeserializer {
// Objects from the attached object descriptions in the serialized user code.
Vector<Handle<Object> >* attached_objects_;
SnapshotByteSource source_;
SnapshotByteSource* source_;
// The address of the next object that will be allocated in each space.
// Each space has a number of chunks reserved by the GC, with each chunk
// fitting into a page. Deserialized objects are allocated into the
......@@ -597,7 +549,16 @@ class Serializer : public SerializerDeserializer {
~Serializer();
virtual void VisitPointers(Object** start, Object** end) OVERRIDE;
void EncodeReservations(List<SerializedData::Reservation>* out) const;
void FinalizeAllocation();
Vector<const uint32_t> FinalAllocationChunks(int space) const {
if (space == LO_SPACE) {
return Vector<const uint32_t>(&large_objects_total_size_, 1);
} else {
DCHECK_EQ(0, pending_chunk_[space]); // No pending chunks.
return completed_chunks_[space].ToConstVector();
}
}
Isolate* isolate() const { return isolate_; }
......@@ -821,7 +782,7 @@ class CodeSerializer : public Serializer {
return source_;
}
const List<uint32_t>* stub_keys() const { return &stub_keys_; }
List<uint32_t>* stub_keys() { return &stub_keys_; }
int num_internalized_strings() const { return num_internalized_strings_; }
private:
......@@ -858,42 +819,10 @@ class CodeSerializer : public Serializer {
};
// Wrapper around reservation sizes and the serialization payload.
class SnapshotData : public SerializedData {
public:
// Used when producing.
SnapshotData(const SnapshotByteSink& sink, const Serializer& ser);
// Used when consuming.
explicit SnapshotData(const byte* data, int size)
: SerializedData(const_cast<byte*>(data), size) {
CHECK(IsSane());
}
Vector<const Reservation> Reservations() const;
Vector<const byte> Payload() const;
Vector<const byte> RawData() const {
return Vector<const byte>(data_, size_);
}
private:
bool IsSane();
// The data header consists of int-sized entries:
// [0] version hash
// [1] number of reservation size entries
// [2] payload length
static const int kCheckSumOffset = 0;
static const int kReservationsOffset = 1;
static const int kPayloadLengthOffset = 2;
static const int kHeaderSize = (kPayloadLengthOffset + 1) * kIntSize;
};
// Wrapper around ScriptData to provide code-serializer-specific functionality.
class SerializedCodeData : public SerializedData {
class SerializedCodeData {
public:
// Used when consuming.
// Used by when consuming.
static SerializedCodeData* FromCachedData(ScriptData* cached_data,
String* source) {
DisallowHeapAllocation no_gc;
......@@ -905,20 +834,75 @@ class SerializedCodeData : public SerializedData {
}
// Used when producing.
SerializedCodeData(const List<byte>& payload, const CodeSerializer& cs);
SerializedCodeData(const List<byte>& payload, CodeSerializer* cs);
~SerializedCodeData() {
if (owns_script_data_) delete script_data_;
}
// Return ScriptData object and relinquish ownership over it to the caller.
ScriptData* GetScriptData();
ScriptData* GetScriptData() {
ScriptData* result = script_data_;
script_data_ = NULL;
DCHECK(owns_script_data_);
owns_script_data_ = false;
return result;
}
class Reservation {
public:
uint32_t chunk_size() const { return ChunkSizeBits::decode(reservation); }
bool is_last_chunk() const { return IsLastChunkBits::decode(reservation); }
Vector<const Reservation> Reservations() const;
Vector<const byte> Payload() const;
private:
uint32_t reservation;
int NumInternalizedStrings() const;
Vector<const uint32_t> CodeStubKeys() const;
DISALLOW_COPY_AND_ASSIGN(Reservation);
};
int NumInternalizedStrings() const {
return GetHeaderValue(kNumInternalizedStringsOffset);
}
Vector<const Reservation> Reservations() const {
return Vector<const Reservation>(reinterpret_cast<const Reservation*>(
script_data_->data() + kHeaderSize),
GetHeaderValue(kReservationsOffset));
}
Vector<const uint32_t> CodeStubKeys() const {
int reservations_size = GetHeaderValue(kReservationsOffset) * kInt32Size;
const byte* start = script_data_->data() + kHeaderSize + reservations_size;
return Vector<const uint32_t>(reinterpret_cast<const uint32_t*>(start),
GetHeaderValue(kNumCodeStubKeysOffset));
}
const byte* Payload() const {
int reservations_size = GetHeaderValue(kReservationsOffset) * kInt32Size;
int code_stubs_size = GetHeaderValue(kNumCodeStubKeysOffset) * kInt32Size;
return script_data_->data() + kHeaderSize + reservations_size +
code_stubs_size;
}
int PayloadLength() const {
int payload_length = GetHeaderValue(kPayloadLengthOffset);
DCHECK_EQ(script_data_->data() + script_data_->length(),
Payload() + payload_length);
return payload_length;
}
private:
explicit SerializedCodeData(ScriptData* data)
: SerializedData(const_cast<byte*>(data->data()), data->length()) {}
: script_data_(data), owns_script_data_(false) {}
void SetHeaderValue(int offset, int value) {
reinterpret_cast<int*>(const_cast<byte*>(script_data_->data()))[offset] =
value;
}
int GetHeaderValue(int offset) const {
return reinterpret_cast<const int*>(script_data_->data())[offset];
}
bool IsSane(String* source);
......@@ -928,14 +912,24 @@ class SerializedCodeData : public SerializedData {
// [0] version hash
// [1] number of internalized strings
// [2] number of code stub keys
// [3] number of reservation size entries
// [4] payload length
// [3] payload length
// [4..10] reservation sizes for spaces from NEW_SPACE to PROPERTY_CELL_SPACE.
static const int kCheckSumOffset = 0;
static const int kNumInternalizedStringsOffset = 1;
static const int kReservationsOffset = 2;
static const int kNumCodeStubKeysOffset = 3;
static const int kPayloadLengthOffset = 4;
static const int kHeaderSize = (kPayloadLengthOffset + 1) * kIntSize;
class ChunkSizeBits : public BitField<uint32_t, 0, 31> {};
class IsLastChunkBits : public BitField<bool, 31, 1> {};
// Following the header, we store, in sequential order
// - code stub keys
// - serialization payload
ScriptData* script_data_;
bool owns_script_data_;
};
} } // namespace v8::internal
......
......@@ -14,14 +14,27 @@
namespace v8 {
namespace internal {
void Snapshot::ReserveSpaceForLinkedInSnapshot(Deserializer* deserializer) {
deserializer->AddReservation(NEW_SPACE, new_space_used_);
deserializer->AddReservation(OLD_POINTER_SPACE, pointer_space_used_);
deserializer->AddReservation(OLD_DATA_SPACE, data_space_used_);
deserializer->AddReservation(CODE_SPACE, code_space_used_);
deserializer->AddReservation(MAP_SPACE, map_space_used_);
deserializer->AddReservation(CELL_SPACE, cell_space_used_);
deserializer->AddReservation(PROPERTY_CELL_SPACE, property_cell_space_used_);
deserializer->AddReservation(LO_SPACE, lo_space_used_);
}
bool Snapshot::Initialize(Isolate* isolate) {
if (size_ > 0) {
base::ElapsedTimer timer;
if (FLAG_profile_deserialization) timer.Start();
SnapshotData snapshot_data(data_, size_);
Deserializer deserializer(&snapshot_data);
if (FLAG_profile_deserialization) {
timer.Start();
}
SnapshotByteSource source(raw_data_, raw_size_);
Deserializer deserializer(&source);
ReserveSpaceForLinkedInSnapshot(&deserializer);
bool success = isolate->Init(&deserializer);
if (FLAG_profile_deserialization) {
double ms = timer.Elapsed().InMillisecondsF();
......@@ -39,11 +52,22 @@ bool Snapshot::HaveASnapshotToStartFrom() {
Handle<Context> Snapshot::NewContextFromSnapshot(Isolate* isolate) {
if (context_size_ == 0) return Handle<Context>();
SnapshotData snapshot_data(context_data_, context_size_);
Deserializer deserializer(&snapshot_data);
if (context_size_ == 0) {
return Handle<Context>();
}
SnapshotByteSource source(context_raw_data_,
context_raw_size_);
Deserializer deserializer(&source);
Object* root;
deserializer.AddReservation(NEW_SPACE, context_new_space_used_);
deserializer.AddReservation(OLD_POINTER_SPACE, context_pointer_space_used_);
deserializer.AddReservation(OLD_DATA_SPACE, context_data_space_used_);
deserializer.AddReservation(CODE_SPACE, context_code_space_used_);
deserializer.AddReservation(MAP_SPACE, context_map_space_used_);
deserializer.AddReservation(CELL_SPACE, context_cell_space_used_);
deserializer.AddReservation(PROPERTY_CELL_SPACE,
context_property_cell_space_used_);
deserializer.AddReservation(LO_SPACE, context_lo_space_used_);
deserializer.DeserializePartial(isolate, &root);
CHECK(root->IsContext());
return Handle<Context>(Context::cast(root));
......
......@@ -12,8 +12,29 @@ namespace v8 {
namespace internal {
const byte Snapshot::data_[] = { 0 };
const byte* Snapshot::raw_data_ = NULL;
const int Snapshot::size_ = 0;
const int Snapshot::raw_size_ = 0;
const byte Snapshot::context_data_[] = { 0 };
const byte* Snapshot::context_raw_data_ = NULL;
const int Snapshot::context_size_ = 0;
const int Snapshot::context_raw_size_ = 0;
const int Snapshot::new_space_used_ = 0;
const int Snapshot::pointer_space_used_ = 0;
const int Snapshot::data_space_used_ = 0;
const int Snapshot::code_space_used_ = 0;
const int Snapshot::map_space_used_ = 0;
const int Snapshot::cell_space_used_ = 0;
const int Snapshot::property_cell_space_used_ = 0;
const int Snapshot::lo_space_used_ = 0;
const int Snapshot::context_new_space_used_ = 0;
const int Snapshot::context_pointer_space_used_ = 0;
const int Snapshot::context_data_space_used_ = 0;
const int Snapshot::context_code_space_used_ = 0;
const int Snapshot::context_map_space_used_ = 0;
const int Snapshot::context_cell_space_used_ = 0;
const int Snapshot::context_property_cell_space_used_ = 0;
const int Snapshot::context_lo_space_used_ = 0;
} } // namespace v8::internal
......@@ -18,8 +18,25 @@ struct SnapshotImpl {
public:
const byte* data;
int size;
int new_space_used;
int pointer_space_used;
int data_space_used;
int code_space_used;
int map_space_used;
int cell_space_used;
int property_cell_space_used;
int lo_space_used;
const byte* context_data;
int context_size;
int context_new_space_used;
int context_pointer_space_used;
int context_data_space_used;
int context_code_space_used;
int context_map_space_used;
int context_cell_space_used;
int context_property_cell_space_used;
int context_lo_space_used;
};
......@@ -32,13 +49,25 @@ bool Snapshot::HaveASnapshotToStartFrom() {
bool Snapshot::Initialize(Isolate* isolate) {
if (!HaveASnapshotToStartFrom()) return false;
base::ElapsedTimer timer;
if (FLAG_profile_deserialization) timer.Start();
if (!HaveASnapshotToStartFrom())
return false;
SnapshotData snapshot_data(snapshot_impl_->data, snapshot_impl_->size);
Deserializer deserializer(&snapshot_data);
base::ElapsedTimer timer;
if (FLAG_profile_deserialization) {
timer.Start();
}
SnapshotByteSource source(snapshot_impl_->data, snapshot_impl_->size);
Deserializer deserializer(&source);
deserializer.AddReservation(NEW_SPACE, snapshot_impl_->new_space_used);
deserializer.AddReservation(OLD_POINTER_SPACE,
snapshot_impl_->pointer_space_used);
deserializer.AddReservation(OLD_DATA_SPACE, snapshot_impl_->data_space_used);
deserializer.AddReservation(CODE_SPACE, snapshot_impl_->code_space_used);
deserializer.AddReservation(MAP_SPACE, snapshot_impl_->map_space_used);
deserializer.AddReservation(CELL_SPACE, snapshot_impl_->cell_space_used);
deserializer.AddReservation(PROPERTY_CELL_SPACE,
snapshot_impl_->property_cell_space_used);
deserializer.AddReservation(LO_SPACE, snapshot_impl_->lo_space_used);
bool success = isolate->Init(&deserializer);
if (FLAG_profile_deserialization) {
double ms = timer.Elapsed().InMillisecondsF();
......@@ -49,11 +78,27 @@ bool Snapshot::Initialize(Isolate* isolate) {
Handle<Context> Snapshot::NewContextFromSnapshot(Isolate* isolate) {
if (!HaveASnapshotToStartFrom()) return Handle<Context>();
SnapshotData snapshot_data(snapshot_impl_->context_data,
snapshot_impl_->context_size);
Deserializer deserializer(&snapshot_data);
if (!HaveASnapshotToStartFrom())
return Handle<Context>();
SnapshotByteSource source(snapshot_impl_->context_data,
snapshot_impl_->context_size);
Deserializer deserializer(&source);
deserializer.AddReservation(NEW_SPACE,
snapshot_impl_->context_new_space_used);
deserializer.AddReservation(OLD_POINTER_SPACE,
snapshot_impl_->context_pointer_space_used);
deserializer.AddReservation(OLD_DATA_SPACE,
snapshot_impl_->context_data_space_used);
deserializer.AddReservation(CODE_SPACE,
snapshot_impl_->context_code_space_used);
deserializer.AddReservation(MAP_SPACE,
snapshot_impl_->context_map_space_used);
deserializer.AddReservation(CELL_SPACE,
snapshot_impl_->context_cell_space_used);
deserializer.AddReservation(PROPERTY_CELL_SPACE,
snapshot_impl_->context_property_cell_space_used);
deserializer.AddReservation(LO_SPACE, snapshot_impl_->context_lo_space_used);
Object* root;
deserializer.DeserializePartial(isolate, &root);
CHECK(root->IsContext());
......@@ -70,10 +115,29 @@ void SetSnapshotFromFile(StartupData* snapshot_blob) {
snapshot_impl_ = new SnapshotImpl;
SnapshotByteSource source(reinterpret_cast<const byte*>(snapshot_blob->data),
snapshot_blob->raw_size);
bool success = source.GetBlob(&snapshot_impl_->data,
&snapshot_impl_->size);
snapshot_impl_->new_space_used = source.GetInt();
snapshot_impl_->pointer_space_used = source.GetInt();
snapshot_impl_->data_space_used = source.GetInt();
snapshot_impl_->code_space_used = source.GetInt();
snapshot_impl_->map_space_used = source.GetInt();
snapshot_impl_->cell_space_used = source.GetInt();
snapshot_impl_->property_cell_space_used = source.GetInt();
snapshot_impl_->lo_space_used = source.GetInt();
success &= source.GetBlob(&snapshot_impl_->context_data,
&snapshot_impl_->context_size);
snapshot_impl_->context_new_space_used = source.GetInt();
snapshot_impl_->context_pointer_space_used = source.GetInt();
snapshot_impl_->context_data_space_used = source.GetInt();
snapshot_impl_->context_code_space_used = source.GetInt();
snapshot_impl_->context_map_space_used = source.GetInt();
snapshot_impl_->context_cell_space_used = source.GetInt();
snapshot_impl_->context_property_cell_space_used = source.GetInt();
snapshot_impl_->context_lo_space_used = source.GetInt();
DCHECK(success);
}
......
......@@ -13,6 +13,15 @@
namespace v8 {
namespace internal {
SnapshotByteSource::SnapshotByteSource(const byte* array, int length)
: data_(array), length_(length), position_(0) {
}
SnapshotByteSource::~SnapshotByteSource() { }
int32_t SnapshotByteSource::GetUnalignedInt() {
DCHECK(position_ < length_); // Require at least one byte left.
int32_t answer = data_[position_];
......@@ -43,17 +52,15 @@ void SnapshotByteSink::PutInt(uintptr_t integer, const char* description) {
if (bytes > 3) Put(static_cast<int>((integer >> 24) & 0xff), "IntPart4");
}
void SnapshotByteSink::PutRaw(const byte* data, int number_of_bytes,
void SnapshotByteSink::PutRaw(byte* data, int number_of_bytes,
const char* description) {
data_.AddAll(Vector<byte>(const_cast<byte*>(data), number_of_bytes));
data_.AddAll(Vector<byte>(data, number_of_bytes));
}
void SnapshotByteSink::PutBlob(Vector<const byte> blob,
void SnapshotByteSink::PutBlob(byte* data, int number_of_bytes,
const char* description) {
PutInt(blob.length(), description);
PutRaw(blob.start(), blob.length(), description);
PutInt(number_of_bytes, description);
PutRaw(data, number_of_bytes, description);
}
......
......@@ -19,13 +19,8 @@ namespace internal {
*/
class SnapshotByteSource FINAL {
public:
SnapshotByteSource(const byte* data, int length)
: data_(data), length_(length), position_(0) {}
explicit SnapshotByteSource(Vector<const byte> payload)
: data_(payload.start()), length_(payload.length()), position_(0) {}
~SnapshotByteSource() {}
SnapshotByteSource(const byte* array, int length);
~SnapshotByteSource();
bool HasMore() { return position_ < length_; }
......@@ -88,8 +83,8 @@ class SnapshotByteSink {
}
void PutInt(uintptr_t integer, const char* description);
void PutRaw(const byte* data, int number_of_bytes, const char* description);
void PutBlob(Vector<const byte> blob, const char* description);
void PutRaw(byte* data, int number_of_bytes, const char* description);
void PutBlob(byte* data, int number_of_bytes, const char* description);
int Position() { return data_.length(); }
const List<byte>& data() const { return data_; }
......
......@@ -23,9 +23,31 @@ class Snapshot {
private:
static const byte data_[];
static const int size_;
static const byte* raw_data_;
static const byte context_data_[];
static const byte* context_raw_data_;
static const int new_space_used_;
static const int pointer_space_used_;
static const int data_space_used_;
static const int code_space_used_;
static const int map_space_used_;
static const int cell_space_used_;
static const int property_cell_space_used_;
static const int lo_space_used_;
static const int context_new_space_used_;
static const int context_pointer_space_used_;
static const int context_data_space_used_;
static const int context_code_space_used_;
static const int context_map_space_used_;
static const int context_cell_space_used_;
static const int context_property_cell_space_used_;
static const int context_lo_space_used_;
static const int size_;
static const int raw_size_;
static const int context_size_;
static const int context_raw_size_;
static void ReserveSpaceForLinkedInSnapshot(Deserializer* deserializer);
DISALLOW_IMPLICIT_CONSTRUCTORS(Snapshot);
};
......
......@@ -114,7 +114,7 @@ TEST(ExternalReferenceDecoder) {
}
void WritePayload(const Vector<const byte>& payload, const char* file_name) {
void WritePayload(const List<byte>& payload, const char* file_name) {
FILE* file = v8::base::OS::FOpen(file_name, "wb");
if (file == NULL) {
PrintF("Unable to write to snapshot file \"%s\"\n", file_name);
......@@ -129,12 +129,50 @@ void WritePayload(const Vector<const byte>& payload, const char* file_name) {
}
void WriteSpaceUsed(Serializer* ser, const char* file_name) {
int file_name_length = StrLength(file_name) + 10;
Vector<char> name = Vector<char>::New(file_name_length + 1);
SNPrintF(name, "%s.size", file_name);
FILE* fp = v8::base::OS::FOpen(name.start(), "w");
name.Dispose();
Vector<const uint32_t> chunks = ser->FinalAllocationChunks(NEW_SPACE);
CHECK_EQ(1, chunks.length());
fprintf(fp, "new %d\n", chunks[0]);
chunks = ser->FinalAllocationChunks(OLD_POINTER_SPACE);
CHECK_EQ(1, chunks.length());
fprintf(fp, "pointer %d\n", chunks[0]);
chunks = ser->FinalAllocationChunks(OLD_DATA_SPACE);
CHECK_EQ(1, chunks.length());
fprintf(fp, "data %d\n", chunks[0]);
chunks = ser->FinalAllocationChunks(CODE_SPACE);
CHECK_EQ(1, chunks.length());
fprintf(fp, "code %d\n", chunks[0]);
chunks = ser->FinalAllocationChunks(MAP_SPACE);
CHECK_EQ(1, chunks.length());
fprintf(fp, "map %d\n", chunks[0]);
chunks = ser->FinalAllocationChunks(CELL_SPACE);
CHECK_EQ(1, chunks.length());
fprintf(fp, "cell %d\n", chunks[0]);
chunks = ser->FinalAllocationChunks(PROPERTY_CELL_SPACE);
CHECK_EQ(1, chunks.length());
fprintf(fp, "property cell %d\n", chunks[0]);
chunks = ser->FinalAllocationChunks(LO_SPACE);
CHECK_EQ(1, chunks.length());
fprintf(fp, "lo %d\n", chunks[0]);
fclose(fp);
}
static bool WriteToFile(Isolate* isolate, const char* snapshot_file) {
SnapshotByteSink sink;
StartupSerializer ser(isolate, &sink);
ser.Serialize();
SnapshotData snapshot_data(sink, ser);
WritePayload(snapshot_data.RawData(), snapshot_file);
ser.FinalizeAllocation();
WritePayload(sink.data(), snapshot_file);
WriteSpaceUsed(&ser, snapshot_file);
return true;
}
......@@ -182,14 +220,53 @@ UNINITIALIZED_TEST(SerializeTwice) {
//----------------------------------------------------------------------------
// Tests that the heap can be deserialized.
static void ReserveSpaceForSnapshot(Deserializer* deserializer,
const char* file_name) {
int file_name_length = StrLength(file_name) + 10;
Vector<char> name = Vector<char>::New(file_name_length + 1);
SNPrintF(name, "%s.size", file_name);
FILE* fp = v8::base::OS::FOpen(name.start(), "r");
name.Dispose();
int new_size, pointer_size, data_size, code_size, map_size, cell_size,
property_cell_size, lo_size;
#if V8_CC_MSVC
// Avoid warning about unsafe fscanf from MSVC.
// Please note that this is only fine if %c and %s are not being used.
#define fscanf fscanf_s
#endif
CHECK_EQ(1, fscanf(fp, "new %d\n", &new_size));
CHECK_EQ(1, fscanf(fp, "pointer %d\n", &pointer_size));
CHECK_EQ(1, fscanf(fp, "data %d\n", &data_size));
CHECK_EQ(1, fscanf(fp, "code %d\n", &code_size));
CHECK_EQ(1, fscanf(fp, "map %d\n", &map_size));
CHECK_EQ(1, fscanf(fp, "cell %d\n", &cell_size));
CHECK_EQ(1, fscanf(fp, "property cell %d\n", &property_cell_size));
CHECK_EQ(1, fscanf(fp, "lo %d\n", &lo_size));
#if V8_CC_MSVC
#undef fscanf
#endif
fclose(fp);
deserializer->AddReservation(NEW_SPACE, new_size);
deserializer->AddReservation(OLD_POINTER_SPACE, pointer_size);
deserializer->AddReservation(OLD_DATA_SPACE, data_size);
deserializer->AddReservation(CODE_SPACE, code_size);
deserializer->AddReservation(MAP_SPACE, map_size);
deserializer->AddReservation(CELL_SPACE, cell_size);
deserializer->AddReservation(PROPERTY_CELL_SPACE, property_cell_size);
deserializer->AddReservation(LO_SPACE, lo_size);
}
v8::Isolate* InitializeFromFile(const char* snapshot_file) {
int len;
byte* str = ReadBytes(snapshot_file, &len);
if (!str) return NULL;
v8::Isolate* v8_isolate = NULL;
{
SnapshotData snapshot_data(str, len);
Deserializer deserializer(&snapshot_data);
SnapshotByteSource source(str, len);
Deserializer deserializer(&source);
ReserveSpaceForSnapshot(&deserializer, snapshot_file);
Isolate* isolate = Isolate::NewForTesting();
v8_isolate = reinterpret_cast<v8::Isolate*>(isolate);
v8::Isolate::Scope isolate_scope(v8_isolate);
......@@ -359,11 +436,14 @@ UNINITIALIZED_TEST(PartialSerialization) {
startup_serializer.SerializeWeakReferences();
SnapshotData startup_snapshot(startup_sink, startup_serializer);
SnapshotData partial_snapshot(partial_sink, partial_serializer);
partial_serializer.FinalizeAllocation();
startup_serializer.FinalizeAllocation();
WritePayload(partial_sink.data(), FLAG_testing_serialization_file);
WritePayload(startup_sink.data(), startup_name.start());
WritePayload(partial_snapshot.RawData(), FLAG_testing_serialization_file);
WritePayload(startup_snapshot.RawData(), startup_name.start());
WriteSpaceUsed(&partial_serializer, FLAG_testing_serialization_file);
WriteSpaceUsed(&startup_serializer, startup_name.start());
startup_name.Dispose();
}
......@@ -393,8 +473,9 @@ UNINITIALIZED_DEPENDENT_TEST(PartialDeserialization, PartialSerialization) {
Isolate* isolate = reinterpret_cast<Isolate*>(v8_isolate);
Object* root;
{
SnapshotData snapshot_data(snapshot, snapshot_size);
Deserializer deserializer(&snapshot_data);
SnapshotByteSource source(snapshot, snapshot_size);
Deserializer deserializer(&source);
ReserveSpaceForSnapshot(&deserializer, file_name);
deserializer.DeserializePartial(isolate, &root);
CHECK(root->IsString());
}
......@@ -404,8 +485,9 @@ UNINITIALIZED_DEPENDENT_TEST(PartialDeserialization, PartialSerialization) {
Object* root2;
{
SnapshotData snapshot_data(snapshot, snapshot_size);
Deserializer deserializer(&snapshot_data);
SnapshotByteSource source(snapshot, snapshot_size);
Deserializer deserializer(&source);
ReserveSpaceForSnapshot(&deserializer, file_name);
deserializer.DeserializePartial(isolate, &root2);
CHECK(root2->IsString());
CHECK(*root_handle == root2);
......@@ -470,11 +552,14 @@ UNINITIALIZED_TEST(ContextSerialization) {
partial_serializer.Serialize(&raw_context);
startup_serializer.SerializeWeakReferences();
SnapshotData startup_snapshot(startup_sink, startup_serializer);
SnapshotData partial_snapshot(partial_sink, partial_serializer);
partial_serializer.FinalizeAllocation();
startup_serializer.FinalizeAllocation();
WritePayload(partial_sink.data(), FLAG_testing_serialization_file);
WritePayload(startup_sink.data(), startup_name.start());
WritePayload(startup_snapshot.RawData(), FLAG_testing_serialization_file);
WritePayload(startup_snapshot.RawData(), startup_name.start());
WriteSpaceUsed(&partial_serializer, FLAG_testing_serialization_file);
WriteSpaceUsed(&startup_serializer, startup_name.start());
startup_name.Dispose();
}
......@@ -503,8 +588,9 @@ UNINITIALIZED_DEPENDENT_TEST(ContextDeserialization, ContextSerialization) {
Isolate* isolate = reinterpret_cast<Isolate*>(v8_isolate);
Object* root;
{
SnapshotData snapshot_data(snapshot, snapshot_size);
Deserializer deserializer(&snapshot_data);
SnapshotByteSource source(snapshot, snapshot_size);
Deserializer deserializer(&source);
ReserveSpaceForSnapshot(&deserializer, file_name);
deserializer.DeserializePartial(isolate, &root);
CHECK(root->IsContext());
}
......@@ -514,8 +600,9 @@ UNINITIALIZED_DEPENDENT_TEST(ContextDeserialization, ContextSerialization) {
Object* root2;
{
SnapshotData snapshot_data(snapshot, snapshot_size);
Deserializer deserializer(&snapshot_data);
SnapshotByteSource source(snapshot, snapshot_size);
Deserializer deserializer(&source);
ReserveSpaceForSnapshot(&deserializer, file_name);
deserializer.DeserializePartial(isolate, &root2);
CHECK(root2->IsContext());
CHECK(*root_handle != root2);
......
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