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

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

Issue 196133017: Experimental parser: merge r19949 (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/parser
Patch Set: Created 6 years, 9 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 | « test/cctest/test-disasm-x64.cc ('k') | test/cctest/test-heap-profiler.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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 Handle<Smi> twenty_four(Smi::FromInt(24), isolate); 268 Handle<Smi> twenty_four(Smi::FromInt(24), isolate);
269 269
270 { 270 {
271 HandleScope inner_scope(isolate); 271 HandleScope inner_scope(isolate);
272 // Allocate a function and keep it in global object's property. 272 // Allocate a function and keep it in global object's property.
273 Handle<JSFunction> function = 273 Handle<JSFunction> function =
274 factory->NewFunction(name, factory->undefined_value()); 274 factory->NewFunction(name, factory->undefined_value());
275 Handle<Map> initial_map = 275 Handle<Map> initial_map =
276 factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); 276 factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize);
277 function->set_initial_map(*initial_map); 277 function->set_initial_map(*initial_map);
278 JSReceiver::SetProperty(global, name, function, NONE, kNonStrictMode); 278 JSReceiver::SetProperty(global, name, function, NONE, SLOPPY);
279 // Allocate an object. Unrooted after leaving the scope. 279 // Allocate an object. Unrooted after leaving the scope.
280 Handle<JSObject> obj = factory->NewJSObject(function); 280 Handle<JSObject> obj = factory->NewJSObject(function);
281 JSReceiver::SetProperty(obj, prop_name, twenty_three, NONE, kNonStrictMode); 281 JSReceiver::SetProperty(obj, prop_name, twenty_three, NONE, SLOPPY);
282 JSReceiver::SetProperty(obj, prop_namex, twenty_four, NONE, kNonStrictMode); 282 JSReceiver::SetProperty(obj, prop_namex, twenty_four, NONE, SLOPPY);
283 283
284 CHECK_EQ(Smi::FromInt(23), obj->GetProperty(*prop_name)); 284 CHECK_EQ(Smi::FromInt(23), obj->GetProperty(*prop_name));
285 CHECK_EQ(Smi::FromInt(24), obj->GetProperty(*prop_namex)); 285 CHECK_EQ(Smi::FromInt(24), obj->GetProperty(*prop_namex));
286 } 286 }
287 287
288 heap->CollectGarbage(NEW_SPACE); 288 heap->CollectGarbage(NEW_SPACE);
289 289
290 // Function should be alive. 290 // Function should be alive.
291 CHECK(JSReceiver::HasLocalProperty(global, name)); 291 CHECK(JSReceiver::HasLocalProperty(global, name));
292 // Check function is retained. 292 // Check function is retained.
293 Object* func_value = CcTest::i_isolate()->context()->global_object()-> 293 Object* func_value = CcTest::i_isolate()->context()->global_object()->
294 GetProperty(*name)->ToObjectChecked(); 294 GetProperty(*name)->ToObjectChecked();
295 CHECK(func_value->IsJSFunction()); 295 CHECK(func_value->IsJSFunction());
296 Handle<JSFunction> function(JSFunction::cast(func_value)); 296 Handle<JSFunction> function(JSFunction::cast(func_value));
297 297
298 { 298 {
299 HandleScope inner_scope(isolate); 299 HandleScope inner_scope(isolate);
300 // Allocate another object, make it reachable from global. 300 // Allocate another object, make it reachable from global.
301 Handle<JSObject> obj = factory->NewJSObject(function); 301 Handle<JSObject> obj = factory->NewJSObject(function);
302 JSReceiver::SetProperty(global, obj_name, obj, NONE, kNonStrictMode); 302 JSReceiver::SetProperty(global, obj_name, obj, NONE, SLOPPY);
303 JSReceiver::SetProperty(obj, prop_name, twenty_three, NONE, kNonStrictMode); 303 JSReceiver::SetProperty(obj, prop_name, twenty_three, NONE, SLOPPY);
304 } 304 }
305 305
306 // After gc, it should survive. 306 // After gc, it should survive.
307 heap->CollectGarbage(NEW_SPACE); 307 heap->CollectGarbage(NEW_SPACE);
308 308
309 CHECK(JSReceiver::HasLocalProperty(global, obj_name)); 309 CHECK(JSReceiver::HasLocalProperty(global, obj_name));
310 CHECK(CcTest::i_isolate()->context()->global_object()-> 310 CHECK(CcTest::i_isolate()->context()->global_object()->
311 GetProperty(*obj_name)->ToObjectChecked()->IsJSObject()); 311 GetProperty(*obj_name)->ToObjectChecked()->IsJSObject());
312 Object* obj = CcTest::i_isolate()->context()->global_object()-> 312 Object* obj = CcTest::i_isolate()->context()->global_object()->
313 GetProperty(*obj_name)->ToObjectChecked(); 313 GetProperty(*obj_name)->ToObjectChecked();
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
628 factory->NewFunction(name, factory->undefined_value()); 628 factory->NewFunction(name, factory->undefined_value());
629 Handle<Map> initial_map = 629 Handle<Map> initial_map =
630 factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); 630 factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize);
631 function->set_initial_map(*initial_map); 631 function->set_initial_map(*initial_map);
632 632
633 Handle<Smi> twenty_three(Smi::FromInt(23), isolate); 633 Handle<Smi> twenty_three(Smi::FromInt(23), isolate);
634 Handle<Smi> twenty_four(Smi::FromInt(24), isolate); 634 Handle<Smi> twenty_four(Smi::FromInt(24), isolate);
635 635
636 Handle<String> prop_name = factory->InternalizeUtf8String("theSlot"); 636 Handle<String> prop_name = factory->InternalizeUtf8String("theSlot");
637 Handle<JSObject> obj = factory->NewJSObject(function); 637 Handle<JSObject> obj = factory->NewJSObject(function);
638 JSReceiver::SetProperty(obj, prop_name, twenty_three, NONE, kNonStrictMode); 638 JSReceiver::SetProperty(obj, prop_name, twenty_three, NONE, SLOPPY);
639 CHECK_EQ(Smi::FromInt(23), obj->GetProperty(*prop_name)); 639 CHECK_EQ(Smi::FromInt(23), obj->GetProperty(*prop_name));
640 // Check that we can add properties to function objects. 640 // Check that we can add properties to function objects.
641 JSReceiver::SetProperty(function, prop_name, twenty_four, NONE, 641 JSReceiver::SetProperty(function, prop_name, twenty_four, NONE, SLOPPY);
642 kNonStrictMode);
643 CHECK_EQ(Smi::FromInt(24), function->GetProperty(*prop_name)); 642 CHECK_EQ(Smi::FromInt(24), function->GetProperty(*prop_name));
644 } 643 }
645 644
646 645
647 TEST(ObjectProperties) { 646 TEST(ObjectProperties) {
648 CcTest::InitializeVM(); 647 CcTest::InitializeVM();
649 Isolate* isolate = CcTest::i_isolate(); 648 Isolate* isolate = CcTest::i_isolate();
650 Factory* factory = isolate->factory(); 649 Factory* factory = isolate->factory();
651 650
652 v8::HandleScope sc(CcTest::isolate()); 651 v8::HandleScope sc(CcTest::isolate());
653 String* object_string = String::cast(CcTest::heap()->Object_string()); 652 String* object_string = String::cast(CcTest::heap()->Object_string());
654 Object* raw_object = CcTest::i_isolate()->context()->global_object()-> 653 Object* raw_object = CcTest::i_isolate()->context()->global_object()->
655 GetProperty(object_string)->ToObjectChecked(); 654 GetProperty(object_string)->ToObjectChecked();
656 JSFunction* object_function = JSFunction::cast(raw_object); 655 JSFunction* object_function = JSFunction::cast(raw_object);
657 Handle<JSFunction> constructor(object_function); 656 Handle<JSFunction> constructor(object_function);
658 Handle<JSObject> obj = factory->NewJSObject(constructor); 657 Handle<JSObject> obj = factory->NewJSObject(constructor);
659 Handle<String> first = factory->InternalizeUtf8String("first"); 658 Handle<String> first = factory->InternalizeUtf8String("first");
660 Handle<String> second = factory->InternalizeUtf8String("second"); 659 Handle<String> second = factory->InternalizeUtf8String("second");
661 660
662 Handle<Smi> one(Smi::FromInt(1), isolate); 661 Handle<Smi> one(Smi::FromInt(1), isolate);
663 Handle<Smi> two(Smi::FromInt(2), isolate); 662 Handle<Smi> two(Smi::FromInt(2), isolate);
664 663
665 // check for empty 664 // check for empty
666 CHECK(!JSReceiver::HasLocalProperty(obj, first)); 665 CHECK(!JSReceiver::HasLocalProperty(obj, first));
667 666
668 // add first 667 // add first
669 JSReceiver::SetProperty(obj, first, one, NONE, kNonStrictMode); 668 JSReceiver::SetProperty(obj, first, one, NONE, SLOPPY);
670 CHECK(JSReceiver::HasLocalProperty(obj, first)); 669 CHECK(JSReceiver::HasLocalProperty(obj, first));
671 670
672 // delete first 671 // delete first
673 JSReceiver::DeleteProperty(obj, first, JSReceiver::NORMAL_DELETION); 672 JSReceiver::DeleteProperty(obj, first, JSReceiver::NORMAL_DELETION);
674 CHECK(!JSReceiver::HasLocalProperty(obj, first)); 673 CHECK(!JSReceiver::HasLocalProperty(obj, first));
675 674
676 // add first and then second 675 // add first and then second
677 JSReceiver::SetProperty(obj, first, one, NONE, kNonStrictMode); 676 JSReceiver::SetProperty(obj, first, one, NONE, SLOPPY);
678 JSReceiver::SetProperty(obj, second, two, NONE, kNonStrictMode); 677 JSReceiver::SetProperty(obj, second, two, NONE, SLOPPY);
679 CHECK(JSReceiver::HasLocalProperty(obj, first)); 678 CHECK(JSReceiver::HasLocalProperty(obj, first));
680 CHECK(JSReceiver::HasLocalProperty(obj, second)); 679 CHECK(JSReceiver::HasLocalProperty(obj, second));
681 680
682 // delete first and then second 681 // delete first and then second
683 JSReceiver::DeleteProperty(obj, first, JSReceiver::NORMAL_DELETION); 682 JSReceiver::DeleteProperty(obj, first, JSReceiver::NORMAL_DELETION);
684 CHECK(JSReceiver::HasLocalProperty(obj, second)); 683 CHECK(JSReceiver::HasLocalProperty(obj, second));
685 JSReceiver::DeleteProperty(obj, second, JSReceiver::NORMAL_DELETION); 684 JSReceiver::DeleteProperty(obj, second, JSReceiver::NORMAL_DELETION);
686 CHECK(!JSReceiver::HasLocalProperty(obj, first)); 685 CHECK(!JSReceiver::HasLocalProperty(obj, first));
687 CHECK(!JSReceiver::HasLocalProperty(obj, second)); 686 CHECK(!JSReceiver::HasLocalProperty(obj, second));
688 687
689 // add first and then second 688 // add first and then second
690 JSReceiver::SetProperty(obj, first, one, NONE, kNonStrictMode); 689 JSReceiver::SetProperty(obj, first, one, NONE, SLOPPY);
691 JSReceiver::SetProperty(obj, second, two, NONE, kNonStrictMode); 690 JSReceiver::SetProperty(obj, second, two, NONE, SLOPPY);
692 CHECK(JSReceiver::HasLocalProperty(obj, first)); 691 CHECK(JSReceiver::HasLocalProperty(obj, first));
693 CHECK(JSReceiver::HasLocalProperty(obj, second)); 692 CHECK(JSReceiver::HasLocalProperty(obj, second));
694 693
695 // delete second and then first 694 // delete second and then first
696 JSReceiver::DeleteProperty(obj, second, JSReceiver::NORMAL_DELETION); 695 JSReceiver::DeleteProperty(obj, second, JSReceiver::NORMAL_DELETION);
697 CHECK(JSReceiver::HasLocalProperty(obj, first)); 696 CHECK(JSReceiver::HasLocalProperty(obj, first));
698 JSReceiver::DeleteProperty(obj, first, JSReceiver::NORMAL_DELETION); 697 JSReceiver::DeleteProperty(obj, first, JSReceiver::NORMAL_DELETION);
699 CHECK(!JSReceiver::HasLocalProperty(obj, first)); 698 CHECK(!JSReceiver::HasLocalProperty(obj, first));
700 CHECK(!JSReceiver::HasLocalProperty(obj, second)); 699 CHECK(!JSReceiver::HasLocalProperty(obj, second));
701 700
702 // check string and internalized string match 701 // check string and internalized string match
703 const char* string1 = "fisk"; 702 const char* string1 = "fisk";
704 Handle<String> s1 = factory->NewStringFromAscii(CStrVector(string1)); 703 Handle<String> s1 = factory->NewStringFromAscii(CStrVector(string1));
705 JSReceiver::SetProperty(obj, s1, one, NONE, kNonStrictMode); 704 JSReceiver::SetProperty(obj, s1, one, NONE, SLOPPY);
706 Handle<String> s1_string = factory->InternalizeUtf8String(string1); 705 Handle<String> s1_string = factory->InternalizeUtf8String(string1);
707 CHECK(JSReceiver::HasLocalProperty(obj, s1_string)); 706 CHECK(JSReceiver::HasLocalProperty(obj, s1_string));
708 707
709 // check internalized string and string match 708 // check internalized string and string match
710 const char* string2 = "fugl"; 709 const char* string2 = "fugl";
711 Handle<String> s2_string = factory->InternalizeUtf8String(string2); 710 Handle<String> s2_string = factory->InternalizeUtf8String(string2);
712 JSReceiver::SetProperty(obj, s2_string, one, NONE, kNonStrictMode); 711 JSReceiver::SetProperty(obj, s2_string, one, NONE, SLOPPY);
713 Handle<String> s2 = factory->NewStringFromAscii(CStrVector(string2)); 712 Handle<String> s2 = factory->NewStringFromAscii(CStrVector(string2));
714 CHECK(JSReceiver::HasLocalProperty(obj, s2)); 713 CHECK(JSReceiver::HasLocalProperty(obj, s2));
715 } 714 }
716 715
717 716
718 TEST(JSObjectMaps) { 717 TEST(JSObjectMaps) {
719 CcTest::InitializeVM(); 718 CcTest::InitializeVM();
720 Isolate* isolate = CcTest::i_isolate(); 719 Isolate* isolate = CcTest::i_isolate();
721 Factory* factory = isolate->factory(); 720 Factory* factory = isolate->factory();
722 721
723 v8::HandleScope sc(CcTest::isolate()); 722 v8::HandleScope sc(CcTest::isolate());
724 Handle<String> name = factory->InternalizeUtf8String("theFunction"); 723 Handle<String> name = factory->InternalizeUtf8String("theFunction");
725 Handle<JSFunction> function = 724 Handle<JSFunction> function =
726 factory->NewFunction(name, factory->undefined_value()); 725 factory->NewFunction(name, factory->undefined_value());
727 Handle<Map> initial_map = 726 Handle<Map> initial_map =
728 factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); 727 factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize);
729 function->set_initial_map(*initial_map); 728 function->set_initial_map(*initial_map);
730 729
731 Handle<String> prop_name = factory->InternalizeUtf8String("theSlot"); 730 Handle<String> prop_name = factory->InternalizeUtf8String("theSlot");
732 Handle<JSObject> obj = factory->NewJSObject(function); 731 Handle<JSObject> obj = factory->NewJSObject(function);
733 732
734 // Set a propery 733 // Set a propery
735 Handle<Smi> twenty_three(Smi::FromInt(23), isolate); 734 Handle<Smi> twenty_three(Smi::FromInt(23), isolate);
736 JSReceiver::SetProperty(obj, prop_name, twenty_three, NONE, kNonStrictMode); 735 JSReceiver::SetProperty(obj, prop_name, twenty_three, NONE, SLOPPY);
737 CHECK_EQ(Smi::FromInt(23), obj->GetProperty(*prop_name)); 736 CHECK_EQ(Smi::FromInt(23), obj->GetProperty(*prop_name));
738 737
739 // Check the map has changed 738 // Check the map has changed
740 CHECK(*initial_map != obj->map()); 739 CHECK(*initial_map != obj->map());
741 } 740 }
742 741
743 742
744 TEST(JSArray) { 743 TEST(JSArray) {
745 CcTest::InitializeVM(); 744 CcTest::InitializeVM();
746 Isolate* isolate = CcTest::i_isolate(); 745 Isolate* isolate = CcTest::i_isolate();
(...skipping 12 matching lines...) Expand all
759 // We just initialized the VM, no heap allocation failure yet. 758 // We just initialized the VM, no heap allocation failure yet.
760 array->Initialize(0)->ToObjectChecked(); 759 array->Initialize(0)->ToObjectChecked();
761 760
762 // Set array length to 0. 761 // Set array length to 0.
763 array->SetElementsLength(Smi::FromInt(0))->ToObjectChecked(); 762 array->SetElementsLength(Smi::FromInt(0))->ToObjectChecked();
764 CHECK_EQ(Smi::FromInt(0), array->length()); 763 CHECK_EQ(Smi::FromInt(0), array->length());
765 // Must be in fast mode. 764 // Must be in fast mode.
766 CHECK(array->HasFastSmiOrObjectElements()); 765 CHECK(array->HasFastSmiOrObjectElements());
767 766
768 // array[length] = name. 767 // array[length] = name.
769 JSReceiver::SetElement(array, 0, name, NONE, kNonStrictMode); 768 JSReceiver::SetElement(array, 0, name, NONE, SLOPPY);
770 CHECK_EQ(Smi::FromInt(1), array->length()); 769 CHECK_EQ(Smi::FromInt(1), array->length());
771 CHECK_EQ(array->GetElement(isolate, 0), *name); 770 CHECK_EQ(array->GetElement(isolate, 0), *name);
772 771
773 // Set array length with larger than smi value. 772 // Set array length with larger than smi value.
774 Handle<Object> length = 773 Handle<Object> length =
775 factory->NewNumberFromUint(static_cast<uint32_t>(Smi::kMaxValue) + 1); 774 factory->NewNumberFromUint(static_cast<uint32_t>(Smi::kMaxValue) + 1);
776 array->SetElementsLength(*length)->ToObjectChecked(); 775 array->SetElementsLength(*length)->ToObjectChecked();
777 776
778 uint32_t int_length = 0; 777 uint32_t int_length = 0;
779 CHECK(length->ToArrayIndex(&int_length)); 778 CHECK(length->ToArrayIndex(&int_length));
780 CHECK_EQ(*length, array->length()); 779 CHECK_EQ(*length, array->length());
781 CHECK(array->HasDictionaryElements()); // Must be in slow mode. 780 CHECK(array->HasDictionaryElements()); // Must be in slow mode.
782 781
783 // array[length] = name. 782 // array[length] = name.
784 JSReceiver::SetElement(array, int_length, name, NONE, kNonStrictMode); 783 JSReceiver::SetElement(array, int_length, name, NONE, SLOPPY);
785 uint32_t new_int_length = 0; 784 uint32_t new_int_length = 0;
786 CHECK(array->length()->ToArrayIndex(&new_int_length)); 785 CHECK(array->length()->ToArrayIndex(&new_int_length));
787 CHECK_EQ(static_cast<double>(int_length), new_int_length - 1); 786 CHECK_EQ(static_cast<double>(int_length), new_int_length - 1);
788 CHECK_EQ(array->GetElement(isolate, int_length), *name); 787 CHECK_EQ(array->GetElement(isolate, int_length), *name);
789 CHECK_EQ(array->GetElement(isolate, 0), *name); 788 CHECK_EQ(array->GetElement(isolate, 0), *name);
790 } 789 }
791 790
792 791
793 TEST(JSObjectCopy) { 792 TEST(JSObjectCopy) {
794 CcTest::InitializeVM(); 793 CcTest::InitializeVM();
795 Isolate* isolate = CcTest::i_isolate(); 794 Isolate* isolate = CcTest::i_isolate();
796 Factory* factory = isolate->factory(); 795 Factory* factory = isolate->factory();
797 796
798 v8::HandleScope sc(CcTest::isolate()); 797 v8::HandleScope sc(CcTest::isolate());
799 String* object_string = String::cast(CcTest::heap()->Object_string()); 798 String* object_string = String::cast(CcTest::heap()->Object_string());
800 Object* raw_object = CcTest::i_isolate()->context()->global_object()-> 799 Object* raw_object = CcTest::i_isolate()->context()->global_object()->
801 GetProperty(object_string)->ToObjectChecked(); 800 GetProperty(object_string)->ToObjectChecked();
802 JSFunction* object_function = JSFunction::cast(raw_object); 801 JSFunction* object_function = JSFunction::cast(raw_object);
803 Handle<JSFunction> constructor(object_function); 802 Handle<JSFunction> constructor(object_function);
804 Handle<JSObject> obj = factory->NewJSObject(constructor); 803 Handle<JSObject> obj = factory->NewJSObject(constructor);
805 Handle<String> first = factory->InternalizeUtf8String("first"); 804 Handle<String> first = factory->InternalizeUtf8String("first");
806 Handle<String> second = factory->InternalizeUtf8String("second"); 805 Handle<String> second = factory->InternalizeUtf8String("second");
807 806
808 Handle<Smi> one(Smi::FromInt(1), isolate); 807 Handle<Smi> one(Smi::FromInt(1), isolate);
809 Handle<Smi> two(Smi::FromInt(2), isolate); 808 Handle<Smi> two(Smi::FromInt(2), isolate);
810 809
811 JSReceiver::SetProperty(obj, first, one, NONE, kNonStrictMode); 810 JSReceiver::SetProperty(obj, first, one, NONE, SLOPPY);
812 JSReceiver::SetProperty(obj, second, two, NONE, kNonStrictMode); 811 JSReceiver::SetProperty(obj, second, two, NONE, SLOPPY);
813 812
814 JSReceiver::SetElement(obj, 0, first, NONE, kNonStrictMode); 813 JSReceiver::SetElement(obj, 0, first, NONE, SLOPPY);
815 JSReceiver::SetElement(obj, 1, second, NONE, kNonStrictMode); 814 JSReceiver::SetElement(obj, 1, second, NONE, SLOPPY);
816 815
817 // Make the clone. 816 // Make the clone.
818 Handle<JSObject> clone = JSObject::Copy(obj); 817 Handle<JSObject> clone = JSObject::Copy(obj);
819 CHECK(!clone.is_identical_to(obj)); 818 CHECK(!clone.is_identical_to(obj));
820 819
821 CHECK_EQ(obj->GetElement(isolate, 0), clone->GetElement(isolate, 0)); 820 CHECK_EQ(obj->GetElement(isolate, 0), clone->GetElement(isolate, 0));
822 CHECK_EQ(obj->GetElement(isolate, 1), clone->GetElement(isolate, 1)); 821 CHECK_EQ(obj->GetElement(isolate, 1), clone->GetElement(isolate, 1));
823 822
824 CHECK_EQ(obj->GetProperty(*first), clone->GetProperty(*first)); 823 CHECK_EQ(obj->GetProperty(*first), clone->GetProperty(*first));
825 CHECK_EQ(obj->GetProperty(*second), clone->GetProperty(*second)); 824 CHECK_EQ(obj->GetProperty(*second), clone->GetProperty(*second));
826 825
827 // Flip the values. 826 // Flip the values.
828 JSReceiver::SetProperty(clone, first, two, NONE, kNonStrictMode); 827 JSReceiver::SetProperty(clone, first, two, NONE, SLOPPY);
829 JSReceiver::SetProperty(clone, second, one, NONE, kNonStrictMode); 828 JSReceiver::SetProperty(clone, second, one, NONE, SLOPPY);
830 829
831 JSReceiver::SetElement(clone, 0, second, NONE, kNonStrictMode); 830 JSReceiver::SetElement(clone, 0, second, NONE, SLOPPY);
832 JSReceiver::SetElement(clone, 1, first, NONE, kNonStrictMode); 831 JSReceiver::SetElement(clone, 1, first, NONE, SLOPPY);
833 832
834 CHECK_EQ(obj->GetElement(isolate, 1), clone->GetElement(isolate, 0)); 833 CHECK_EQ(obj->GetElement(isolate, 1), clone->GetElement(isolate, 0));
835 CHECK_EQ(obj->GetElement(isolate, 0), clone->GetElement(isolate, 1)); 834 CHECK_EQ(obj->GetElement(isolate, 0), clone->GetElement(isolate, 1));
836 835
837 CHECK_EQ(obj->GetProperty(*second), clone->GetProperty(*first)); 836 CHECK_EQ(obj->GetProperty(*second), clone->GetProperty(*first));
838 CHECK_EQ(obj->GetProperty(*first), clone->GetProperty(*second)); 837 CHECK_EQ(obj->GetProperty(*first), clone->GetProperty(*second));
839 } 838 }
840 839
841 840
842 TEST(StringAllocation) { 841 TEST(StringAllocation) {
(...skipping 1154 matching lines...) Expand 10 before | Expand all | Expand 10 after
1997 CcTest::heap()->CollectGarbage(OLD_POINTER_SPACE); 1996 CcTest::heap()->CollectGarbage(OLD_POINTER_SPACE);
1998 } 1997 }
1999 1998
2000 1999
2001 TEST(PrototypeTransitionClearing) { 2000 TEST(PrototypeTransitionClearing) {
2002 CcTest::InitializeVM(); 2001 CcTest::InitializeVM();
2003 Isolate* isolate = CcTest::i_isolate(); 2002 Isolate* isolate = CcTest::i_isolate();
2004 Factory* factory = isolate->factory(); 2003 Factory* factory = isolate->factory();
2005 v8::HandleScope scope(CcTest::isolate()); 2004 v8::HandleScope scope(CcTest::isolate());
2006 2005
2006 CompileRun("var base = {};");
2007 Handle<JSObject> baseObject =
2008 v8::Utils::OpenHandle(
2009 *v8::Handle<v8::Object>::Cast(
2010 CcTest::global()->Get(v8_str("base"))));
2011 int initialTransitions = baseObject->map()->NumberOfProtoTransitions();
2012
2007 CompileRun( 2013 CompileRun(
2008 "var base = {};"
2009 "var live = [];" 2014 "var live = [];"
2010 "for (var i = 0; i < 10; i++) {" 2015 "for (var i = 0; i < 10; i++) {"
2011 " var object = {};" 2016 " var object = {};"
2012 " var prototype = {};" 2017 " var prototype = {};"
2013 " object.__proto__ = prototype;" 2018 " object.__proto__ = prototype;"
2014 " if (i >= 3) live.push(object, prototype);" 2019 " if (i >= 3) live.push(object, prototype);"
2015 "}"); 2020 "}");
2016 2021
2017 Handle<JSObject> baseObject =
2018 v8::Utils::OpenHandle(
2019 *v8::Handle<v8::Object>::Cast(
2020 CcTest::global()->Get(v8_str("base"))));
2021
2022 // Verify that only dead prototype transitions are cleared. 2022 // Verify that only dead prototype transitions are cleared.
2023 CHECK_EQ(10, baseObject->map()->NumberOfProtoTransitions()); 2023 CHECK_EQ(initialTransitions + 10,
2024 baseObject->map()->NumberOfProtoTransitions());
2024 CcTest::heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); 2025 CcTest::heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
2025 const int transitions = 10 - 3; 2026 const int transitions = 10 - 3;
2026 CHECK_EQ(transitions, baseObject->map()->NumberOfProtoTransitions()); 2027 CHECK_EQ(initialTransitions + transitions,
2028 baseObject->map()->NumberOfProtoTransitions());
2027 2029
2028 // Verify that prototype transitions array was compacted. 2030 // Verify that prototype transitions array was compacted.
2029 FixedArray* trans = baseObject->map()->GetPrototypeTransitions(); 2031 FixedArray* trans = baseObject->map()->GetPrototypeTransitions();
2030 for (int i = 0; i < transitions; i++) { 2032 for (int i = initialTransitions; i < initialTransitions + transitions; i++) {
2031 int j = Map::kProtoTransitionHeaderSize + 2033 int j = Map::kProtoTransitionHeaderSize +
2032 i * Map::kProtoTransitionElementsPerEntry; 2034 i * Map::kProtoTransitionElementsPerEntry;
2033 CHECK(trans->get(j + Map::kProtoTransitionMapOffset)->IsMap()); 2035 CHECK(trans->get(j + Map::kProtoTransitionMapOffset)->IsMap());
2034 Object* proto = trans->get(j + Map::kProtoTransitionPrototypeOffset); 2036 Object* proto = trans->get(j + Map::kProtoTransitionPrototypeOffset);
2035 CHECK(proto->IsTheHole() || proto->IsJSObject()); 2037 CHECK(proto->IsJSObject());
2036 } 2038 }
2037 2039
2038 // Make sure next prototype is placed on an old-space evacuation candidate. 2040 // Make sure next prototype is placed on an old-space evacuation candidate.
2039 Handle<JSObject> prototype; 2041 Handle<JSObject> prototype;
2040 PagedSpace* space = CcTest::heap()->old_pointer_space(); 2042 PagedSpace* space = CcTest::heap()->old_pointer_space();
2041 { 2043 {
2042 AlwaysAllocateScope always_allocate; 2044 AlwaysAllocateScope always_allocate;
2043 SimulateFullSpace(space); 2045 SimulateFullSpace(space);
2044 prototype = factory->NewJSArray(32 * KB, FAST_HOLEY_ELEMENTS, TENURED); 2046 prototype = factory->NewJSArray(32 * KB, FAST_HOLEY_ELEMENTS, TENURED);
2045 } 2047 }
(...skipping 802 matching lines...) Expand 10 before | Expand all | Expand 10 after
2848 // originating from two different native contexts. 2850 // originating from two different native contexts.
2849 CcTest::global()->Set(v8_str("fun1"), fun1); 2851 CcTest::global()->Set(v8_str("fun1"), fun1);
2850 CcTest::global()->Set(v8_str("fun2"), fun2); 2852 CcTest::global()->Set(v8_str("fun2"), fun2);
2851 CompileRun("function f(a, b) { a(); b(); } f(fun1, fun2);"); 2853 CompileRun("function f(a, b) { a(); b(); } f(fun1, fun2);");
2852 2854
2853 Handle<JSFunction> f = 2855 Handle<JSFunction> f =
2854 v8::Utils::OpenHandle( 2856 v8::Utils::OpenHandle(
2855 *v8::Handle<v8::Function>::Cast( 2857 *v8::Handle<v8::Function>::Cast(
2856 CcTest::global()->Get(v8_str("f")))); 2858 CcTest::global()->Get(v8_str("f"))));
2857 2859
2858 Handle<FixedArray> feedback_vector(TypeFeedbackInfo::cast( 2860 Handle<FixedArray> feedback_vector(f->shared()->feedback_vector());
2859 f->shared()->code()->type_feedback_info())->feedback_vector());
2860 2861
2861 CHECK_EQ(2, feedback_vector->length()); 2862 CHECK_EQ(2, feedback_vector->length());
2862 CHECK(feedback_vector->get(0)->IsJSFunction()); 2863 CHECK(feedback_vector->get(0)->IsJSFunction());
2863 CHECK(feedback_vector->get(1)->IsJSFunction()); 2864 CHECK(feedback_vector->get(1)->IsJSFunction());
2864 2865
2865 SimulateIncrementalMarking(); 2866 SimulateIncrementalMarking();
2866 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); 2867 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags);
2867 2868
2868 CHECK_EQ(2, feedback_vector->length()); 2869 CHECK_EQ(2, feedback_vector->length());
2869 CHECK(feedback_vector->get(0)->IsTheHole()); 2870 CHECK_EQ(feedback_vector->get(0),
2870 CHECK(feedback_vector->get(1)->IsTheHole()); 2871 *TypeFeedbackInfo::UninitializedSentinel(CcTest::i_isolate()));
2872 CHECK_EQ(feedback_vector->get(1),
2873 *TypeFeedbackInfo::UninitializedSentinel(CcTest::i_isolate()));
2871 } 2874 }
2872 2875
2873 2876
2874 static Code* FindFirstIC(Code* code, Code::Kind kind) { 2877 static Code* FindFirstIC(Code* code, Code::Kind kind) {
2875 int mask = RelocInfo::ModeMask(RelocInfo::CODE_TARGET) | 2878 int mask = RelocInfo::ModeMask(RelocInfo::CODE_TARGET) |
2876 RelocInfo::ModeMask(RelocInfo::CONSTRUCT_CALL) | 2879 RelocInfo::ModeMask(RelocInfo::CONSTRUCT_CALL) |
2877 RelocInfo::ModeMask(RelocInfo::CODE_TARGET_WITH_ID); 2880 RelocInfo::ModeMask(RelocInfo::CODE_TARGET_WITH_ID);
2878 for (RelocIterator it(code, mask); !it.done(); it.next()) { 2881 for (RelocIterator it(code, mask); !it.done(); it.next()) {
2879 RelocInfo* info = it.rinfo(); 2882 RelocInfo* info = it.rinfo();
2880 Code* target = Code::GetCodeFromTargetAddress(info->target_address()); 2883 Code* target = Code::GetCodeFromTargetAddress(info->target_address());
(...skipping 805 matching lines...) Expand 10 before | Expand all | Expand 10 after
3686 code = scope.CloseAndEscape(Handle<Code>(bar->code())); 3689 code = scope.CloseAndEscape(Handle<Code>(bar->code()));
3687 } 3690 }
3688 3691
3689 // Now make sure that a gc should get rid of the function 3692 // Now make sure that a gc should get rid of the function
3690 for (int i = 0; i < 4; i++) { 3693 for (int i = 0; i < 4; i++) {
3691 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); 3694 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
3692 } 3695 }
3693 3696
3694 ASSERT(code->marked_for_deoptimization()); 3697 ASSERT(code->marked_for_deoptimization());
3695 } 3698 }
3699
3700
3701 #ifdef DEBUG
3702 TEST(AddInstructionChangesNewSpacePromotion) {
3703 i::FLAG_allow_natives_syntax = true;
3704 i::FLAG_expose_gc = true;
3705 i::FLAG_stress_compaction = true;
3706 i::FLAG_gc_interval = 1000;
3707 CcTest::InitializeVM();
3708 if (!i::FLAG_allocation_site_pretenuring) return;
3709 v8::HandleScope scope(CcTest::isolate());
3710 Isolate* isolate = CcTest::i_isolate();
3711 Heap* heap = isolate->heap();
3712
3713 CompileRun(
3714 "function add(a, b) {"
3715 " return a + b;"
3716 "}"
3717 "add(1, 2);"
3718 "add(\"a\", \"b\");"
3719 "var oldSpaceObject;"
3720 "gc();"
3721 "function crash(x) {"
3722 " var object = {a: null, b: null};"
3723 " var result = add(1.5, x | 0);"
3724 " object.a = result;"
3725 " oldSpaceObject = object;"
3726 " return object;"
3727 "}"
3728 "crash(1);"
3729 "crash(1);"
3730 "%OptimizeFunctionOnNextCall(crash);"
3731 "crash(1);");
3732
3733 v8::Handle<v8::Object> global = CcTest::global();
3734 v8::Handle<v8::Function> g =
3735 v8::Handle<v8::Function>::Cast(global->Get(v8_str("crash")));
3736 v8::Handle<v8::Value> args1[] = { v8_num(1) };
3737 heap->DisableInlineAllocation();
3738 heap->set_allocation_timeout(1);
3739 g->Call(global, 1, args1);
3740 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
3741 }
3742 #endif
OLDNEW
« no previous file with comments | « test/cctest/test-disasm-x64.cc ('k') | test/cctest/test-heap-profiler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698