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

Side by Side Diff: src/builtins.cc

Issue 9663002: Use CopyElements for SetFastDoubleElementsCapacityAndLength (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fix bugs Created 8 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 | « no previous file | src/elements.h » ('j') | src/elements.cc » ('J')
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 490 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 501
502 if (new_length > elms->length()) { 502 if (new_length > elms->length()) {
503 // New backing storage is needed. 503 // New backing storage is needed.
504 int capacity = new_length + (new_length >> 1) + 16; 504 int capacity = new_length + (new_length >> 1) + 16;
505 Object* obj; 505 Object* obj;
506 { MaybeObject* maybe_obj = heap->AllocateUninitializedFixedArray(capacity); 506 { MaybeObject* maybe_obj = heap->AllocateUninitializedFixedArray(capacity);
507 if (!maybe_obj->ToObject(&obj)) return maybe_obj; 507 if (!maybe_obj->ToObject(&obj)) return maybe_obj;
508 } 508 }
509 FixedArray* new_elms = FixedArray::cast(obj); 509 FixedArray* new_elms = FixedArray::cast(obj);
510 510
511 AssertNoAllocation no_gc; 511 CopyObjectToObjectElements(elms, FAST_ELEMENTS, 0,
Jakob Kummerow 2012/03/12 15:33:28 Did you delete this line on purpose? AFAICS we don
danno 2012/03/12 20:35:03 The AssertNoAllocation doesn't help here, and actu
512 CopyObjectToObjectElements(&no_gc, elms, FAST_ELEMENTS, 0,
513 new_elms, FAST_ELEMENTS, 0, len); 512 new_elms, FAST_ELEMENTS, 0, len);
514 FillWithHoles(heap, new_elms, new_length, capacity); 513 FillWithHoles(heap, new_elms, new_length, capacity);
515 514
516 elms = new_elms; 515 elms = new_elms;
517 } 516 }
518 517
519 // Add the provided values. 518 // Add the provided values.
520 AssertNoAllocation no_gc; 519 AssertNoAllocation no_gc;
521 WriteBarrierMode mode = elms->GetWriteBarrierMode(no_gc); 520 WriteBarrierMode mode = elms->GetWriteBarrierMode(no_gc);
522 for (int index = 0; index < to_add; index++) { 521 for (int index = 0; index < to_add; index++) {
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
639 638
640 if (new_length > elms->length()) { 639 if (new_length > elms->length()) {
641 // New backing storage is needed. 640 // New backing storage is needed.
642 int capacity = new_length + (new_length >> 1) + 16; 641 int capacity = new_length + (new_length >> 1) + 16;
643 Object* obj; 642 Object* obj;
644 { MaybeObject* maybe_obj = heap->AllocateUninitializedFixedArray(capacity); 643 { MaybeObject* maybe_obj = heap->AllocateUninitializedFixedArray(capacity);
645 if (!maybe_obj->ToObject(&obj)) return maybe_obj; 644 if (!maybe_obj->ToObject(&obj)) return maybe_obj;
646 } 645 }
647 FixedArray* new_elms = FixedArray::cast(obj); 646 FixedArray* new_elms = FixedArray::cast(obj);
648 AssertNoAllocation no_gc; 647 AssertNoAllocation no_gc;
649 CopyObjectToObjectElements(&no_gc, elms, FAST_ELEMENTS, 0, 648 CopyObjectToObjectElements(elms, FAST_ELEMENTS, 0,
650 new_elms, FAST_ELEMENTS, to_add, len); 649 new_elms, FAST_ELEMENTS, to_add, len);
651 FillWithHoles(heap, new_elms, new_length, capacity); 650 FillWithHoles(heap, new_elms, new_length, capacity);
652 elms = new_elms; 651 elms = new_elms;
653 array->set_elements(elms); 652 array->set_elements(elms);
654 } else { 653 } else {
655 AssertNoAllocation no_gc; 654 AssertNoAllocation no_gc;
656 MoveElements(heap, &no_gc, elms, to_add, elms, 0, len); 655 MoveElements(heap, &no_gc, elms, to_add, elms, 0, len);
657 } 656 }
658 657
659 // Add the provided values. 658 // Add the provided values.
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
751 int result_len = Max(final - k, 0); 750 int result_len = Max(final - k, 0);
752 751
753 MaybeObject* maybe_array = 752 MaybeObject* maybe_array =
754 heap->AllocateJSArrayAndStorage(elements_kind, 753 heap->AllocateJSArrayAndStorage(elements_kind,
755 result_len, 754 result_len,
756 result_len); 755 result_len);
757 JSArray* result_array; 756 JSArray* result_array;
758 if (!maybe_array->To(&result_array)) return maybe_array; 757 if (!maybe_array->To(&result_array)) return maybe_array;
759 758
760 AssertNoAllocation no_gc; 759 AssertNoAllocation no_gc;
761 CopyObjectToObjectElements(&no_gc, elms, FAST_ELEMENTS, k, 760 CopyObjectToObjectElements(elms, FAST_ELEMENTS, k,
762 FixedArray::cast(result_array->elements()), 761 FixedArray::cast(result_array->elements()),
763 FAST_ELEMENTS, 0, result_len); 762 FAST_ELEMENTS, 0, result_len);
764 763
765 return result_array; 764 return result_array;
766 } 765 }
767 766
768 767
769 BUILTIN(ArraySplice) { 768 BUILTIN(ArraySplice) {
770 Heap* heap = isolate->heap(); 769 Heap* heap = isolate->heap();
771 Object* receiver = *args.receiver(); 770 Object* receiver = *args.receiver();
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
826 JSObject::cast(receiver)->GetElementsKind(); 825 JSObject::cast(receiver)->GetElementsKind();
827 MaybeObject* maybe_array = 826 MaybeObject* maybe_array =
828 heap->AllocateJSArrayAndStorage(elements_kind, 827 heap->AllocateJSArrayAndStorage(elements_kind,
829 actual_delete_count, 828 actual_delete_count,
830 actual_delete_count); 829 actual_delete_count);
831 if (!maybe_array->To(&result_array)) return maybe_array; 830 if (!maybe_array->To(&result_array)) return maybe_array;
832 831
833 { 832 {
834 AssertNoAllocation no_gc; 833 AssertNoAllocation no_gc;
835 // Fill newly created array. 834 // Fill newly created array.
836 CopyObjectToObjectElements(&no_gc, elms, FAST_ELEMENTS, actual_start, 835 CopyObjectToObjectElements(elms, FAST_ELEMENTS, actual_start,
837 FixedArray::cast(result_array->elements()), 836 FixedArray::cast(result_array->elements()),
838 FAST_ELEMENTS, 0, actual_delete_count); 837 FAST_ELEMENTS, 0, actual_delete_count);
839 } 838 }
840 839
841 int item_count = (n_arguments > 1) ? (n_arguments - 2) : 0; 840 int item_count = (n_arguments > 1) ? (n_arguments - 2) : 0;
842 int new_length = len - actual_delete_count + item_count; 841 int new_length = len - actual_delete_count + item_count;
843 842
844 bool elms_changed = false; 843 bool elms_changed = false;
845 if (item_count < actual_delete_count) { 844 if (item_count < actual_delete_count) {
846 // Shrink the array. 845 // Shrink the array.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
878 Object* obj; 877 Object* obj;
879 { MaybeObject* maybe_obj = 878 { MaybeObject* maybe_obj =
880 heap->AllocateUninitializedFixedArray(capacity); 879 heap->AllocateUninitializedFixedArray(capacity);
881 if (!maybe_obj->ToObject(&obj)) return maybe_obj; 880 if (!maybe_obj->ToObject(&obj)) return maybe_obj;
882 } 881 }
883 FixedArray* new_elms = FixedArray::cast(obj); 882 FixedArray* new_elms = FixedArray::cast(obj);
884 883
885 { 884 {
886 AssertNoAllocation no_gc; 885 AssertNoAllocation no_gc;
887 // Copy the part before actual_start as is. 886 // Copy the part before actual_start as is.
888 CopyObjectToObjectElements(&no_gc, elms, FAST_ELEMENTS, 0, 887 CopyObjectToObjectElements(elms, FAST_ELEMENTS, 0,
889 new_elms, FAST_ELEMENTS, 0, actual_start); 888 new_elms, FAST_ELEMENTS, 0, actual_start);
890 const int to_copy = len - actual_delete_count - actual_start; 889 const int to_copy = len - actual_delete_count - actual_start;
891 CopyObjectToObjectElements(&no_gc, elms, FAST_ELEMENTS, 890 CopyObjectToObjectElements(elms, FAST_ELEMENTS,
892 actual_start + actual_delete_count, 891 actual_start + actual_delete_count,
893 new_elms, FAST_ELEMENTS, 892 new_elms, FAST_ELEMENTS,
894 actual_start + item_count, to_copy); 893 actual_start + item_count, to_copy);
895 } 894 }
896 895
897 FillWithHoles(heap, new_elms, new_length, capacity); 896 FillWithHoles(heap, new_elms, new_length, capacity);
898 897
899 elms = new_elms; 898 elms = new_elms;
900 elms_changed = true; 899 elms_changed = true;
901 } else { 900 } else {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
966 // Allocate result. 965 // Allocate result.
967 JSArray* result_array; 966 JSArray* result_array;
968 MaybeObject* maybe_array = 967 MaybeObject* maybe_array =
969 heap->AllocateJSArrayAndStorage(elements_kind, 968 heap->AllocateJSArrayAndStorage(elements_kind,
970 result_len, 969 result_len,
971 result_len); 970 result_len);
972 if (!maybe_array->To(&result_array)) return maybe_array; 971 if (!maybe_array->To(&result_array)) return maybe_array;
973 if (result_len == 0) return result_array; 972 if (result_len == 0) return result_array;
974 973
975 // Copy data. 974 // Copy data.
976 AssertNoAllocation no_gc;
Jakob Kummerow 2012/03/12 15:33:28 Same question here.
danno 2012/03/12 20:35:03 See above. On 2012/03/12 15:33:28, Jakob wrote:
977 int start_pos = 0; 975 int start_pos = 0;
978 FixedArray* result_elms(FixedArray::cast(result_array->elements())); 976 FixedArray* result_elms(FixedArray::cast(result_array->elements()));
979 for (int i = 0; i < n_arguments; i++) { 977 for (int i = 0; i < n_arguments; i++) {
980 JSArray* array = JSArray::cast(args[i]); 978 JSArray* array = JSArray::cast(args[i]);
981 int len = Smi::cast(array->length())->value(); 979 int len = Smi::cast(array->length())->value();
982 FixedArray* elms = FixedArray::cast(array->elements()); 980 FixedArray* elms = FixedArray::cast(array->elements());
983 CopyObjectToObjectElements(&no_gc, elms, FAST_ELEMENTS, 0, 981 CopyObjectToObjectElements(elms, FAST_ELEMENTS, 0,
984 result_elms, FAST_ELEMENTS, 982 result_elms, FAST_ELEMENTS,
985 start_pos, len); 983 start_pos, len);
986 start_pos += len; 984 start_pos += len;
987 } 985 }
988 ASSERT(start_pos == result_len); 986 ASSERT(start_pos == result_len);
989 987
990 return result_array; 988 return result_array;
991 } 989 }
992 990
993 991
(...skipping 744 matching lines...) Expand 10 before | Expand all | Expand 10 after
1738 return Handle<Code>(code_address); \ 1736 return Handle<Code>(code_address); \
1739 } 1737 }
1740 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) 1738 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C)
1741 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) 1739 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A)
1742 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) 1740 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A)
1743 #undef DEFINE_BUILTIN_ACCESSOR_C 1741 #undef DEFINE_BUILTIN_ACCESSOR_C
1744 #undef DEFINE_BUILTIN_ACCESSOR_A 1742 #undef DEFINE_BUILTIN_ACCESSOR_A
1745 1743
1746 1744
1747 } } // namespace v8::internal 1745 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | src/elements.h » ('j') | src/elements.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698