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

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

Issue 394793002: Verify that source string matches serialized code. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: add check that compilation did not trigger when deserializing Created 6 years, 5 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/serialize.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 14 matching lines...) Expand all
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 #include <signal.h> 28 #include <signal.h>
29 29
30 #include <sys/stat.h> 30 #include <sys/stat.h>
31 31
32 #include "src/v8.h" 32 #include "src/v8.h"
33 33
34 #include "src/bootstrapper.h" 34 #include "src/bootstrapper.h"
35 #include "src/compilation-cache.h"
35 #include "src/debug.h" 36 #include "src/debug.h"
36 #include "src/ic-inl.h" 37 #include "src/ic-inl.h"
37 #include "src/natives.h" 38 #include "src/natives.h"
38 #include "src/objects.h" 39 #include "src/objects.h"
39 #include "src/runtime.h" 40 #include "src/runtime.h"
40 #include "src/scopeinfo.h" 41 #include "src/scopeinfo.h"
41 #include "src/serialize.h" 42 #include "src/serialize.h"
42 #include "src/snapshot.h" 43 #include "src/snapshot.h"
43 #include "src/spaces.h" 44 #include "src/spaces.h"
44 #include "test/cctest/cctest.h" 45 #include "test/cctest/cctest.h"
(...skipping 623 matching lines...) Expand 10 before | Expand all | Expand 10 after
668 HeapIterator iterator(CcTest::heap()); 669 HeapIterator iterator(CcTest::heap());
669 DisallowHeapAllocation no_allocation; 670 DisallowHeapAllocation no_allocation;
670 int counter = 0; 671 int counter = 0;
671 for (HeapObject* obj = iterator.next(); obj != NULL; obj = iterator.next()) { 672 for (HeapObject* obj = iterator.next(); obj != NULL; obj = iterator.next()) {
672 if (obj->IsCode() && Code::cast(obj)->kind() == Code::BUILTIN) counter++; 673 if (obj->IsCode() && Code::cast(obj)->kind() == Code::BUILTIN) counter++;
673 } 674 }
674 return counter; 675 return counter;
675 } 676 }
676 677
677 678
679 static int compile_counter = 0;
680
681 void* CreateHistogramForCompiling(const char* name, int min, int max,
682 size_t buckets) {
683 if (strcmp(name, "V8.Compile") == 0) return reinterpret_cast<void*>(1);
684 return NULL;
685 }
686
687
688 void AddHistogramSampleCallback(void* histogram, int sample) {
689 compile_counter++;
690 }
691
692
678 TEST(SerializeToplevelOnePlusOne) { 693 TEST(SerializeToplevelOnePlusOne) {
679 FLAG_serialize_toplevel = true; 694 FLAG_serialize_toplevel = true;
680 LocalContext context; 695 LocalContext context;
696 // We use histogram counters to verify that compile did not trigger when
mvstanton 2014/07/15 14:39:36 Could this "VerifyNoCompilation" stuff be wrapped
697 // we intend to deserialize code from cache.
698 CcTest::isolate()->SetCreateHistogramFunction(CreateHistogramForCompiling);
699 CcTest::isolate()->SetAddHistogramSampleFunction(AddHistogramSampleCallback);
700 Isolate* isolate = CcTest::i_isolate();
701 isolate->compilation_cache()->Disable(); // Disable same-isolate code cache.
702
681 v8::HandleScope scope(CcTest::isolate()); 703 v8::HandleScope scope(CcTest::isolate());
682 704
683 const char* source1 = "1 + 1"; 705 const char* source = "1 + 1";
684 const char* source2 = "1 + 2"; // Use alternate string to verify caching.
685 706
686 Isolate* isolate = CcTest::i_isolate(); 707 Handle<String> orig_source = isolate->factory()
687 Handle<String> source1_string = isolate->factory() 708 ->NewStringFromUtf8(CStrVector(source))
688 ->NewStringFromUtf8(CStrVector(source1)) 709 .ToHandleChecked();
689 .ToHandleChecked(); 710 Handle<String> copy_source = isolate->factory()
690 711 ->NewStringFromUtf8(CStrVector(source))
691 Handle<String> source2_string = isolate->factory() 712 .ToHandleChecked();
692 ->NewStringFromUtf8(CStrVector(source2)) 713 CHECK(!orig_source.is_identical_to(copy_source));
693 .ToHandleChecked(); 714 CHECK(orig_source->Equals(*copy_source));
694 715
695 ScriptData* cache = NULL; 716 ScriptData* cache = NULL;
717 compile_counter = 0;
696 718
697 Handle<SharedFunctionInfo> orig = 719 Handle<SharedFunctionInfo> orig =
698 Compiler::CompileScript(source1_string, Handle<String>(), 0, 0, false, 720 Compiler::CompileScript(orig_source, Handle<String>(), 0, 0, false,
699 Handle<Context>(isolate->native_context()), NULL, 721 Handle<Context>(isolate->native_context()), NULL,
700 &cache, PRODUCE_CACHED_DATA, NOT_NATIVES_CODE); 722 &cache, PRODUCE_CACHED_DATA, NOT_NATIVES_CODE);
723 CHECK_EQ(1, compile_counter); // Compile counter was incremented.
701 724
702 int builtins_count = CountBuiltins(); 725 int builtins_count = CountBuiltins();
703 726
704 Handle<SharedFunctionInfo> copy = 727 Handle<SharedFunctionInfo> copy =
705 Compiler::CompileScript(source2_string, Handle<String>(), 0, 0, false, 728 Compiler::CompileScript(copy_source, Handle<String>(), 0, 0, false,
706 Handle<Context>(isolate->native_context()), NULL, 729 Handle<Context>(isolate->native_context()), NULL,
707 &cache, CONSUME_CACHED_DATA, NOT_NATIVES_CODE); 730 &cache, CONSUME_CACHED_DATA, NOT_NATIVES_CODE);
708 731 CHECK_EQ(1, compile_counter); // Compile counter was not incremented.
709 CHECK_NE(*orig, *copy); 732 CHECK_NE(*orig, *copy);
710 CHECK(Script::cast(copy->script())->source() == *source2_string); 733 CHECK(Script::cast(copy->script())->source() == *copy_source);
711 734
712 Handle<JSFunction> copy_fun = 735 Handle<JSFunction> copy_fun =
713 isolate->factory()->NewFunctionFromSharedFunctionInfo( 736 isolate->factory()->NewFunctionFromSharedFunctionInfo(
714 copy, isolate->native_context()); 737 copy, isolate->native_context());
715 Handle<JSObject> global(isolate->context()->global_object()); 738 Handle<JSObject> global(isolate->context()->global_object());
716 Handle<Object> copy_result = 739 Handle<Object> copy_result =
717 Execution::Call(isolate, copy_fun, global, 0, NULL).ToHandleChecked(); 740 Execution::Call(isolate, copy_fun, global, 0, NULL).ToHandleChecked();
718 CHECK_EQ(2, Handle<Smi>::cast(copy_result)->value()); 741 CHECK_EQ(2, Handle<Smi>::cast(copy_result)->value());
719 742
720 CHECK_EQ(builtins_count, CountBuiltins()); 743 CHECK_EQ(builtins_count, CountBuiltins());
721 744
722 delete cache; 745 delete cache;
723 } 746 }
724 747
725 748
726 TEST(SerializeToplevelInternalizedString) { 749 TEST(SerializeToplevelInternalizedString) {
727 FLAG_serialize_toplevel = true; 750 FLAG_serialize_toplevel = true;
728 LocalContext context; 751 LocalContext context;
752 // We use histogram counters to verify that compile did not trigger when
753 // we intend to deserialize code from cache.
754 CcTest::isolate()->SetCreateHistogramFunction(CreateHistogramForCompiling);
755 CcTest::isolate()->SetAddHistogramSampleFunction(AddHistogramSampleCallback);
756 Isolate* isolate = CcTest::i_isolate();
757 isolate->compilation_cache()->Disable(); // Disable same-isolate code cache.
758
729 v8::HandleScope scope(CcTest::isolate()); 759 v8::HandleScope scope(CcTest::isolate());
730 760
731 const char* source1 = "'string1'"; 761 const char* source = "'string1'";
732 const char* source2 = "'string2'"; // Use alternate string to verify caching.
733 762
734 Isolate* isolate = CcTest::i_isolate(); 763 Handle<String> orig_source = isolate->factory()
735 Handle<String> source1_string = isolate->factory() 764 ->NewStringFromUtf8(CStrVector(source))
736 ->NewStringFromUtf8(CStrVector(source1)) 765 .ToHandleChecked();
737 .ToHandleChecked(); 766 Handle<String> copy_source = isolate->factory()
767 ->NewStringFromUtf8(CStrVector(source))
768 .ToHandleChecked();
769 CHECK(!orig_source.is_identical_to(copy_source));
770 CHECK(orig_source->Equals(*copy_source));
738 771
739 Handle<String> source2_string = isolate->factory()
740 ->NewStringFromUtf8(CStrVector(source2))
741 .ToHandleChecked();
742 Handle<JSObject> global(isolate->context()->global_object()); 772 Handle<JSObject> global(isolate->context()->global_object());
743 ScriptData* cache = NULL; 773 ScriptData* cache = NULL;
774 compile_counter = 0;
744 775
745 Handle<SharedFunctionInfo> orig = 776 Handle<SharedFunctionInfo> orig =
746 Compiler::CompileScript(source1_string, Handle<String>(), 0, 0, false, 777 Compiler::CompileScript(orig_source, Handle<String>(), 0, 0, false,
747 Handle<Context>(isolate->native_context()), NULL, 778 Handle<Context>(isolate->native_context()), NULL,
748 &cache, PRODUCE_CACHED_DATA, NOT_NATIVES_CODE); 779 &cache, PRODUCE_CACHED_DATA, NOT_NATIVES_CODE);
780 CHECK_EQ(1, compile_counter); // Compile counter was incremented.
749 Handle<JSFunction> orig_fun = 781 Handle<JSFunction> orig_fun =
750 isolate->factory()->NewFunctionFromSharedFunctionInfo( 782 isolate->factory()->NewFunctionFromSharedFunctionInfo(
751 orig, isolate->native_context()); 783 orig, isolate->native_context());
752 Handle<Object> orig_result = 784 Handle<Object> orig_result =
753 Execution::Call(isolate, orig_fun, global, 0, NULL).ToHandleChecked(); 785 Execution::Call(isolate, orig_fun, global, 0, NULL).ToHandleChecked();
754 CHECK(orig_result->IsInternalizedString()); 786 CHECK(orig_result->IsInternalizedString());
755 787
756 int builtins_count = CountBuiltins(); 788 int builtins_count = CountBuiltins();
757 789
758 Handle<SharedFunctionInfo> copy = 790 Handle<SharedFunctionInfo> copy =
759 Compiler::CompileScript(source2_string, Handle<String>(), 0, 0, false, 791 Compiler::CompileScript(copy_source, Handle<String>(), 0, 0, false,
760 Handle<Context>(isolate->native_context()), NULL, 792 Handle<Context>(isolate->native_context()), NULL,
761 &cache, CONSUME_CACHED_DATA, NOT_NATIVES_CODE); 793 &cache, CONSUME_CACHED_DATA, NOT_NATIVES_CODE);
794 CHECK_EQ(1, compile_counter); // Compile counter was not incremented.
762 CHECK_NE(*orig, *copy); 795 CHECK_NE(*orig, *copy);
763 CHECK(Script::cast(copy->script())->source() == *source2_string); 796 CHECK(Script::cast(copy->script())->source() == *copy_source);
764 797
765 Handle<JSFunction> copy_fun = 798 Handle<JSFunction> copy_fun =
766 isolate->factory()->NewFunctionFromSharedFunctionInfo( 799 isolate->factory()->NewFunctionFromSharedFunctionInfo(
767 copy, isolate->native_context()); 800 copy, isolate->native_context());
768 CHECK_NE(*orig_fun, *copy_fun); 801 CHECK_NE(*orig_fun, *copy_fun);
769 Handle<Object> copy_result = 802 Handle<Object> copy_result =
770 Execution::Call(isolate, copy_fun, global, 0, NULL).ToHandleChecked(); 803 Execution::Call(isolate, copy_fun, global, 0, NULL).ToHandleChecked();
771 CHECK(orig_result.is_identical_to(copy_result)); 804 CHECK(orig_result.is_identical_to(copy_result));
772 Handle<String> expected = 805 Handle<String> expected =
773 isolate->factory()->NewStringFromAsciiChecked("string1"); 806 isolate->factory()->NewStringFromAsciiChecked("string1");
774 807
775 CHECK(Handle<String>::cast(copy_result)->Equals(*expected)); 808 CHECK(Handle<String>::cast(copy_result)->Equals(*expected));
776 CHECK_EQ(builtins_count, CountBuiltins()); 809 CHECK_EQ(builtins_count, CountBuiltins());
777 810
778 delete cache; 811 delete cache;
779 } 812 }
OLDNEW
« no previous file with comments | « src/serialize.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698