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 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 v8::HandleScope scope(isolate); | 149 v8::HandleScope scope(isolate); |
150 v8::Context::New(isolate); | 150 v8::Context::New(isolate); |
151 } | 151 } |
152 | 152 |
153 Isolate* internal_isolate = reinterpret_cast<Isolate*>(isolate); | 153 Isolate* internal_isolate = reinterpret_cast<Isolate*>(isolate); |
154 internal_isolate->heap()->CollectAllAvailableGarbage("serialize"); | 154 internal_isolate->heap()->CollectAllAvailableGarbage("serialize"); |
155 WriteToFile(internal_isolate, FLAG_testing_serialization_file); | 155 WriteToFile(internal_isolate, FLAG_testing_serialization_file); |
156 } | 156 } |
157 | 157 |
158 | 158 |
159 Vector<const uint8_t> ConstructSource(Vector<const uint8_t> head, | |
160 Vector<const uint8_t> body, | |
161 Vector<const uint8_t> tail, int repeats) { | |
162 int source_length = head.length() + body.length() * repeats + tail.length(); | |
163 uint8_t* source = NewArray<uint8_t>(static_cast<size_t>(source_length)); | |
164 CopyChars(source, head.start(), head.length()); | |
165 for (int i = 0; i < repeats; i++) { | |
166 CopyChars(source + head.length() + i * body.length(), body.start(), | |
167 body.length()); | |
168 } | |
169 CopyChars(source + head.length() + repeats * body.length(), tail.start(), | |
170 tail.length()); | |
171 return Vector<const uint8_t>(const_cast<const uint8_t*>(source), | |
172 source_length); | |
173 } | |
174 | |
175 | |
176 // Test that the whole heap can be serialized. | 159 // Test that the whole heap can be serialized. |
177 UNINITIALIZED_TEST(Serialize) { | 160 UNINITIALIZED_TEST(Serialize) { |
178 if (!Snapshot::HaveASnapshotToStartFrom()) { | 161 if (!Snapshot::HaveASnapshotToStartFrom()) { |
179 v8::Isolate::CreateParams params; | 162 v8::Isolate::CreateParams params; |
180 params.enable_serializer = true; | 163 params.enable_serializer = true; |
181 v8::Isolate* isolate = v8::Isolate::New(params); | 164 v8::Isolate* isolate = v8::Isolate::New(params); |
182 Serialize(isolate); | 165 Serialize(isolate); |
183 } | 166 } |
184 } | 167 } |
185 | 168 |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 const char* c_source = "\"1234\".length"; | 293 const char* c_source = "\"1234\".length"; |
311 v8::Local<v8::String> source = v8::String::NewFromUtf8(isolate, c_source); | 294 v8::Local<v8::String> source = v8::String::NewFromUtf8(isolate, c_source); |
312 v8::Local<v8::Script> script = v8::Script::Compile(source); | 295 v8::Local<v8::Script> script = v8::Script::Compile(source); |
313 CHECK_EQ(4, script->Run()->Int32Value()); | 296 CHECK_EQ(4, script->Run()->Int32Value()); |
314 } | 297 } |
315 isolate->Dispose(); | 298 isolate->Dispose(); |
316 } | 299 } |
317 } | 300 } |
318 | 301 |
319 | 302 |
320 // Test that the whole heap can be serialized. | |
321 UNINITIALIZED_TEST(SerializeMultiplePages) { | |
322 if (!Snapshot::HaveASnapshotToStartFrom()) { | |
323 v8::Isolate::CreateParams params; | |
324 params.enable_serializer = true; | |
325 v8::Isolate* isolate = v8::Isolate::New(params); | |
326 { | |
327 v8::Isolate::Scope isolate_scope(isolate); | |
328 v8::HandleScope handle_scope(isolate); | |
329 v8::Local<v8::Context> context = v8::Context::New(isolate); | |
330 v8::Context::Scope context_scope(context); | |
331 Vector<const uint8_t> source = ConstructSource( | |
332 STATIC_CHAR_VECTOR("var s='"), STATIC_CHAR_VECTOR("A"), | |
333 STATIC_CHAR_VECTOR("';"), Page::kMaxRegularHeapObjectSize - 100); | |
334 v8::Handle<v8::String> source_str = v8::String::NewFromOneByte( | |
335 isolate, source.start(), v8::String::kNormalString, source.length()); | |
336 CompileRun(source_str); | |
337 } | |
338 | |
339 Isolate* internal_isolate = reinterpret_cast<Isolate*>(isolate); | |
340 internal_isolate->heap()->CollectAllAvailableGarbage("serialize"); | |
341 WriteToFile(internal_isolate, FLAG_testing_serialization_file); | |
342 } | |
343 } | |
344 | |
345 | |
346 UNINITIALIZED_TEST(PartialSerialization) { | 303 UNINITIALIZED_TEST(PartialSerialization) { |
347 if (!Snapshot::HaveASnapshotToStartFrom()) { | 304 if (!Snapshot::HaveASnapshotToStartFrom()) { |
348 v8::Isolate::CreateParams params; | 305 v8::Isolate::CreateParams params; |
349 params.enable_serializer = true; | 306 params.enable_serializer = true; |
350 v8::Isolate* v8_isolate = v8::Isolate::New(params); | 307 v8::Isolate* v8_isolate = v8::Isolate::New(params); |
351 Isolate* isolate = reinterpret_cast<Isolate*>(v8_isolate); | 308 Isolate* isolate = reinterpret_cast<Isolate*>(v8_isolate); |
352 v8_isolate->Enter(); | 309 v8_isolate->Enter(); |
353 { | 310 { |
354 Heap* heap = isolate->heap(); | 311 Heap* heap = isolate->heap(); |
355 | 312 |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
582 } | 539 } |
583 } | 540 } |
584 | 541 |
585 | 542 |
586 UNINITIALIZED_TEST(CustomContextSerialization) { | 543 UNINITIALIZED_TEST(CustomContextSerialization) { |
587 if (!Snapshot::HaveASnapshotToStartFrom()) { | 544 if (!Snapshot::HaveASnapshotToStartFrom()) { |
588 v8::Isolate::CreateParams params; | 545 v8::Isolate::CreateParams params; |
589 params.enable_serializer = true; | 546 params.enable_serializer = true; |
590 v8::Isolate* v8_isolate = v8::Isolate::New(params); | 547 v8::Isolate* v8_isolate = v8::Isolate::New(params); |
591 Isolate* isolate = reinterpret_cast<Isolate*>(v8_isolate); | 548 Isolate* isolate = reinterpret_cast<Isolate*>(v8_isolate); |
| 549 Heap* heap = isolate->heap(); |
592 { | 550 { |
593 v8::Isolate::Scope isolate_scope(v8_isolate); | 551 v8::Isolate::Scope isolate_scope(v8_isolate); |
594 | 552 |
595 v8::Persistent<v8::Context> env; | 553 v8::Persistent<v8::Context> env; |
596 { | 554 { |
597 HandleScope scope(isolate); | 555 HandleScope scope(isolate); |
598 env.Reset(v8_isolate, v8::Context::New(v8_isolate)); | 556 env.Reset(v8_isolate, v8::Context::New(v8_isolate)); |
599 } | 557 } |
600 DCHECK(!env.IsEmpty()); | 558 DCHECK(!env.IsEmpty()); |
601 { | 559 { |
602 v8::HandleScope handle_scope(v8_isolate); | 560 v8::HandleScope handle_scope(v8_isolate); |
603 v8::Local<v8::Context>::New(v8_isolate, env)->Enter(); | 561 v8::Local<v8::Context>::New(v8_isolate, env)->Enter(); |
604 // After execution, e's function context refers to the global object. | 562 // After execution, e's function context refers to the global object. |
605 CompileRun( | 563 CompileRun( |
606 "var e;" | 564 "var e;" |
607 "(function() {" | 565 "(function() {" |
608 " e = function(s) { return eval (s); }" | 566 " e = function(s) { return eval (s); }" |
609 "})();" | 567 "})();" |
610 "var o = this;" | 568 "var o = this;" |
611 "var r = Math.random() + Math.cos(0);" | 569 "var r = Math.random() + Math.cos(0);" |
612 "var f = (function(a, b) { return a + b; }).bind(1, 2, 3);" | 570 "var f = (function(a, b) { return a + b; }).bind(1, 2, 3);" |
613 "var s = parseInt('12345');"); | 571 "var s = parseInt('12345');"); |
614 | |
615 Vector<const uint8_t> source = ConstructSource( | |
616 STATIC_CHAR_VECTOR("function g() { return [,"), | |
617 STATIC_CHAR_VECTOR("1,"), | |
618 STATIC_CHAR_VECTOR("];} a = g(); b = g(); b.push(1);"), 100000); | |
619 v8::Handle<v8::String> source_str = v8::String::NewFromOneByte( | |
620 v8_isolate, source.start(), v8::String::kNormalString, | |
621 source.length()); | |
622 CompileRun(source_str); | |
623 source.Dispose(); | |
624 } | 572 } |
625 // Make sure all builtin scripts are cached. | 573 // Make sure all builtin scripts are cached. |
626 { | 574 { |
627 HandleScope scope(isolate); | 575 HandleScope scope(isolate); |
628 for (int i = 0; i < Natives::GetBuiltinsCount(); i++) { | 576 for (int i = 0; i < Natives::GetBuiltinsCount(); i++) { |
629 isolate->bootstrapper()->NativesSourceLookup(i); | 577 isolate->bootstrapper()->NativesSourceLookup(i); |
630 } | 578 } |
631 } | 579 } |
632 // If we don't do this then we end up with a stray root pointing at the | 580 // If we don't do this then we end up with a stray root pointing at the |
633 // context even after we have disposed of env. | 581 // context even after we have disposed of env. |
634 isolate->heap()->CollectAllAvailableGarbage("snapshotting"); | 582 heap->CollectAllGarbage(Heap::kNoGCFlags); |
635 | 583 |
636 int file_name_length = StrLength(FLAG_testing_serialization_file) + 10; | 584 int file_name_length = StrLength(FLAG_testing_serialization_file) + 10; |
637 Vector<char> startup_name = Vector<char>::New(file_name_length + 1); | 585 Vector<char> startup_name = Vector<char>::New(file_name_length + 1); |
638 SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file); | 586 SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file); |
639 | 587 |
640 { | 588 { |
641 v8::HandleScope handle_scope(v8_isolate); | 589 v8::HandleScope handle_scope(v8_isolate); |
642 v8::Local<v8::Context>::New(v8_isolate, env)->Exit(); | 590 v8::Local<v8::Context>::New(v8_isolate, env)->Exit(); |
643 } | 591 } |
644 | 592 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
712 v8::Handle<v8::Context> v8_context = v8::Utils::ToLocal(context); | 660 v8::Handle<v8::Context> v8_context = v8::Utils::ToLocal(context); |
713 v8::Context::Scope context_scope(v8_context); | 661 v8::Context::Scope context_scope(v8_context); |
714 double r = CompileRun("r")->ToNumber(v8_isolate)->Value(); | 662 double r = CompileRun("r")->ToNumber(v8_isolate)->Value(); |
715 CHECK(r >= 1 && r <= 2); | 663 CHECK(r >= 1 && r <= 2); |
716 int f = CompileRun("f()")->ToNumber(v8_isolate)->Int32Value(); | 664 int f = CompileRun("f()")->ToNumber(v8_isolate)->Int32Value(); |
717 CHECK_EQ(5, f); | 665 CHECK_EQ(5, f); |
718 f = CompileRun("e('f()')")->ToNumber(v8_isolate)->Int32Value(); | 666 f = CompileRun("e('f()')")->ToNumber(v8_isolate)->Int32Value(); |
719 CHECK_EQ(5, f); | 667 CHECK_EQ(5, f); |
720 v8::Handle<v8::String> s = CompileRun("s")->ToString(v8_isolate); | 668 v8::Handle<v8::String> s = CompileRun("s")->ToString(v8_isolate); |
721 CHECK(s->Equals(v8_str("12345"))); | 669 CHECK(s->Equals(v8_str("12345"))); |
722 int a = CompileRun("a.length")->ToNumber(v8_isolate)->Int32Value(); | |
723 CHECK_EQ(100001, a); | |
724 int b = CompileRun("b.length")->ToNumber(v8_isolate)->Int32Value(); | |
725 CHECK_EQ(100002, b); | |
726 } | 670 } |
727 } | 671 } |
728 v8_isolate->Dispose(); | 672 v8_isolate->Dispose(); |
729 } | 673 } |
730 } | 674 } |
731 | 675 |
732 | 676 |
733 TEST(TestThatAlwaysSucceeds) { | 677 TEST(TestThatAlwaysSucceeds) { |
734 } | 678 } |
735 | 679 |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
868 Handle<String> expected = | 812 Handle<String> expected = |
869 isolate->factory()->NewStringFromAsciiChecked("string1"); | 813 isolate->factory()->NewStringFromAsciiChecked("string1"); |
870 | 814 |
871 CHECK(Handle<String>::cast(copy_result)->Equals(*expected)); | 815 CHECK(Handle<String>::cast(copy_result)->Equals(*expected)); |
872 CHECK_EQ(builtins_count, CountBuiltins()); | 816 CHECK_EQ(builtins_count, CountBuiltins()); |
873 | 817 |
874 delete cache; | 818 delete cache; |
875 } | 819 } |
876 | 820 |
877 | 821 |
| 822 Vector<const uint8_t> ConstructSource(Vector<const uint8_t> head, |
| 823 Vector<const uint8_t> body, |
| 824 Vector<const uint8_t> tail, int repeats) { |
| 825 int source_length = head.length() + body.length() * repeats + tail.length(); |
| 826 uint8_t* source = NewArray<uint8_t>(static_cast<size_t>(source_length)); |
| 827 CopyChars(source, head.start(), head.length()); |
| 828 for (int i = 0; i < repeats; i++) { |
| 829 CopyChars(source + head.length() + i * body.length(), body.start(), |
| 830 body.length()); |
| 831 } |
| 832 CopyChars(source + head.length() + repeats * body.length(), tail.start(), |
| 833 tail.length()); |
| 834 return Vector<const uint8_t>(const_cast<const uint8_t*>(source), |
| 835 source_length); |
| 836 } |
| 837 |
| 838 |
878 TEST(SerializeToplevelLargeCodeObject) { | 839 TEST(SerializeToplevelLargeCodeObject) { |
879 FLAG_serialize_toplevel = true; | 840 FLAG_serialize_toplevel = true; |
880 LocalContext context; | 841 LocalContext context; |
881 Isolate* isolate = CcTest::i_isolate(); | 842 Isolate* isolate = CcTest::i_isolate(); |
882 isolate->compilation_cache()->Disable(); // Disable same-isolate code cache. | 843 isolate->compilation_cache()->Disable(); // Disable same-isolate code cache. |
883 | 844 |
884 v8::HandleScope scope(CcTest::isolate()); | 845 v8::HandleScope scope(CcTest::isolate()); |
885 | 846 |
886 Vector<const uint8_t> source = | 847 Vector<const uint8_t> source = |
887 ConstructSource(STATIC_CHAR_VECTOR("var j=1; try { if (j) throw 1;"), | 848 ConstructSource(STATIC_CHAR_VECTOR("var j=1; try { if (j) throw 1;"), |
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1399 { | 1360 { |
1400 DisallowCompilation no_compile(reinterpret_cast<Isolate*>(isolate2)); | 1361 DisallowCompilation no_compile(reinterpret_cast<Isolate*>(isolate2)); |
1401 script = v8::ScriptCompiler::CompileUnbound( | 1362 script = v8::ScriptCompiler::CompileUnbound( |
1402 isolate2, &source, v8::ScriptCompiler::kConsumeCodeCache); | 1363 isolate2, &source, v8::ScriptCompiler::kConsumeCodeCache); |
1403 } | 1364 } |
1404 v8::Local<v8::Value> result = script->BindToCurrentContext()->Run(); | 1365 v8::Local<v8::Value> result = script->BindToCurrentContext()->Run(); |
1405 CHECK(result->ToString(isolate2)->Equals(v8_str("XY"))); | 1366 CHECK(result->ToString(isolate2)->Equals(v8_str("XY"))); |
1406 } | 1367 } |
1407 isolate2->Dispose(); | 1368 isolate2->Dispose(); |
1408 } | 1369 } |
OLD | NEW |