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

Side by Side Diff: src/builtins.cc

Issue 11416238: Move CopyElements to the accessor of the target. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed more comments. Created 8 years 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 558 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 569
570 if (new_length > elms->length()) { 570 if (new_length > elms->length()) {
571 // New backing storage is needed. 571 // New backing storage is needed.
572 int capacity = new_length + (new_length >> 1) + 16; 572 int capacity = new_length + (new_length >> 1) + 16;
573 FixedArray* new_elms; 573 FixedArray* new_elms;
574 MaybeObject* maybe_obj = heap->AllocateUninitializedFixedArray(capacity); 574 MaybeObject* maybe_obj = heap->AllocateUninitializedFixedArray(capacity);
575 if (!maybe_obj->To(&new_elms)) return maybe_obj; 575 if (!maybe_obj->To(&new_elms)) return maybe_obj;
576 576
577 ElementsAccessor* accessor = array->GetElementsAccessor(); 577 ElementsAccessor* accessor = array->GetElementsAccessor();
578 MaybeObject* maybe_failure = accessor->CopyElements( 578 MaybeObject* maybe_failure = accessor->CopyElements(
579 NULL, 0, new_elms, kind, 0, 579 NULL, 0, kind, new_elms, 0,
580 ElementsAccessor::kCopyToEndAndInitializeToHole, elms_obj); 580 ElementsAccessor::kCopyToEndAndInitializeToHole, elms_obj);
581 ASSERT(!maybe_failure->IsFailure()); 581 ASSERT(!maybe_failure->IsFailure());
582 USE(maybe_failure); 582 USE(maybe_failure);
583 583
584 elms = new_elms; 584 elms = new_elms;
585 } 585 }
586 586
587 // Add the provided values. 587 // Add the provided values.
588 AssertNoAllocation no_gc; 588 AssertNoAllocation no_gc;
589 WriteBarrierMode mode = elms->GetWriteBarrierMode(no_gc); 589 WriteBarrierMode mode = elms->GetWriteBarrierMode(no_gc);
(...skipping 26 matching lines...) Expand all
616 616
617 if (new_length > elms_len) { 617 if (new_length > elms_len) {
618 // New backing storage is needed. 618 // New backing storage is needed.
619 int capacity = new_length + (new_length >> 1) + 16; 619 int capacity = new_length + (new_length >> 1) + 16;
620 MaybeObject* maybe_obj = 620 MaybeObject* maybe_obj =
621 heap->AllocateUninitializedFixedDoubleArray(capacity); 621 heap->AllocateUninitializedFixedDoubleArray(capacity);
622 if (!maybe_obj->To(&new_elms)) return maybe_obj; 622 if (!maybe_obj->To(&new_elms)) return maybe_obj;
623 623
624 ElementsAccessor* accessor = array->GetElementsAccessor(); 624 ElementsAccessor* accessor = array->GetElementsAccessor();
625 MaybeObject* maybe_failure = accessor->CopyElements( 625 MaybeObject* maybe_failure = accessor->CopyElements(
626 NULL, 0, new_elms, kind, 0, 626 NULL, 0, kind, new_elms, 0,
627 ElementsAccessor::kCopyToEndAndInitializeToHole, elms_obj); 627 ElementsAccessor::kCopyToEndAndInitializeToHole, elms_obj);
628 ASSERT(!maybe_failure->IsFailure()); 628 ASSERT(!maybe_failure->IsFailure());
629 USE(maybe_failure); 629 USE(maybe_failure);
630 } else { 630 } else {
631 // to_add is > 0 and new_length <= elms_len, so elms_obj cannot be the 631 // to_add is > 0 and new_length <= elms_len, so elms_obj cannot be the
632 // empty_fixed_array. 632 // empty_fixed_array.
633 new_elms = FixedDoubleArray::cast(elms_obj); 633 new_elms = FixedDoubleArray::cast(elms_obj);
634 } 634 }
635 635
636 // Add the provided values. 636 // Add the provided values.
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
778 if (new_length > elms->length()) { 778 if (new_length > elms->length()) {
779 // New backing storage is needed. 779 // New backing storage is needed.
780 int capacity = new_length + (new_length >> 1) + 16; 780 int capacity = new_length + (new_length >> 1) + 16;
781 FixedArray* new_elms; 781 FixedArray* new_elms;
782 MaybeObject* maybe_elms = heap->AllocateUninitializedFixedArray(capacity); 782 MaybeObject* maybe_elms = heap->AllocateUninitializedFixedArray(capacity);
783 if (!maybe_elms->To(&new_elms)) return maybe_elms; 783 if (!maybe_elms->To(&new_elms)) return maybe_elms;
784 784
785 ElementsKind kind = array->GetElementsKind(); 785 ElementsKind kind = array->GetElementsKind();
786 ElementsAccessor* accessor = array->GetElementsAccessor(); 786 ElementsAccessor* accessor = array->GetElementsAccessor();
787 MaybeObject* maybe_failure = accessor->CopyElements( 787 MaybeObject* maybe_failure = accessor->CopyElements(
788 NULL, 0, new_elms, kind, to_add, 788 NULL, 0, kind, new_elms, to_add,
789 ElementsAccessor::kCopyToEndAndInitializeToHole, elms); 789 ElementsAccessor::kCopyToEndAndInitializeToHole, elms);
790 ASSERT(!maybe_failure->IsFailure()); 790 ASSERT(!maybe_failure->IsFailure());
791 USE(maybe_failure); 791 USE(maybe_failure);
792 792
793 elms = new_elms; 793 elms = new_elms;
794 array->set_elements(elms); 794 array->set_elements(elms);
795 } else { 795 } else {
796 AssertNoAllocation no_gc; 796 AssertNoAllocation no_gc;
797 MoveElements(heap, &no_gc, elms, to_add, elms, 0, len); 797 MoveElements(heap, &no_gc, elms, to_add, elms, 0, len);
798 } 798 }
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
927 JSArray* result_array; 927 JSArray* result_array;
928 MaybeObject* maybe_array = heap->AllocateJSArrayAndStorage(kind, 928 MaybeObject* maybe_array = heap->AllocateJSArrayAndStorage(kind,
929 result_len, 929 result_len,
930 result_len); 930 result_len);
931 931
932 AssertNoAllocation no_gc; 932 AssertNoAllocation no_gc;
933 if (result_len == 0) return maybe_array; 933 if (result_len == 0) return maybe_array;
934 if (!maybe_array->To(&result_array)) return maybe_array; 934 if (!maybe_array->To(&result_array)) return maybe_array;
935 935
936 ElementsAccessor* accessor = object->GetElementsAccessor(); 936 ElementsAccessor* accessor = object->GetElementsAccessor();
937 MaybeObject* maybe_failure = 937 MaybeObject* maybe_failure = accessor->CopyElements(
938 accessor->CopyElements(NULL, k, result_array->elements(), 938 NULL, k, kind, result_array->elements(), 0, result_len, elms);
939 kind, 0, result_len, elms);
940 ASSERT(!maybe_failure->IsFailure()); 939 ASSERT(!maybe_failure->IsFailure());
941 USE(maybe_failure); 940 USE(maybe_failure);
942 941
943 return result_array; 942 return result_array;
944 } 943 }
945 944
946 945
947 BUILTIN(ArraySplice) { 946 BUILTIN(ArraySplice) {
948 Heap* heap = isolate->heap(); 947 Heap* heap = isolate->heap();
949 Object* receiver = *args.receiver(); 948 Object* receiver = *args.receiver();
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
1030 JSArray* result_array = NULL; 1029 JSArray* result_array = NULL;
1031 MaybeObject* maybe_array = 1030 MaybeObject* maybe_array =
1032 heap->AllocateJSArrayAndStorage(elements_kind, 1031 heap->AllocateJSArrayAndStorage(elements_kind,
1033 actual_delete_count, 1032 actual_delete_count,
1034 actual_delete_count); 1033 actual_delete_count);
1035 if (!maybe_array->To(&result_array)) return maybe_array; 1034 if (!maybe_array->To(&result_array)) return maybe_array;
1036 1035
1037 if (actual_delete_count > 0) { 1036 if (actual_delete_count > 0) {
1038 AssertNoAllocation no_gc; 1037 AssertNoAllocation no_gc;
1039 ElementsAccessor* accessor = array->GetElementsAccessor(); 1038 ElementsAccessor* accessor = array->GetElementsAccessor();
1040 MaybeObject* maybe_failure = 1039 MaybeObject* maybe_failure = accessor->CopyElements(
1041 accessor->CopyElements(NULL, actual_start, result_array->elements(), 1040 NULL, actual_start, elements_kind, result_array->elements(),
1042 elements_kind, 0, actual_delete_count, elms_obj); 1041 0, actual_delete_count, elms_obj);
1043 // Cannot fail since the origin and target array are of the same elements 1042 // Cannot fail since the origin and target array are of the same elements
1044 // kind. 1043 // kind.
1045 ASSERT(!maybe_failure->IsFailure()); 1044 ASSERT(!maybe_failure->IsFailure());
1046 USE(maybe_failure); 1045 USE(maybe_failure);
1047 } 1046 }
1048 1047
1049 bool elms_changed = false; 1048 bool elms_changed = false;
1050 if (item_count < actual_delete_count) { 1049 if (item_count < actual_delete_count) {
1051 // Shrink the array. 1050 // Shrink the array.
1052 const bool trim_array = !heap->lo_space()->Contains(elms_obj) && 1051 const bool trim_array = !heap->lo_space()->Contains(elms_obj) &&
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1098 MaybeObject* maybe_obj = heap->AllocateUninitializedFixedArray(capacity); 1097 MaybeObject* maybe_obj = heap->AllocateUninitializedFixedArray(capacity);
1099 if (!maybe_obj->To(&new_elms)) return maybe_obj; 1098 if (!maybe_obj->To(&new_elms)) return maybe_obj;
1100 1099
1101 AssertNoAllocation no_gc; 1100 AssertNoAllocation no_gc;
1102 1101
1103 ElementsKind kind = array->GetElementsKind(); 1102 ElementsKind kind = array->GetElementsKind();
1104 ElementsAccessor* accessor = array->GetElementsAccessor(); 1103 ElementsAccessor* accessor = array->GetElementsAccessor();
1105 if (actual_start > 0) { 1104 if (actual_start > 0) {
1106 // Copy the part before actual_start as is. 1105 // Copy the part before actual_start as is.
1107 MaybeObject* maybe_failure = accessor->CopyElements( 1106 MaybeObject* maybe_failure = accessor->CopyElements(
1108 NULL, 0, new_elms, kind, 0, actual_start, elms); 1107 NULL, 0, kind, new_elms, 0, actual_start, elms);
1109 ASSERT(!maybe_failure->IsFailure()); 1108 ASSERT(!maybe_failure->IsFailure());
1110 USE(maybe_failure); 1109 USE(maybe_failure);
1111 } 1110 }
1112 MaybeObject* maybe_failure = accessor->CopyElements( 1111 MaybeObject* maybe_failure = accessor->CopyElements(
1113 NULL, actual_start + actual_delete_count, new_elms, kind, 1112 NULL, actual_start + actual_delete_count, kind, new_elms,
1114 actual_start + item_count, 1113 actual_start + item_count,
1115 ElementsAccessor::kCopyToEndAndInitializeToHole, elms); 1114 ElementsAccessor::kCopyToEndAndInitializeToHole, elms);
1116 ASSERT(!maybe_failure->IsFailure()); 1115 ASSERT(!maybe_failure->IsFailure());
1117 USE(maybe_failure); 1116 USE(maybe_failure);
1118 1117
1119 elms_obj = new_elms; 1118 elms_obj = new_elms;
1120 elms_changed = true; 1119 elms_changed = true;
1121 } else { 1120 } else {
1122 AssertNoAllocation no_gc; 1121 AssertNoAllocation no_gc;
1123 MoveElements(heap, &no_gc, 1122 MoveElements(heap, &no_gc,
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
1213 MaybeObject* maybe_array = 1212 MaybeObject* maybe_array =
1214 heap->AllocateJSArrayAndStorage(elements_kind, 1213 heap->AllocateJSArrayAndStorage(elements_kind,
1215 result_len, 1214 result_len,
1216 result_len, 1215 result_len,
1217 mode); 1216 mode);
1218 if (!maybe_array->To(&result_array)) return maybe_array; 1217 if (!maybe_array->To(&result_array)) return maybe_array;
1219 if (result_len == 0) return result_array; 1218 if (result_len == 0) return result_array;
1220 1219
1221 int j = 0; 1220 int j = 0;
1222 FixedArrayBase* storage = result_array->elements(); 1221 FixedArrayBase* storage = result_array->elements();
1222 ElementsAccessor* accessor = ElementsAccessor::ForKind(elements_kind);
1223 for (int i = 0; i < n_arguments; i++) { 1223 for (int i = 0; i < n_arguments; i++) {
1224 JSArray* array = JSArray::cast(args[i]); 1224 JSArray* array = JSArray::cast(args[i]);
1225 int len = Smi::cast(array->length())->value(); 1225 int len = Smi::cast(array->length())->value();
1226 ElementsKind from_kind = array->GetElementsKind();
1226 if (len > 0) { 1227 if (len > 0) {
1227 ElementsAccessor* accessor = array->GetElementsAccessor();
1228 MaybeObject* maybe_failure = 1228 MaybeObject* maybe_failure =
1229 accessor->CopyElements(array, 0, storage, elements_kind, j, len); 1229 accessor->CopyElements(array, 0, from_kind, storage, j, len);
1230 if (maybe_failure->IsFailure()) return maybe_failure; 1230 if (maybe_failure->IsFailure()) return maybe_failure;
1231 j += len; 1231 j += len;
1232 } 1232 }
1233 } 1233 }
1234 1234
1235 ASSERT(j == result_len); 1235 ASSERT(j == result_len);
1236 1236
1237 return result_array; 1237 return result_array;
1238 } 1238 }
1239 1239
(...skipping 695 matching lines...) Expand 10 before | Expand all | Expand 10 after
1935 return Handle<Code>(code_address); \ 1935 return Handle<Code>(code_address); \
1936 } 1936 }
1937 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) 1937 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C)
1938 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) 1938 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A)
1939 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) 1939 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A)
1940 #undef DEFINE_BUILTIN_ACCESSOR_C 1940 #undef DEFINE_BUILTIN_ACCESSOR_C
1941 #undef DEFINE_BUILTIN_ACCESSOR_A 1941 #undef DEFINE_BUILTIN_ACCESSOR_A
1942 1942
1943 1943
1944 } } // namespace v8::internal 1944 } } // 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