Chromium Code Reviews

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

Issue 581223004: Support large objects in the serializer/deserializer. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | | Annotate | Revision Log
« src/serialize.h ('K') | « src/snapshot-source-sink.cc ('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 768 matching lines...)
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...)
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 }
OLDNEW
« src/serialize.h ('K') | « src/snapshot-source-sink.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine