| OLD | NEW |
| 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 545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 556 MaybeObject* maybe_failure = accessor->CopyElements( | 556 MaybeObject* maybe_failure = accessor->CopyElements( |
| 557 NULL, 0, kind, new_elms, 0, | 557 NULL, 0, kind, new_elms, 0, |
| 558 ElementsAccessor::kCopyToEndAndInitializeToHole, elms_obj); | 558 ElementsAccessor::kCopyToEndAndInitializeToHole, elms_obj); |
| 559 ASSERT(!maybe_failure->IsFailure()); | 559 ASSERT(!maybe_failure->IsFailure()); |
| 560 USE(maybe_failure); | 560 USE(maybe_failure); |
| 561 | 561 |
| 562 elms = new_elms; | 562 elms = new_elms; |
| 563 } | 563 } |
| 564 | 564 |
| 565 // Add the provided values. | 565 // Add the provided values. |
| 566 AssertNoAllocation no_gc; | 566 DisallowHeapAllocation no_gc; |
| 567 WriteBarrierMode mode = elms->GetWriteBarrierMode(no_gc); | 567 WriteBarrierMode mode = elms->GetWriteBarrierMode(no_gc); |
| 568 for (int index = 0; index < to_add; index++) { | 568 for (int index = 0; index < to_add; index++) { |
| 569 elms->set(index + len, args[index + 1], mode); | 569 elms->set(index + len, args[index + 1], mode); |
| 570 } | 570 } |
| 571 | 571 |
| 572 if (elms != array->elements()) { | 572 if (elms != array->elements()) { |
| 573 array->set_elements(elms); | 573 array->set_elements(elms); |
| 574 } | 574 } |
| 575 | 575 |
| 576 // Set the length. | 576 // Set the length. |
| (...skipping 28 matching lines...) Expand all Loading... |
| 605 ElementsAccessor::kCopyToEndAndInitializeToHole, elms_obj); | 605 ElementsAccessor::kCopyToEndAndInitializeToHole, elms_obj); |
| 606 ASSERT(!maybe_failure->IsFailure()); | 606 ASSERT(!maybe_failure->IsFailure()); |
| 607 USE(maybe_failure); | 607 USE(maybe_failure); |
| 608 } else { | 608 } else { |
| 609 // to_add is > 0 and new_length <= elms_len, so elms_obj cannot be the | 609 // to_add is > 0 and new_length <= elms_len, so elms_obj cannot be the |
| 610 // empty_fixed_array. | 610 // empty_fixed_array. |
| 611 new_elms = FixedDoubleArray::cast(elms_obj); | 611 new_elms = FixedDoubleArray::cast(elms_obj); |
| 612 } | 612 } |
| 613 | 613 |
| 614 // Add the provided values. | 614 // Add the provided values. |
| 615 AssertNoAllocation no_gc; | 615 DisallowHeapAllocation no_gc; |
| 616 int index; | 616 int index; |
| 617 for (index = 0; index < to_add; index++) { | 617 for (index = 0; index < to_add; index++) { |
| 618 Object* arg = args[index + 1]; | 618 Object* arg = args[index + 1]; |
| 619 new_elms->set(index + len, arg->Number()); | 619 new_elms->set(index + len, arg->Number()); |
| 620 } | 620 } |
| 621 | 621 |
| 622 if (new_elms != array->elements()) { | 622 if (new_elms != array->elements()) { |
| 623 array->set_elements(new_elms); | 623 array->set_elements(new_elms); |
| 624 } | 624 } |
| 625 | 625 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 688 if (first->IsTheHole()) { | 688 if (first->IsTheHole()) { |
| 689 first = heap->undefined_value(); | 689 first = heap->undefined_value(); |
| 690 } | 690 } |
| 691 | 691 |
| 692 if (!heap->lo_space()->Contains(elms_obj)) { | 692 if (!heap->lo_space()->Contains(elms_obj)) { |
| 693 array->set_elements(LeftTrimFixedArray(heap, elms_obj, 1)); | 693 array->set_elements(LeftTrimFixedArray(heap, elms_obj, 1)); |
| 694 } else { | 694 } else { |
| 695 // Shift the elements. | 695 // Shift the elements. |
| 696 if (elms_obj->IsFixedArray()) { | 696 if (elms_obj->IsFixedArray()) { |
| 697 FixedArray* elms = FixedArray::cast(elms_obj); | 697 FixedArray* elms = FixedArray::cast(elms_obj); |
| 698 AssertNoAllocation no_gc; | 698 DisallowHeapAllocation no_gc; |
| 699 heap->MoveElements(elms, 0, 1, len - 1); | 699 heap->MoveElements(elms, 0, 1, len - 1); |
| 700 elms->set(len - 1, heap->the_hole_value()); | 700 elms->set(len - 1, heap->the_hole_value()); |
| 701 } else { | 701 } else { |
| 702 FixedDoubleArray* elms = FixedDoubleArray::cast(elms_obj); | 702 FixedDoubleArray* elms = FixedDoubleArray::cast(elms_obj); |
| 703 MoveDoubleElements(elms, 0, elms, 1, len - 1); | 703 MoveDoubleElements(elms, 0, elms, 1, len - 1); |
| 704 elms->set_the_hole(len - 1); | 704 elms->set_the_hole(len - 1); |
| 705 } | 705 } |
| 706 } | 706 } |
| 707 | 707 |
| 708 // Set the length. | 708 // Set the length. |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 755 ElementsAccessor* accessor = array->GetElementsAccessor(); | 755 ElementsAccessor* accessor = array->GetElementsAccessor(); |
| 756 MaybeObject* maybe_failure = accessor->CopyElements( | 756 MaybeObject* maybe_failure = accessor->CopyElements( |
| 757 NULL, 0, kind, new_elms, to_add, | 757 NULL, 0, kind, new_elms, to_add, |
| 758 ElementsAccessor::kCopyToEndAndInitializeToHole, elms); | 758 ElementsAccessor::kCopyToEndAndInitializeToHole, elms); |
| 759 ASSERT(!maybe_failure->IsFailure()); | 759 ASSERT(!maybe_failure->IsFailure()); |
| 760 USE(maybe_failure); | 760 USE(maybe_failure); |
| 761 | 761 |
| 762 elms = new_elms; | 762 elms = new_elms; |
| 763 array->set_elements(elms); | 763 array->set_elements(elms); |
| 764 } else { | 764 } else { |
| 765 AssertNoAllocation no_gc; | 765 DisallowHeapAllocation no_gc; |
| 766 heap->MoveElements(elms, to_add, 0, len); | 766 heap->MoveElements(elms, to_add, 0, len); |
| 767 } | 767 } |
| 768 | 768 |
| 769 // Add the provided values. | 769 // Add the provided values. |
| 770 AssertNoAllocation no_gc; | 770 DisallowHeapAllocation no_gc; |
| 771 WriteBarrierMode mode = elms->GetWriteBarrierMode(no_gc); | 771 WriteBarrierMode mode = elms->GetWriteBarrierMode(no_gc); |
| 772 for (int i = 0; i < to_add; i++) { | 772 for (int i = 0; i < to_add; i++) { |
| 773 elms->set(i, args[i + 1], mode); | 773 elms->set(i, args[i + 1], mode); |
| 774 } | 774 } |
| 775 | 775 |
| 776 // Set the length. | 776 // Set the length. |
| 777 array->set_length(Smi::FromInt(new_length)); | 777 array->set_length(Smi::FromInt(new_length)); |
| 778 return Smi::FromInt(new_length); | 778 return Smi::FromInt(new_length); |
| 779 } | 779 } |
| 780 | 780 |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 891 } else if (!receiver->IsJSArray()) { | 891 } else if (!receiver->IsJSArray()) { |
| 892 return CallJsBuiltin(isolate, "ArraySlice", args); | 892 return CallJsBuiltin(isolate, "ArraySlice", args); |
| 893 } | 893 } |
| 894 } | 894 } |
| 895 | 895 |
| 896 JSArray* result_array; | 896 JSArray* result_array; |
| 897 MaybeObject* maybe_array = heap->AllocateJSArrayAndStorage(kind, | 897 MaybeObject* maybe_array = heap->AllocateJSArrayAndStorage(kind, |
| 898 result_len, | 898 result_len, |
| 899 result_len); | 899 result_len); |
| 900 | 900 |
| 901 AssertNoAllocation no_gc; | 901 DisallowHeapAllocation no_gc; |
| 902 if (result_len == 0) return maybe_array; | 902 if (result_len == 0) return maybe_array; |
| 903 if (!maybe_array->To(&result_array)) return maybe_array; | 903 if (!maybe_array->To(&result_array)) return maybe_array; |
| 904 | 904 |
| 905 ElementsAccessor* accessor = object->GetElementsAccessor(); | 905 ElementsAccessor* accessor = object->GetElementsAccessor(); |
| 906 MaybeObject* maybe_failure = accessor->CopyElements( | 906 MaybeObject* maybe_failure = accessor->CopyElements( |
| 907 NULL, k, kind, result_array->elements(), 0, result_len, elms); | 907 NULL, k, kind, result_array->elements(), 0, result_len, elms); |
| 908 ASSERT(!maybe_failure->IsFailure()); | 908 ASSERT(!maybe_failure->IsFailure()); |
| 909 USE(maybe_failure); | 909 USE(maybe_failure); |
| 910 | 910 |
| 911 return result_array; | 911 return result_array; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 993 } | 993 } |
| 994 | 994 |
| 995 JSArray* result_array = NULL; | 995 JSArray* result_array = NULL; |
| 996 MaybeObject* maybe_array = | 996 MaybeObject* maybe_array = |
| 997 heap->AllocateJSArrayAndStorage(elements_kind, | 997 heap->AllocateJSArrayAndStorage(elements_kind, |
| 998 actual_delete_count, | 998 actual_delete_count, |
| 999 actual_delete_count); | 999 actual_delete_count); |
| 1000 if (!maybe_array->To(&result_array)) return maybe_array; | 1000 if (!maybe_array->To(&result_array)) return maybe_array; |
| 1001 | 1001 |
| 1002 if (actual_delete_count > 0) { | 1002 if (actual_delete_count > 0) { |
| 1003 AssertNoAllocation no_gc; | 1003 DisallowHeapAllocation no_gc; |
| 1004 ElementsAccessor* accessor = array->GetElementsAccessor(); | 1004 ElementsAccessor* accessor = array->GetElementsAccessor(); |
| 1005 MaybeObject* maybe_failure = accessor->CopyElements( | 1005 MaybeObject* maybe_failure = accessor->CopyElements( |
| 1006 NULL, actual_start, elements_kind, result_array->elements(), | 1006 NULL, actual_start, elements_kind, result_array->elements(), |
| 1007 0, actual_delete_count, elms_obj); | 1007 0, actual_delete_count, elms_obj); |
| 1008 // Cannot fail since the origin and target array are of the same elements | 1008 // Cannot fail since the origin and target array are of the same elements |
| 1009 // kind. | 1009 // kind. |
| 1010 ASSERT(!maybe_failure->IsFailure()); | 1010 ASSERT(!maybe_failure->IsFailure()); |
| 1011 USE(maybe_failure); | 1011 USE(maybe_failure); |
| 1012 } | 1012 } |
| 1013 | 1013 |
| 1014 bool elms_changed = false; | 1014 bool elms_changed = false; |
| 1015 if (item_count < actual_delete_count) { | 1015 if (item_count < actual_delete_count) { |
| 1016 // Shrink the array. | 1016 // Shrink the array. |
| 1017 const bool trim_array = !heap->lo_space()->Contains(elms_obj) && | 1017 const bool trim_array = !heap->lo_space()->Contains(elms_obj) && |
| 1018 ((actual_start + item_count) < | 1018 ((actual_start + item_count) < |
| 1019 (len - actual_delete_count - actual_start)); | 1019 (len - actual_delete_count - actual_start)); |
| 1020 if (trim_array) { | 1020 if (trim_array) { |
| 1021 const int delta = actual_delete_count - item_count; | 1021 const int delta = actual_delete_count - item_count; |
| 1022 | 1022 |
| 1023 if (elms_obj->IsFixedDoubleArray()) { | 1023 if (elms_obj->IsFixedDoubleArray()) { |
| 1024 FixedDoubleArray* elms = FixedDoubleArray::cast(elms_obj); | 1024 FixedDoubleArray* elms = FixedDoubleArray::cast(elms_obj); |
| 1025 MoveDoubleElements(elms, delta, elms, 0, actual_start); | 1025 MoveDoubleElements(elms, delta, elms, 0, actual_start); |
| 1026 } else { | 1026 } else { |
| 1027 FixedArray* elms = FixedArray::cast(elms_obj); | 1027 FixedArray* elms = FixedArray::cast(elms_obj); |
| 1028 AssertNoAllocation no_gc; | 1028 DisallowHeapAllocation no_gc; |
| 1029 heap->MoveElements(elms, delta, 0, actual_start); | 1029 heap->MoveElements(elms, delta, 0, actual_start); |
| 1030 } | 1030 } |
| 1031 | 1031 |
| 1032 elms_obj = LeftTrimFixedArray(heap, elms_obj, delta); | 1032 elms_obj = LeftTrimFixedArray(heap, elms_obj, delta); |
| 1033 | 1033 |
| 1034 elms_changed = true; | 1034 elms_changed = true; |
| 1035 } else { | 1035 } else { |
| 1036 if (elms_obj->IsFixedDoubleArray()) { | 1036 if (elms_obj->IsFixedDoubleArray()) { |
| 1037 FixedDoubleArray* elms = FixedDoubleArray::cast(elms_obj); | 1037 FixedDoubleArray* elms = FixedDoubleArray::cast(elms_obj); |
| 1038 MoveDoubleElements(elms, actual_start + item_count, | 1038 MoveDoubleElements(elms, actual_start + item_count, |
| 1039 elms, actual_start + actual_delete_count, | 1039 elms, actual_start + actual_delete_count, |
| 1040 (len - actual_delete_count - actual_start)); | 1040 (len - actual_delete_count - actual_start)); |
| 1041 FillWithHoles(elms, new_length, len); | 1041 FillWithHoles(elms, new_length, len); |
| 1042 } else { | 1042 } else { |
| 1043 FixedArray* elms = FixedArray::cast(elms_obj); | 1043 FixedArray* elms = FixedArray::cast(elms_obj); |
| 1044 AssertNoAllocation no_gc; | 1044 DisallowHeapAllocation no_gc; |
| 1045 heap->MoveElements(elms, actual_start + item_count, | 1045 heap->MoveElements(elms, actual_start + item_count, |
| 1046 actual_start + actual_delete_count, | 1046 actual_start + actual_delete_count, |
| 1047 (len - actual_delete_count - actual_start)); | 1047 (len - actual_delete_count - actual_start)); |
| 1048 FillWithHoles(heap, elms, new_length, len); | 1048 FillWithHoles(heap, elms, new_length, len); |
| 1049 } | 1049 } |
| 1050 } | 1050 } |
| 1051 } else if (item_count > actual_delete_count) { | 1051 } else if (item_count > actual_delete_count) { |
| 1052 FixedArray* elms = FixedArray::cast(elms_obj); | 1052 FixedArray* elms = FixedArray::cast(elms_obj); |
| 1053 // Currently fixed arrays cannot grow too big, so | 1053 // Currently fixed arrays cannot grow too big, so |
| 1054 // we should never hit this case. | 1054 // we should never hit this case. |
| 1055 ASSERT((item_count - actual_delete_count) <= (Smi::kMaxValue - len)); | 1055 ASSERT((item_count - actual_delete_count) <= (Smi::kMaxValue - len)); |
| 1056 | 1056 |
| 1057 // Check if array need to grow. | 1057 // Check if array need to grow. |
| 1058 if (new_length > elms->length()) { | 1058 if (new_length > elms->length()) { |
| 1059 // New backing storage is needed. | 1059 // New backing storage is needed. |
| 1060 int capacity = new_length + (new_length >> 1) + 16; | 1060 int capacity = new_length + (new_length >> 1) + 16; |
| 1061 FixedArray* new_elms; | 1061 FixedArray* new_elms; |
| 1062 MaybeObject* maybe_obj = heap->AllocateUninitializedFixedArray(capacity); | 1062 MaybeObject* maybe_obj = heap->AllocateUninitializedFixedArray(capacity); |
| 1063 if (!maybe_obj->To(&new_elms)) return maybe_obj; | 1063 if (!maybe_obj->To(&new_elms)) return maybe_obj; |
| 1064 | 1064 |
| 1065 AssertNoAllocation no_gc; | 1065 DisallowHeapAllocation no_gc; |
| 1066 | 1066 |
| 1067 ElementsKind kind = array->GetElementsKind(); | 1067 ElementsKind kind = array->GetElementsKind(); |
| 1068 ElementsAccessor* accessor = array->GetElementsAccessor(); | 1068 ElementsAccessor* accessor = array->GetElementsAccessor(); |
| 1069 if (actual_start > 0) { | 1069 if (actual_start > 0) { |
| 1070 // Copy the part before actual_start as is. | 1070 // Copy the part before actual_start as is. |
| 1071 MaybeObject* maybe_failure = accessor->CopyElements( | 1071 MaybeObject* maybe_failure = accessor->CopyElements( |
| 1072 NULL, 0, kind, new_elms, 0, actual_start, elms); | 1072 NULL, 0, kind, new_elms, 0, actual_start, elms); |
| 1073 ASSERT(!maybe_failure->IsFailure()); | 1073 ASSERT(!maybe_failure->IsFailure()); |
| 1074 USE(maybe_failure); | 1074 USE(maybe_failure); |
| 1075 } | 1075 } |
| 1076 MaybeObject* maybe_failure = accessor->CopyElements( | 1076 MaybeObject* maybe_failure = accessor->CopyElements( |
| 1077 NULL, actual_start + actual_delete_count, kind, new_elms, | 1077 NULL, actual_start + actual_delete_count, kind, new_elms, |
| 1078 actual_start + item_count, | 1078 actual_start + item_count, |
| 1079 ElementsAccessor::kCopyToEndAndInitializeToHole, elms); | 1079 ElementsAccessor::kCopyToEndAndInitializeToHole, elms); |
| 1080 ASSERT(!maybe_failure->IsFailure()); | 1080 ASSERT(!maybe_failure->IsFailure()); |
| 1081 USE(maybe_failure); | 1081 USE(maybe_failure); |
| 1082 | 1082 |
| 1083 elms_obj = new_elms; | 1083 elms_obj = new_elms; |
| 1084 elms_changed = true; | 1084 elms_changed = true; |
| 1085 } else { | 1085 } else { |
| 1086 AssertNoAllocation no_gc; | 1086 DisallowHeapAllocation no_gc; |
| 1087 heap->MoveElements(elms, actual_start + item_count, | 1087 heap->MoveElements(elms, actual_start + item_count, |
| 1088 actual_start + actual_delete_count, | 1088 actual_start + actual_delete_count, |
| 1089 (len - actual_delete_count - actual_start)); | 1089 (len - actual_delete_count - actual_start)); |
| 1090 } | 1090 } |
| 1091 } | 1091 } |
| 1092 | 1092 |
| 1093 if (IsFastDoubleElementsKind(elements_kind)) { | 1093 if (IsFastDoubleElementsKind(elements_kind)) { |
| 1094 FixedDoubleArray* elms = FixedDoubleArray::cast(elms_obj); | 1094 FixedDoubleArray* elms = FixedDoubleArray::cast(elms_obj); |
| 1095 for (int k = actual_start; k < actual_start + item_count; k++) { | 1095 for (int k = actual_start; k < actual_start + item_count; k++) { |
| 1096 Object* arg = args[3 + k - actual_start]; | 1096 Object* arg = args[3 + k - actual_start]; |
| 1097 if (arg->IsSmi()) { | 1097 if (arg->IsSmi()) { |
| 1098 elms->set(k, Smi::cast(arg)->value()); | 1098 elms->set(k, Smi::cast(arg)->value()); |
| 1099 } else { | 1099 } else { |
| 1100 elms->set(k, HeapNumber::cast(arg)->value()); | 1100 elms->set(k, HeapNumber::cast(arg)->value()); |
| 1101 } | 1101 } |
| 1102 } | 1102 } |
| 1103 } else { | 1103 } else { |
| 1104 FixedArray* elms = FixedArray::cast(elms_obj); | 1104 FixedArray* elms = FixedArray::cast(elms_obj); |
| 1105 AssertNoAllocation no_gc; | 1105 DisallowHeapAllocation no_gc; |
| 1106 WriteBarrierMode mode = elms->GetWriteBarrierMode(no_gc); | 1106 WriteBarrierMode mode = elms->GetWriteBarrierMode(no_gc); |
| 1107 for (int k = actual_start; k < actual_start + item_count; k++) { | 1107 for (int k = actual_start; k < actual_start + item_count; k++) { |
| 1108 elms->set(k, args[3 + k - actual_start], mode); | 1108 elms->set(k, args[3 + k - actual_start], mode); |
| 1109 } | 1109 } |
| 1110 } | 1110 } |
| 1111 | 1111 |
| 1112 if (elms_changed) { | 1112 if (elms_changed) { |
| 1113 array->set_elements(elms_obj); | 1113 array->set_elements(elms_obj); |
| 1114 } | 1114 } |
| 1115 // Set the length. | 1115 // Set the length. |
| (...skipping 767 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1883 return Handle<Code>(code_address); \ | 1883 return Handle<Code>(code_address); \ |
| 1884 } | 1884 } |
| 1885 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) | 1885 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) |
| 1886 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) | 1886 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) |
| 1887 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) | 1887 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) |
| 1888 #undef DEFINE_BUILTIN_ACCESSOR_C | 1888 #undef DEFINE_BUILTIN_ACCESSOR_C |
| 1889 #undef DEFINE_BUILTIN_ACCESSOR_A | 1889 #undef DEFINE_BUILTIN_ACCESSOR_A |
| 1890 | 1890 |
| 1891 | 1891 |
| 1892 } } // namespace v8::internal | 1892 } } // namespace v8::internal |
| OLD | NEW |