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 1749 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1760 | 1760 |
1761 return AddInstruction(new (zone()) | 1761 return AddInstruction(new (zone()) |
1762 HLoadKeyed(native_context, index, NULL, FAST_ELEMENTS)); | 1762 HLoadKeyed(native_context, index, NULL, FAST_ELEMENTS)); |
1763 } | 1763 } |
1764 | 1764 |
1765 | 1765 |
1766 HGraphBuilder::JSArrayBuilder::JSArrayBuilder(HGraphBuilder* builder, | 1766 HGraphBuilder::JSArrayBuilder::JSArrayBuilder(HGraphBuilder* builder, |
1767 ElementsKind kind, | 1767 ElementsKind kind, |
1768 HValue* allocation_site_payload, | 1768 HValue* allocation_site_payload, |
1769 AllocationSiteMode mode) : | 1769 AllocationSiteMode mode) : |
1770 builder_(builder), | 1770 builder_(builder), |
1771 kind_(kind), | 1771 kind_(kind), |
1772 allocation_site_payload_(allocation_site_payload) { | 1772 allocation_site_payload_(allocation_site_payload), |
| 1773 constructor_function_(NULL) { |
1773 if (mode == DONT_TRACK_ALLOCATION_SITE) { | 1774 if (mode == DONT_TRACK_ALLOCATION_SITE) { |
1774 mode_ = mode; | 1775 mode_ = mode; |
1775 } else { | 1776 } else { |
1776 mode_ = AllocationSiteInfo::GetMode(kind); | 1777 mode_ = AllocationSiteInfo::GetMode(kind); |
1777 } | 1778 } |
1778 } | 1779 } |
1779 | 1780 |
1780 | 1781 |
| 1782 HGraphBuilder::JSArrayBuilder::JSArrayBuilder(HGraphBuilder* builder, |
| 1783 ElementsKind kind, |
| 1784 HValue* constructor_function) : |
| 1785 builder_(builder), |
| 1786 kind_(kind), |
| 1787 mode_(DONT_TRACK_ALLOCATION_SITE), |
| 1788 allocation_site_payload_(NULL), |
| 1789 constructor_function_(constructor_function) { |
| 1790 } |
| 1791 |
| 1792 |
1781 HValue* HGraphBuilder::JSArrayBuilder::EmitMapCode(HValue* context) { | 1793 HValue* HGraphBuilder::JSArrayBuilder::EmitMapCode(HValue* context) { |
1782 HInstruction* native_context = builder()->BuildGetNativeContext(context); | 1794 HInstruction* native_context = builder()->BuildGetNativeContext(context); |
1783 | 1795 |
1784 HInstruction* index = builder()->AddInstruction(new(zone()) | 1796 HInstruction* index = builder()->AddInstruction(new(zone()) |
1785 HConstant(Context::JS_ARRAY_MAPS_INDEX, Representation::Integer32())); | 1797 HConstant(Context::JS_ARRAY_MAPS_INDEX, Representation::Integer32())); |
1786 | 1798 |
1787 HInstruction* map_array = builder()->AddInstruction(new(zone()) | 1799 HInstruction* map_array = builder()->AddInstruction(new(zone()) |
1788 HLoadKeyed(native_context, index, NULL, FAST_ELEMENTS)); | 1800 HLoadKeyed(native_context, index, NULL, FAST_ELEMENTS)); |
1789 | 1801 |
1790 HInstruction* kind_index = builder()->AddInstruction(new(zone()) | 1802 HInstruction* kind_index = builder()->AddInstruction(new(zone()) |
1791 HConstant(kind_, Representation::Integer32())); | 1803 HConstant(kind_, Representation::Integer32())); |
1792 | 1804 |
1793 return builder()->AddInstruction(new(zone()) | 1805 return builder()->AddInstruction(new(zone()) |
1794 HLoadKeyed(map_array, kind_index, NULL, FAST_ELEMENTS)); | 1806 HLoadKeyed(map_array, kind_index, NULL, FAST_ELEMENTS)); |
1795 } | 1807 } |
1796 | 1808 |
1797 | 1809 |
| 1810 HValue* HGraphBuilder::JSArrayBuilder::EmitInternalMapCode() { |
| 1811 // Find the map near the constructor function |
| 1812 HObjectAccess access = HObjectAccess::ForPrototypeOrInitialMap(); |
| 1813 return AddInstruction( |
| 1814 builder()->BuildLoadNamedField(constructor_function_, |
| 1815 access, |
| 1816 Representation::Tagged())); |
| 1817 } |
| 1818 |
| 1819 |
1798 HValue* HGraphBuilder::JSArrayBuilder::EstablishAllocationSize( | 1820 HValue* HGraphBuilder::JSArrayBuilder::EstablishAllocationSize( |
1799 HValue* length_node) { | 1821 HValue* length_node) { |
1800 HValue* context = builder()->environment()->LookupContext(); | 1822 HValue* context = builder()->environment()->LookupContext(); |
1801 ASSERT(length_node != NULL); | 1823 ASSERT(length_node != NULL); |
1802 | 1824 |
1803 int base_size = JSArray::kSize; | 1825 int base_size = JSArray::kSize; |
1804 if (mode_ == TRACK_ALLOCATION_SITE) { | 1826 if (mode_ == TRACK_ALLOCATION_SITE) { |
1805 base_size += AllocationSiteInfo::kSize; | 1827 base_size += AllocationSiteInfo::kSize; |
1806 } | 1828 } |
1807 | 1829 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1874 bool fill_with_hole) { | 1896 bool fill_with_hole) { |
1875 HValue* context = builder()->environment()->LookupContext(); | 1897 HValue* context = builder()->environment()->LookupContext(); |
1876 | 1898 |
1877 // Allocate (dealing with failure appropriately) | 1899 // Allocate (dealing with failure appropriately) |
1878 HAllocate::Flags flags = HAllocate::DefaultFlags(kind_); | 1900 HAllocate::Flags flags = HAllocate::DefaultFlags(kind_); |
1879 HAllocate* new_object = new(zone()) HAllocate(context, size_in_bytes, | 1901 HAllocate* new_object = new(zone()) HAllocate(context, size_in_bytes, |
1880 HType::JSArray(), flags); | 1902 HType::JSArray(), flags); |
1881 AddInstruction(new_object); | 1903 AddInstruction(new_object); |
1882 | 1904 |
1883 // Fill in the fields: map, properties, length | 1905 // Fill in the fields: map, properties, length |
1884 HValue* map = EmitMapCode(context); | 1906 HValue* map; |
| 1907 if (constructor_function_ != NULL) { |
| 1908 map = EmitInternalMapCode(); |
| 1909 } else { |
| 1910 map = EmitMapCode(context); |
| 1911 } |
1885 elements_location_ = builder()->BuildJSArrayHeader(new_object, | 1912 elements_location_ = builder()->BuildJSArrayHeader(new_object, |
1886 map, | 1913 map, |
1887 mode_, | 1914 mode_, |
1888 allocation_site_payload_, | 1915 allocation_site_payload_, |
1889 length_field); | 1916 length_field); |
1890 | 1917 |
1891 // Initialize the elements | 1918 // Initialize the elements |
1892 builder()->BuildInitializeElementsHeader(elements_location_, kind_, capacity); | 1919 builder()->BuildInitializeElementsHeader(elements_location_, kind_, capacity); |
1893 | 1920 |
1894 if (fill_with_hole) { | 1921 if (fill_with_hole) { |
(...skipping 9603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11498 } | 11525 } |
11499 } | 11526 } |
11500 | 11527 |
11501 #ifdef DEBUG | 11528 #ifdef DEBUG |
11502 if (graph_ != NULL) graph_->Verify(false); // No full verify. | 11529 if (graph_ != NULL) graph_->Verify(false); // No full verify. |
11503 if (allocator_ != NULL) allocator_->Verify(); | 11530 if (allocator_ != NULL) allocator_->Verify(); |
11504 #endif | 11531 #endif |
11505 } | 11532 } |
11506 | 11533 |
11507 } } // namespace v8::internal | 11534 } } // namespace v8::internal |
OLD | NEW |