Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(503)

Unified Diff: test/cctest/test-serialize.cc

Issue 669133003: De-virtualize snapshot sink. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: addressed comment Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/snapshot-source-sink.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-serialize.cc
diff --git a/test/cctest/test-serialize.cc b/test/cctest/test-serialize.cc
index e73e426c4d00782b99bb414a4a0a345969312738..62c1d8297770b5c8147b203a5c512beea7ed6582 100644
--- a/test/cctest/test-serialize.cc
+++ b/test/cctest/test-serialize.cc
@@ -114,41 +114,25 @@ TEST(ExternalReferenceDecoder) {
}
-class FileByteSink : public SnapshotByteSink {
- public:
- explicit FileByteSink(const char* snapshot_file) {
- fp_ = v8::base::OS::FOpen(snapshot_file, "wb");
- file_name_ = snapshot_file;
- if (fp_ == NULL) {
- PrintF("Unable to write to snapshot file \"%s\"\n", snapshot_file);
- exit(1);
- }
- }
- virtual ~FileByteSink() {
- if (fp_ != NULL) {
- fclose(fp_);
- }
+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);
+ exit(1);
}
- virtual void Put(byte b, const char* description) {
- if (fp_ != NULL) {
- fputc(b, fp_);
- }
- }
- virtual int Position() {
- return ftell(fp_);
+ size_t written = fwrite(payload.begin(), 1, payload.length(), file);
+ if (written != static_cast<size_t>(payload.length())) {
+ i::PrintF("Writing snapshot file failed.. Aborting.\n");
+ exit(1);
}
- void WriteSpaceUsed(Serializer* serializer);
-
- private:
- FILE* fp_;
- const char* file_name_;
-};
+ fclose(file);
+}
-void FileByteSink::WriteSpaceUsed(Serializer* ser) {
- int file_name_length = StrLength(file_name_) + 10;
+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_);
+ SNPrintF(name, "%s.size", file_name);
FILE* fp = v8::base::OS::FOpen(name.start(), "w");
name.Dispose();
@@ -181,12 +165,13 @@ void FileByteSink::WriteSpaceUsed(Serializer* ser) {
static bool WriteToFile(Isolate* isolate, const char* snapshot_file) {
- FileByteSink file(snapshot_file);
- StartupSerializer ser(isolate, &file);
+ SnapshotByteSink sink;
+ StartupSerializer ser(isolate, &sink);
ser.Serialize();
ser.FinalizeAllocation();
- file.WriteSpaceUsed(&ser);
+ WritePayload(sink.data(), snapshot_file);
+ WriteSpaceUsed(&ser, snapshot_file);
return true;
}
@@ -440,21 +425,26 @@ UNINITIALIZED_TEST(PartialSerialization) {
}
env.Reset();
- FileByteSink startup_sink(startup_name.start());
+ SnapshotByteSink startup_sink;
StartupSerializer startup_serializer(isolate, &startup_sink);
startup_serializer.SerializeStrongReferences();
- FileByteSink partial_sink(FLAG_testing_serialization_file);
- PartialSerializer p_ser(isolate, &startup_serializer, &partial_sink);
- p_ser.Serialize(&raw_foo);
+ SnapshotByteSink partial_sink;
+ PartialSerializer partial_serializer(isolate, &startup_serializer,
+ &partial_sink);
+ partial_serializer.Serialize(&raw_foo);
+
startup_serializer.SerializeWeakReferences();
- p_ser.FinalizeAllocation();
+ partial_serializer.FinalizeAllocation();
startup_serializer.FinalizeAllocation();
- partial_sink.WriteSpaceUsed(&p_ser);
+ WritePayload(partial_sink.data(), FLAG_testing_serialization_file);
+ WritePayload(startup_sink.data(), startup_name.start());
+
+ WriteSpaceUsed(&partial_serializer, FLAG_testing_serialization_file);
+ WriteSpaceUsed(&startup_serializer, startup_name.start());
- startup_sink.WriteSpaceUsed(&startup_serializer);
startup_name.Dispose();
}
v8_isolate->Exit();
@@ -552,21 +542,25 @@ UNINITIALIZED_TEST(ContextSerialization) {
env.Reset();
- FileByteSink startup_sink(startup_name.start());
+ SnapshotByteSink startup_sink;
StartupSerializer startup_serializer(isolate, &startup_sink);
startup_serializer.SerializeStrongReferences();
- FileByteSink partial_sink(FLAG_testing_serialization_file);
- PartialSerializer p_ser(isolate, &startup_serializer, &partial_sink);
- p_ser.Serialize(&raw_context);
+ SnapshotByteSink partial_sink;
+ PartialSerializer partial_serializer(isolate, &startup_serializer,
+ &partial_sink);
+ partial_serializer.Serialize(&raw_context);
startup_serializer.SerializeWeakReferences();
- p_ser.FinalizeAllocation();
+ partial_serializer.FinalizeAllocation();
startup_serializer.FinalizeAllocation();
- partial_sink.WriteSpaceUsed(&p_ser);
+ WritePayload(partial_sink.data(), FLAG_testing_serialization_file);
+ WritePayload(startup_sink.data(), startup_name.start());
+
+ WriteSpaceUsed(&partial_serializer, FLAG_testing_serialization_file);
+ WriteSpaceUsed(&startup_serializer, startup_name.start());
- startup_sink.WriteSpaceUsed(&startup_serializer);
startup_name.Dispose();
}
v8_isolate->Dispose();
« no previous file with comments | « src/snapshot-source-sink.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698