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

Side by Side Diff: src/builtins.cc

Issue 9638014: Implement efficient element copying in ElementsAccessors. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Review feedback 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') | 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 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 303
304 304
305 BUILTIN(ArrayCodeGeneric) { 305 BUILTIN(ArrayCodeGeneric) {
306 return ArrayCodeGenericCommon( 306 return ArrayCodeGenericCommon(
307 &args, 307 &args,
308 isolate, 308 isolate,
309 isolate->context()->global_context()->array_function()); 309 isolate->context()->global_context()->array_function());
310 } 310 }
311 311
312 312
313 static void CopyElements(Heap* heap,
314 AssertNoAllocation* no_gc,
315 FixedArray* dst,
316 int dst_index,
317 FixedArray* src,
318 int src_index,
319 int len) {
320 if (len == 0) return;
321 ASSERT(dst != src); // Use MoveElements instead.
322 ASSERT(dst->map() != HEAP->fixed_cow_array_map());
323 ASSERT(len > 0);
324 CopyWords(dst->data_start() + dst_index,
325 src->data_start() + src_index,
326 len);
327 WriteBarrierMode mode = dst->GetWriteBarrierMode(*no_gc);
328 if (mode == UPDATE_WRITE_BARRIER) {
329 heap->RecordWrites(dst->address(), dst->OffsetOfElementAt(dst_index), len);
330 }
331 heap->incremental_marking()->RecordWrites(dst);
332 }
333
334
335 static void MoveElements(Heap* heap, 313 static void MoveElements(Heap* heap,
336 AssertNoAllocation* no_gc, 314 AssertNoAllocation* no_gc,
337 FixedArray* dst, 315 FixedArray* dst,
338 int dst_index, 316 int dst_index,
339 FixedArray* src, 317 FixedArray* src,
340 int src_index, 318 int src_index,
341 int len) { 319 int len) {
342 if (len == 0) return; 320 if (len == 0) return;
343 ASSERT(dst->map() != HEAP->fixed_cow_array_map()); 321 ASSERT(dst->map() != HEAP->fixed_cow_array_map());
344 memmove(dst->data_start() + dst_index, 322 memmove(dst->data_start() + dst_index,
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 if (new_length > elms->length()) { 502 if (new_length > elms->length()) {
525 // New backing storage is needed. 503 // New backing storage is needed.
526 int capacity = new_length + (new_length >> 1) + 16; 504 int capacity = new_length + (new_length >> 1) + 16;
527 Object* obj; 505 Object* obj;
528 { MaybeObject* maybe_obj = heap->AllocateUninitializedFixedArray(capacity); 506 { MaybeObject* maybe_obj = heap->AllocateUninitializedFixedArray(capacity);
529 if (!maybe_obj->ToObject(&obj)) return maybe_obj; 507 if (!maybe_obj->ToObject(&obj)) return maybe_obj;
530 } 508 }
531 FixedArray* new_elms = FixedArray::cast(obj); 509 FixedArray* new_elms = FixedArray::cast(obj);
532 510
533 AssertNoAllocation no_gc; 511 AssertNoAllocation no_gc;
534 CopyElements(heap, &no_gc, new_elms, 0, elms, 0, len); 512 CopyObjectToObjectElements(&no_gc, elms, FAST_ELEMENTS, 0,
513 new_elms, FAST_ELEMENTS, 0, len);
535 FillWithHoles(heap, new_elms, new_length, capacity); 514 FillWithHoles(heap, new_elms, new_length, capacity);
536 515
537 elms = new_elms; 516 elms = new_elms;
538 } 517 }
539 518
540 // Add the provided values. 519 // Add the provided values.
541 AssertNoAllocation no_gc; 520 AssertNoAllocation no_gc;
542 WriteBarrierMode mode = elms->GetWriteBarrierMode(no_gc); 521 WriteBarrierMode mode = elms->GetWriteBarrierMode(no_gc);
543 for (int index = 0; index < to_add; index++) { 522 for (int index = 0; index < to_add; index++) {
544 elms->set(index + len, args[index + 1], mode); 523 elms->set(index + len, args[index + 1], mode);
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
660 639
661 if (new_length > elms->length()) { 640 if (new_length > elms->length()) {
662 // New backing storage is needed. 641 // New backing storage is needed.
663 int capacity = new_length + (new_length >> 1) + 16; 642 int capacity = new_length + (new_length >> 1) + 16;
664 Object* obj; 643 Object* obj;
665 { MaybeObject* maybe_obj = heap->AllocateUninitializedFixedArray(capacity); 644 { MaybeObject* maybe_obj = heap->AllocateUninitializedFixedArray(capacity);
666 if (!maybe_obj->ToObject(&obj)) return maybe_obj; 645 if (!maybe_obj->ToObject(&obj)) return maybe_obj;
667 } 646 }
668 FixedArray* new_elms = FixedArray::cast(obj); 647 FixedArray* new_elms = FixedArray::cast(obj);
669 AssertNoAllocation no_gc; 648 AssertNoAllocation no_gc;
670 CopyElements(heap, &no_gc, new_elms, to_add, elms, 0, len); 649 CopyObjectToObjectElements(&no_gc, elms, FAST_ELEMENTS, 0,
650 new_elms, FAST_ELEMENTS, to_add, len);
671 FillWithHoles(heap, new_elms, new_length, capacity); 651 FillWithHoles(heap, new_elms, new_length, capacity);
672 elms = new_elms; 652 elms = new_elms;
673 array->set_elements(elms); 653 array->set_elements(elms);
674 } else { 654 } else {
675 AssertNoAllocation no_gc; 655 AssertNoAllocation no_gc;
676 MoveElements(heap, &no_gc, elms, to_add, elms, 0, len); 656 MoveElements(heap, &no_gc, elms, to_add, elms, 0, len);
677 } 657 }
678 658
679 // Add the provided values. 659 // Add the provided values.
680 AssertNoAllocation no_gc; 660 AssertNoAllocation no_gc;
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
771 int result_len = Max(final - k, 0); 751 int result_len = Max(final - k, 0);
772 752
773 MaybeObject* maybe_array = 753 MaybeObject* maybe_array =
774 heap->AllocateJSArrayAndStorage(elements_kind, 754 heap->AllocateJSArrayAndStorage(elements_kind,
775 result_len, 755 result_len,
776 result_len); 756 result_len);
777 JSArray* result_array; 757 JSArray* result_array;
778 if (!maybe_array->To(&result_array)) return maybe_array; 758 if (!maybe_array->To(&result_array)) return maybe_array;
779 759
780 AssertNoAllocation no_gc; 760 AssertNoAllocation no_gc;
781 CopyElements(heap, &no_gc, FixedArray::cast(result_array->elements()), 0, 761 CopyObjectToObjectElements(&no_gc, elms, FAST_ELEMENTS, k,
782 elms, k, result_len); 762 FixedArray::cast(result_array->elements()),
763 FAST_ELEMENTS, 0, result_len);
783 764
784 return result_array; 765 return result_array;
785 } 766 }
786 767
787 768
788 BUILTIN(ArraySplice) { 769 BUILTIN(ArraySplice) {
789 Heap* heap = isolate->heap(); 770 Heap* heap = isolate->heap();
790 Object* receiver = *args.receiver(); 771 Object* receiver = *args.receiver();
791 Object* elms_obj; 772 Object* elms_obj;
792 { MaybeObject* maybe_elms_obj = 773 { MaybeObject* maybe_elms_obj =
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
845 JSObject::cast(receiver)->GetElementsKind(); 826 JSObject::cast(receiver)->GetElementsKind();
846 MaybeObject* maybe_array = 827 MaybeObject* maybe_array =
847 heap->AllocateJSArrayAndStorage(elements_kind, 828 heap->AllocateJSArrayAndStorage(elements_kind,
848 actual_delete_count, 829 actual_delete_count,
849 actual_delete_count); 830 actual_delete_count);
850 if (!maybe_array->To(&result_array)) return maybe_array; 831 if (!maybe_array->To(&result_array)) return maybe_array;
851 832
852 { 833 {
853 AssertNoAllocation no_gc; 834 AssertNoAllocation no_gc;
854 // Fill newly created array. 835 // Fill newly created array.
855 CopyElements(heap, 836 CopyObjectToObjectElements(&no_gc, elms, FAST_ELEMENTS, actual_start,
856 &no_gc, 837 FixedArray::cast(result_array->elements()),
857 FixedArray::cast(result_array->elements()), 0, 838 FAST_ELEMENTS, 0, actual_delete_count);
858 elms, actual_start,
859 actual_delete_count);
860 } 839 }
861 840
862 int item_count = (n_arguments > 1) ? (n_arguments - 2) : 0; 841 int item_count = (n_arguments > 1) ? (n_arguments - 2) : 0;
863 int new_length = len - actual_delete_count + item_count; 842 int new_length = len - actual_delete_count + item_count;
864 843
865 bool elms_changed = false; 844 bool elms_changed = false;
866 if (item_count < actual_delete_count) { 845 if (item_count < actual_delete_count) {
867 // Shrink the array. 846 // Shrink the array.
868 const bool trim_array = !heap->lo_space()->Contains(elms) && 847 const bool trim_array = !heap->lo_space()->Contains(elms) &&
869 ((actual_start + item_count) < 848 ((actual_start + item_count) <
(...skipping 29 matching lines...) Expand all
899 Object* obj; 878 Object* obj;
900 { MaybeObject* maybe_obj = 879 { MaybeObject* maybe_obj =
901 heap->AllocateUninitializedFixedArray(capacity); 880 heap->AllocateUninitializedFixedArray(capacity);
902 if (!maybe_obj->ToObject(&obj)) return maybe_obj; 881 if (!maybe_obj->ToObject(&obj)) return maybe_obj;
903 } 882 }
904 FixedArray* new_elms = FixedArray::cast(obj); 883 FixedArray* new_elms = FixedArray::cast(obj);
905 884
906 { 885 {
907 AssertNoAllocation no_gc; 886 AssertNoAllocation no_gc;
908 // Copy the part before actual_start as is. 887 // Copy the part before actual_start as is.
909 CopyElements(heap, &no_gc, new_elms, 0, elms, 0, actual_start); 888 CopyObjectToObjectElements(&no_gc, elms, FAST_ELEMENTS, 0,
889 new_elms, FAST_ELEMENTS, 0, actual_start);
910 const int to_copy = len - actual_delete_count - actual_start; 890 const int to_copy = len - actual_delete_count - actual_start;
911 CopyElements(heap, &no_gc, 891 CopyObjectToObjectElements(&no_gc, elms, FAST_ELEMENTS,
912 new_elms, actual_start + item_count, 892 actual_start + actual_delete_count,
913 elms, actual_start + actual_delete_count, 893 new_elms, FAST_ELEMENTS,
914 to_copy); 894 actual_start + item_count, to_copy);
915 } 895 }
916 896
917 FillWithHoles(heap, new_elms, new_length, capacity); 897 FillWithHoles(heap, new_elms, new_length, capacity);
918 898
919 elms = new_elms; 899 elms = new_elms;
920 elms_changed = true; 900 elms_changed = true;
921 } else { 901 } else {
922 AssertNoAllocation no_gc; 902 AssertNoAllocation no_gc;
923 MoveElements(heap, &no_gc, 903 MoveElements(heap, &no_gc,
924 elms, actual_start + item_count, 904 elms, actual_start + item_count,
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
993 if (result_len == 0) return result_array; 973 if (result_len == 0) return result_array;
994 974
995 // Copy data. 975 // Copy data.
996 AssertNoAllocation no_gc; 976 AssertNoAllocation no_gc;
997 int start_pos = 0; 977 int start_pos = 0;
998 FixedArray* result_elms(FixedArray::cast(result_array->elements())); 978 FixedArray* result_elms(FixedArray::cast(result_array->elements()));
999 for (int i = 0; i < n_arguments; i++) { 979 for (int i = 0; i < n_arguments; i++) {
1000 JSArray* array = JSArray::cast(args[i]); 980 JSArray* array = JSArray::cast(args[i]);
1001 int len = Smi::cast(array->length())->value(); 981 int len = Smi::cast(array->length())->value();
1002 FixedArray* elms = FixedArray::cast(array->elements()); 982 FixedArray* elms = FixedArray::cast(array->elements());
1003 CopyElements(heap, &no_gc, result_elms, start_pos, elms, 0, len); 983 CopyObjectToObjectElements(&no_gc, elms, FAST_ELEMENTS, 0,
984 result_elms, FAST_ELEMENTS,
985 start_pos, len);
1004 start_pos += len; 986 start_pos += len;
1005 } 987 }
1006 ASSERT(start_pos == result_len); 988 ASSERT(start_pos == result_len);
1007 989
1008 return result_array; 990 return result_array;
1009 } 991 }
1010 992
1011 993
1012 // ----------------------------------------------------------------------------- 994 // -----------------------------------------------------------------------------
1013 // Strict mode poison pills 995 // Strict mode poison pills
(...skipping 742 matching lines...) Expand 10 before | Expand all | Expand 10 after
1756 return Handle<Code>(code_address); \ 1738 return Handle<Code>(code_address); \
1757 } 1739 }
1758 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) 1740 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C)
1759 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) 1741 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A)
1760 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) 1742 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A)
1761 #undef DEFINE_BUILTIN_ACCESSOR_C 1743 #undef DEFINE_BUILTIN_ACCESSOR_C
1762 #undef DEFINE_BUILTIN_ACCESSOR_A 1744 #undef DEFINE_BUILTIN_ACCESSOR_A
1763 1745
1764 1746
1765 } } // namespace v8::internal 1747 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | src/elements.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698