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

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

Issue 654243003: Revert "Break deserializer reservations into chunks that fit onto a page." (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: 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(Serializer* serializer); 140 void WriteSpaceUsed(int new_space_used, int pointer_space_used,
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);
141 144
142 private: 145 private:
143 FILE* fp_; 146 FILE* fp_;
144 const char* file_name_; 147 const char* file_name_;
145 }; 148 };
146 149
147 150
148 void FileByteSink::WriteSpaceUsed(Serializer* ser) { 151 void FileByteSink::WriteSpaceUsed(int new_space_used, int pointer_space_used,
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) {
149 int file_name_length = StrLength(file_name_) + 10; 156 int file_name_length = StrLength(file_name_) + 10;
150 Vector<char> name = Vector<char>::New(file_name_length + 1); 157 Vector<char> name = Vector<char>::New(file_name_length + 1);
151 SNPrintF(name, "%s.size", file_name_); 158 SNPrintF(name, "%s.size", file_name_);
152 FILE* fp = v8::base::OS::FOpen(name.start(), "w"); 159 FILE* fp = v8::base::OS::FOpen(name.start(), "w");
153 name.Dispose(); 160 name.Dispose();
154 161 fprintf(fp, "new %d\n", new_space_used);
155 Vector<const uint32_t> chunks = ser->FinalAllocationChunks(NEW_SPACE); 162 fprintf(fp, "pointer %d\n", pointer_space_used);
156 CHECK_EQ(1, chunks.length()); 163 fprintf(fp, "data %d\n", data_space_used);
157 fprintf(fp, "new %d\n", chunks[0]); 164 fprintf(fp, "code %d\n", code_space_used);
158 chunks = ser->FinalAllocationChunks(OLD_POINTER_SPACE); 165 fprintf(fp, "map %d\n", map_space_used);
159 CHECK_EQ(1, chunks.length()); 166 fprintf(fp, "cell %d\n", cell_space_used);
160 fprintf(fp, "pointer %d\n", chunks[0]); 167 fprintf(fp, "property cell %d\n", property_cell_space_used);
161 chunks = ser->FinalAllocationChunks(OLD_DATA_SPACE); 168 fprintf(fp, "lo %d\n", lo_space_used);
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]);
179 fclose(fp); 169 fclose(fp);
180 } 170 }
181 171
182 172
183 static bool WriteToFile(Isolate* isolate, const char* snapshot_file) { 173 static bool WriteToFile(Isolate* isolate, const char* snapshot_file) {
184 FileByteSink file(snapshot_file); 174 FileByteSink file(snapshot_file);
185 StartupSerializer ser(isolate, &file); 175 StartupSerializer ser(isolate, &file);
186 ser.Serialize(); 176 ser.Serialize();
187 ser.FinalizeAllocation();
188 177
189 file.WriteSpaceUsed(&ser); 178 file.WriteSpaceUsed(ser.CurrentAllocationAddress(NEW_SPACE),
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));
190 186
191 return true; 187 return true;
192 } 188 }
193 189
194 190
195 static void Serialize(v8::Isolate* isolate) { 191 static void Serialize(v8::Isolate* isolate) {
196 // We have to create one context. One reason for this is so that the builtins 192 // We have to create one context. One reason for this is so that the builtins
197 // can be loaded from v8natives.js and their addresses can be processed. This 193 // can be loaded from v8natives.js and their addresses can be processed. This
198 // will clear the pending fixups array, which would otherwise contain GC roots 194 // will clear the pending fixups array, which would otherwise contain GC roots
199 // that would confuse the serialization/deserialization process. 195 // that would confuse the serialization/deserialization process.
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 CHECK_EQ(1, fscanf(fp, "data %d\n", &data_size)); 251 CHECK_EQ(1, fscanf(fp, "data %d\n", &data_size));
256 CHECK_EQ(1, fscanf(fp, "code %d\n", &code_size)); 252 CHECK_EQ(1, fscanf(fp, "code %d\n", &code_size));
257 CHECK_EQ(1, fscanf(fp, "map %d\n", &map_size)); 253 CHECK_EQ(1, fscanf(fp, "map %d\n", &map_size));
258 CHECK_EQ(1, fscanf(fp, "cell %d\n", &cell_size)); 254 CHECK_EQ(1, fscanf(fp, "cell %d\n", &cell_size));
259 CHECK_EQ(1, fscanf(fp, "property cell %d\n", &property_cell_size)); 255 CHECK_EQ(1, fscanf(fp, "property cell %d\n", &property_cell_size));
260 CHECK_EQ(1, fscanf(fp, "lo %d\n", &lo_size)); 256 CHECK_EQ(1, fscanf(fp, "lo %d\n", &lo_size));
261 #ifdef _MSC_VER 257 #ifdef _MSC_VER
262 #undef fscanf 258 #undef fscanf
263 #endif 259 #endif
264 fclose(fp); 260 fclose(fp);
265 deserializer->AddReservation(NEW_SPACE, new_size); 261 deserializer->set_reservation(NEW_SPACE, new_size);
266 deserializer->AddReservation(OLD_POINTER_SPACE, pointer_size); 262 deserializer->set_reservation(OLD_POINTER_SPACE, pointer_size);
267 deserializer->AddReservation(OLD_DATA_SPACE, data_size); 263 deserializer->set_reservation(OLD_DATA_SPACE, data_size);
268 deserializer->AddReservation(CODE_SPACE, code_size); 264 deserializer->set_reservation(CODE_SPACE, code_size);
269 deserializer->AddReservation(MAP_SPACE, map_size); 265 deserializer->set_reservation(MAP_SPACE, map_size);
270 deserializer->AddReservation(CELL_SPACE, cell_size); 266 deserializer->set_reservation(CELL_SPACE, cell_size);
271 deserializer->AddReservation(PROPERTY_CELL_SPACE, property_cell_size); 267 deserializer->set_reservation(PROPERTY_CELL_SPACE, property_cell_size);
272 deserializer->AddReservation(LO_SPACE, lo_size); 268 deserializer->set_reservation(LO_SPACE, lo_size);
273 } 269 }
274 270
275 271
276 v8::Isolate* InitializeFromFile(const char* snapshot_file) { 272 v8::Isolate* InitializeFromFile(const char* snapshot_file) {
277 int len; 273 int len;
278 byte* str = ReadBytes(snapshot_file, &len); 274 byte* str = ReadBytes(snapshot_file, &len);
279 if (!str) return NULL; 275 if (!str) return NULL;
280 v8::Isolate* v8_isolate = NULL; 276 v8::Isolate* v8_isolate = NULL;
281 { 277 {
282 SnapshotByteSource source(str, len); 278 SnapshotByteSource source(str, len);
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 438
443 FileByteSink startup_sink(startup_name.start()); 439 FileByteSink startup_sink(startup_name.start());
444 StartupSerializer startup_serializer(isolate, &startup_sink); 440 StartupSerializer startup_serializer(isolate, &startup_sink);
445 startup_serializer.SerializeStrongReferences(); 441 startup_serializer.SerializeStrongReferences();
446 442
447 FileByteSink partial_sink(FLAG_testing_serialization_file); 443 FileByteSink partial_sink(FLAG_testing_serialization_file);
448 PartialSerializer p_ser(isolate, &startup_serializer, &partial_sink); 444 PartialSerializer p_ser(isolate, &startup_serializer, &partial_sink);
449 p_ser.Serialize(&raw_foo); 445 p_ser.Serialize(&raw_foo);
450 startup_serializer.SerializeWeakReferences(); 446 startup_serializer.SerializeWeakReferences();
451 447
452 p_ser.FinalizeAllocation(); 448 partial_sink.WriteSpaceUsed(
453 startup_serializer.FinalizeAllocation(); 449 p_ser.CurrentAllocationAddress(NEW_SPACE),
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));
454 457
455 partial_sink.WriteSpaceUsed(&p_ser); 458 startup_sink.WriteSpaceUsed(
456 459 startup_serializer.CurrentAllocationAddress(NEW_SPACE),
457 startup_sink.WriteSpaceUsed(&startup_serializer); 460 startup_serializer.CurrentAllocationAddress(OLD_POINTER_SPACE),
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));
458 startup_name.Dispose(); 467 startup_name.Dispose();
459 } 468 }
460 v8_isolate->Exit(); 469 v8_isolate->Exit();
461 v8_isolate->Dispose(); 470 v8_isolate->Dispose();
462 } 471 }
463 } 472 }
464 473
465 474
466 UNINITIALIZED_DEPENDENT_TEST(PartialDeserialization, PartialSerialization) { 475 UNINITIALIZED_DEPENDENT_TEST(PartialDeserialization, PartialSerialization) {
467 if (!Snapshot::HaveASnapshotToStartFrom()) { 476 if (!Snapshot::HaveASnapshotToStartFrom()) {
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
554 563
555 FileByteSink startup_sink(startup_name.start()); 564 FileByteSink startup_sink(startup_name.start());
556 StartupSerializer startup_serializer(isolate, &startup_sink); 565 StartupSerializer startup_serializer(isolate, &startup_sink);
557 startup_serializer.SerializeStrongReferences(); 566 startup_serializer.SerializeStrongReferences();
558 567
559 FileByteSink partial_sink(FLAG_testing_serialization_file); 568 FileByteSink partial_sink(FLAG_testing_serialization_file);
560 PartialSerializer p_ser(isolate, &startup_serializer, &partial_sink); 569 PartialSerializer p_ser(isolate, &startup_serializer, &partial_sink);
561 p_ser.Serialize(&raw_context); 570 p_ser.Serialize(&raw_context);
562 startup_serializer.SerializeWeakReferences(); 571 startup_serializer.SerializeWeakReferences();
563 572
564 p_ser.FinalizeAllocation(); 573 partial_sink.WriteSpaceUsed(
565 startup_serializer.FinalizeAllocation(); 574 p_ser.CurrentAllocationAddress(NEW_SPACE),
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));
566 582
567 partial_sink.WriteSpaceUsed(&p_ser); 583 startup_sink.WriteSpaceUsed(
568 584 startup_serializer.CurrentAllocationAddress(NEW_SPACE),
569 startup_sink.WriteSpaceUsed(&startup_serializer); 585 startup_serializer.CurrentAllocationAddress(OLD_POINTER_SPACE),
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));
570 startup_name.Dispose(); 592 startup_name.Dispose();
571 } 593 }
572 v8_isolate->Dispose(); 594 v8_isolate->Dispose();
573 } 595 }
574 } 596 }
575 597
576 598
577 UNINITIALIZED_DEPENDENT_TEST(ContextDeserialization, ContextSerialization) { 599 UNINITIALIZED_DEPENDENT_TEST(ContextDeserialization, ContextSerialization) {
578 if (!Snapshot::HaveASnapshotToStartFrom()) { 600 if (!Snapshot::HaveASnapshotToStartFrom()) {
579 int file_name_length = StrLength(FLAG_testing_serialization_file) + 10; 601 int file_name_length = StrLength(FLAG_testing_serialization_file) + 10;
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
872 Execution::Call(isolate, copy_fun, global, 0, NULL).ToHandleChecked(); 894 Execution::Call(isolate, copy_fun, global, 0, NULL).ToHandleChecked();
873 895
874 CHECK_EQ(6 * 1000000, Handle<String>::cast(copy_result)->length()); 896 CHECK_EQ(6 * 1000000, Handle<String>::cast(copy_result)->length());
875 CHECK(isolate->heap()->InSpace(HeapObject::cast(*copy_result), LO_SPACE)); 897 CHECK(isolate->heap()->InSpace(HeapObject::cast(*copy_result), LO_SPACE));
876 898
877 delete cache; 899 delete cache;
878 source.Dispose(); 900 source.Dispose();
879 } 901 }
880 902
881 903
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
954 class SerializerOneByteResource 904 class SerializerOneByteResource
955 : public v8::String::ExternalOneByteStringResource { 905 : public v8::String::ExternalOneByteStringResource {
956 public: 906 public:
957 SerializerOneByteResource(const char* data, size_t length) 907 SerializerOneByteResource(const char* data, size_t length)
958 : data_(data), length_(length) {} 908 : data_(data), length_(length) {}
959 virtual const char* data() const { return data_; } 909 virtual const char* data() const { return data_; }
960 virtual size_t length() const { return length_; } 910 virtual size_t length() const { return length_; }
961 911
962 private: 912 private:
963 const char* data_; 913 const char* data_;
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
1205 { 1155 {
1206 DisallowCompilation no_compile(reinterpret_cast<Isolate*>(isolate2)); 1156 DisallowCompilation no_compile(reinterpret_cast<Isolate*>(isolate2));
1207 script = v8::ScriptCompiler::CompileUnbound( 1157 script = v8::ScriptCompiler::CompileUnbound(
1208 isolate2, &source, v8::ScriptCompiler::kConsumeCodeCache); 1158 isolate2, &source, v8::ScriptCompiler::kConsumeCodeCache);
1209 } 1159 }
1210 v8::Local<v8::Value> result = script->BindToCurrentContext()->Run(); 1160 v8::Local<v8::Value> result = script->BindToCurrentContext()->Run();
1211 CHECK(result->ToString()->Equals(v8_str("abcdef"))); 1161 CHECK(result->ToString()->Equals(v8_str("abcdef")));
1212 } 1162 }
1213 isolate2->Dispose(); 1163 isolate2->Dispose();
1214 } 1164 }
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