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 1603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1614 if (!IsFastObjectElementsKind(elements_kind)) { | 1614 if (!IsFastObjectElementsKind(elements_kind)) { |
1615 if (IsFastHoleyElementsKind(elements_kind)) { | 1615 if (IsFastHoleyElementsKind(elements_kind)) { |
1616 TransitionElementsKind(object, FAST_HOLEY_ELEMENTS); | 1616 TransitionElementsKind(object, FAST_HOLEY_ELEMENTS); |
1617 } else { | 1617 } else { |
1618 TransitionElementsKind(object, FAST_ELEMENTS); | 1618 TransitionElementsKind(object, FAST_ELEMENTS); |
1619 } | 1619 } |
1620 } | 1620 } |
1621 } | 1621 } |
1622 | 1622 |
1623 | 1623 |
1624 MaybeObject* JSObject::EnsureCanContainElements(Object** objects, | 1624 void JSObject::EnsureCanContainElements(Handle<JSObject> object, |
1625 uint32_t count, | 1625 Object** objects, |
1626 EnsureElementsMode mode) { | 1626 uint32_t count, |
1627 ElementsKind current_kind = map()->elements_kind(); | 1627 EnsureElementsMode mode) { |
| 1628 ElementsKind current_kind = object->map()->elements_kind(); |
1628 ElementsKind target_kind = current_kind; | 1629 ElementsKind target_kind = current_kind; |
1629 ASSERT(mode != ALLOW_COPIED_DOUBLE_ELEMENTS); | 1630 { |
1630 bool is_holey = IsFastHoleyElementsKind(current_kind); | 1631 DisallowHeapAllocation no_allocation; |
1631 if (current_kind == FAST_HOLEY_ELEMENTS) return this; | 1632 ASSERT(mode != ALLOW_COPIED_DOUBLE_ELEMENTS); |
1632 Heap* heap = GetHeap(); | 1633 bool is_holey = IsFastHoleyElementsKind(current_kind); |
1633 Object* the_hole = heap->the_hole_value(); | 1634 if (current_kind == FAST_HOLEY_ELEMENTS) return; |
1634 for (uint32_t i = 0; i < count; ++i) { | 1635 Heap* heap = object->GetHeap(); |
1635 Object* current = *objects++; | 1636 Object* the_hole = heap->the_hole_value(); |
1636 if (current == the_hole) { | 1637 for (uint32_t i = 0; i < count; ++i) { |
1637 is_holey = true; | 1638 Object* current = *objects++; |
1638 target_kind = GetHoleyElementsKind(target_kind); | 1639 if (current == the_hole) { |
1639 } else if (!current->IsSmi()) { | 1640 is_holey = true; |
1640 if (mode == ALLOW_CONVERTED_DOUBLE_ELEMENTS && current->IsNumber()) { | 1641 target_kind = GetHoleyElementsKind(target_kind); |
1641 if (IsFastSmiElementsKind(target_kind)) { | 1642 } else if (!current->IsSmi()) { |
1642 if (is_holey) { | 1643 if (mode == ALLOW_CONVERTED_DOUBLE_ELEMENTS && current->IsNumber()) { |
1643 target_kind = FAST_HOLEY_DOUBLE_ELEMENTS; | 1644 if (IsFastSmiElementsKind(target_kind)) { |
1644 } else { | 1645 if (is_holey) { |
1645 target_kind = FAST_DOUBLE_ELEMENTS; | 1646 target_kind = FAST_HOLEY_DOUBLE_ELEMENTS; |
| 1647 } else { |
| 1648 target_kind = FAST_DOUBLE_ELEMENTS; |
| 1649 } |
1646 } | 1650 } |
| 1651 } else if (is_holey) { |
| 1652 target_kind = FAST_HOLEY_ELEMENTS; |
| 1653 break; |
| 1654 } else { |
| 1655 target_kind = FAST_ELEMENTS; |
1647 } | 1656 } |
1648 } else if (is_holey) { | |
1649 target_kind = FAST_HOLEY_ELEMENTS; | |
1650 break; | |
1651 } else { | |
1652 target_kind = FAST_ELEMENTS; | |
1653 } | 1657 } |
1654 } | 1658 } |
1655 } | 1659 } |
1656 | |
1657 if (target_kind != current_kind) { | 1660 if (target_kind != current_kind) { |
1658 return TransitionElementsKind(target_kind); | 1661 TransitionElementsKind(object, target_kind); |
1659 } | 1662 } |
1660 return this; | |
1661 } | 1663 } |
1662 | 1664 |
1663 | 1665 |
1664 // TODO(ishell): Temporary wrapper until handlified. | |
1665 void JSObject::EnsureCanContainElements(Handle<JSObject> object, | 1666 void JSObject::EnsureCanContainElements(Handle<JSObject> object, |
1666 Handle<FixedArrayBase> elements, | 1667 Handle<FixedArrayBase> elements, |
1667 uint32_t length, | 1668 uint32_t length, |
1668 EnsureElementsMode mode) { | 1669 EnsureElementsMode mode) { |
1669 CALL_HEAP_FUNCTION_VOID(object->GetIsolate(), | 1670 Heap* heap = object->GetHeap(); |
1670 object->EnsureCanContainElements(*elements, | 1671 if (elements->map() != heap->fixed_double_array_map()) { |
1671 length, | 1672 ASSERT(elements->map() == heap->fixed_array_map() || |
1672 mode)); | 1673 elements->map() == heap->fixed_cow_array_map()); |
| 1674 if (mode == ALLOW_COPIED_DOUBLE_ELEMENTS) { |
| 1675 mode = DONT_ALLOW_DOUBLE_ELEMENTS; |
| 1676 } |
| 1677 Object** objects = |
| 1678 Handle<FixedArray>::cast(elements)->GetFirstElementAddress(); |
| 1679 EnsureCanContainElements(object, objects, length, mode); |
| 1680 return; |
| 1681 } |
| 1682 |
| 1683 ASSERT(mode == ALLOW_COPIED_DOUBLE_ELEMENTS); |
| 1684 if (object->GetElementsKind() == FAST_HOLEY_SMI_ELEMENTS) { |
| 1685 TransitionElementsKind(object, FAST_HOLEY_DOUBLE_ELEMENTS); |
| 1686 } else if (object->GetElementsKind() == FAST_SMI_ELEMENTS) { |
| 1687 Handle<FixedDoubleArray> double_array = |
| 1688 Handle<FixedDoubleArray>::cast(elements); |
| 1689 for (uint32_t i = 0; i < length; ++i) { |
| 1690 if (double_array->is_the_hole(i)) { |
| 1691 TransitionElementsKind(object, FAST_HOLEY_DOUBLE_ELEMENTS); |
| 1692 return; |
| 1693 } |
| 1694 } |
| 1695 TransitionElementsKind(object, FAST_DOUBLE_ELEMENTS); |
| 1696 } |
1673 } | 1697 } |
1674 | 1698 |
1675 | 1699 |
1676 MaybeObject* JSObject::EnsureCanContainElements(FixedArrayBase* elements, | |
1677 uint32_t length, | |
1678 EnsureElementsMode mode) { | |
1679 if (elements->map() != GetHeap()->fixed_double_array_map()) { | |
1680 ASSERT(elements->map() == GetHeap()->fixed_array_map() || | |
1681 elements->map() == GetHeap()->fixed_cow_array_map()); | |
1682 if (mode == ALLOW_COPIED_DOUBLE_ELEMENTS) { | |
1683 mode = DONT_ALLOW_DOUBLE_ELEMENTS; | |
1684 } | |
1685 Object** objects = FixedArray::cast(elements)->GetFirstElementAddress(); | |
1686 return EnsureCanContainElements(objects, length, mode); | |
1687 } | |
1688 | |
1689 ASSERT(mode == ALLOW_COPIED_DOUBLE_ELEMENTS); | |
1690 if (GetElementsKind() == FAST_HOLEY_SMI_ELEMENTS) { | |
1691 return TransitionElementsKind(FAST_HOLEY_DOUBLE_ELEMENTS); | |
1692 } else if (GetElementsKind() == FAST_SMI_ELEMENTS) { | |
1693 FixedDoubleArray* double_array = FixedDoubleArray::cast(elements); | |
1694 for (uint32_t i = 0; i < length; ++i) { | |
1695 if (double_array->is_the_hole(i)) { | |
1696 return TransitionElementsKind(FAST_HOLEY_DOUBLE_ELEMENTS); | |
1697 } | |
1698 } | |
1699 return TransitionElementsKind(FAST_DOUBLE_ELEMENTS); | |
1700 } | |
1701 | |
1702 return this; | |
1703 } | |
1704 | |
1705 | |
1706 MaybeObject* JSObject::GetElementsTransitionMap(Isolate* isolate, | 1700 MaybeObject* JSObject::GetElementsTransitionMap(Isolate* isolate, |
1707 ElementsKind to_kind) { | 1701 ElementsKind to_kind) { |
1708 Map* current_map = map(); | 1702 Map* current_map = map(); |
1709 ElementsKind from_kind = current_map->elements_kind(); | 1703 ElementsKind from_kind = current_map->elements_kind(); |
1710 if (from_kind == to_kind) return current_map; | 1704 if (from_kind == to_kind) return current_map; |
1711 | 1705 |
1712 Context* native_context = isolate->context()->native_context(); | 1706 Context* native_context = isolate->context()->native_context(); |
1713 Object* maybe_array_maps = native_context->js_array_maps(); | 1707 Object* maybe_array_maps = native_context->js_array_maps(); |
1714 if (maybe_array_maps->IsFixedArray()) { | 1708 if (maybe_array_maps->IsFixedArray()) { |
1715 FixedArray* array_maps = FixedArray::cast(maybe_array_maps); | 1709 FixedArray* array_maps = FixedArray::cast(maybe_array_maps); |
(...skipping 5105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6821 #undef READ_UINT32_FIELD | 6815 #undef READ_UINT32_FIELD |
6822 #undef WRITE_UINT32_FIELD | 6816 #undef WRITE_UINT32_FIELD |
6823 #undef READ_SHORT_FIELD | 6817 #undef READ_SHORT_FIELD |
6824 #undef WRITE_SHORT_FIELD | 6818 #undef WRITE_SHORT_FIELD |
6825 #undef READ_BYTE_FIELD | 6819 #undef READ_BYTE_FIELD |
6826 #undef WRITE_BYTE_FIELD | 6820 #undef WRITE_BYTE_FIELD |
6827 | 6821 |
6828 } } // namespace v8::internal | 6822 } } // namespace v8::internal |
6829 | 6823 |
6830 #endif // V8_OBJECTS_INL_H_ | 6824 #endif // V8_OBJECTS_INL_H_ |
OLD | NEW |