OLD | NEW |
1 // Copyright 2006-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2009 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 7431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7442 | 7442 |
7443 Handle<FixedArray> storage() { return storage_; } | 7443 Handle<FixedArray> storage() { return storage_; } |
7444 | 7444 |
7445 private: | 7445 private: |
7446 Handle<FixedArray> storage_; | 7446 Handle<FixedArray> storage_; |
7447 // Limit on the accepted indices. Elements with indices larger than the | 7447 // Limit on the accepted indices. Elements with indices larger than the |
7448 // limit are ignored by the visitor. | 7448 // limit are ignored by the visitor. |
7449 uint32_t index_limit_; | 7449 uint32_t index_limit_; |
7450 // Index after last seen index. Always less than or equal to index_limit_. | 7450 // Index after last seen index. Always less than or equal to index_limit_. |
7451 uint32_t index_offset_; | 7451 uint32_t index_offset_; |
7452 bool fast_elements_; | 7452 const bool fast_elements_; |
7453 }; | 7453 }; |
7454 | 7454 |
7455 | 7455 |
7456 template<class ExternalArrayClass, class ElementType> | 7456 template<class ExternalArrayClass, class ElementType> |
7457 static uint32_t IterateExternalArrayElements(Handle<JSObject> receiver, | 7457 static uint32_t IterateExternalArrayElements(Handle<JSObject> receiver, |
7458 bool elements_are_ints, | 7458 bool elements_are_ints, |
7459 bool elements_are_guaranteed_smis, | 7459 bool elements_are_guaranteed_smis, |
7460 uint32_t range, | 7460 uint32_t range, |
7461 ArrayConcatVisitor* visitor) { | 7461 ArrayConcatVisitor* visitor) { |
7462 Handle<ExternalArrayClass> array( | 7462 Handle<ExternalArrayClass> array( |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7759 // If estimated number of elements is more than half of length, a | 7759 // If estimated number of elements is more than half of length, a |
7760 // fixed array (fast case) is more time and space-efficient than a | 7760 // fixed array (fast case) is more time and space-efficient than a |
7761 // dictionary. | 7761 // dictionary. |
7762 bool fast_case = (estimate_nof_elements * 2) >= result_length; | 7762 bool fast_case = (estimate_nof_elements * 2) >= result_length; |
7763 | 7763 |
7764 Handle<FixedArray> storage; | 7764 Handle<FixedArray> storage; |
7765 if (fast_case) { | 7765 if (fast_case) { |
7766 // The backing storage array must have non-existing elements to | 7766 // The backing storage array must have non-existing elements to |
7767 // preserve holes across concat operations. | 7767 // preserve holes across concat operations. |
7768 storage = Factory::NewFixedArrayWithHoles(result_length); | 7768 storage = Factory::NewFixedArrayWithHoles(result_length); |
7769 | 7769 result->set_map(*Factory::GetFastElementsMap(Handle<Map>(result->map()))); |
7770 } else { | 7770 } else { |
7771 // TODO(126): move 25% pre-allocation logic into Dictionary::Allocate | 7771 // TODO(126): move 25% pre-allocation logic into Dictionary::Allocate |
7772 uint32_t at_least_space_for = estimate_nof_elements + | 7772 uint32_t at_least_space_for = estimate_nof_elements + |
7773 (estimate_nof_elements >> 2); | 7773 (estimate_nof_elements >> 2); |
7774 storage = Handle<FixedArray>::cast( | 7774 storage = Handle<FixedArray>::cast( |
7775 Factory::NewNumberDictionary(at_least_space_for)); | 7775 Factory::NewNumberDictionary(at_least_space_for)); |
| 7776 result->set_map(*Factory::GetSlowElementsMap(Handle<Map>(result->map()))); |
7776 } | 7777 } |
7777 | 7778 |
7778 Handle<Object> len = Factory::NewNumber(static_cast<double>(result_length)); | 7779 Handle<Object> len = Factory::NewNumber(static_cast<double>(result_length)); |
7779 | 7780 |
7780 ArrayConcatVisitor visitor(storage, result_length, fast_case); | 7781 ArrayConcatVisitor visitor(storage, result_length, fast_case); |
7781 | 7782 |
7782 IterateArguments(arguments, &visitor); | 7783 IterateArguments(arguments, &visitor); |
7783 | 7784 |
7784 result->set_length(*len); | 7785 result->set_length(*len); |
7785 // Please note the storage might have changed in the visitor. | 7786 // Please note the storage might have changed in the visitor. |
(...skipping 29 matching lines...) Expand all Loading... |
7815 CONVERT_NUMBER_CHECKED(uint32_t, limit, Uint32, args[1]); | 7816 CONVERT_NUMBER_CHECKED(uint32_t, limit, Uint32, args[1]); |
7816 return object->PrepareElementsForSort(limit); | 7817 return object->PrepareElementsForSort(limit); |
7817 } | 7818 } |
7818 | 7819 |
7819 | 7820 |
7820 // Move contents of argument 0 (an array) to argument 1 (an array) | 7821 // Move contents of argument 0 (an array) to argument 1 (an array) |
7821 static Object* Runtime_MoveArrayContents(Arguments args) { | 7822 static Object* Runtime_MoveArrayContents(Arguments args) { |
7822 ASSERT(args.length() == 2); | 7823 ASSERT(args.length() == 2); |
7823 CONVERT_CHECKED(JSArray, from, args[0]); | 7824 CONVERT_CHECKED(JSArray, from, args[0]); |
7824 CONVERT_CHECKED(JSArray, to, args[1]); | 7825 CONVERT_CHECKED(JSArray, to, args[1]); |
7825 to->SetContent(FixedArray::cast(from->elements())); | 7826 HeapObject* new_elements = from->elements(); |
| 7827 Object* new_map; |
| 7828 if (new_elements->map() == Heap::fixed_array_map()) { |
| 7829 new_map = to->map()->GetFastElementsMap(); |
| 7830 } else { |
| 7831 new_map = to->map()->GetSlowElementsMap(); |
| 7832 } |
| 7833 if (new_map->IsFailure()) return new_map; |
| 7834 to->set_map(Map::cast(new_map)); |
| 7835 to->set_elements(new_elements); |
7826 to->set_length(from->length()); | 7836 to->set_length(from->length()); |
7827 from->SetContent(Heap::empty_fixed_array()); | 7837 Object* obj = from->ResetElements(); |
| 7838 if (obj->IsFailure()) return obj; |
7828 from->set_length(Smi::FromInt(0)); | 7839 from->set_length(Smi::FromInt(0)); |
7829 return to; | 7840 return to; |
7830 } | 7841 } |
7831 | 7842 |
7832 | 7843 |
7833 // How many elements does this array have? | 7844 // How many elements does this array have? |
7834 static Object* Runtime_EstimateNumberOfElements(Arguments args) { | 7845 static Object* Runtime_EstimateNumberOfElements(Arguments args) { |
7835 ASSERT(args.length() == 1); | 7846 ASSERT(args.length() == 1); |
7836 CONVERT_CHECKED(JSArray, array, args[0]); | 7847 CONVERT_CHECKED(JSArray, array, args[0]); |
7837 HeapObject* elements = array->elements(); | 7848 HeapObject* elements = array->elements(); |
(...skipping 2530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10368 } else { | 10379 } else { |
10369 // Handle last resort GC and make sure to allow future allocations | 10380 // Handle last resort GC and make sure to allow future allocations |
10370 // to grow the heap without causing GCs (if possible). | 10381 // to grow the heap without causing GCs (if possible). |
10371 Counters::gc_last_resort_from_js.Increment(); | 10382 Counters::gc_last_resort_from_js.Increment(); |
10372 Heap::CollectAllGarbage(false); | 10383 Heap::CollectAllGarbage(false); |
10373 } | 10384 } |
10374 } | 10385 } |
10375 | 10386 |
10376 | 10387 |
10377 } } // namespace v8::internal | 10388 } } // namespace v8::internal |
OLD | NEW |