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 1710 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1721 if (double_array->is_the_hole(i)) { | 1721 if (double_array->is_the_hole(i)) { |
1722 TransitionElementsKind(object, FAST_HOLEY_DOUBLE_ELEMENTS); | 1722 TransitionElementsKind(object, FAST_HOLEY_DOUBLE_ELEMENTS); |
1723 return; | 1723 return; |
1724 } | 1724 } |
1725 } | 1725 } |
1726 TransitionElementsKind(object, FAST_DOUBLE_ELEMENTS); | 1726 TransitionElementsKind(object, FAST_DOUBLE_ELEMENTS); |
1727 } | 1727 } |
1728 } | 1728 } |
1729 | 1729 |
1730 | 1730 |
1731 MaybeObject* JSObject::GetElementsTransitionMap(Isolate* isolate, | |
1732 ElementsKind to_kind) { | |
1733 Map* current_map = map(); | |
1734 ElementsKind from_kind = current_map->elements_kind(); | |
1735 if (from_kind == to_kind) return current_map; | |
1736 | |
1737 Context* native_context = isolate->context()->native_context(); | |
1738 Object* maybe_array_maps = native_context->js_array_maps(); | |
1739 if (maybe_array_maps->IsFixedArray()) { | |
1740 FixedArray* array_maps = FixedArray::cast(maybe_array_maps); | |
1741 if (array_maps->get(from_kind) == current_map) { | |
1742 Object* maybe_transitioned_map = array_maps->get(to_kind); | |
1743 if (maybe_transitioned_map->IsMap()) { | |
1744 return Map::cast(maybe_transitioned_map); | |
1745 } | |
1746 } | |
1747 } | |
1748 | |
1749 return GetElementsTransitionMapSlow(to_kind); | |
1750 } | |
1751 | |
1752 | |
1753 void JSObject::SetMapAndElements(Handle<JSObject> object, | 1731 void JSObject::SetMapAndElements(Handle<JSObject> object, |
1754 Handle<Map> new_map, | 1732 Handle<Map> new_map, |
1755 Handle<FixedArrayBase> value) { | 1733 Handle<FixedArrayBase> value) { |
1756 JSObject::MigrateToMap(object, new_map); | 1734 JSObject::MigrateToMap(object, new_map); |
1757 ASSERT((object->map()->has_fast_smi_or_object_elements() || | 1735 ASSERT((object->map()->has_fast_smi_or_object_elements() || |
1758 (*value == object->GetHeap()->empty_fixed_array())) == | 1736 (*value == object->GetHeap()->empty_fixed_array())) == |
1759 (value->map() == object->GetHeap()->fixed_array_map() || | 1737 (value->map() == object->GetHeap()->fixed_array_map() || |
1760 value->map() == object->GetHeap()->fixed_cow_array_map())); | 1738 value->map() == object->GetHeap()->fixed_cow_array_map())); |
1761 ASSERT((*value == object->GetHeap()->empty_fixed_array()) || | 1739 ASSERT((*value == object->GetHeap()->empty_fixed_array()) || |
1762 (object->map()->has_fast_double_elements() == | 1740 (object->map()->has_fast_double_elements() == |
(...skipping 27 matching lines...) Expand all Loading... |
1790 FixedTypedArrayBase* empty_array = | 1768 FixedTypedArrayBase* empty_array = |
1791 GetHeap()->EmptyFixedTypedArrayForMap(map()); | 1769 GetHeap()->EmptyFixedTypedArrayForMap(map()); |
1792 ASSERT(!GetHeap()->InNewSpace(empty_array)); | 1770 ASSERT(!GetHeap()->InNewSpace(empty_array)); |
1793 WRITE_FIELD(this, kElementsOffset, empty_array); | 1771 WRITE_FIELD(this, kElementsOffset, empty_array); |
1794 } else { | 1772 } else { |
1795 UNREACHABLE(); | 1773 UNREACHABLE(); |
1796 } | 1774 } |
1797 } | 1775 } |
1798 | 1776 |
1799 | 1777 |
1800 MaybeObject* JSObject::ResetElements() { | |
1801 if (map()->is_observed()) { | |
1802 // Maintain invariant that observed elements are always in dictionary mode. | |
1803 SeededNumberDictionary* dictionary; | |
1804 MaybeObject* maybe = SeededNumberDictionary::Allocate(GetHeap(), 0); | |
1805 if (!maybe->To(&dictionary)) return maybe; | |
1806 if (map() == GetHeap()->sloppy_arguments_elements_map()) { | |
1807 FixedArray::cast(elements())->set(1, dictionary); | |
1808 } else { | |
1809 set_elements(dictionary); | |
1810 } | |
1811 return this; | |
1812 } | |
1813 | |
1814 ElementsKind elements_kind = GetInitialFastElementsKind(); | |
1815 if (!FLAG_smi_only_arrays) { | |
1816 elements_kind = FastSmiToObjectElementsKind(elements_kind); | |
1817 } | |
1818 MaybeObject* maybe = GetElementsTransitionMap(GetIsolate(), elements_kind); | |
1819 Map* map; | |
1820 if (!maybe->To(&map)) return maybe; | |
1821 set_map(map); | |
1822 initialize_elements(); | |
1823 | |
1824 return this; | |
1825 } | |
1826 | |
1827 | |
1828 Handle<String> JSObject::ExpectedTransitionKey(Handle<Map> map) { | 1778 Handle<String> JSObject::ExpectedTransitionKey(Handle<Map> map) { |
1829 DisallowHeapAllocation no_gc; | 1779 DisallowHeapAllocation no_gc; |
1830 if (!map->HasTransitionArray()) return Handle<String>::null(); | 1780 if (!map->HasTransitionArray()) return Handle<String>::null(); |
1831 TransitionArray* transitions = map->transitions(); | 1781 TransitionArray* transitions = map->transitions(); |
1832 if (!transitions->IsSimpleTransition()) return Handle<String>::null(); | 1782 if (!transitions->IsSimpleTransition()) return Handle<String>::null(); |
1833 int transition = TransitionArray::kSimpleTransitionIndex; | 1783 int transition = TransitionArray::kSimpleTransitionIndex; |
1834 PropertyDetails details = transitions->GetTargetDetails(transition); | 1784 PropertyDetails details = transitions->GetTargetDetails(transition); |
1835 Name* name = transitions->GetKey(transition); | 1785 Name* name = transitions->GetKey(transition); |
1836 if (details.type() != FIELD) return Handle<String>::null(); | 1786 if (details.type() != FIELD) return Handle<String>::null(); |
1837 if (details.attributes() != NONE) return Handle<String>::null(); | 1787 if (details.attributes() != NONE) return Handle<String>::null(); |
(...skipping 894 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2732 | 2682 |
2733 | 2683 |
2734 AccessorDescriptor* DescriptorArray::GetCallbacks(int descriptor_number) { | 2684 AccessorDescriptor* DescriptorArray::GetCallbacks(int descriptor_number) { |
2735 ASSERT(GetType(descriptor_number) == CALLBACKS); | 2685 ASSERT(GetType(descriptor_number) == CALLBACKS); |
2736 Foreign* p = Foreign::cast(GetCallbacksObject(descriptor_number)); | 2686 Foreign* p = Foreign::cast(GetCallbacksObject(descriptor_number)); |
2737 return reinterpret_cast<AccessorDescriptor*>(p->foreign_address()); | 2687 return reinterpret_cast<AccessorDescriptor*>(p->foreign_address()); |
2738 } | 2688 } |
2739 | 2689 |
2740 | 2690 |
2741 void DescriptorArray::Get(int descriptor_number, Descriptor* desc) { | 2691 void DescriptorArray::Get(int descriptor_number, Descriptor* desc) { |
2742 desc->Init(GetKey(descriptor_number), | 2692 desc->Init(handle(GetKey(descriptor_number), GetIsolate()), |
2743 GetValue(descriptor_number), | 2693 handle(GetValue(descriptor_number), GetIsolate()), |
2744 GetDetails(descriptor_number)); | 2694 GetDetails(descriptor_number)); |
2745 } | 2695 } |
2746 | 2696 |
2747 | 2697 |
2748 void DescriptorArray::Set(int descriptor_number, | 2698 void DescriptorArray::Set(int descriptor_number, |
2749 Descriptor* desc, | 2699 Descriptor* desc, |
2750 const WhitenessWitness&) { | 2700 const WhitenessWitness&) { |
2751 // Range check. | 2701 // Range check. |
2752 ASSERT(descriptor_number < number_of_descriptors()); | 2702 ASSERT(descriptor_number < number_of_descriptors()); |
2753 | 2703 |
2754 NoIncrementalWriteBarrierSet(this, | 2704 NoIncrementalWriteBarrierSet(this, |
2755 ToKeyIndex(descriptor_number), | 2705 ToKeyIndex(descriptor_number), |
2756 desc->GetKey()); | 2706 *desc->GetKey()); |
2757 NoIncrementalWriteBarrierSet(this, | 2707 NoIncrementalWriteBarrierSet(this, |
2758 ToValueIndex(descriptor_number), | 2708 ToValueIndex(descriptor_number), |
2759 desc->GetValue()); | 2709 *desc->GetValue()); |
2760 NoIncrementalWriteBarrierSet(this, | 2710 NoIncrementalWriteBarrierSet(this, |
2761 ToDetailsIndex(descriptor_number), | 2711 ToDetailsIndex(descriptor_number), |
2762 desc->GetDetails().AsSmi()); | 2712 desc->GetDetails().AsSmi()); |
2763 } | 2713 } |
2764 | 2714 |
2765 | 2715 |
2766 void DescriptorArray::Set(int descriptor_number, Descriptor* desc) { | 2716 void DescriptorArray::Set(int descriptor_number, Descriptor* desc) { |
2767 // Range check. | 2717 // Range check. |
2768 ASSERT(descriptor_number < number_of_descriptors()); | 2718 ASSERT(descriptor_number < number_of_descriptors()); |
2769 | 2719 |
2770 set(ToKeyIndex(descriptor_number), desc->GetKey()); | 2720 set(ToKeyIndex(descriptor_number), *desc->GetKey()); |
2771 set(ToValueIndex(descriptor_number), desc->GetValue()); | 2721 set(ToValueIndex(descriptor_number), *desc->GetValue()); |
2772 set(ToDetailsIndex(descriptor_number), desc->GetDetails().AsSmi()); | 2722 set(ToDetailsIndex(descriptor_number), desc->GetDetails().AsSmi()); |
2773 } | 2723 } |
2774 | 2724 |
2775 | 2725 |
2776 void DescriptorArray::Append(Descriptor* desc, | 2726 void DescriptorArray::Append(Descriptor* desc, |
2777 const WhitenessWitness& witness) { | 2727 const WhitenessWitness& witness) { |
2778 int descriptor_number = number_of_descriptors(); | 2728 int descriptor_number = number_of_descriptors(); |
2779 SetNumberOfDescriptors(descriptor_number + 1); | 2729 SetNumberOfDescriptors(descriptor_number + 1); |
2780 Set(descriptor_number, desc, witness); | 2730 Set(descriptor_number, desc, witness); |
2781 | 2731 |
(...skipping 2115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4897 return transitions()->GetTarget(transition_index); | 4847 return transitions()->GetTarget(transition_index); |
4898 } | 4848 } |
4899 | 4849 |
4900 | 4850 |
4901 int Map::SearchTransition(Name* name) { | 4851 int Map::SearchTransition(Name* name) { |
4902 if (HasTransitionArray()) return transitions()->Search(name); | 4852 if (HasTransitionArray()) return transitions()->Search(name); |
4903 return TransitionArray::kNotFound; | 4853 return TransitionArray::kNotFound; |
4904 } | 4854 } |
4905 | 4855 |
4906 | 4856 |
4907 MaybeObject* Map::set_elements_transition_map(Map* transitioned_map) { | |
4908 TransitionArray* transitions; | |
4909 MaybeObject* maybe_transitions = AddTransition( | |
4910 GetHeap()->elements_transition_symbol(), | |
4911 transitioned_map, | |
4912 FULL_TRANSITION); | |
4913 if (!maybe_transitions->To(&transitions)) return maybe_transitions; | |
4914 set_transitions(transitions); | |
4915 return transitions; | |
4916 } | |
4917 | |
4918 | |
4919 FixedArray* Map::GetPrototypeTransitions() { | 4857 FixedArray* Map::GetPrototypeTransitions() { |
4920 if (!HasTransitionArray()) return GetHeap()->empty_fixed_array(); | 4858 if (!HasTransitionArray()) return GetHeap()->empty_fixed_array(); |
4921 if (!transitions()->HasPrototypeTransitions()) { | 4859 if (!transitions()->HasPrototypeTransitions()) { |
4922 return GetHeap()->empty_fixed_array(); | 4860 return GetHeap()->empty_fixed_array(); |
4923 } | 4861 } |
4924 return transitions()->GetPrototypeTransitions(); | 4862 return transitions()->GetPrototypeTransitions(); |
4925 } | 4863 } |
4926 | 4864 |
4927 | 4865 |
4928 MaybeObject* Map::SetPrototypeTransitions(FixedArray* proto_transitions) { | 4866 MaybeObject* Map::SetPrototypeTransitions(FixedArray* proto_transitions) { |
(...skipping 1995 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6924 #undef READ_UINT32_FIELD | 6862 #undef READ_UINT32_FIELD |
6925 #undef WRITE_UINT32_FIELD | 6863 #undef WRITE_UINT32_FIELD |
6926 #undef READ_SHORT_FIELD | 6864 #undef READ_SHORT_FIELD |
6927 #undef WRITE_SHORT_FIELD | 6865 #undef WRITE_SHORT_FIELD |
6928 #undef READ_BYTE_FIELD | 6866 #undef READ_BYTE_FIELD |
6929 #undef WRITE_BYTE_FIELD | 6867 #undef WRITE_BYTE_FIELD |
6930 | 6868 |
6931 } } // namespace v8::internal | 6869 } } // namespace v8::internal |
6932 | 6870 |
6933 #endif // V8_OBJECTS_INL_H_ | 6871 #endif // V8_OBJECTS_INL_H_ |
OLD | NEW |