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

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

Issue 882633002: Reland "Only use FreeSpace objects in the free list" (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: fix windows build Created 5 years, 11 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
« no previous file with comments | « test/cctest/test-heap.cc ('k') | test/cctest/test-spaces.cc » ('j') | 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 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
159 // Test that the whole heap can be serialized. 176 // Test that the whole heap can be serialized.
160 UNINITIALIZED_TEST(Serialize) { 177 UNINITIALIZED_TEST(Serialize) {
161 if (!Snapshot::HaveASnapshotToStartFrom()) { 178 if (!Snapshot::HaveASnapshotToStartFrom()) {
162 v8::Isolate::CreateParams params; 179 v8::Isolate::CreateParams params;
163 params.enable_serializer = true; 180 params.enable_serializer = true;
164 v8::Isolate* isolate = v8::Isolate::New(params); 181 v8::Isolate* isolate = v8::Isolate::New(params);
165 Serialize(isolate); 182 Serialize(isolate);
166 } 183 }
167 } 184 }
168 185
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 } 556 }
540 } 557 }
541 558
542 559
543 UNINITIALIZED_TEST(CustomContextSerialization) { 560 UNINITIALIZED_TEST(CustomContextSerialization) {
544 if (!Snapshot::HaveASnapshotToStartFrom()) { 561 if (!Snapshot::HaveASnapshotToStartFrom()) {
545 v8::Isolate::CreateParams params; 562 v8::Isolate::CreateParams params;
546 params.enable_serializer = true; 563 params.enable_serializer = true;
547 v8::Isolate* v8_isolate = v8::Isolate::New(params); 564 v8::Isolate* v8_isolate = v8::Isolate::New(params);
548 Isolate* isolate = reinterpret_cast<Isolate*>(v8_isolate); 565 Isolate* isolate = reinterpret_cast<Isolate*>(v8_isolate);
549 Heap* heap = isolate->heap();
550 { 566 {
551 v8::Isolate::Scope isolate_scope(v8_isolate); 567 v8::Isolate::Scope isolate_scope(v8_isolate);
552 568
553 v8::Persistent<v8::Context> env; 569 v8::Persistent<v8::Context> env;
554 { 570 {
555 HandleScope scope(isolate); 571 HandleScope scope(isolate);
556 env.Reset(v8_isolate, v8::Context::New(v8_isolate)); 572 env.Reset(v8_isolate, v8::Context::New(v8_isolate));
557 } 573 }
558 DCHECK(!env.IsEmpty()); 574 DCHECK(!env.IsEmpty());
559 { 575 {
560 v8::HandleScope handle_scope(v8_isolate); 576 v8::HandleScope handle_scope(v8_isolate);
561 v8::Local<v8::Context>::New(v8_isolate, env)->Enter(); 577 v8::Local<v8::Context>::New(v8_isolate, env)->Enter();
562 // After execution, e's function context refers to the global object. 578 // After execution, e's function context refers to the global object.
563 CompileRun( 579 CompileRun(
564 "var e;" 580 "var e;"
565 "(function() {" 581 "(function() {"
566 " e = function(s) { return eval (s); }" 582 " e = function(s) { return eval (s); }"
567 "})();" 583 "})();"
568 "var o = this;" 584 "var o = this;"
569 "var r = Math.random() + Math.cos(0);" 585 "var r = Math.random() + Math.cos(0);"
570 "var f = (function(a, b) { return a + b; }).bind(1, 2, 3);" 586 "var f = (function(a, b) { return a + b; }).bind(1, 2, 3);"
571 "var s = parseInt('12345');"); 587 "var s = parseInt('12345');");
588
589 Vector<const uint8_t> source = ConstructSource(
590 STATIC_CHAR_VECTOR("function g() { return [,"),
591 STATIC_CHAR_VECTOR("1,"),
592 STATIC_CHAR_VECTOR("];} a = g(); b = g(); b.push(1);"), 100000);
593 v8::Handle<v8::String> source_str = v8::String::NewFromOneByte(
594 v8_isolate, source.start(), v8::String::kNormalString,
595 source.length());
596 CompileRun(source_str);
597 source.Dispose();
572 } 598 }
573 // Make sure all builtin scripts are cached. 599 // Make sure all builtin scripts are cached.
574 { 600 {
575 HandleScope scope(isolate); 601 HandleScope scope(isolate);
576 for (int i = 0; i < Natives::GetBuiltinsCount(); i++) { 602 for (int i = 0; i < Natives::GetBuiltinsCount(); i++) {
577 isolate->bootstrapper()->NativesSourceLookup(i); 603 isolate->bootstrapper()->NativesSourceLookup(i);
578 } 604 }
579 } 605 }
580 // If we don't do this then we end up with a stray root pointing at the 606 // If we don't do this then we end up with a stray root pointing at the
581 // context even after we have disposed of env. 607 // context even after we have disposed of env.
582 heap->CollectAllGarbage(Heap::kNoGCFlags); 608 isolate->heap()->CollectAllAvailableGarbage("snapshotting");
583 609
584 int file_name_length = StrLength(FLAG_testing_serialization_file) + 10; 610 int file_name_length = StrLength(FLAG_testing_serialization_file) + 10;
585 Vector<char> startup_name = Vector<char>::New(file_name_length + 1); 611 Vector<char> startup_name = Vector<char>::New(file_name_length + 1);
586 SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file); 612 SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file);
587 613
588 { 614 {
589 v8::HandleScope handle_scope(v8_isolate); 615 v8::HandleScope handle_scope(v8_isolate);
590 v8::Local<v8::Context>::New(v8_isolate, env)->Exit(); 616 v8::Local<v8::Context>::New(v8_isolate, env)->Exit();
591 } 617 }
592 618
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
660 v8::Handle<v8::Context> v8_context = v8::Utils::ToLocal(context); 686 v8::Handle<v8::Context> v8_context = v8::Utils::ToLocal(context);
661 v8::Context::Scope context_scope(v8_context); 687 v8::Context::Scope context_scope(v8_context);
662 double r = CompileRun("r")->ToNumber(v8_isolate)->Value(); 688 double r = CompileRun("r")->ToNumber(v8_isolate)->Value();
663 CHECK(r >= 1 && r <= 2); 689 CHECK(r >= 1 && r <= 2);
664 int f = CompileRun("f()")->ToNumber(v8_isolate)->Int32Value(); 690 int f = CompileRun("f()")->ToNumber(v8_isolate)->Int32Value();
665 CHECK_EQ(5, f); 691 CHECK_EQ(5, f);
666 f = CompileRun("e('f()')")->ToNumber(v8_isolate)->Int32Value(); 692 f = CompileRun("e('f()')")->ToNumber(v8_isolate)->Int32Value();
667 CHECK_EQ(5, f); 693 CHECK_EQ(5, f);
668 v8::Handle<v8::String> s = CompileRun("s")->ToString(v8_isolate); 694 v8::Handle<v8::String> s = CompileRun("s")->ToString(v8_isolate);
669 CHECK(s->Equals(v8_str("12345"))); 695 CHECK(s->Equals(v8_str("12345")));
696 int a = CompileRun("a.length")->ToNumber(v8_isolate)->Int32Value();
697 CHECK_EQ(100001, a);
698 int b = CompileRun("b.length")->ToNumber(v8_isolate)->Int32Value();
699 CHECK_EQ(100002, b);
670 } 700 }
671 } 701 }
672 v8_isolate->Dispose(); 702 v8_isolate->Dispose();
673 } 703 }
674 } 704 }
675 705
676 706
677 TEST(TestThatAlwaysSucceeds) { 707 TEST(TestThatAlwaysSucceeds) {
678 } 708 }
679 709
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
812 Handle<String> expected = 842 Handle<String> expected =
813 isolate->factory()->NewStringFromAsciiChecked("string1"); 843 isolate->factory()->NewStringFromAsciiChecked("string1");
814 844
815 CHECK(Handle<String>::cast(copy_result)->Equals(*expected)); 845 CHECK(Handle<String>::cast(copy_result)->Equals(*expected));
816 CHECK_EQ(builtins_count, CountBuiltins()); 846 CHECK_EQ(builtins_count, CountBuiltins());
817 847
818 delete cache; 848 delete cache;
819 } 849 }
820 850
821 851
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
839 TEST(SerializeToplevelLargeCodeObject) { 852 TEST(SerializeToplevelLargeCodeObject) {
840 FLAG_serialize_toplevel = true; 853 FLAG_serialize_toplevel = true;
841 LocalContext context; 854 LocalContext context;
842 Isolate* isolate = CcTest::i_isolate(); 855 Isolate* isolate = CcTest::i_isolate();
843 isolate->compilation_cache()->Disable(); // Disable same-isolate code cache. 856 isolate->compilation_cache()->Disable(); // Disable same-isolate code cache.
844 857
845 v8::HandleScope scope(CcTest::isolate()); 858 v8::HandleScope scope(CcTest::isolate());
846 859
847 Vector<const uint8_t> source = 860 Vector<const uint8_t> source =
848 ConstructSource(STATIC_CHAR_VECTOR("var j=1; try { if (j) throw 1;"), 861 ConstructSource(STATIC_CHAR_VECTOR("var j=1; try { if (j) throw 1;"),
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after
1360 { 1373 {
1361 DisallowCompilation no_compile(reinterpret_cast<Isolate*>(isolate2)); 1374 DisallowCompilation no_compile(reinterpret_cast<Isolate*>(isolate2));
1362 script = v8::ScriptCompiler::CompileUnbound( 1375 script = v8::ScriptCompiler::CompileUnbound(
1363 isolate2, &source, v8::ScriptCompiler::kConsumeCodeCache); 1376 isolate2, &source, v8::ScriptCompiler::kConsumeCodeCache);
1364 } 1377 }
1365 v8::Local<v8::Value> result = script->BindToCurrentContext()->Run(); 1378 v8::Local<v8::Value> result = script->BindToCurrentContext()->Run();
1366 CHECK(result->ToString(isolate2)->Equals(v8_str("XY"))); 1379 CHECK(result->ToString(isolate2)->Equals(v8_str("XY")));
1367 } 1380 }
1368 isolate2->Dispose(); 1381 isolate2->Dispose();
1369 } 1382 }
OLDNEW
« no previous file with comments | « test/cctest/test-heap.cc ('k') | test/cctest/test-spaces.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698