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

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

Issue 1172683003: Use the LookupIterator for SetElement and friends (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebase Created 5 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
« no previous file with comments | « test/cctest/test-api.cc ('k') | test/cctest/test-migrations.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 773 matching lines...) Expand 10 before | Expand all | Expand 10 after
784 // We just initialized the VM, no heap allocation failure yet. 784 // We just initialized the VM, no heap allocation failure yet.
785 JSArray::Initialize(array, 0); 785 JSArray::Initialize(array, 0);
786 786
787 // Set array length to 0. 787 // Set array length to 0.
788 JSArray::SetElementsLength(array, handle(Smi::FromInt(0), isolate)).Check(); 788 JSArray::SetElementsLength(array, handle(Smi::FromInt(0), isolate)).Check();
789 CHECK_EQ(Smi::FromInt(0), array->length()); 789 CHECK_EQ(Smi::FromInt(0), array->length());
790 // Must be in fast mode. 790 // Must be in fast mode.
791 CHECK(array->HasFastSmiOrObjectElements()); 791 CHECK(array->HasFastSmiOrObjectElements());
792 792
793 // array[length] = name. 793 // array[length] = name.
794 JSReceiver::SetElement(array, 0, name, NONE, SLOPPY).Check(); 794 JSReceiver::SetElement(array, 0, name, SLOPPY).Check();
795 CHECK_EQ(Smi::FromInt(1), array->length()); 795 CHECK_EQ(Smi::FromInt(1), array->length());
796 element = i::Object::GetElement(isolate, array, 0).ToHandleChecked(); 796 element = i::Object::GetElement(isolate, array, 0).ToHandleChecked();
797 CHECK_EQ(*element, *name); 797 CHECK_EQ(*element, *name);
798 798
799 // Set array length with larger than smi value. 799 // Set array length with larger than smi value.
800 Handle<Object> length = 800 Handle<Object> length =
801 factory->NewNumberFromUint(static_cast<uint32_t>(Smi::kMaxValue) + 1); 801 factory->NewNumberFromUint(static_cast<uint32_t>(Smi::kMaxValue) + 1);
802 JSArray::SetElementsLength(array, length).Check(); 802 JSArray::SetElementsLength(array, length).Check();
803 803
804 uint32_t int_length = 0; 804 uint32_t int_length = 0;
805 CHECK(length->ToArrayIndex(&int_length)); 805 CHECK(length->ToArrayIndex(&int_length));
806 CHECK_EQ(*length, array->length()); 806 CHECK_EQ(*length, array->length());
807 CHECK(array->HasDictionaryElements()); // Must be in slow mode. 807 CHECK(array->HasDictionaryElements()); // Must be in slow mode.
808 808
809 // array[length] = name. 809 // array[length] = name.
810 JSReceiver::SetElement(array, int_length, name, NONE, SLOPPY).Check(); 810 JSReceiver::SetElement(array, int_length, name, SLOPPY).Check();
811 uint32_t new_int_length = 0; 811 uint32_t new_int_length = 0;
812 CHECK(array->length()->ToArrayIndex(&new_int_length)); 812 CHECK(array->length()->ToArrayIndex(&new_int_length));
813 CHECK_EQ(static_cast<double>(int_length), new_int_length - 1); 813 CHECK_EQ(static_cast<double>(int_length), new_int_length - 1);
814 element = Object::GetElement(isolate, array, int_length).ToHandleChecked(); 814 element = Object::GetElement(isolate, array, int_length).ToHandleChecked();
815 CHECK_EQ(*element, *name); 815 CHECK_EQ(*element, *name);
816 element = Object::GetElement(isolate, array, 0).ToHandleChecked(); 816 element = Object::GetElement(isolate, array, 0).ToHandleChecked();
817 CHECK_EQ(*element, *name); 817 CHECK_EQ(*element, *name);
818 } 818 }
819 819
820 820
(...skipping 10 matching lines...) Expand all
831 Handle<JSObject> obj = factory->NewJSObject(constructor); 831 Handle<JSObject> obj = factory->NewJSObject(constructor);
832 Handle<String> first = factory->InternalizeUtf8String("first"); 832 Handle<String> first = factory->InternalizeUtf8String("first");
833 Handle<String> second = factory->InternalizeUtf8String("second"); 833 Handle<String> second = factory->InternalizeUtf8String("second");
834 834
835 Handle<Smi> one(Smi::FromInt(1), isolate); 835 Handle<Smi> one(Smi::FromInt(1), isolate);
836 Handle<Smi> two(Smi::FromInt(2), isolate); 836 Handle<Smi> two(Smi::FromInt(2), isolate);
837 837
838 JSReceiver::SetProperty(obj, first, one, SLOPPY).Check(); 838 JSReceiver::SetProperty(obj, first, one, SLOPPY).Check();
839 JSReceiver::SetProperty(obj, second, two, SLOPPY).Check(); 839 JSReceiver::SetProperty(obj, second, two, SLOPPY).Check();
840 840
841 JSReceiver::SetElement(obj, 0, first, NONE, SLOPPY).Check(); 841 JSReceiver::SetElement(obj, 0, first, SLOPPY).Check();
842 JSReceiver::SetElement(obj, 1, second, NONE, SLOPPY).Check(); 842 JSReceiver::SetElement(obj, 1, second, SLOPPY).Check();
843 843
844 // Make the clone. 844 // Make the clone.
845 Handle<Object> value1, value2; 845 Handle<Object> value1, value2;
846 Handle<JSObject> clone = factory->CopyJSObject(obj); 846 Handle<JSObject> clone = factory->CopyJSObject(obj);
847 CHECK(!clone.is_identical_to(obj)); 847 CHECK(!clone.is_identical_to(obj));
848 848
849 value1 = Object::GetElement(isolate, obj, 0).ToHandleChecked(); 849 value1 = Object::GetElement(isolate, obj, 0).ToHandleChecked();
850 value2 = Object::GetElement(isolate, clone, 0).ToHandleChecked(); 850 value2 = Object::GetElement(isolate, clone, 0).ToHandleChecked();
851 CHECK_EQ(*value1, *value2); 851 CHECK_EQ(*value1, *value2);
852 value1 = Object::GetElement(isolate, obj, 1).ToHandleChecked(); 852 value1 = Object::GetElement(isolate, obj, 1).ToHandleChecked();
853 value2 = Object::GetElement(isolate, clone, 1).ToHandleChecked(); 853 value2 = Object::GetElement(isolate, clone, 1).ToHandleChecked();
854 CHECK_EQ(*value1, *value2); 854 CHECK_EQ(*value1, *value2);
855 855
856 value1 = Object::GetProperty(obj, first).ToHandleChecked(); 856 value1 = Object::GetProperty(obj, first).ToHandleChecked();
857 value2 = Object::GetProperty(clone, first).ToHandleChecked(); 857 value2 = Object::GetProperty(clone, first).ToHandleChecked();
858 CHECK_EQ(*value1, *value2); 858 CHECK_EQ(*value1, *value2);
859 value1 = Object::GetProperty(obj, second).ToHandleChecked(); 859 value1 = Object::GetProperty(obj, second).ToHandleChecked();
860 value2 = Object::GetProperty(clone, second).ToHandleChecked(); 860 value2 = Object::GetProperty(clone, second).ToHandleChecked();
861 CHECK_EQ(*value1, *value2); 861 CHECK_EQ(*value1, *value2);
862 862
863 // Flip the values. 863 // Flip the values.
864 JSReceiver::SetProperty(clone, first, two, SLOPPY).Check(); 864 JSReceiver::SetProperty(clone, first, two, SLOPPY).Check();
865 JSReceiver::SetProperty(clone, second, one, SLOPPY).Check(); 865 JSReceiver::SetProperty(clone, second, one, SLOPPY).Check();
866 866
867 JSReceiver::SetElement(clone, 0, second, NONE, SLOPPY).Check(); 867 JSReceiver::SetElement(clone, 0, second, SLOPPY).Check();
868 JSReceiver::SetElement(clone, 1, first, NONE, SLOPPY).Check(); 868 JSReceiver::SetElement(clone, 1, first, SLOPPY).Check();
869 869
870 value1 = Object::GetElement(isolate, obj, 1).ToHandleChecked(); 870 value1 = Object::GetElement(isolate, obj, 1).ToHandleChecked();
871 value2 = Object::GetElement(isolate, clone, 0).ToHandleChecked(); 871 value2 = Object::GetElement(isolate, clone, 0).ToHandleChecked();
872 CHECK_EQ(*value1, *value2); 872 CHECK_EQ(*value1, *value2);
873 value1 = Object::GetElement(isolate, obj, 0).ToHandleChecked(); 873 value1 = Object::GetElement(isolate, obj, 0).ToHandleChecked();
874 value2 = Object::GetElement(isolate, clone, 1).ToHandleChecked(); 874 value2 = Object::GetElement(isolate, clone, 1).ToHandleChecked();
875 CHECK_EQ(*value1, *value2); 875 CHECK_EQ(*value1, *value2);
876 876
877 value1 = Object::GetProperty(obj, second).ToHandleChecked(); 877 value1 = Object::GetProperty(obj, second).ToHandleChecked();
878 value2 = Object::GetProperty(clone, first).ToHandleChecked(); 878 value2 = Object::GetProperty(clone, first).ToHandleChecked();
(...skipping 5084 matching lines...) Expand 10 before | Expand all | Expand 10 after
5963 size_t counter2 = 2000; 5963 size_t counter2 = 2000;
5964 tracer->SampleAllocation(time2, counter2, counter2); 5964 tracer->SampleAllocation(time2, counter2, counter2);
5965 size_t throughput = tracer->AllocationThroughputInBytesPerMillisecond(100); 5965 size_t throughput = tracer->AllocationThroughputInBytesPerMillisecond(100);
5966 CHECK_EQ(2 * (counter2 - counter1) / (time2 - time1), throughput); 5966 CHECK_EQ(2 * (counter2 - counter1) / (time2 - time1), throughput);
5967 int time3 = 1000; 5967 int time3 = 1000;
5968 size_t counter3 = 30000; 5968 size_t counter3 = 30000;
5969 tracer->SampleAllocation(time3, counter3, counter3); 5969 tracer->SampleAllocation(time3, counter3, counter3);
5970 throughput = tracer->AllocationThroughputInBytesPerMillisecond(100); 5970 throughput = tracer->AllocationThroughputInBytesPerMillisecond(100);
5971 CHECK_EQ(2 * (counter3 - counter1) / (time3 - time1), throughput); 5971 CHECK_EQ(2 * (counter3 - counter1) / (time3 - time1), throughput);
5972 } 5972 }
OLDNEW
« no previous file with comments | « test/cctest/test-api.cc ('k') | test/cctest/test-migrations.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698