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

Side by Side Diff: test/cctest/test-serialize.cc

Issue 653033002: Break deserializer reservations into chunks that fit onto a page. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: addressed comments and rebase 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/vector.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2007-2010 the V8 project authors. All rights reserved. 1 // Copyright 2007-2010 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 } 130 }
131 } 131 }
132 virtual void Put(byte b, const char* description) { 132 virtual void Put(byte b, const char* description) {
133 if (fp_ != NULL) { 133 if (fp_ != NULL) {
134 fputc(b, fp_); 134 fputc(b, fp_);
135 } 135 }
136 } 136 }
137 virtual int Position() { 137 virtual int Position() {
138 return ftell(fp_); 138 return ftell(fp_);
139 } 139 }
140 void WriteSpaceUsed(int new_space_used, int pointer_space_used, 140 void WriteSpaceUsed(Serializer* serializer);
141 int data_space_used, int code_space_used,
142 int map_space_used, int cell_space_used,
143 int property_cell_space_used, int lo_space_used);
144 141
145 private: 142 private:
146 FILE* fp_; 143 FILE* fp_;
147 const char* file_name_; 144 const char* file_name_;
148 }; 145 };
149 146
150 147
151 void FileByteSink::WriteSpaceUsed(int new_space_used, int pointer_space_used, 148 void FileByteSink::WriteSpaceUsed(Serializer* ser) {
152 int data_space_used, int code_space_used,
153 int map_space_used, int cell_space_used,
154 int property_cell_space_used,
155 int lo_space_used) {
156 int file_name_length = StrLength(file_name_) + 10; 149 int file_name_length = StrLength(file_name_) + 10;
157 Vector<char> name = Vector<char>::New(file_name_length + 1); 150 Vector<char> name = Vector<char>::New(file_name_length + 1);
158 SNPrintF(name, "%s.size", file_name_); 151 SNPrintF(name, "%s.size", file_name_);
159 FILE* fp = v8::base::OS::FOpen(name.start(), "w"); 152 FILE* fp = v8::base::OS::FOpen(name.start(), "w");
160 name.Dispose(); 153 name.Dispose();
161 fprintf(fp, "new %d\n", new_space_used); 154
162 fprintf(fp, "pointer %d\n", pointer_space_used); 155 Vector<const uint32_t> chunks = ser->FinalAllocationChunks(NEW_SPACE);
163 fprintf(fp, "data %d\n", data_space_used); 156 CHECK_EQ(1, chunks.length());
164 fprintf(fp, "code %d\n", code_space_used); 157 fprintf(fp, "new %d\n", chunks[0]);
165 fprintf(fp, "map %d\n", map_space_used); 158 chunks = ser->FinalAllocationChunks(OLD_POINTER_SPACE);
166 fprintf(fp, "cell %d\n", cell_space_used); 159 CHECK_EQ(1, chunks.length());
167 fprintf(fp, "property cell %d\n", property_cell_space_used); 160 fprintf(fp, "pointer %d\n", chunks[0]);
168 fprintf(fp, "lo %d\n", lo_space_used); 161 chunks = ser->FinalAllocationChunks(OLD_DATA_SPACE);
162 CHECK_EQ(1, chunks.length());
163 fprintf(fp, "data %d\n", chunks[0]);
164 chunks = ser->FinalAllocationChunks(CODE_SPACE);
165 CHECK_EQ(1, chunks.length());
166 fprintf(fp, "code %d\n", chunks[0]);
167 chunks = ser->FinalAllocationChunks(MAP_SPACE);
168 CHECK_EQ(1, chunks.length());
169 fprintf(fp, "map %d\n", chunks[0]);
170 chunks = ser->FinalAllocationChunks(CELL_SPACE);
171 CHECK_EQ(1, chunks.length());
172 fprintf(fp, "cell %d\n", chunks[0]);
173 chunks = ser->FinalAllocationChunks(PROPERTY_CELL_SPACE);
174 CHECK_EQ(1, chunks.length());
175 fprintf(fp, "property cell %d\n", chunks[0]);
176 chunks = ser->FinalAllocationChunks(LO_SPACE);
177 CHECK_EQ(1, chunks.length());
178 fprintf(fp, "lo %d\n", chunks[0]);
169 fclose(fp); 179 fclose(fp);
170 } 180 }
171 181
172 182
173 static bool WriteToFile(Isolate* isolate, const char* snapshot_file) { 183 static bool WriteToFile(Isolate* isolate, const char* snapshot_file) {
174 FileByteSink file(snapshot_file); 184 FileByteSink file(snapshot_file);
175 StartupSerializer ser(isolate, &file); 185 StartupSerializer ser(isolate, &file);
176 ser.Serialize(); 186 ser.Serialize();
187 ser.FinalizeAllocation();
177 188
178 file.WriteSpaceUsed(ser.CurrentAllocationAddress(NEW_SPACE), 189 file.WriteSpaceUsed(&ser);
179 ser.CurrentAllocationAddress(OLD_POINTER_SPACE),
180 ser.CurrentAllocationAddress(OLD_DATA_SPACE),
181 ser.CurrentAllocationAddress(CODE_SPACE),
182 ser.CurrentAllocationAddress(MAP_SPACE),
183 ser.CurrentAllocationAddress(CELL_SPACE),
184 ser.CurrentAllocationAddress(PROPERTY_CELL_SPACE),
185 ser.CurrentAllocationAddress(LO_SPACE));
186 190
187 return true; 191 return true;
188 } 192 }
189 193
190 194
191 static void Serialize(v8::Isolate* isolate) { 195 static void Serialize(v8::Isolate* isolate) {
192 // We have to create one context. One reason for this is so that the builtins 196 // We have to create one context. One reason for this is so that the builtins
193 // can be loaded from v8natives.js and their addresses can be processed. This 197 // can be loaded from v8natives.js and their addresses can be processed. This
194 // will clear the pending fixups array, which would otherwise contain GC roots 198 // will clear the pending fixups array, which would otherwise contain GC roots
195 // that would confuse the serialization/deserialization process. 199 // that would confuse the serialization/deserialization process.
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 CHECK_EQ(1, fscanf(fp, "data %d\n", &data_size)); 255 CHECK_EQ(1, fscanf(fp, "data %d\n", &data_size));
252 CHECK_EQ(1, fscanf(fp, "code %d\n", &code_size)); 256 CHECK_EQ(1, fscanf(fp, "code %d\n", &code_size));
253 CHECK_EQ(1, fscanf(fp, "map %d\n", &map_size)); 257 CHECK_EQ(1, fscanf(fp, "map %d\n", &map_size));
254 CHECK_EQ(1, fscanf(fp, "cell %d\n", &cell_size)); 258 CHECK_EQ(1, fscanf(fp, "cell %d\n", &cell_size));
255 CHECK_EQ(1, fscanf(fp, "property cell %d\n", &property_cell_size)); 259 CHECK_EQ(1, fscanf(fp, "property cell %d\n", &property_cell_size));
256 CHECK_EQ(1, fscanf(fp, "lo %d\n", &lo_size)); 260 CHECK_EQ(1, fscanf(fp, "lo %d\n", &lo_size));
257 #ifdef _MSC_VER 261 #ifdef _MSC_VER
258 #undef fscanf 262 #undef fscanf
259 #endif 263 #endif
260 fclose(fp); 264 fclose(fp);
261 deserializer->set_reservation(NEW_SPACE, new_size); 265 deserializer->AddReservation(NEW_SPACE, new_size);
262 deserializer->set_reservation(OLD_POINTER_SPACE, pointer_size); 266 deserializer->AddReservation(OLD_POINTER_SPACE, pointer_size);
263 deserializer->set_reservation(OLD_DATA_SPACE, data_size); 267 deserializer->AddReservation(OLD_DATA_SPACE, data_size);
264 deserializer->set_reservation(CODE_SPACE, code_size); 268 deserializer->AddReservation(CODE_SPACE, code_size);
265 deserializer->set_reservation(MAP_SPACE, map_size); 269 deserializer->AddReservation(MAP_SPACE, map_size);
266 deserializer->set_reservation(CELL_SPACE, cell_size); 270 deserializer->AddReservation(CELL_SPACE, cell_size);
267 deserializer->set_reservation(PROPERTY_CELL_SPACE, property_cell_size); 271 deserializer->AddReservation(PROPERTY_CELL_SPACE, property_cell_size);
268 deserializer->set_reservation(LO_SPACE, lo_size); 272 deserializer->AddReservation(LO_SPACE, lo_size);
269 } 273 }
270 274
271 275
272 v8::Isolate* InitializeFromFile(const char* snapshot_file) { 276 v8::Isolate* InitializeFromFile(const char* snapshot_file) {
273 int len; 277 int len;
274 byte* str = ReadBytes(snapshot_file, &len); 278 byte* str = ReadBytes(snapshot_file, &len);
275 if (!str) return NULL; 279 if (!str) return NULL;
276 v8::Isolate* v8_isolate = NULL; 280 v8::Isolate* v8_isolate = NULL;
277 { 281 {
278 SnapshotByteSource source(str, len); 282 SnapshotByteSource source(str, len);
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 442
439 FileByteSink startup_sink(startup_name.start()); 443 FileByteSink startup_sink(startup_name.start());
440 StartupSerializer startup_serializer(isolate, &startup_sink); 444 StartupSerializer startup_serializer(isolate, &startup_sink);
441 startup_serializer.SerializeStrongReferences(); 445 startup_serializer.SerializeStrongReferences();
442 446
443 FileByteSink partial_sink(FLAG_testing_serialization_file); 447 FileByteSink partial_sink(FLAG_testing_serialization_file);
444 PartialSerializer p_ser(isolate, &startup_serializer, &partial_sink); 448 PartialSerializer p_ser(isolate, &startup_serializer, &partial_sink);
445 p_ser.Serialize(&raw_foo); 449 p_ser.Serialize(&raw_foo);
446 startup_serializer.SerializeWeakReferences(); 450 startup_serializer.SerializeWeakReferences();
447 451
448 partial_sink.WriteSpaceUsed( 452 p_ser.FinalizeAllocation();
449 p_ser.CurrentAllocationAddress(NEW_SPACE), 453 startup_serializer.FinalizeAllocation();
450 p_ser.CurrentAllocationAddress(OLD_POINTER_SPACE),
451 p_ser.CurrentAllocationAddress(OLD_DATA_SPACE),
452 p_ser.CurrentAllocationAddress(CODE_SPACE),
453 p_ser.CurrentAllocationAddress(MAP_SPACE),
454 p_ser.CurrentAllocationAddress(CELL_SPACE),
455 p_ser.CurrentAllocationAddress(PROPERTY_CELL_SPACE),
456 p_ser.CurrentAllocationAddress(LO_SPACE));
457 454
458 startup_sink.WriteSpaceUsed( 455 partial_sink.WriteSpaceUsed(&p_ser);
459 startup_serializer.CurrentAllocationAddress(NEW_SPACE), 456
460 startup_serializer.CurrentAllocationAddress(OLD_POINTER_SPACE), 457 startup_sink.WriteSpaceUsed(&startup_serializer);
461 startup_serializer.CurrentAllocationAddress(OLD_DATA_SPACE),
462 startup_serializer.CurrentAllocationAddress(CODE_SPACE),
463 startup_serializer.CurrentAllocationAddress(MAP_SPACE),
464 startup_serializer.CurrentAllocationAddress(CELL_SPACE),
465 startup_serializer.CurrentAllocationAddress(PROPERTY_CELL_SPACE),
466 startup_serializer.CurrentAllocationAddress(LO_SPACE));
467 startup_name.Dispose(); 458 startup_name.Dispose();
468 } 459 }
469 v8_isolate->Exit(); 460 v8_isolate->Exit();
470 v8_isolate->Dispose(); 461 v8_isolate->Dispose();
471 } 462 }
472 } 463 }
473 464
474 465
475 UNINITIALIZED_DEPENDENT_TEST(PartialDeserialization, PartialSerialization) { 466 UNINITIALIZED_DEPENDENT_TEST(PartialDeserialization, PartialSerialization) {
476 if (!Snapshot::HaveASnapshotToStartFrom()) { 467 if (!Snapshot::HaveASnapshotToStartFrom()) {
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
563 554
564 FileByteSink startup_sink(startup_name.start()); 555 FileByteSink startup_sink(startup_name.start());
565 StartupSerializer startup_serializer(isolate, &startup_sink); 556 StartupSerializer startup_serializer(isolate, &startup_sink);
566 startup_serializer.SerializeStrongReferences(); 557 startup_serializer.SerializeStrongReferences();
567 558
568 FileByteSink partial_sink(FLAG_testing_serialization_file); 559 FileByteSink partial_sink(FLAG_testing_serialization_file);
569 PartialSerializer p_ser(isolate, &startup_serializer, &partial_sink); 560 PartialSerializer p_ser(isolate, &startup_serializer, &partial_sink);
570 p_ser.Serialize(&raw_context); 561 p_ser.Serialize(&raw_context);
571 startup_serializer.SerializeWeakReferences(); 562 startup_serializer.SerializeWeakReferences();
572 563
573 partial_sink.WriteSpaceUsed( 564 p_ser.FinalizeAllocation();
574 p_ser.CurrentAllocationAddress(NEW_SPACE), 565 startup_serializer.FinalizeAllocation();
575 p_ser.CurrentAllocationAddress(OLD_POINTER_SPACE),
576 p_ser.CurrentAllocationAddress(OLD_DATA_SPACE),
577 p_ser.CurrentAllocationAddress(CODE_SPACE),
578 p_ser.CurrentAllocationAddress(MAP_SPACE),
579 p_ser.CurrentAllocationAddress(CELL_SPACE),
580 p_ser.CurrentAllocationAddress(PROPERTY_CELL_SPACE),
581 p_ser.CurrentAllocationAddress(LO_SPACE));
582 566
583 startup_sink.WriteSpaceUsed( 567 partial_sink.WriteSpaceUsed(&p_ser);
584 startup_serializer.CurrentAllocationAddress(NEW_SPACE), 568
585 startup_serializer.CurrentAllocationAddress(OLD_POINTER_SPACE), 569 startup_sink.WriteSpaceUsed(&startup_serializer);
586 startup_serializer.CurrentAllocationAddress(OLD_DATA_SPACE),
587 startup_serializer.CurrentAllocationAddress(CODE_SPACE),
588 startup_serializer.CurrentAllocationAddress(MAP_SPACE),
589 startup_serializer.CurrentAllocationAddress(CELL_SPACE),
590 startup_serializer.CurrentAllocationAddress(PROPERTY_CELL_SPACE),
591 startup_serializer.CurrentAllocationAddress(LO_SPACE));
592 startup_name.Dispose(); 570 startup_name.Dispose();
593 } 571 }
594 v8_isolate->Dispose(); 572 v8_isolate->Dispose();
595 } 573 }
596 } 574 }
597 575
598 576
599 UNINITIALIZED_DEPENDENT_TEST(ContextDeserialization, ContextSerialization) { 577 UNINITIALIZED_DEPENDENT_TEST(ContextDeserialization, ContextSerialization) {
600 if (!Snapshot::HaveASnapshotToStartFrom()) { 578 if (!Snapshot::HaveASnapshotToStartFrom()) {
601 int file_name_length = StrLength(FLAG_testing_serialization_file) + 10; 579 int file_name_length = StrLength(FLAG_testing_serialization_file) + 10;
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
894 Execution::Call(isolate, copy_fun, global, 0, NULL).ToHandleChecked(); 872 Execution::Call(isolate, copy_fun, global, 0, NULL).ToHandleChecked();
895 873
896 CHECK_EQ(6 * 1000000, Handle<String>::cast(copy_result)->length()); 874 CHECK_EQ(6 * 1000000, Handle<String>::cast(copy_result)->length());
897 CHECK(isolate->heap()->InSpace(HeapObject::cast(*copy_result), LO_SPACE)); 875 CHECK(isolate->heap()->InSpace(HeapObject::cast(*copy_result), LO_SPACE));
898 876
899 delete cache; 877 delete cache;
900 source.Dispose(); 878 source.Dispose();
901 } 879 }
902 880
903 881
882 TEST(SerializeToplevelThreeBigStrings) {
883 FLAG_serialize_toplevel = true;
884 LocalContext context;
885 Isolate* isolate = CcTest::i_isolate();
886 Factory* f = isolate->factory();
887 isolate->compilation_cache()->Disable(); // Disable same-isolate code cache.
888
889 v8::HandleScope scope(CcTest::isolate());
890
891 Vector<const uint8_t> source_a =
892 ConstructSource(STATIC_CHAR_VECTOR("var a = \""), STATIC_CHAR_VECTOR("a"),
893 STATIC_CHAR_VECTOR("\";"), 700000);
894 Handle<String> source_a_str =
895 f->NewStringFromOneByte(source_a).ToHandleChecked();
896
897 Vector<const uint8_t> source_b =
898 ConstructSource(STATIC_CHAR_VECTOR("var b = \""), STATIC_CHAR_VECTOR("b"),
899 STATIC_CHAR_VECTOR("\";"), 600000);
900 Handle<String> source_b_str =
901 f->NewStringFromOneByte(source_b).ToHandleChecked();
902
903 Vector<const uint8_t> source_c =
904 ConstructSource(STATIC_CHAR_VECTOR("var c = \""), STATIC_CHAR_VECTOR("c"),
905 STATIC_CHAR_VECTOR("\";"), 500000);
906 Handle<String> source_c_str =
907 f->NewStringFromOneByte(source_c).ToHandleChecked();
908
909 Handle<String> source_str =
910 f->NewConsString(
911 f->NewConsString(source_a_str, source_b_str).ToHandleChecked(),
912 source_c_str).ToHandleChecked();
913
914 Handle<JSObject> global(isolate->context()->global_object());
915 ScriptData* cache = NULL;
916
917 Handle<SharedFunctionInfo> orig = Compiler::CompileScript(
918 source_str, Handle<String>(), 0, 0, false,
919 Handle<Context>(isolate->native_context()), NULL, &cache,
920 v8::ScriptCompiler::kProduceCodeCache, NOT_NATIVES_CODE);
921
922 Handle<SharedFunctionInfo> copy;
923 {
924 DisallowCompilation no_compile_expected(isolate);
925 copy = Compiler::CompileScript(
926 source_str, Handle<String>(), 0, 0, false,
927 Handle<Context>(isolate->native_context()), NULL, &cache,
928 v8::ScriptCompiler::kConsumeCodeCache, NOT_NATIVES_CODE);
929 }
930 CHECK_NE(*orig, *copy);
931
932 Handle<JSFunction> copy_fun =
933 isolate->factory()->NewFunctionFromSharedFunctionInfo(
934 copy, isolate->native_context());
935
936 Execution::Call(isolate, copy_fun, global, 0, NULL);
937
938 CHECK_EQ(600000 + 700000, CompileRun("(a + b).length")->Int32Value());
939 CHECK_EQ(500000 + 600000, CompileRun("(b + c).length")->Int32Value());
940 Heap* heap = isolate->heap();
941 CHECK(heap->InSpace(*v8::Utils::OpenHandle(*CompileRun("a")->ToString()),
942 OLD_DATA_SPACE));
943 CHECK(heap->InSpace(*v8::Utils::OpenHandle(*CompileRun("b")->ToString()),
944 OLD_DATA_SPACE));
945 CHECK(heap->InSpace(*v8::Utils::OpenHandle(*CompileRun("c")->ToString()),
946 OLD_DATA_SPACE));
947
948 delete cache;
949 source_a.Dispose();
950 source_b.Dispose();
951 }
952
953
904 class SerializerOneByteResource 954 class SerializerOneByteResource
905 : public v8::String::ExternalOneByteStringResource { 955 : public v8::String::ExternalOneByteStringResource {
906 public: 956 public:
907 SerializerOneByteResource(const char* data, size_t length) 957 SerializerOneByteResource(const char* data, size_t length)
908 : data_(data), length_(length) {} 958 : data_(data), length_(length) {}
909 virtual const char* data() const { return data_; } 959 virtual const char* data() const { return data_; }
910 virtual size_t length() const { return length_; } 960 virtual size_t length() const { return length_; }
911 961
912 private: 962 private:
913 const char* data_; 963 const char* data_;
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
1155 { 1205 {
1156 DisallowCompilation no_compile(reinterpret_cast<Isolate*>(isolate2)); 1206 DisallowCompilation no_compile(reinterpret_cast<Isolate*>(isolate2));
1157 script = v8::ScriptCompiler::CompileUnbound( 1207 script = v8::ScriptCompiler::CompileUnbound(
1158 isolate2, &source, v8::ScriptCompiler::kConsumeCodeCache); 1208 isolate2, &source, v8::ScriptCompiler::kConsumeCodeCache);
1159 } 1209 }
1160 v8::Local<v8::Value> result = script->BindToCurrentContext()->Run(); 1210 v8::Local<v8::Value> result = script->BindToCurrentContext()->Run();
1161 CHECK(result->ToString()->Equals(v8_str("abcdef"))); 1211 CHECK(result->ToString()->Equals(v8_str("abcdef")));
1162 } 1212 }
1163 isolate2->Dispose(); 1213 isolate2->Dispose();
1164 } 1214 }
OLDNEW
« no previous file with comments | « src/vector.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698