OLD | NEW |
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 Loading... |
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( | 140 void WriteSpaceUsed(int new_space_used, int pointer_space_used, |
141 int new_space_used, | 141 int data_space_used, int code_space_used, |
142 int pointer_space_used, | 142 int map_space_used, int cell_space_used, |
143 int data_space_used, | 143 int property_cell_space_used, int lo_space_used); |
144 int code_space_used, | |
145 int map_space_used, | |
146 int cell_space_used, | |
147 int property_cell_space_used); | |
148 | 144 |
149 private: | 145 private: |
150 FILE* fp_; | 146 FILE* fp_; |
151 const char* file_name_; | 147 const char* file_name_; |
152 }; | 148 }; |
153 | 149 |
154 | 150 |
155 void FileByteSink::WriteSpaceUsed( | 151 void FileByteSink::WriteSpaceUsed(int new_space_used, int pointer_space_used, |
156 int new_space_used, | 152 int data_space_used, int code_space_used, |
157 int pointer_space_used, | 153 int map_space_used, int cell_space_used, |
158 int data_space_used, | 154 int property_cell_space_used, |
159 int code_space_used, | 155 int lo_space_used) { |
160 int map_space_used, | |
161 int cell_space_used, | |
162 int property_cell_space_used) { | |
163 int file_name_length = StrLength(file_name_) + 10; | 156 int file_name_length = StrLength(file_name_) + 10; |
164 Vector<char> name = Vector<char>::New(file_name_length + 1); | 157 Vector<char> name = Vector<char>::New(file_name_length + 1); |
165 SNPrintF(name, "%s.size", file_name_); | 158 SNPrintF(name, "%s.size", file_name_); |
166 FILE* fp = v8::base::OS::FOpen(name.start(), "w"); | 159 FILE* fp = v8::base::OS::FOpen(name.start(), "w"); |
167 name.Dispose(); | 160 name.Dispose(); |
168 fprintf(fp, "new %d\n", new_space_used); | 161 fprintf(fp, "new %d\n", new_space_used); |
169 fprintf(fp, "pointer %d\n", pointer_space_used); | 162 fprintf(fp, "pointer %d\n", pointer_space_used); |
170 fprintf(fp, "data %d\n", data_space_used); | 163 fprintf(fp, "data %d\n", data_space_used); |
171 fprintf(fp, "code %d\n", code_space_used); | 164 fprintf(fp, "code %d\n", code_space_used); |
172 fprintf(fp, "map %d\n", map_space_used); | 165 fprintf(fp, "map %d\n", map_space_used); |
173 fprintf(fp, "cell %d\n", cell_space_used); | 166 fprintf(fp, "cell %d\n", cell_space_used); |
174 fprintf(fp, "property cell %d\n", property_cell_space_used); | 167 fprintf(fp, "property cell %d\n", property_cell_space_used); |
| 168 fprintf(fp, "lo %d\n", lo_space_used); |
175 fclose(fp); | 169 fclose(fp); |
176 } | 170 } |
177 | 171 |
178 | 172 |
179 static bool WriteToFile(Isolate* isolate, const char* snapshot_file) { | 173 static bool WriteToFile(Isolate* isolate, const char* snapshot_file) { |
180 FileByteSink file(snapshot_file); | 174 FileByteSink file(snapshot_file); |
181 StartupSerializer ser(isolate, &file); | 175 StartupSerializer ser(isolate, &file); |
182 ser.Serialize(); | 176 ser.Serialize(); |
183 | 177 |
184 file.WriteSpaceUsed( | 178 file.WriteSpaceUsed(ser.CurrentAllocationAddress(NEW_SPACE), |
185 ser.CurrentAllocationAddress(NEW_SPACE), | 179 ser.CurrentAllocationAddress(OLD_POINTER_SPACE), |
186 ser.CurrentAllocationAddress(OLD_POINTER_SPACE), | 180 ser.CurrentAllocationAddress(OLD_DATA_SPACE), |
187 ser.CurrentAllocationAddress(OLD_DATA_SPACE), | 181 ser.CurrentAllocationAddress(CODE_SPACE), |
188 ser.CurrentAllocationAddress(CODE_SPACE), | 182 ser.CurrentAllocationAddress(MAP_SPACE), |
189 ser.CurrentAllocationAddress(MAP_SPACE), | 183 ser.CurrentAllocationAddress(CELL_SPACE), |
190 ser.CurrentAllocationAddress(CELL_SPACE), | 184 ser.CurrentAllocationAddress(PROPERTY_CELL_SPACE), |
191 ser.CurrentAllocationAddress(PROPERTY_CELL_SPACE)); | 185 ser.CurrentAllocationAddress(LO_SPACE)); |
192 | 186 |
193 return true; | 187 return true; |
194 } | 188 } |
195 | 189 |
196 | 190 |
197 static void Serialize(v8::Isolate* isolate) { | 191 static void Serialize(v8::Isolate* isolate) { |
198 // 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 |
199 // 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 |
200 // 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 |
201 // that would confuse the serialization/deserialization process. | 195 // that would confuse the serialization/deserialization process. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 | 233 |
240 | 234 |
241 static void ReserveSpaceForSnapshot(Deserializer* deserializer, | 235 static void ReserveSpaceForSnapshot(Deserializer* deserializer, |
242 const char* file_name) { | 236 const char* file_name) { |
243 int file_name_length = StrLength(file_name) + 10; | 237 int file_name_length = StrLength(file_name) + 10; |
244 Vector<char> name = Vector<char>::New(file_name_length + 1); | 238 Vector<char> name = Vector<char>::New(file_name_length + 1); |
245 SNPrintF(name, "%s.size", file_name); | 239 SNPrintF(name, "%s.size", file_name); |
246 FILE* fp = v8::base::OS::FOpen(name.start(), "r"); | 240 FILE* fp = v8::base::OS::FOpen(name.start(), "r"); |
247 name.Dispose(); | 241 name.Dispose(); |
248 int new_size, pointer_size, data_size, code_size, map_size, cell_size, | 242 int new_size, pointer_size, data_size, code_size, map_size, cell_size, |
249 property_cell_size; | 243 property_cell_size, lo_size; |
250 #ifdef _MSC_VER | 244 #ifdef _MSC_VER |
251 // Avoid warning about unsafe fscanf from MSVC. | 245 // Avoid warning about unsafe fscanf from MSVC. |
252 // Please note that this is only fine if %c and %s are not being used. | 246 // Please note that this is only fine if %c and %s are not being used. |
253 #define fscanf fscanf_s | 247 #define fscanf fscanf_s |
254 #endif | 248 #endif |
255 CHECK_EQ(1, fscanf(fp, "new %d\n", &new_size)); | 249 CHECK_EQ(1, fscanf(fp, "new %d\n", &new_size)); |
256 CHECK_EQ(1, fscanf(fp, "pointer %d\n", &pointer_size)); | 250 CHECK_EQ(1, fscanf(fp, "pointer %d\n", &pointer_size)); |
257 CHECK_EQ(1, fscanf(fp, "data %d\n", &data_size)); | 251 CHECK_EQ(1, fscanf(fp, "data %d\n", &data_size)); |
258 CHECK_EQ(1, fscanf(fp, "code %d\n", &code_size)); | 252 CHECK_EQ(1, fscanf(fp, "code %d\n", &code_size)); |
259 CHECK_EQ(1, fscanf(fp, "map %d\n", &map_size)); | 253 CHECK_EQ(1, fscanf(fp, "map %d\n", &map_size)); |
260 CHECK_EQ(1, fscanf(fp, "cell %d\n", &cell_size)); | 254 CHECK_EQ(1, fscanf(fp, "cell %d\n", &cell_size)); |
261 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)); |
| 256 CHECK_EQ(1, fscanf(fp, "lo %d\n", &lo_size)); |
262 #ifdef _MSC_VER | 257 #ifdef _MSC_VER |
263 #undef fscanf | 258 #undef fscanf |
264 #endif | 259 #endif |
265 fclose(fp); | 260 fclose(fp); |
266 deserializer->set_reservation(NEW_SPACE, new_size); | 261 deserializer->set_reservation(NEW_SPACE, new_size); |
267 deserializer->set_reservation(OLD_POINTER_SPACE, pointer_size); | 262 deserializer->set_reservation(OLD_POINTER_SPACE, pointer_size); |
268 deserializer->set_reservation(OLD_DATA_SPACE, data_size); | 263 deserializer->set_reservation(OLD_DATA_SPACE, data_size); |
269 deserializer->set_reservation(CODE_SPACE, code_size); | 264 deserializer->set_reservation(CODE_SPACE, code_size); |
270 deserializer->set_reservation(MAP_SPACE, map_size); | 265 deserializer->set_reservation(MAP_SPACE, map_size); |
271 deserializer->set_reservation(CELL_SPACE, cell_size); | 266 deserializer->set_reservation(CELL_SPACE, cell_size); |
272 deserializer->set_reservation(PROPERTY_CELL_SPACE, property_cell_size); | 267 deserializer->set_reservation(PROPERTY_CELL_SPACE, property_cell_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 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
449 p_ser.Serialize(&raw_foo); | 445 p_ser.Serialize(&raw_foo); |
450 startup_serializer.SerializeWeakReferences(); | 446 startup_serializer.SerializeWeakReferences(); |
451 | 447 |
452 partial_sink.WriteSpaceUsed( | 448 partial_sink.WriteSpaceUsed( |
453 p_ser.CurrentAllocationAddress(NEW_SPACE), | 449 p_ser.CurrentAllocationAddress(NEW_SPACE), |
454 p_ser.CurrentAllocationAddress(OLD_POINTER_SPACE), | 450 p_ser.CurrentAllocationAddress(OLD_POINTER_SPACE), |
455 p_ser.CurrentAllocationAddress(OLD_DATA_SPACE), | 451 p_ser.CurrentAllocationAddress(OLD_DATA_SPACE), |
456 p_ser.CurrentAllocationAddress(CODE_SPACE), | 452 p_ser.CurrentAllocationAddress(CODE_SPACE), |
457 p_ser.CurrentAllocationAddress(MAP_SPACE), | 453 p_ser.CurrentAllocationAddress(MAP_SPACE), |
458 p_ser.CurrentAllocationAddress(CELL_SPACE), | 454 p_ser.CurrentAllocationAddress(CELL_SPACE), |
459 p_ser.CurrentAllocationAddress(PROPERTY_CELL_SPACE)); | 455 p_ser.CurrentAllocationAddress(PROPERTY_CELL_SPACE), |
| 456 p_ser.CurrentAllocationAddress(LO_SPACE)); |
460 | 457 |
461 startup_sink.WriteSpaceUsed( | 458 startup_sink.WriteSpaceUsed( |
462 startup_serializer.CurrentAllocationAddress(NEW_SPACE), | 459 startup_serializer.CurrentAllocationAddress(NEW_SPACE), |
463 startup_serializer.CurrentAllocationAddress(OLD_POINTER_SPACE), | 460 startup_serializer.CurrentAllocationAddress(OLD_POINTER_SPACE), |
464 startup_serializer.CurrentAllocationAddress(OLD_DATA_SPACE), | 461 startup_serializer.CurrentAllocationAddress(OLD_DATA_SPACE), |
465 startup_serializer.CurrentAllocationAddress(CODE_SPACE), | 462 startup_serializer.CurrentAllocationAddress(CODE_SPACE), |
466 startup_serializer.CurrentAllocationAddress(MAP_SPACE), | 463 startup_serializer.CurrentAllocationAddress(MAP_SPACE), |
467 startup_serializer.CurrentAllocationAddress(CELL_SPACE), | 464 startup_serializer.CurrentAllocationAddress(CELL_SPACE), |
468 startup_serializer.CurrentAllocationAddress(PROPERTY_CELL_SPACE)); | 465 startup_serializer.CurrentAllocationAddress(PROPERTY_CELL_SPACE), |
| 466 startup_serializer.CurrentAllocationAddress(LO_SPACE)); |
469 startup_name.Dispose(); | 467 startup_name.Dispose(); |
470 } | 468 } |
471 v8_isolate->Exit(); | 469 v8_isolate->Exit(); |
472 v8_isolate->Dispose(); | 470 v8_isolate->Dispose(); |
473 } | 471 } |
474 } | 472 } |
475 | 473 |
476 | 474 |
477 UNINITIALIZED_DEPENDENT_TEST(PartialDeserialization, PartialSerialization) { | 475 UNINITIALIZED_DEPENDENT_TEST(PartialDeserialization, PartialSerialization) { |
478 if (!Snapshot::HaveASnapshotToStartFrom()) { | 476 if (!Snapshot::HaveASnapshotToStartFrom()) { |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
572 p_ser.Serialize(&raw_context); | 570 p_ser.Serialize(&raw_context); |
573 startup_serializer.SerializeWeakReferences(); | 571 startup_serializer.SerializeWeakReferences(); |
574 | 572 |
575 partial_sink.WriteSpaceUsed( | 573 partial_sink.WriteSpaceUsed( |
576 p_ser.CurrentAllocationAddress(NEW_SPACE), | 574 p_ser.CurrentAllocationAddress(NEW_SPACE), |
577 p_ser.CurrentAllocationAddress(OLD_POINTER_SPACE), | 575 p_ser.CurrentAllocationAddress(OLD_POINTER_SPACE), |
578 p_ser.CurrentAllocationAddress(OLD_DATA_SPACE), | 576 p_ser.CurrentAllocationAddress(OLD_DATA_SPACE), |
579 p_ser.CurrentAllocationAddress(CODE_SPACE), | 577 p_ser.CurrentAllocationAddress(CODE_SPACE), |
580 p_ser.CurrentAllocationAddress(MAP_SPACE), | 578 p_ser.CurrentAllocationAddress(MAP_SPACE), |
581 p_ser.CurrentAllocationAddress(CELL_SPACE), | 579 p_ser.CurrentAllocationAddress(CELL_SPACE), |
582 p_ser.CurrentAllocationAddress(PROPERTY_CELL_SPACE)); | 580 p_ser.CurrentAllocationAddress(PROPERTY_CELL_SPACE), |
| 581 p_ser.CurrentAllocationAddress(LO_SPACE)); |
583 | 582 |
584 startup_sink.WriteSpaceUsed( | 583 startup_sink.WriteSpaceUsed( |
585 startup_serializer.CurrentAllocationAddress(NEW_SPACE), | 584 startup_serializer.CurrentAllocationAddress(NEW_SPACE), |
586 startup_serializer.CurrentAllocationAddress(OLD_POINTER_SPACE), | 585 startup_serializer.CurrentAllocationAddress(OLD_POINTER_SPACE), |
587 startup_serializer.CurrentAllocationAddress(OLD_DATA_SPACE), | 586 startup_serializer.CurrentAllocationAddress(OLD_DATA_SPACE), |
588 startup_serializer.CurrentAllocationAddress(CODE_SPACE), | 587 startup_serializer.CurrentAllocationAddress(CODE_SPACE), |
589 startup_serializer.CurrentAllocationAddress(MAP_SPACE), | 588 startup_serializer.CurrentAllocationAddress(MAP_SPACE), |
590 startup_serializer.CurrentAllocationAddress(CELL_SPACE), | 589 startup_serializer.CurrentAllocationAddress(CELL_SPACE), |
591 startup_serializer.CurrentAllocationAddress(PROPERTY_CELL_SPACE)); | 590 startup_serializer.CurrentAllocationAddress(PROPERTY_CELL_SPACE), |
| 591 startup_serializer.CurrentAllocationAddress(LO_SPACE)); |
592 startup_name.Dispose(); | 592 startup_name.Dispose(); |
593 } | 593 } |
594 v8_isolate->Dispose(); | 594 v8_isolate->Dispose(); |
595 } | 595 } |
596 } | 596 } |
597 | 597 |
598 | 598 |
599 UNINITIALIZED_DEPENDENT_TEST(ContextDeserialization, ContextSerialization) { | 599 UNINITIALIZED_DEPENDENT_TEST(ContextDeserialization, ContextSerialization) { |
600 if (!Snapshot::HaveASnapshotToStartFrom()) { | 600 if (!Snapshot::HaveASnapshotToStartFrom()) { |
601 int file_name_length = StrLength(FLAG_testing_serialization_file) + 10; | 601 int file_name_length = StrLength(FLAG_testing_serialization_file) + 10; |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
779 Handle<String> expected = | 779 Handle<String> expected = |
780 isolate->factory()->NewStringFromAsciiChecked("string1"); | 780 isolate->factory()->NewStringFromAsciiChecked("string1"); |
781 | 781 |
782 CHECK(Handle<String>::cast(copy_result)->Equals(*expected)); | 782 CHECK(Handle<String>::cast(copy_result)->Equals(*expected)); |
783 CHECK_EQ(builtins_count, CountBuiltins()); | 783 CHECK_EQ(builtins_count, CountBuiltins()); |
784 | 784 |
785 delete cache; | 785 delete cache; |
786 } | 786 } |
787 | 787 |
788 | 788 |
| 789 Vector<const uint8_t> ConstructSource(Vector<const uint8_t> head, |
| 790 Vector<const uint8_t> body, |
| 791 Vector<const uint8_t> tail, int repeats) { |
| 792 int source_length = head.length() + body.length() * repeats + tail.length(); |
| 793 uint8_t* source = NewArray<uint8_t>(static_cast<size_t>(source_length)); |
| 794 CopyChars(source, head.start(), head.length()); |
| 795 for (int i = 0; i < repeats; i++) { |
| 796 CopyChars(source + head.length() + i * body.length(), body.start(), |
| 797 body.length()); |
| 798 } |
| 799 CopyChars(source + head.length() + repeats * body.length(), tail.start(), |
| 800 tail.length()); |
| 801 return Vector<const uint8_t>(const_cast<const uint8_t*>(source), |
| 802 source_length); |
| 803 } |
| 804 |
| 805 |
| 806 TEST(SerializeToplevelLargeCodeObject) { |
| 807 FLAG_serialize_toplevel = true; |
| 808 LocalContext context; |
| 809 Isolate* isolate = CcTest::i_isolate(); |
| 810 isolate->compilation_cache()->Disable(); // Disable same-isolate code cache. |
| 811 |
| 812 v8::HandleScope scope(CcTest::isolate()); |
| 813 |
| 814 Vector<const uint8_t> source = |
| 815 ConstructSource(STATIC_CHAR_VECTOR("var j=1; try { if (j) throw 1;"), |
| 816 STATIC_CHAR_VECTOR("for(var i=0;i<1;i++)j++;"), |
| 817 STATIC_CHAR_VECTOR("} catch (e) { j=7; } j"), 10000); |
| 818 Handle<String> source_str = |
| 819 isolate->factory()->NewStringFromOneByte(source).ToHandleChecked(); |
| 820 |
| 821 Handle<JSObject> global(isolate->context()->global_object()); |
| 822 ScriptData* cache = NULL; |
| 823 |
| 824 Handle<SharedFunctionInfo> orig = Compiler::CompileScript( |
| 825 source_str, Handle<String>(), 0, 0, false, |
| 826 Handle<Context>(isolate->native_context()), NULL, &cache, |
| 827 v8::ScriptCompiler::kProduceCodeCache, NOT_NATIVES_CODE); |
| 828 |
| 829 CHECK(isolate->heap()->InSpace(orig->code(), LO_SPACE)); |
| 830 |
| 831 Handle<SharedFunctionInfo> copy; |
| 832 { |
| 833 DisallowCompilation no_compile_expected(isolate); |
| 834 copy = Compiler::CompileScript( |
| 835 source_str, Handle<String>(), 0, 0, false, |
| 836 Handle<Context>(isolate->native_context()), NULL, &cache, |
| 837 v8::ScriptCompiler::kConsumeCodeCache, NOT_NATIVES_CODE); |
| 838 } |
| 839 CHECK_NE(*orig, *copy); |
| 840 |
| 841 Handle<JSFunction> copy_fun = |
| 842 isolate->factory()->NewFunctionFromSharedFunctionInfo( |
| 843 copy, isolate->native_context()); |
| 844 |
| 845 Handle<Object> copy_result = |
| 846 Execution::Call(isolate, copy_fun, global, 0, NULL).ToHandleChecked(); |
| 847 |
| 848 int result_int; |
| 849 CHECK(copy_result->ToInt32(&result_int)); |
| 850 CHECK_EQ(7, result_int); |
| 851 |
| 852 delete cache; |
| 853 source.Dispose(); |
| 854 } |
| 855 |
| 856 |
| 857 TEST(SerializeToplevelLargeString) { |
| 858 FLAG_serialize_toplevel = true; |
| 859 LocalContext context; |
| 860 Isolate* isolate = CcTest::i_isolate(); |
| 861 isolate->compilation_cache()->Disable(); // Disable same-isolate code cache. |
| 862 |
| 863 v8::HandleScope scope(CcTest::isolate()); |
| 864 |
| 865 Vector<const uint8_t> source = ConstructSource( |
| 866 STATIC_CHAR_VECTOR("var s = \""), STATIC_CHAR_VECTOR("abcdef"), |
| 867 STATIC_CHAR_VECTOR("\"; s"), 1000000); |
| 868 Handle<String> source_str = |
| 869 isolate->factory()->NewStringFromOneByte(source).ToHandleChecked(); |
| 870 |
| 871 Handle<JSObject> global(isolate->context()->global_object()); |
| 872 ScriptData* cache = NULL; |
| 873 |
| 874 Handle<SharedFunctionInfo> orig = Compiler::CompileScript( |
| 875 source_str, Handle<String>(), 0, 0, false, |
| 876 Handle<Context>(isolate->native_context()), NULL, &cache, |
| 877 v8::ScriptCompiler::kProduceCodeCache, NOT_NATIVES_CODE); |
| 878 |
| 879 Handle<SharedFunctionInfo> copy; |
| 880 { |
| 881 DisallowCompilation no_compile_expected(isolate); |
| 882 copy = Compiler::CompileScript( |
| 883 source_str, Handle<String>(), 0, 0, false, |
| 884 Handle<Context>(isolate->native_context()), NULL, &cache, |
| 885 v8::ScriptCompiler::kConsumeCodeCache, NOT_NATIVES_CODE); |
| 886 } |
| 887 CHECK_NE(*orig, *copy); |
| 888 |
| 889 Handle<JSFunction> copy_fun = |
| 890 isolate->factory()->NewFunctionFromSharedFunctionInfo( |
| 891 copy, isolate->native_context()); |
| 892 |
| 893 Handle<Object> copy_result = |
| 894 Execution::Call(isolate, copy_fun, global, 0, NULL).ToHandleChecked(); |
| 895 |
| 896 CHECK_EQ(6 * 1000000, Handle<String>::cast(copy_result)->length()); |
| 897 CHECK(isolate->heap()->InSpace(HeapObject::cast(*copy_result), LO_SPACE)); |
| 898 |
| 899 delete cache; |
| 900 source.Dispose(); |
| 901 } |
| 902 |
| 903 |
789 TEST(SerializeToplevelIsolates) { | 904 TEST(SerializeToplevelIsolates) { |
790 FLAG_serialize_toplevel = true; | 905 FLAG_serialize_toplevel = true; |
791 | 906 |
792 const char* source = "function f() { return 'abc'; }; f() + 'def'"; | 907 const char* source = "function f() { return 'abc'; }; f() + 'def'"; |
793 v8::ScriptCompiler::CachedData* cache; | 908 v8::ScriptCompiler::CachedData* cache; |
794 | 909 |
795 v8::Isolate* isolate1 = v8::Isolate::New(); | 910 v8::Isolate* isolate1 = v8::Isolate::New(); |
796 { | 911 { |
797 v8::Isolate::Scope iscope(isolate1); | 912 v8::Isolate::Scope iscope(isolate1); |
798 v8::HandleScope scope(isolate1); | 913 v8::HandleScope scope(isolate1); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
830 { | 945 { |
831 DisallowCompilation no_compile(reinterpret_cast<Isolate*>(isolate2)); | 946 DisallowCompilation no_compile(reinterpret_cast<Isolate*>(isolate2)); |
832 script = v8::ScriptCompiler::CompileUnbound( | 947 script = v8::ScriptCompiler::CompileUnbound( |
833 isolate2, &source, v8::ScriptCompiler::kConsumeCodeCache); | 948 isolate2, &source, v8::ScriptCompiler::kConsumeCodeCache); |
834 } | 949 } |
835 v8::Local<v8::Value> result = script->BindToCurrentContext()->Run(); | 950 v8::Local<v8::Value> result = script->BindToCurrentContext()->Run(); |
836 CHECK(result->ToString()->Equals(v8_str("abcdef"))); | 951 CHECK(result->ToString()->Equals(v8_str("abcdef"))); |
837 } | 952 } |
838 isolate2->Dispose(); | 953 isolate2->Dispose(); |
839 } | 954 } |
OLD | NEW |