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

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

Issue 16337005: Deprecate FACTORY helper macro. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 6 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-func-name-inference.cc ('k') | test/cctest/test-mark-compact.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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 HeapObject* obj_copy = HeapObject::cast(copy); 139 HeapObject* obj_copy = HeapObject::cast(copy);
140 Object* not_right = heap->FindCodeObject(obj_copy->address() + 140 Object* not_right = heap->FindCodeObject(obj_copy->address() +
141 obj_copy->Size() / 2); 141 obj_copy->Size() / 2);
142 CHECK(not_right != code); 142 CHECK(not_right != code);
143 } 143 }
144 144
145 145
146 TEST(HeapObjects) { 146 TEST(HeapObjects) {
147 CcTest::InitializeVM(); 147 CcTest::InitializeVM();
148 Isolate* isolate = Isolate::Current(); 148 Isolate* isolate = Isolate::Current();
149 Factory* factory = isolate->factory();
149 Heap* heap = isolate->heap(); 150 Heap* heap = isolate->heap();
150 151
151 HandleScope sc(isolate); 152 HandleScope sc(isolate);
152 Object* value = heap->NumberFromDouble(1.000123)->ToObjectChecked(); 153 Object* value = heap->NumberFromDouble(1.000123)->ToObjectChecked();
153 CHECK(value->IsHeapNumber()); 154 CHECK(value->IsHeapNumber());
154 CHECK(value->IsNumber()); 155 CHECK(value->IsNumber());
155 CHECK_EQ(1.000123, value->Number()); 156 CHECK_EQ(1.000123, value->Number());
156 157
157 value = heap->NumberFromDouble(1.0)->ToObjectChecked(); 158 value = heap->NumberFromDouble(1.0)->ToObjectChecked();
158 CHECK(value->IsSmi()); 159 CHECK(value->IsSmi());
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 value = maybe_value->ToObjectChecked(); 195 value = maybe_value->ToObjectChecked();
195 CHECK(value->IsHeapNumber()); 196 CHECK(value->IsHeapNumber());
196 CHECK(value->IsNumber()); 197 CHECK(value->IsNumber());
197 CHECK_EQ(static_cast<double>(static_cast<uint32_t>(1) << 31), 198 CHECK_EQ(static_cast<double>(static_cast<uint32_t>(1) << 31),
198 value->Number()); 199 value->Number());
199 200
200 // nan oddball checks 201 // nan oddball checks
201 CHECK(heap->nan_value()->IsNumber()); 202 CHECK(heap->nan_value()->IsNumber());
202 CHECK(std::isnan(heap->nan_value()->Number())); 203 CHECK(std::isnan(heap->nan_value()->Number()));
203 204
204 Handle<String> s = FACTORY->NewStringFromAscii(CStrVector("fisk hest ")); 205 Handle<String> s = factory->NewStringFromAscii(CStrVector("fisk hest "));
205 CHECK(s->IsString()); 206 CHECK(s->IsString());
206 CHECK_EQ(10, s->length()); 207 CHECK_EQ(10, s->length());
207 208
208 String* object_string = String::cast(heap->Object_string()); 209 String* object_string = String::cast(heap->Object_string());
209 CHECK( 210 CHECK(
210 Isolate::Current()->context()->global_object()->HasLocalProperty( 211 Isolate::Current()->context()->global_object()->HasLocalProperty(
211 object_string)); 212 object_string));
212 213
213 // Check ToString for oddballs 214 // Check ToString for oddballs
214 CheckOddball(isolate, heap->true_value(), "true"); 215 CheckOddball(isolate, heap->true_value(), "true");
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 VerifyStringAllocation(isolate, "a"); 333 VerifyStringAllocation(isolate, "a");
333 VerifyStringAllocation(isolate, "ab"); 334 VerifyStringAllocation(isolate, "ab");
334 VerifyStringAllocation(isolate, "abc"); 335 VerifyStringAllocation(isolate, "abc");
335 VerifyStringAllocation(isolate, "abcd"); 336 VerifyStringAllocation(isolate, "abcd");
336 VerifyStringAllocation(isolate, "fiskerdrengen er paa havet"); 337 VerifyStringAllocation(isolate, "fiskerdrengen er paa havet");
337 } 338 }
338 339
339 340
340 TEST(LocalHandles) { 341 TEST(LocalHandles) {
341 CcTest::InitializeVM(); 342 CcTest::InitializeVM();
343 Isolate* isolate = Isolate::Current();
344 Factory* factory = isolate->factory();
342 345
343 v8::HandleScope scope(CcTest::isolate()); 346 v8::HandleScope scope(CcTest::isolate());
344 const char* name = "Kasper the spunky"; 347 const char* name = "Kasper the spunky";
345 Handle<String> string = FACTORY->NewStringFromAscii(CStrVector(name)); 348 Handle<String> string = factory->NewStringFromAscii(CStrVector(name));
346 CHECK_EQ(StrLength(name), string->length()); 349 CHECK_EQ(StrLength(name), string->length());
347 } 350 }
348 351
349 352
350 TEST(GlobalHandles) { 353 TEST(GlobalHandles) {
351 CcTest::InitializeVM(); 354 CcTest::InitializeVM();
352 Isolate* isolate = Isolate::Current(); 355 Isolate* isolate = Isolate::Current();
353 Heap* heap = isolate->heap(); 356 Heap* heap = isolate->heap();
354 Factory* factory = isolate->factory(); 357 Factory* factory = isolate->factory();
355 GlobalHandles* global_handles = isolate->global_handles(); 358 GlobalHandles* global_handles = isolate->global_handles();
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
602 TEST(StringTable) { 605 TEST(StringTable) {
603 CcTest::InitializeVM(); 606 CcTest::InitializeVM();
604 607
605 CheckInternalizedStrings(not_so_random_string_table); 608 CheckInternalizedStrings(not_so_random_string_table);
606 CheckInternalizedStrings(not_so_random_string_table); 609 CheckInternalizedStrings(not_so_random_string_table);
607 } 610 }
608 611
609 612
610 TEST(FunctionAllocation) { 613 TEST(FunctionAllocation) {
611 CcTest::InitializeVM(); 614 CcTest::InitializeVM();
615 Isolate* isolate = Isolate::Current();
616 Factory* factory = isolate->factory();
612 617
613 v8::HandleScope sc(CcTest::isolate()); 618 v8::HandleScope sc(CcTest::isolate());
614 Handle<String> name = FACTORY->InternalizeUtf8String("theFunction"); 619 Handle<String> name = factory->InternalizeUtf8String("theFunction");
615 Handle<JSFunction> function = 620 Handle<JSFunction> function =
616 FACTORY->NewFunction(name, FACTORY->undefined_value()); 621 factory->NewFunction(name, factory->undefined_value());
617 Handle<Map> initial_map = 622 Handle<Map> initial_map =
618 FACTORY->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); 623 factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize);
619 function->set_initial_map(*initial_map); 624 function->set_initial_map(*initial_map);
620 625
621 Handle<String> prop_name = FACTORY->InternalizeUtf8String("theSlot"); 626 Handle<String> prop_name = factory->InternalizeUtf8String("theSlot");
622 Handle<JSObject> obj = FACTORY->NewJSObject(function); 627 Handle<JSObject> obj = factory->NewJSObject(function);
623 obj->SetProperty( 628 obj->SetProperty(
624 *prop_name, Smi::FromInt(23), NONE, kNonStrictMode)->ToObjectChecked(); 629 *prop_name, Smi::FromInt(23), NONE, kNonStrictMode)->ToObjectChecked();
625 CHECK_EQ(Smi::FromInt(23), obj->GetProperty(*prop_name)); 630 CHECK_EQ(Smi::FromInt(23), obj->GetProperty(*prop_name));
626 // Check that we can add properties to function objects. 631 // Check that we can add properties to function objects.
627 function->SetProperty( 632 function->SetProperty(
628 *prop_name, Smi::FromInt(24), NONE, kNonStrictMode)->ToObjectChecked(); 633 *prop_name, Smi::FromInt(24), NONE, kNonStrictMode)->ToObjectChecked();
629 CHECK_EQ(Smi::FromInt(24), function->GetProperty(*prop_name)); 634 CHECK_EQ(Smi::FromInt(24), function->GetProperty(*prop_name));
630 } 635 }
631 636
632 637
633 TEST(ObjectProperties) { 638 TEST(ObjectProperties) {
634 CcTest::InitializeVM(); 639 CcTest::InitializeVM();
640 Isolate* isolate = Isolate::Current();
641 Factory* factory = isolate->factory();
635 642
636 v8::HandleScope sc(CcTest::isolate()); 643 v8::HandleScope sc(CcTest::isolate());
637 String* object_string = String::cast(HEAP->Object_string()); 644 String* object_string = String::cast(HEAP->Object_string());
638 Object* raw_object = Isolate::Current()->context()->global_object()-> 645 Object* raw_object = Isolate::Current()->context()->global_object()->
639 GetProperty(object_string)->ToObjectChecked(); 646 GetProperty(object_string)->ToObjectChecked();
640 JSFunction* object_function = JSFunction::cast(raw_object); 647 JSFunction* object_function = JSFunction::cast(raw_object);
641 Handle<JSFunction> constructor(object_function); 648 Handle<JSFunction> constructor(object_function);
642 Handle<JSObject> obj = FACTORY->NewJSObject(constructor); 649 Handle<JSObject> obj = factory->NewJSObject(constructor);
643 Handle<String> first = FACTORY->InternalizeUtf8String("first"); 650 Handle<String> first = factory->InternalizeUtf8String("first");
644 Handle<String> second = FACTORY->InternalizeUtf8String("second"); 651 Handle<String> second = factory->InternalizeUtf8String("second");
645 652
646 // check for empty 653 // check for empty
647 CHECK(!obj->HasLocalProperty(*first)); 654 CHECK(!obj->HasLocalProperty(*first));
648 655
649 // add first 656 // add first
650 obj->SetProperty( 657 obj->SetProperty(
651 *first, Smi::FromInt(1), NONE, kNonStrictMode)->ToObjectChecked(); 658 *first, Smi::FromInt(1), NONE, kNonStrictMode)->ToObjectChecked();
652 CHECK(obj->HasLocalProperty(*first)); 659 CHECK(obj->HasLocalProperty(*first));
653 660
654 // delete first 661 // delete first
(...skipping 25 matching lines...) Expand all
680 687
681 // delete second and then first 688 // delete second and then first
682 CHECK(obj->DeleteProperty(*second, JSObject::NORMAL_DELETION)); 689 CHECK(obj->DeleteProperty(*second, JSObject::NORMAL_DELETION));
683 CHECK(obj->HasLocalProperty(*first)); 690 CHECK(obj->HasLocalProperty(*first));
684 CHECK(obj->DeleteProperty(*first, JSObject::NORMAL_DELETION)); 691 CHECK(obj->DeleteProperty(*first, JSObject::NORMAL_DELETION));
685 CHECK(!obj->HasLocalProperty(*first)); 692 CHECK(!obj->HasLocalProperty(*first));
686 CHECK(!obj->HasLocalProperty(*second)); 693 CHECK(!obj->HasLocalProperty(*second));
687 694
688 // check string and internalized string match 695 // check string and internalized string match
689 const char* string1 = "fisk"; 696 const char* string1 = "fisk";
690 Handle<String> s1 = FACTORY->NewStringFromAscii(CStrVector(string1)); 697 Handle<String> s1 = factory->NewStringFromAscii(CStrVector(string1));
691 obj->SetProperty( 698 obj->SetProperty(
692 *s1, Smi::FromInt(1), NONE, kNonStrictMode)->ToObjectChecked(); 699 *s1, Smi::FromInt(1), NONE, kNonStrictMode)->ToObjectChecked();
693 Handle<String> s1_string = FACTORY->InternalizeUtf8String(string1); 700 Handle<String> s1_string = factory->InternalizeUtf8String(string1);
694 CHECK(obj->HasLocalProperty(*s1_string)); 701 CHECK(obj->HasLocalProperty(*s1_string));
695 702
696 // check internalized string and string match 703 // check internalized string and string match
697 const char* string2 = "fugl"; 704 const char* string2 = "fugl";
698 Handle<String> s2_string = FACTORY->InternalizeUtf8String(string2); 705 Handle<String> s2_string = factory->InternalizeUtf8String(string2);
699 obj->SetProperty( 706 obj->SetProperty(
700 *s2_string, Smi::FromInt(1), NONE, kNonStrictMode)->ToObjectChecked(); 707 *s2_string, Smi::FromInt(1), NONE, kNonStrictMode)->ToObjectChecked();
701 Handle<String> s2 = FACTORY->NewStringFromAscii(CStrVector(string2)); 708 Handle<String> s2 = factory->NewStringFromAscii(CStrVector(string2));
702 CHECK(obj->HasLocalProperty(*s2)); 709 CHECK(obj->HasLocalProperty(*s2));
703 } 710 }
704 711
705 712
706 TEST(JSObjectMaps) { 713 TEST(JSObjectMaps) {
707 CcTest::InitializeVM(); 714 CcTest::InitializeVM();
715 Isolate* isolate = Isolate::Current();
716 Factory* factory = isolate->factory();
708 717
709 v8::HandleScope sc(CcTest::isolate()); 718 v8::HandleScope sc(CcTest::isolate());
710 Handle<String> name = FACTORY->InternalizeUtf8String("theFunction"); 719 Handle<String> name = factory->InternalizeUtf8String("theFunction");
711 Handle<JSFunction> function = 720 Handle<JSFunction> function =
712 FACTORY->NewFunction(name, FACTORY->undefined_value()); 721 factory->NewFunction(name, factory->undefined_value());
713 Handle<Map> initial_map = 722 Handle<Map> initial_map =
714 FACTORY->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); 723 factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize);
715 function->set_initial_map(*initial_map); 724 function->set_initial_map(*initial_map);
716 725
717 Handle<String> prop_name = FACTORY->InternalizeUtf8String("theSlot"); 726 Handle<String> prop_name = factory->InternalizeUtf8String("theSlot");
718 Handle<JSObject> obj = FACTORY->NewJSObject(function); 727 Handle<JSObject> obj = factory->NewJSObject(function);
719 728
720 // Set a propery 729 // Set a propery
721 obj->SetProperty( 730 obj->SetProperty(
722 *prop_name, Smi::FromInt(23), NONE, kNonStrictMode)->ToObjectChecked(); 731 *prop_name, Smi::FromInt(23), NONE, kNonStrictMode)->ToObjectChecked();
723 CHECK_EQ(Smi::FromInt(23), obj->GetProperty(*prop_name)); 732 CHECK_EQ(Smi::FromInt(23), obj->GetProperty(*prop_name));
724 733
725 // Check the map has changed 734 // Check the map has changed
726 CHECK(*initial_map != obj->map()); 735 CHECK(*initial_map != obj->map());
727 } 736 }
728 737
729 738
730 TEST(JSArray) { 739 TEST(JSArray) {
731 CcTest::InitializeVM(); 740 CcTest::InitializeVM();
741 Isolate* isolate = Isolate::Current();
742 Factory* factory = isolate->factory();
732 743
733 v8::HandleScope sc(CcTest::isolate()); 744 v8::HandleScope sc(CcTest::isolate());
734 Handle<String> name = FACTORY->InternalizeUtf8String("Array"); 745 Handle<String> name = factory->InternalizeUtf8String("Array");
735 Object* raw_object = Isolate::Current()->context()->global_object()-> 746 Object* raw_object = Isolate::Current()->context()->global_object()->
736 GetProperty(*name)->ToObjectChecked(); 747 GetProperty(*name)->ToObjectChecked();
737 Handle<JSFunction> function = Handle<JSFunction>( 748 Handle<JSFunction> function = Handle<JSFunction>(
738 JSFunction::cast(raw_object)); 749 JSFunction::cast(raw_object));
739 750
740 // Allocate the object. 751 // Allocate the object.
741 Handle<JSObject> object = FACTORY->NewJSObject(function); 752 Handle<JSObject> object = factory->NewJSObject(function);
742 Handle<JSArray> array = Handle<JSArray>::cast(object); 753 Handle<JSArray> array = Handle<JSArray>::cast(object);
743 // We just initialized the VM, no heap allocation failure yet. 754 // We just initialized the VM, no heap allocation failure yet.
744 array->Initialize(0)->ToObjectChecked(); 755 array->Initialize(0)->ToObjectChecked();
745 756
746 // Set array length to 0. 757 // Set array length to 0.
747 array->SetElementsLength(Smi::FromInt(0))->ToObjectChecked(); 758 array->SetElementsLength(Smi::FromInt(0))->ToObjectChecked();
748 CHECK_EQ(Smi::FromInt(0), array->length()); 759 CHECK_EQ(Smi::FromInt(0), array->length());
749 // Must be in fast mode. 760 // Must be in fast mode.
750 CHECK(array->HasFastSmiOrObjectElements()); 761 CHECK(array->HasFastSmiOrObjectElements());
751 762
752 // array[length] = name. 763 // array[length] = name.
753 array->SetElement(0, *name, NONE, kNonStrictMode)->ToObjectChecked(); 764 array->SetElement(0, *name, NONE, kNonStrictMode)->ToObjectChecked();
754 CHECK_EQ(Smi::FromInt(1), array->length()); 765 CHECK_EQ(Smi::FromInt(1), array->length());
755 CHECK_EQ(array->GetElement(0), *name); 766 CHECK_EQ(array->GetElement(0), *name);
756 767
757 // Set array length with larger than smi value. 768 // Set array length with larger than smi value.
758 Handle<Object> length = 769 Handle<Object> length =
759 FACTORY->NewNumberFromUint(static_cast<uint32_t>(Smi::kMaxValue) + 1); 770 factory->NewNumberFromUint(static_cast<uint32_t>(Smi::kMaxValue) + 1);
760 array->SetElementsLength(*length)->ToObjectChecked(); 771 array->SetElementsLength(*length)->ToObjectChecked();
761 772
762 uint32_t int_length = 0; 773 uint32_t int_length = 0;
763 CHECK(length->ToArrayIndex(&int_length)); 774 CHECK(length->ToArrayIndex(&int_length));
764 CHECK_EQ(*length, array->length()); 775 CHECK_EQ(*length, array->length());
765 CHECK(array->HasDictionaryElements()); // Must be in slow mode. 776 CHECK(array->HasDictionaryElements()); // Must be in slow mode.
766 777
767 // array[length] = name. 778 // array[length] = name.
768 array->SetElement(int_length, *name, NONE, kNonStrictMode)->ToObjectChecked(); 779 array->SetElement(int_length, *name, NONE, kNonStrictMode)->ToObjectChecked();
769 uint32_t new_int_length = 0; 780 uint32_t new_int_length = 0;
770 CHECK(array->length()->ToArrayIndex(&new_int_length)); 781 CHECK(array->length()->ToArrayIndex(&new_int_length));
771 CHECK_EQ(static_cast<double>(int_length), new_int_length - 1); 782 CHECK_EQ(static_cast<double>(int_length), new_int_length - 1);
772 CHECK_EQ(array->GetElement(int_length), *name); 783 CHECK_EQ(array->GetElement(int_length), *name);
773 CHECK_EQ(array->GetElement(0), *name); 784 CHECK_EQ(array->GetElement(0), *name);
774 } 785 }
775 786
776 787
777 TEST(JSObjectCopy) { 788 TEST(JSObjectCopy) {
778 CcTest::InitializeVM(); 789 CcTest::InitializeVM();
790 Isolate* isolate = Isolate::Current();
791 Factory* factory = isolate->factory();
779 792
780 v8::HandleScope sc(CcTest::isolate()); 793 v8::HandleScope sc(CcTest::isolate());
781 String* object_string = String::cast(HEAP->Object_string()); 794 String* object_string = String::cast(HEAP->Object_string());
782 Object* raw_object = Isolate::Current()->context()->global_object()-> 795 Object* raw_object = Isolate::Current()->context()->global_object()->
783 GetProperty(object_string)->ToObjectChecked(); 796 GetProperty(object_string)->ToObjectChecked();
784 JSFunction* object_function = JSFunction::cast(raw_object); 797 JSFunction* object_function = JSFunction::cast(raw_object);
785 Handle<JSFunction> constructor(object_function); 798 Handle<JSFunction> constructor(object_function);
786 Handle<JSObject> obj = FACTORY->NewJSObject(constructor); 799 Handle<JSObject> obj = factory->NewJSObject(constructor);
787 Handle<String> first = FACTORY->InternalizeUtf8String("first"); 800 Handle<String> first = factory->InternalizeUtf8String("first");
788 Handle<String> second = FACTORY->InternalizeUtf8String("second"); 801 Handle<String> second = factory->InternalizeUtf8String("second");
789 802
790 obj->SetProperty( 803 obj->SetProperty(
791 *first, Smi::FromInt(1), NONE, kNonStrictMode)->ToObjectChecked(); 804 *first, Smi::FromInt(1), NONE, kNonStrictMode)->ToObjectChecked();
792 obj->SetProperty( 805 obj->SetProperty(
793 *second, Smi::FromInt(2), NONE, kNonStrictMode)->ToObjectChecked(); 806 *second, Smi::FromInt(2), NONE, kNonStrictMode)->ToObjectChecked();
794 807
795 obj->SetElement(0, *first, NONE, kNonStrictMode)->ToObjectChecked(); 808 obj->SetElement(0, *first, NONE, kNonStrictMode)->ToObjectChecked();
796 obj->SetElement(1, *second, NONE, kNonStrictMode)->ToObjectChecked(); 809 obj->SetElement(1, *second, NONE, kNonStrictMode)->ToObjectChecked();
797 810
798 // Make the clone. 811 // Make the clone.
(...skipping 18 matching lines...) Expand all
817 CHECK_EQ(obj->GetElement(1), clone->GetElement(0)); 830 CHECK_EQ(obj->GetElement(1), clone->GetElement(0));
818 CHECK_EQ(obj->GetElement(0), clone->GetElement(1)); 831 CHECK_EQ(obj->GetElement(0), clone->GetElement(1));
819 832
820 CHECK_EQ(obj->GetProperty(*second), clone->GetProperty(*first)); 833 CHECK_EQ(obj->GetProperty(*second), clone->GetProperty(*first));
821 CHECK_EQ(obj->GetProperty(*first), clone->GetProperty(*second)); 834 CHECK_EQ(obj->GetProperty(*first), clone->GetProperty(*second));
822 } 835 }
823 836
824 837
825 TEST(StringAllocation) { 838 TEST(StringAllocation) {
826 CcTest::InitializeVM(); 839 CcTest::InitializeVM();
840 Isolate* isolate = Isolate::Current();
841 Factory* factory = isolate->factory();
827 842
828 const unsigned char chars[] = { 0xe5, 0xa4, 0xa7 }; 843 const unsigned char chars[] = { 0xe5, 0xa4, 0xa7 };
829 for (int length = 0; length < 100; length++) { 844 for (int length = 0; length < 100; length++) {
830 v8::HandleScope scope(CcTest::isolate()); 845 v8::HandleScope scope(CcTest::isolate());
831 char* non_ascii = NewArray<char>(3 * length + 1); 846 char* non_ascii = NewArray<char>(3 * length + 1);
832 char* ascii = NewArray<char>(length + 1); 847 char* ascii = NewArray<char>(length + 1);
833 non_ascii[3 * length] = 0; 848 non_ascii[3 * length] = 0;
834 ascii[length] = 0; 849 ascii[length] = 0;
835 for (int i = 0; i < length; i++) { 850 for (int i = 0; i < length; i++) {
836 ascii[i] = 'a'; 851 ascii[i] = 'a';
837 non_ascii[3 * i] = chars[0]; 852 non_ascii[3 * i] = chars[0];
838 non_ascii[3 * i + 1] = chars[1]; 853 non_ascii[3 * i + 1] = chars[1];
839 non_ascii[3 * i + 2] = chars[2]; 854 non_ascii[3 * i + 2] = chars[2];
840 } 855 }
841 Handle<String> non_ascii_sym = 856 Handle<String> non_ascii_sym =
842 FACTORY->InternalizeUtf8String( 857 factory->InternalizeUtf8String(
843 Vector<const char>(non_ascii, 3 * length)); 858 Vector<const char>(non_ascii, 3 * length));
844 CHECK_EQ(length, non_ascii_sym->length()); 859 CHECK_EQ(length, non_ascii_sym->length());
845 Handle<String> ascii_sym = 860 Handle<String> ascii_sym =
846 FACTORY->InternalizeOneByteString(OneByteVector(ascii, length)); 861 factory->InternalizeOneByteString(OneByteVector(ascii, length));
847 CHECK_EQ(length, ascii_sym->length()); 862 CHECK_EQ(length, ascii_sym->length());
848 Handle<String> non_ascii_str = 863 Handle<String> non_ascii_str =
849 FACTORY->NewStringFromUtf8(Vector<const char>(non_ascii, 3 * length)); 864 factory->NewStringFromUtf8(Vector<const char>(non_ascii, 3 * length));
850 non_ascii_str->Hash(); 865 non_ascii_str->Hash();
851 CHECK_EQ(length, non_ascii_str->length()); 866 CHECK_EQ(length, non_ascii_str->length());
852 Handle<String> ascii_str = 867 Handle<String> ascii_str =
853 FACTORY->NewStringFromUtf8(Vector<const char>(ascii, length)); 868 factory->NewStringFromUtf8(Vector<const char>(ascii, length));
854 ascii_str->Hash(); 869 ascii_str->Hash();
855 CHECK_EQ(length, ascii_str->length()); 870 CHECK_EQ(length, ascii_str->length());
856 DeleteArray(non_ascii); 871 DeleteArray(non_ascii);
857 DeleteArray(ascii); 872 DeleteArray(ascii);
858 } 873 }
859 } 874 }
860 875
861 876
862 static int ObjectsFoundInHeap(Heap* heap, Handle<Object> objs[], int size) { 877 static int ObjectsFoundInHeap(Heap* heap, Handle<Object> objs[], int size) {
863 // Count the number of objects found in the heap. 878 // Count the number of objects found in the heap.
864 int found_count = 0; 879 int found_count = 0;
865 HeapIterator iterator(heap); 880 HeapIterator iterator(heap);
866 for (HeapObject* obj = iterator.next(); obj != NULL; obj = iterator.next()) { 881 for (HeapObject* obj = iterator.next(); obj != NULL; obj = iterator.next()) {
867 for (int i = 0; i < size; i++) { 882 for (int i = 0; i < size; i++) {
868 if (*objs[i] == obj) { 883 if (*objs[i] == obj) {
869 found_count++; 884 found_count++;
870 } 885 }
871 } 886 }
872 } 887 }
873 return found_count; 888 return found_count;
874 } 889 }
875 890
876 891
877 TEST(Iteration) { 892 TEST(Iteration) {
878 CcTest::InitializeVM(); 893 CcTest::InitializeVM();
894 Isolate* isolate = Isolate::Current();
895 Factory* factory = isolate->factory();
879 v8::HandleScope scope(CcTest::isolate()); 896 v8::HandleScope scope(CcTest::isolate());
880 897
881 // Array of objects to scan haep for. 898 // Array of objects to scan haep for.
882 const int objs_count = 6; 899 const int objs_count = 6;
883 Handle<Object> objs[objs_count]; 900 Handle<Object> objs[objs_count];
884 int next_objs_index = 0; 901 int next_objs_index = 0;
885 902
886 // Allocate a JS array to OLD_POINTER_SPACE and NEW_SPACE 903 // Allocate a JS array to OLD_POINTER_SPACE and NEW_SPACE
887 objs[next_objs_index++] = FACTORY->NewJSArray(10); 904 objs[next_objs_index++] = factory->NewJSArray(10);
888 objs[next_objs_index++] = FACTORY->NewJSArray(10, 905 objs[next_objs_index++] = factory->NewJSArray(10,
889 FAST_HOLEY_ELEMENTS, 906 FAST_HOLEY_ELEMENTS,
890 TENURED); 907 TENURED);
891 908
892 // Allocate a small string to OLD_DATA_SPACE and NEW_SPACE 909 // Allocate a small string to OLD_DATA_SPACE and NEW_SPACE
893 objs[next_objs_index++] = 910 objs[next_objs_index++] =
894 FACTORY->NewStringFromAscii(CStrVector("abcdefghij")); 911 factory->NewStringFromAscii(CStrVector("abcdefghij"));
895 objs[next_objs_index++] = 912 objs[next_objs_index++] =
896 FACTORY->NewStringFromAscii(CStrVector("abcdefghij"), TENURED); 913 factory->NewStringFromAscii(CStrVector("abcdefghij"), TENURED);
897 914
898 // Allocate a large string (for large object space). 915 // Allocate a large string (for large object space).
899 int large_size = Page::kMaxNonCodeHeapObjectSize + 1; 916 int large_size = Page::kMaxNonCodeHeapObjectSize + 1;
900 char* str = new char[large_size]; 917 char* str = new char[large_size];
901 for (int i = 0; i < large_size - 1; ++i) str[i] = 'a'; 918 for (int i = 0; i < large_size - 1; ++i) str[i] = 'a';
902 str[large_size - 1] = '\0'; 919 str[large_size - 1] = '\0';
903 objs[next_objs_index++] = 920 objs[next_objs_index++] =
904 FACTORY->NewStringFromAscii(CStrVector(str), TENURED); 921 factory->NewStringFromAscii(CStrVector(str), TENURED);
905 delete[] str; 922 delete[] str;
906 923
907 // Add a Map object to look for. 924 // Add a Map object to look for.
908 objs[next_objs_index++] = Handle<Map>(HeapObject::cast(*objs[0])->map()); 925 objs[next_objs_index++] = Handle<Map>(HeapObject::cast(*objs[0])->map());
909 926
910 CHECK_EQ(objs_count, next_objs_index); 927 CHECK_EQ(objs_count, next_objs_index);
911 CHECK_EQ(objs_count, ObjectsFoundInHeap(HEAP, objs, objs_count)); 928 CHECK_EQ(objs_count, ObjectsFoundInHeap(HEAP, objs, objs_count));
912 } 929 }
913 930
914 931
(...skipping 14 matching lines...) Expand all
929 946
930 947
931 static int LenFromSize(int size) { 948 static int LenFromSize(int size) {
932 return (size - FixedArray::kHeaderSize) / kPointerSize; 949 return (size - FixedArray::kHeaderSize) / kPointerSize;
933 } 950 }
934 951
935 952
936 TEST(Regression39128) { 953 TEST(Regression39128) {
937 // Test case for crbug.com/39128. 954 // Test case for crbug.com/39128.
938 CcTest::InitializeVM(); 955 CcTest::InitializeVM();
956 Isolate* isolate = Isolate::Current();
957 Factory* factory = isolate->factory();
939 958
940 // Increase the chance of 'bump-the-pointer' allocation in old space. 959 // Increase the chance of 'bump-the-pointer' allocation in old space.
941 HEAP->CollectAllGarbage(Heap::kNoGCFlags); 960 HEAP->CollectAllGarbage(Heap::kNoGCFlags);
942 961
943 v8::HandleScope scope(CcTest::isolate()); 962 v8::HandleScope scope(CcTest::isolate());
944 963
945 // The plan: create JSObject which references objects in new space. 964 // The plan: create JSObject which references objects in new space.
946 // Then clone this object (forcing it to go into old space) and check 965 // Then clone this object (forcing it to go into old space) and check
947 // that region dirty marks are updated correctly. 966 // that region dirty marks are updated correctly.
948 967
949 // Step 1: prepare a map for the object. We add 1 inobject property to it. 968 // Step 1: prepare a map for the object. We add 1 inobject property to it.
950 Handle<JSFunction> object_ctor( 969 Handle<JSFunction> object_ctor(
951 Isolate::Current()->native_context()->object_function()); 970 Isolate::Current()->native_context()->object_function());
952 CHECK(object_ctor->has_initial_map()); 971 CHECK(object_ctor->has_initial_map());
953 Handle<Map> object_map(object_ctor->initial_map()); 972 Handle<Map> object_map(object_ctor->initial_map());
954 // Create a map with single inobject property. 973 // Create a map with single inobject property.
955 Handle<Map> my_map = FACTORY->CopyMap(object_map, 1); 974 Handle<Map> my_map = factory->CopyMap(object_map, 1);
956 int n_properties = my_map->inobject_properties(); 975 int n_properties = my_map->inobject_properties();
957 CHECK_GT(n_properties, 0); 976 CHECK_GT(n_properties, 0);
958 977
959 int object_size = my_map->instance_size(); 978 int object_size = my_map->instance_size();
960 979
961 // Step 2: allocate a lot of objects so to almost fill new space: we need 980 // Step 2: allocate a lot of objects so to almost fill new space: we need
962 // just enough room to allocate JSObject and thus fill the newspace. 981 // just enough room to allocate JSObject and thus fill the newspace.
963 982
964 int allocation_amount = Min(FixedArray::kMaxSize, 983 int allocation_amount = Min(FixedArray::kMaxSize,
965 HEAP->MaxObjectSizeInNewSpace()); 984 HEAP->MaxObjectSizeInNewSpace());
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1006 } 1025 }
1007 CHECK(HEAP->old_pointer_space()->Contains(clone->address())); 1026 CHECK(HEAP->old_pointer_space()->Contains(clone->address()));
1008 } 1027 }
1009 1028
1010 1029
1011 TEST(TestCodeFlushing) { 1030 TEST(TestCodeFlushing) {
1012 // If we do not flush code this test is invalid. 1031 // If we do not flush code this test is invalid.
1013 if (!FLAG_flush_code) return; 1032 if (!FLAG_flush_code) return;
1014 i::FLAG_allow_natives_syntax = true; 1033 i::FLAG_allow_natives_syntax = true;
1015 CcTest::InitializeVM(); 1034 CcTest::InitializeVM();
1035 Isolate* isolate = Isolate::Current();
1036 Factory* factory = isolate->factory();
1016 v8::HandleScope scope(CcTest::isolate()); 1037 v8::HandleScope scope(CcTest::isolate());
1017 const char* source = "function foo() {" 1038 const char* source = "function foo() {"
1018 " var x = 42;" 1039 " var x = 42;"
1019 " var y = 42;" 1040 " var y = 42;"
1020 " var z = x + y;" 1041 " var z = x + y;"
1021 "};" 1042 "};"
1022 "foo()"; 1043 "foo()";
1023 Handle<String> foo_name = FACTORY->InternalizeUtf8String("foo"); 1044 Handle<String> foo_name = factory->InternalizeUtf8String("foo");
1024 1045
1025 // This compile will add the code to the compilation cache. 1046 // This compile will add the code to the compilation cache.
1026 { v8::HandleScope scope(CcTest::isolate()); 1047 { v8::HandleScope scope(CcTest::isolate());
1027 CompileRun(source); 1048 CompileRun(source);
1028 } 1049 }
1029 1050
1030 // Check function is compiled. 1051 // Check function is compiled.
1031 Object* func_value = Isolate::Current()->context()->global_object()-> 1052 Object* func_value = Isolate::Current()->context()->global_object()->
1032 GetProperty(*foo_name)->ToObjectChecked(); 1053 GetProperty(*foo_name)->ToObjectChecked();
1033 CHECK(func_value->IsJSFunction()); 1054 CHECK(func_value->IsJSFunction());
(...skipping 19 matching lines...) Expand all
1053 CHECK(function->shared()->is_compiled()); 1074 CHECK(function->shared()->is_compiled());
1054 CHECK(function->is_compiled()); 1075 CHECK(function->is_compiled());
1055 } 1076 }
1056 1077
1057 1078
1058 TEST(TestCodeFlushingIncremental) { 1079 TEST(TestCodeFlushingIncremental) {
1059 // If we do not flush code this test is invalid. 1080 // If we do not flush code this test is invalid.
1060 if (!FLAG_flush_code || !FLAG_flush_code_incrementally) return; 1081 if (!FLAG_flush_code || !FLAG_flush_code_incrementally) return;
1061 i::FLAG_allow_natives_syntax = true; 1082 i::FLAG_allow_natives_syntax = true;
1062 CcTest::InitializeVM(); 1083 CcTest::InitializeVM();
1084 Isolate* isolate = Isolate::Current();
1085 Factory* factory = isolate->factory();
1063 v8::HandleScope scope(CcTest::isolate()); 1086 v8::HandleScope scope(CcTest::isolate());
1064 const char* source = "function foo() {" 1087 const char* source = "function foo() {"
1065 " var x = 42;" 1088 " var x = 42;"
1066 " var y = 42;" 1089 " var y = 42;"
1067 " var z = x + y;" 1090 " var z = x + y;"
1068 "};" 1091 "};"
1069 "foo()"; 1092 "foo()";
1070 Handle<String> foo_name = FACTORY->InternalizeUtf8String("foo"); 1093 Handle<String> foo_name = factory->InternalizeUtf8String("foo");
1071 1094
1072 // This compile will add the code to the compilation cache. 1095 // This compile will add the code to the compilation cache.
1073 { v8::HandleScope scope(CcTest::isolate()); 1096 { v8::HandleScope scope(CcTest::isolate());
1074 CompileRun(source); 1097 CompileRun(source);
1075 } 1098 }
1076 1099
1077 // Check function is compiled. 1100 // Check function is compiled.
1078 Object* func_value = Isolate::Current()->context()->global_object()-> 1101 Object* func_value = Isolate::Current()->context()->global_object()->
1079 GetProperty(*foo_name)->ToObjectChecked(); 1102 GetProperty(*foo_name)->ToObjectChecked();
1080 CHECK(func_value->IsJSFunction()); 1103 CHECK(func_value->IsJSFunction());
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1119 CHECK(function->shared()->is_compiled() || !function->IsOptimized()); 1142 CHECK(function->shared()->is_compiled() || !function->IsOptimized());
1120 CHECK(function->is_compiled() || !function->IsOptimized()); 1143 CHECK(function->is_compiled() || !function->IsOptimized());
1121 } 1144 }
1122 1145
1123 1146
1124 TEST(TestCodeFlushingIncrementalScavenge) { 1147 TEST(TestCodeFlushingIncrementalScavenge) {
1125 // If we do not flush code this test is invalid. 1148 // If we do not flush code this test is invalid.
1126 if (!FLAG_flush_code || !FLAG_flush_code_incrementally) return; 1149 if (!FLAG_flush_code || !FLAG_flush_code_incrementally) return;
1127 i::FLAG_allow_natives_syntax = true; 1150 i::FLAG_allow_natives_syntax = true;
1128 CcTest::InitializeVM(); 1151 CcTest::InitializeVM();
1152 Isolate* isolate = Isolate::Current();
1153 Factory* factory = isolate->factory();
1129 v8::HandleScope scope(CcTest::isolate()); 1154 v8::HandleScope scope(CcTest::isolate());
1130 const char* source = "var foo = function() {" 1155 const char* source = "var foo = function() {"
1131 " var x = 42;" 1156 " var x = 42;"
1132 " var y = 42;" 1157 " var y = 42;"
1133 " var z = x + y;" 1158 " var z = x + y;"
1134 "};" 1159 "};"
1135 "foo();" 1160 "foo();"
1136 "var bar = function() {" 1161 "var bar = function() {"
1137 " var x = 23;" 1162 " var x = 23;"
1138 "};" 1163 "};"
1139 "bar();"; 1164 "bar();";
1140 Handle<String> foo_name = FACTORY->InternalizeUtf8String("foo"); 1165 Handle<String> foo_name = factory->InternalizeUtf8String("foo");
1141 Handle<String> bar_name = FACTORY->InternalizeUtf8String("bar"); 1166 Handle<String> bar_name = factory->InternalizeUtf8String("bar");
1142 1167
1143 // Perfrom one initial GC to enable code flushing. 1168 // Perfrom one initial GC to enable code flushing.
1144 HEAP->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); 1169 HEAP->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
1145 1170
1146 // This compile will add the code to the compilation cache. 1171 // This compile will add the code to the compilation cache.
1147 { v8::HandleScope scope(CcTest::isolate()); 1172 { v8::HandleScope scope(CcTest::isolate());
1148 CompileRun(source); 1173 CompileRun(source);
1149 } 1174 }
1150 1175
1151 // Check functions are compiled. 1176 // Check functions are compiled.
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1186 CHECK(!function->is_compiled() || function->IsOptimized()); 1211 CHECK(!function->is_compiled() || function->IsOptimized());
1187 } 1212 }
1188 1213
1189 1214
1190 TEST(TestCodeFlushingIncrementalAbort) { 1215 TEST(TestCodeFlushingIncrementalAbort) {
1191 // If we do not flush code this test is invalid. 1216 // If we do not flush code this test is invalid.
1192 if (!FLAG_flush_code || !FLAG_flush_code_incrementally) return; 1217 if (!FLAG_flush_code || !FLAG_flush_code_incrementally) return;
1193 i::FLAG_allow_natives_syntax = true; 1218 i::FLAG_allow_natives_syntax = true;
1194 CcTest::InitializeVM(); 1219 CcTest::InitializeVM();
1195 Isolate* isolate = Isolate::Current(); 1220 Isolate* isolate = Isolate::Current();
1221 Factory* factory = isolate->factory();
1196 Heap* heap = isolate->heap(); 1222 Heap* heap = isolate->heap();
1197 v8::HandleScope scope(CcTest::isolate()); 1223 v8::HandleScope scope(CcTest::isolate());
1198 const char* source = "function foo() {" 1224 const char* source = "function foo() {"
1199 " var x = 42;" 1225 " var x = 42;"
1200 " var y = 42;" 1226 " var y = 42;"
1201 " var z = x + y;" 1227 " var z = x + y;"
1202 "};" 1228 "};"
1203 "foo()"; 1229 "foo()";
1204 Handle<String> foo_name = FACTORY->InternalizeUtf8String("foo"); 1230 Handle<String> foo_name = factory->InternalizeUtf8String("foo");
1205 1231
1206 // This compile will add the code to the compilation cache. 1232 // This compile will add the code to the compilation cache.
1207 { v8::HandleScope scope(CcTest::isolate()); 1233 { v8::HandleScope scope(CcTest::isolate());
1208 CompileRun(source); 1234 CompileRun(source);
1209 } 1235 }
1210 1236
1211 // Check function is compiled. 1237 // Check function is compiled.
1212 Object* func_value = Isolate::Current()->context()->global_object()-> 1238 Object* func_value = Isolate::Current()->context()->global_object()->
1213 GetProperty(*foo_name)->ToObjectChecked(); 1239 GetProperty(*foo_name)->ToObjectChecked();
1214 CHECK(func_value->IsJSFunction()); 1240 CHECK(func_value->IsJSFunction());
(...skipping 670 matching lines...) Expand 10 before | Expand all | Expand 10 after
1885 g->Call(global, 0, NULL); 1911 g->Call(global, 0, NULL);
1886 } 1912 }
1887 1913
1888 HEAP->incremental_marking()->set_should_hurry(true); 1914 HEAP->incremental_marking()->set_should_hurry(true);
1889 HEAP->CollectGarbage(OLD_POINTER_SPACE); 1915 HEAP->CollectGarbage(OLD_POINTER_SPACE);
1890 } 1916 }
1891 1917
1892 1918
1893 TEST(PrototypeTransitionClearing) { 1919 TEST(PrototypeTransitionClearing) {
1894 CcTest::InitializeVM(); 1920 CcTest::InitializeVM();
1921 Isolate* isolate = Isolate::Current();
1922 Factory* factory = isolate->factory();
1895 v8::HandleScope scope(CcTest::isolate()); 1923 v8::HandleScope scope(CcTest::isolate());
1896 1924
1897 CompileRun( 1925 CompileRun(
1898 "var base = {};" 1926 "var base = {};"
1899 "var live = [];" 1927 "var live = [];"
1900 "for (var i = 0; i < 10; i++) {" 1928 "for (var i = 0; i < 10; i++) {"
1901 " var object = {};" 1929 " var object = {};"
1902 " var prototype = {};" 1930 " var prototype = {};"
1903 " object.__proto__ = prototype;" 1931 " object.__proto__ = prototype;"
1904 " if (i >= 3) live.push(object, prototype);" 1932 " if (i >= 3) live.push(object, prototype);"
(...skipping 19 matching lines...) Expand all
1924 Object* proto = trans->get(j + Map::kProtoTransitionPrototypeOffset); 1952 Object* proto = trans->get(j + Map::kProtoTransitionPrototypeOffset);
1925 CHECK(proto->IsTheHole() || proto->IsJSObject()); 1953 CHECK(proto->IsTheHole() || proto->IsJSObject());
1926 } 1954 }
1927 1955
1928 // Make sure next prototype is placed on an old-space evacuation candidate. 1956 // Make sure next prototype is placed on an old-space evacuation candidate.
1929 Handle<JSObject> prototype; 1957 Handle<JSObject> prototype;
1930 PagedSpace* space = HEAP->old_pointer_space(); 1958 PagedSpace* space = HEAP->old_pointer_space();
1931 { 1959 {
1932 AlwaysAllocateScope always_allocate; 1960 AlwaysAllocateScope always_allocate;
1933 SimulateFullSpace(space); 1961 SimulateFullSpace(space);
1934 prototype = FACTORY->NewJSArray(32 * KB, FAST_HOLEY_ELEMENTS, TENURED); 1962 prototype = factory->NewJSArray(32 * KB, FAST_HOLEY_ELEMENTS, TENURED);
1935 } 1963 }
1936 1964
1937 // Add a prototype on an evacuation candidate and verify that transition 1965 // Add a prototype on an evacuation candidate and verify that transition
1938 // clearing correctly records slots in prototype transition array. 1966 // clearing correctly records slots in prototype transition array.
1939 i::FLAG_always_compact = true; 1967 i::FLAG_always_compact = true;
1940 Handle<Map> map(baseObject->map()); 1968 Handle<Map> map(baseObject->map());
1941 CHECK(!space->LastPage()->Contains( 1969 CHECK(!space->LastPage()->Contains(
1942 map->GetPrototypeTransitions()->address())); 1970 map->GetPrototypeTransitions()->address()));
1943 CHECK(space->LastPage()->Contains(prototype->address())); 1971 CHECK(space->LastPage()->Contains(prototype->address()));
1944 baseObject->SetPrototype(*prototype, false)->ToObjectChecked(); 1972 baseObject->SetPrototype(*prototype, false)->ToObjectChecked();
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
2283 CHECK(root->map()->IsMap()); 2311 CHECK(root->map()->IsMap());
2284 } 2312 }
2285 2313
2286 2314
2287 TEST(ReleaseOverReservedPages) { 2315 TEST(ReleaseOverReservedPages) {
2288 i::FLAG_trace_gc = true; 2316 i::FLAG_trace_gc = true;
2289 // The optimizer can allocate stuff, messing up the test. 2317 // The optimizer can allocate stuff, messing up the test.
2290 i::FLAG_crankshaft = false; 2318 i::FLAG_crankshaft = false;
2291 i::FLAG_always_opt = false; 2319 i::FLAG_always_opt = false;
2292 CcTest::InitializeVM(); 2320 CcTest::InitializeVM();
2321 Isolate* isolate = Isolate::Current();
2322 Factory* factory = isolate->factory();
2293 v8::HandleScope scope(CcTest::isolate()); 2323 v8::HandleScope scope(CcTest::isolate());
2294 static const int number_of_test_pages = 20; 2324 static const int number_of_test_pages = 20;
2295 2325
2296 // Prepare many pages with low live-bytes count. 2326 // Prepare many pages with low live-bytes count.
2297 PagedSpace* old_pointer_space = HEAP->old_pointer_space(); 2327 PagedSpace* old_pointer_space = HEAP->old_pointer_space();
2298 CHECK_EQ(1, old_pointer_space->CountTotalPages()); 2328 CHECK_EQ(1, old_pointer_space->CountTotalPages());
2299 for (int i = 0; i < number_of_test_pages; i++) { 2329 for (int i = 0; i < number_of_test_pages; i++) {
2300 AlwaysAllocateScope always_allocate; 2330 AlwaysAllocateScope always_allocate;
2301 SimulateFullSpace(old_pointer_space); 2331 SimulateFullSpace(old_pointer_space);
2302 FACTORY->NewFixedArray(1, TENURED); 2332 factory->NewFixedArray(1, TENURED);
2303 } 2333 }
2304 CHECK_EQ(number_of_test_pages + 1, old_pointer_space->CountTotalPages()); 2334 CHECK_EQ(number_of_test_pages + 1, old_pointer_space->CountTotalPages());
2305 2335
2306 // Triggering one GC will cause a lot of garbage to be discovered but 2336 // Triggering one GC will cause a lot of garbage to be discovered but
2307 // even spread across all allocated pages. 2337 // even spread across all allocated pages.
2308 HEAP->CollectAllGarbage(Heap::kNoGCFlags, "triggered for preparation"); 2338 HEAP->CollectAllGarbage(Heap::kNoGCFlags, "triggered for preparation");
2309 CHECK_GE(number_of_test_pages + 1, old_pointer_space->CountTotalPages()); 2339 CHECK_GE(number_of_test_pages + 1, old_pointer_space->CountTotalPages());
2310 2340
2311 // Triggering subsequent GCs should cause at least half of the pages 2341 // Triggering subsequent GCs should cause at least half of the pages
2312 // to be released to the OS after at most two cycles. 2342 // to be released to the OS after at most two cycles.
2313 HEAP->CollectAllGarbage(Heap::kNoGCFlags, "triggered by test 1"); 2343 HEAP->CollectAllGarbage(Heap::kNoGCFlags, "triggered by test 1");
2314 CHECK_GE(number_of_test_pages + 1, old_pointer_space->CountTotalPages()); 2344 CHECK_GE(number_of_test_pages + 1, old_pointer_space->CountTotalPages());
2315 HEAP->CollectAllGarbage(Heap::kNoGCFlags, "triggered by test 2"); 2345 HEAP->CollectAllGarbage(Heap::kNoGCFlags, "triggered by test 2");
2316 CHECK_GE(number_of_test_pages + 1, old_pointer_space->CountTotalPages() * 2); 2346 CHECK_GE(number_of_test_pages + 1, old_pointer_space->CountTotalPages() * 2);
2317 2347
2318 // Triggering a last-resort GC should cause all pages to be released to the 2348 // Triggering a last-resort GC should cause all pages to be released to the
2319 // OS so that other processes can seize the memory. If we get a failure here 2349 // OS so that other processes can seize the memory. If we get a failure here
2320 // where there are 2 pages left instead of 1, then we should increase the 2350 // where there are 2 pages left instead of 1, then we should increase the
2321 // size of the first page a little in SizeOfFirstPage in spaces.cc. The 2351 // size of the first page a little in SizeOfFirstPage in spaces.cc. The
2322 // first page should be small in order to reduce memory used when the VM 2352 // first page should be small in order to reduce memory used when the VM
2323 // boots, but if the 20 small arrays don't fit on the first page then that's 2353 // boots, but if the 20 small arrays don't fit on the first page then that's
2324 // an indication that it is too small. 2354 // an indication that it is too small.
2325 HEAP->CollectAllAvailableGarbage("triggered really hard"); 2355 HEAP->CollectAllAvailableGarbage("triggered really hard");
2326 CHECK_EQ(1, old_pointer_space->CountTotalPages()); 2356 CHECK_EQ(1, old_pointer_space->CountTotalPages());
2327 } 2357 }
2328 2358
2329 2359
2330 TEST(Regress2237) { 2360 TEST(Regress2237) {
2331 CcTest::InitializeVM(); 2361 CcTest::InitializeVM();
2362 Isolate* isolate = Isolate::Current();
2363 Factory* factory = isolate->factory();
2332 v8::HandleScope scope(CcTest::isolate()); 2364 v8::HandleScope scope(CcTest::isolate());
2333 Handle<String> slice(HEAP->empty_string()); 2365 Handle<String> slice(HEAP->empty_string());
2334 2366
2335 { 2367 {
2336 // Generate a parent that lives in new-space. 2368 // Generate a parent that lives in new-space.
2337 v8::HandleScope inner_scope(CcTest::isolate()); 2369 v8::HandleScope inner_scope(CcTest::isolate());
2338 const char* c = "This text is long enough to trigger sliced strings."; 2370 const char* c = "This text is long enough to trigger sliced strings.";
2339 Handle<String> s = FACTORY->NewStringFromAscii(CStrVector(c)); 2371 Handle<String> s = factory->NewStringFromAscii(CStrVector(c));
2340 CHECK(s->IsSeqOneByteString()); 2372 CHECK(s->IsSeqOneByteString());
2341 CHECK(HEAP->InNewSpace(*s)); 2373 CHECK(HEAP->InNewSpace(*s));
2342 2374
2343 // Generate a sliced string that is based on the above parent and 2375 // Generate a sliced string that is based on the above parent and
2344 // lives in old-space. 2376 // lives in old-space.
2345 SimulateFullSpace(HEAP->new_space()); 2377 SimulateFullSpace(HEAP->new_space());
2346 AlwaysAllocateScope always_allocate; 2378 AlwaysAllocateScope always_allocate;
2347 Handle<String> t = FACTORY->NewProperSubString(s, 5, 35); 2379 Handle<String> t = factory->NewProperSubString(s, 5, 35);
2348 CHECK(t->IsSlicedString()); 2380 CHECK(t->IsSlicedString());
2349 CHECK(!HEAP->InNewSpace(*t)); 2381 CHECK(!HEAP->InNewSpace(*t));
2350 *slice.location() = *t.location(); 2382 *slice.location() = *t.location();
2351 } 2383 }
2352 2384
2353 CHECK(SlicedString::cast(*slice)->parent()->IsSeqOneByteString()); 2385 CHECK(SlicedString::cast(*slice)->parent()->IsSeqOneByteString());
2354 HEAP->CollectAllGarbage(Heap::kNoGCFlags); 2386 HEAP->CollectAllGarbage(Heap::kNoGCFlags);
2355 CHECK(SlicedString::cast(*slice)->parent()->IsSeqOneByteString()); 2387 CHECK(SlicedString::cast(*slice)->parent()->IsSeqOneByteString());
2356 } 2388 }
2357 2389
(...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after
2893 v8::internal::MaybeObject* maybe = space->AllocateRaw(new_linear_size); 2925 v8::internal::MaybeObject* maybe = space->AllocateRaw(new_linear_size);
2894 v8::internal::FreeListNode* node = v8::internal::FreeListNode::cast(maybe); 2926 v8::internal::FreeListNode* node = v8::internal::FreeListNode::cast(maybe);
2895 node->set_size(space->heap(), new_linear_size); 2927 node->set_size(space->heap(), new_linear_size);
2896 } 2928 }
2897 2929
2898 2930
2899 TEST(Regress169928) { 2931 TEST(Regress169928) {
2900 i::FLAG_allow_natives_syntax = true; 2932 i::FLAG_allow_natives_syntax = true;
2901 i::FLAG_crankshaft = false; 2933 i::FLAG_crankshaft = false;
2902 CcTest::InitializeVM(); 2934 CcTest::InitializeVM();
2935 Isolate* isolate = Isolate::Current();
2936 Factory* factory = isolate->factory();
2903 v8::HandleScope scope(CcTest::isolate()); 2937 v8::HandleScope scope(CcTest::isolate());
2904 2938
2905 // Some flags turn Scavenge collections into Mark-sweep collections 2939 // Some flags turn Scavenge collections into Mark-sweep collections
2906 // and hence are incompatible with this test case. 2940 // and hence are incompatible with this test case.
2907 if (FLAG_gc_global || FLAG_stress_compaction) return; 2941 if (FLAG_gc_global || FLAG_stress_compaction) return;
2908 2942
2909 // Prepare the environment 2943 // Prepare the environment
2910 CompileRun("function fastliteralcase(literal, value) {" 2944 CompileRun("function fastliteralcase(literal, value) {"
2911 " literal[0] = value;" 2945 " literal[0] = value;"
2912 " return literal;" 2946 " return literal;"
(...skipping 10 matching lines...) Expand all
2923 v8::Local<v8::String> mote_code_string = 2957 v8::Local<v8::String> mote_code_string =
2924 v8_str("fastliteralcase(mote, 2.5);"); 2958 v8_str("fastliteralcase(mote, 2.5);");
2925 2959
2926 v8::Local<v8::String> array_name = v8_str("mote"); 2960 v8::Local<v8::String> array_name = v8_str("mote");
2927 v8::Context::GetCurrent()->Global()->Set(array_name, v8::Int32::New(0)); 2961 v8::Context::GetCurrent()->Global()->Set(array_name, v8::Int32::New(0));
2928 2962
2929 // First make sure we flip spaces 2963 // First make sure we flip spaces
2930 HEAP->CollectGarbage(NEW_SPACE); 2964 HEAP->CollectGarbage(NEW_SPACE);
2931 2965
2932 // Allocate the object. 2966 // Allocate the object.
2933 Handle<FixedArray> array_data = FACTORY->NewFixedArray(2, NOT_TENURED); 2967 Handle<FixedArray> array_data = factory->NewFixedArray(2, NOT_TENURED);
2934 array_data->set(0, Smi::FromInt(1)); 2968 array_data->set(0, Smi::FromInt(1));
2935 array_data->set(1, Smi::FromInt(2)); 2969 array_data->set(1, Smi::FromInt(2));
2936 2970
2937 AllocateAllButNBytes(HEAP->new_space(), 2971 AllocateAllButNBytes(HEAP->new_space(),
2938 JSArray::kSize + AllocationSiteInfo::kSize + 2972 JSArray::kSize + AllocationSiteInfo::kSize +
2939 kPointerSize); 2973 kPointerSize);
2940 2974
2941 Handle<JSArray> array = FACTORY->NewJSArrayWithElements(array_data, 2975 Handle<JSArray> array = factory->NewJSArrayWithElements(array_data,
2942 FAST_SMI_ELEMENTS, 2976 FAST_SMI_ELEMENTS,
2943 NOT_TENURED); 2977 NOT_TENURED);
2944 2978
2945 CHECK_EQ(Smi::FromInt(2), array->length()); 2979 CHECK_EQ(Smi::FromInt(2), array->length());
2946 CHECK(array->HasFastSmiOrObjectElements()); 2980 CHECK(array->HasFastSmiOrObjectElements());
2947 2981
2948 // We need filler the size of AllocationSiteInfo object, plus an extra 2982 // We need filler the size of AllocationSiteInfo object, plus an extra
2949 // fill pointer value. 2983 // fill pointer value.
2950 MaybeObject* maybe_object = HEAP->AllocateRaw( 2984 MaybeObject* maybe_object = HEAP->AllocateRaw(
2951 AllocationSiteInfo::kSize + kPointerSize, NEW_SPACE, OLD_POINTER_SPACE); 2985 AllocationSiteInfo::kSize + kPointerSize, NEW_SPACE, OLD_POINTER_SPACE);
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
3113 " var a = new Array(n);" 3147 " var a = new Array(n);"
3114 " for (var i = 0; i < n; i += 100) a[i] = i;" 3148 " for (var i = 0; i < n; i += 100) a[i] = i;"
3115 "};" 3149 "};"
3116 "f(10 * 1024 * 1024);"); 3150 "f(10 * 1024 * 1024);");
3117 IncrementalMarking* marking = HEAP->incremental_marking(); 3151 IncrementalMarking* marking = HEAP->incremental_marking();
3118 if (marking->IsStopped()) marking->Start(); 3152 if (marking->IsStopped()) marking->Start();
3119 // This big step should be sufficient to mark the whole array. 3153 // This big step should be sufficient to mark the whole array.
3120 marking->Step(100 * MB, IncrementalMarking::NO_GC_VIA_STACK_GUARD); 3154 marking->Step(100 * MB, IncrementalMarking::NO_GC_VIA_STACK_GUARD);
3121 ASSERT(marking->IsComplete()); 3155 ASSERT(marking->IsComplete());
3122 } 3156 }
OLDNEW
« no previous file with comments | « test/cctest/test-func-name-inference.cc ('k') | test/cctest/test-mark-compact.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698