Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(169)

Side by Side Diff: src/factory.cc

Issue 1347263003: Pretenure builtin typed arrays. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/factory.h ('k') | src/runtime/runtime.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/factory.h" 5 #include "src/factory.h"
6 6
7 #include "src/allocation-site-scopes.h" 7 #include "src/allocation-site-scopes.h"
8 #include "src/base/bits.h" 8 #include "src/base/bits.h"
9 #include "src/bootstrapper.h" 9 #include "src/bootstrapper.h"
10 #include "src/conversions.h" 10 #include "src/conversions.h"
(...skipping 1608 matching lines...) Expand 10 before | Expand all | Expand 10 after
1619 JSFunction::EnsureHasInitialMap(function); 1619 JSFunction::EnsureHasInitialMap(function);
1620 Handle<Map> map(function->initial_map()); 1620 Handle<Map> map(function->initial_map());
1621 DCHECK(map->instance_type() == JS_GENERATOR_OBJECT_TYPE); 1621 DCHECK(map->instance_type() == JS_GENERATOR_OBJECT_TYPE);
1622 CALL_HEAP_FUNCTION( 1622 CALL_HEAP_FUNCTION(
1623 isolate(), 1623 isolate(),
1624 isolate()->heap()->AllocateJSObjectFromMap(*map), 1624 isolate()->heap()->AllocateJSObjectFromMap(*map),
1625 JSGeneratorObject); 1625 JSGeneratorObject);
1626 } 1626 }
1627 1627
1628 1628
1629 Handle<JSArrayBuffer> Factory::NewJSArrayBuffer(SharedFlag shared) { 1629 Handle<JSArrayBuffer> Factory::NewJSArrayBuffer(SharedFlag shared,
1630 PretenureFlag pretenure) {
1630 Handle<JSFunction> array_buffer_fun( 1631 Handle<JSFunction> array_buffer_fun(
1631 shared == SharedFlag::kShared 1632 shared == SharedFlag::kShared
1632 ? isolate()->native_context()->shared_array_buffer_fun() 1633 ? isolate()->native_context()->shared_array_buffer_fun()
1633 : isolate()->native_context()->array_buffer_fun()); 1634 : isolate()->native_context()->array_buffer_fun());
1634 CALL_HEAP_FUNCTION( 1635 CALL_HEAP_FUNCTION(isolate(), isolate()->heap()->AllocateJSObject(
1635 isolate(), 1636 *array_buffer_fun, pretenure),
1636 isolate()->heap()->AllocateJSObject(*array_buffer_fun), 1637 JSArrayBuffer);
1637 JSArrayBuffer);
1638 } 1638 }
1639 1639
1640 1640
1641 Handle<JSDataView> Factory::NewJSDataView() { 1641 Handle<JSDataView> Factory::NewJSDataView() {
1642 Handle<JSFunction> data_view_fun( 1642 Handle<JSFunction> data_view_fun(
1643 isolate()->native_context()->data_view_fun()); 1643 isolate()->native_context()->data_view_fun());
1644 CALL_HEAP_FUNCTION( 1644 CALL_HEAP_FUNCTION(
1645 isolate(), 1645 isolate(),
1646 isolate()->heap()->AllocateJSObject(*data_view_fun), 1646 isolate()->heap()->AllocateJSObject(*data_view_fun),
1647 JSDataView); 1647 JSDataView);
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
1777 default: 1777 default:
1778 UNREACHABLE(); 1778 UNREACHABLE();
1779 return NULL; 1779 return NULL;
1780 } 1780 }
1781 } 1781 }
1782 1782
1783 1783
1784 void SetupArrayBufferView(i::Isolate* isolate, 1784 void SetupArrayBufferView(i::Isolate* isolate,
1785 i::Handle<i::JSArrayBufferView> obj, 1785 i::Handle<i::JSArrayBufferView> obj,
1786 i::Handle<i::JSArrayBuffer> buffer, 1786 i::Handle<i::JSArrayBuffer> buffer,
1787 size_t byte_offset, size_t byte_length) { 1787 size_t byte_offset, size_t byte_length,
1788 PretenureFlag pretenure = NOT_TENURED) {
1788 DCHECK(byte_offset + byte_length <= 1789 DCHECK(byte_offset + byte_length <=
1789 static_cast<size_t>(buffer->byte_length()->Number())); 1790 static_cast<size_t>(buffer->byte_length()->Number()));
1790 1791
1791 obj->set_buffer(*buffer); 1792 obj->set_buffer(*buffer);
1792 1793
1793 i::Handle<i::Object> byte_offset_object = 1794 i::Handle<i::Object> byte_offset_object =
1794 isolate->factory()->NewNumberFromSize(byte_offset); 1795 isolate->factory()->NewNumberFromSize(byte_offset, pretenure);
1795 obj->set_byte_offset(*byte_offset_object); 1796 obj->set_byte_offset(*byte_offset_object);
1796 1797
1797 i::Handle<i::Object> byte_length_object = 1798 i::Handle<i::Object> byte_length_object =
1798 isolate->factory()->NewNumberFromSize(byte_length); 1799 isolate->factory()->NewNumberFromSize(byte_length, pretenure);
1799 obj->set_byte_length(*byte_length_object); 1800 obj->set_byte_length(*byte_length_object);
1800 } 1801 }
1801 1802
1802 1803
1803 } // namespace 1804 } // namespace
1804 1805
1805 1806
1806 Handle<JSTypedArray> Factory::NewJSTypedArray(ExternalArrayType type) { 1807 Handle<JSTypedArray> Factory::NewJSTypedArray(ExternalArrayType type,
1808 PretenureFlag pretenure) {
1807 Handle<JSFunction> typed_array_fun_handle(GetTypedArrayFun(type, isolate())); 1809 Handle<JSFunction> typed_array_fun_handle(GetTypedArrayFun(type, isolate()));
1808 1810
1809 CALL_HEAP_FUNCTION( 1811 CALL_HEAP_FUNCTION(isolate(), isolate()->heap()->AllocateJSObject(
1810 isolate(), 1812 *typed_array_fun_handle, pretenure),
1811 isolate()->heap()->AllocateJSObject(*typed_array_fun_handle), 1813 JSTypedArray);
1812 JSTypedArray);
1813 } 1814 }
1814 1815
1815 1816
1816 Handle<JSTypedArray> Factory::NewJSTypedArray(ElementsKind elements_kind) { 1817 Handle<JSTypedArray> Factory::NewJSTypedArray(ElementsKind elements_kind,
1818 PretenureFlag pretenure) {
1817 Handle<JSFunction> typed_array_fun_handle( 1819 Handle<JSFunction> typed_array_fun_handle(
1818 GetTypedArrayFun(elements_kind, isolate())); 1820 GetTypedArrayFun(elements_kind, isolate()));
1819 1821
1820 CALL_HEAP_FUNCTION( 1822 CALL_HEAP_FUNCTION(isolate(), isolate()->heap()->AllocateJSObject(
1821 isolate(), isolate()->heap()->AllocateJSObject(*typed_array_fun_handle), 1823 *typed_array_fun_handle, pretenure),
1822 JSTypedArray); 1824 JSTypedArray);
1823 } 1825 }
1824 1826
1825 1827
1826 Handle<JSTypedArray> Factory::NewJSTypedArray(ExternalArrayType type, 1828 Handle<JSTypedArray> Factory::NewJSTypedArray(ExternalArrayType type,
1827 Handle<JSArrayBuffer> buffer, 1829 Handle<JSArrayBuffer> buffer,
1828 size_t byte_offset, 1830 size_t byte_offset, size_t length,
1829 size_t length) { 1831 PretenureFlag pretenure) {
1830 Handle<JSTypedArray> obj = NewJSTypedArray(type); 1832 Handle<JSTypedArray> obj = NewJSTypedArray(type, pretenure);
1831 1833
1832 size_t element_size = GetExternalArrayElementSize(type); 1834 size_t element_size = GetExternalArrayElementSize(type);
1833 ElementsKind elements_kind = GetExternalArrayElementsKind(type); 1835 ElementsKind elements_kind = GetExternalArrayElementsKind(type);
1834 1836
1835 CHECK(byte_offset % element_size == 0); 1837 CHECK(byte_offset % element_size == 0);
1836 1838
1837 CHECK(length <= (std::numeric_limits<size_t>::max() / element_size)); 1839 CHECK(length <= (std::numeric_limits<size_t>::max() / element_size));
1838 CHECK(length <= static_cast<size_t>(Smi::kMaxValue)); 1840 CHECK(length <= static_cast<size_t>(Smi::kMaxValue));
1839 size_t byte_length = length * element_size; 1841 size_t byte_length = length * element_size;
1840 SetupArrayBufferView(isolate(), obj, buffer, byte_offset, byte_length); 1842 SetupArrayBufferView(isolate(), obj, buffer, byte_offset, byte_length,
1843 pretenure);
1841 1844
1842 Handle<Object> length_object = NewNumberFromSize(length); 1845 Handle<Object> length_object = NewNumberFromSize(length, pretenure);
1843 obj->set_length(*length_object); 1846 obj->set_length(*length_object);
1844 1847
1845 Handle<FixedTypedArrayBase> elements = NewFixedTypedArrayWithExternalPointer( 1848 Handle<FixedTypedArrayBase> elements = NewFixedTypedArrayWithExternalPointer(
1846 static_cast<int>(length), type, 1849 static_cast<int>(length), type,
1847 static_cast<uint8_t*>(buffer->backing_store()) + byte_offset); 1850 static_cast<uint8_t*>(buffer->backing_store()) + byte_offset, pretenure);
1848 Handle<Map> map = JSObject::GetElementsTransitionMap(obj, elements_kind); 1851 Handle<Map> map = JSObject::GetElementsTransitionMap(obj, elements_kind);
1849 JSObject::SetMapAndElements(obj, map, elements); 1852 JSObject::SetMapAndElements(obj, map, elements);
1850 return obj; 1853 return obj;
1851 } 1854 }
1852 1855
1853 1856
1854 Handle<JSTypedArray> Factory::NewJSTypedArray(ElementsKind elements_kind, 1857 Handle<JSTypedArray> Factory::NewJSTypedArray(ElementsKind elements_kind,
1855 size_t number_of_elements) { 1858 size_t number_of_elements,
1856 Handle<JSTypedArray> obj = NewJSTypedArray(elements_kind); 1859 PretenureFlag pretenure) {
1860 Handle<JSTypedArray> obj = NewJSTypedArray(elements_kind, pretenure);
1857 1861
1858 size_t element_size = GetFixedTypedArraysElementSize(elements_kind); 1862 size_t element_size = GetFixedTypedArraysElementSize(elements_kind);
1859 ExternalArrayType array_type = GetArrayTypeFromElementsKind(elements_kind); 1863 ExternalArrayType array_type = GetArrayTypeFromElementsKind(elements_kind);
1860 1864
1861 CHECK(number_of_elements <= 1865 CHECK(number_of_elements <=
1862 (std::numeric_limits<size_t>::max() / element_size)); 1866 (std::numeric_limits<size_t>::max() / element_size));
1863 CHECK(number_of_elements <= static_cast<size_t>(Smi::kMaxValue)); 1867 CHECK(number_of_elements <= static_cast<size_t>(Smi::kMaxValue));
1864 size_t byte_length = number_of_elements * element_size; 1868 size_t byte_length = number_of_elements * element_size;
1865 1869
1866 obj->set_byte_offset(Smi::FromInt(0)); 1870 obj->set_byte_offset(Smi::FromInt(0));
1867 i::Handle<i::Object> byte_length_object = 1871 i::Handle<i::Object> byte_length_object =
1868 isolate()->factory()->NewNumberFromSize(byte_length); 1872 NewNumberFromSize(byte_length, pretenure);
1869 obj->set_byte_length(*byte_length_object); 1873 obj->set_byte_length(*byte_length_object);
1870 Handle<Object> length_object = NewNumberFromSize(number_of_elements); 1874 Handle<Object> length_object =
1875 NewNumberFromSize(number_of_elements, pretenure);
1871 obj->set_length(*length_object); 1876 obj->set_length(*length_object);
1872 1877
1873 Handle<JSArrayBuffer> buffer = isolate()->factory()->NewJSArrayBuffer(); 1878 Handle<JSArrayBuffer> buffer =
1879 NewJSArrayBuffer(SharedFlag::kNotShared, pretenure);
1874 JSArrayBuffer::Setup(buffer, isolate(), true, NULL, byte_length, 1880 JSArrayBuffer::Setup(buffer, isolate(), true, NULL, byte_length,
1875 SharedFlag::kNotShared); 1881 SharedFlag::kNotShared);
1876 obj->set_buffer(*buffer); 1882 obj->set_buffer(*buffer);
1877 Handle<FixedTypedArrayBase> elements = 1883 Handle<FixedTypedArrayBase> elements = NewFixedTypedArray(
1878 isolate()->factory()->NewFixedTypedArray( 1884 static_cast<int>(number_of_elements), array_type, true, pretenure);
1879 static_cast<int>(number_of_elements), array_type, true);
1880 obj->set_elements(*elements); 1885 obj->set_elements(*elements);
1881 return obj; 1886 return obj;
1882 } 1887 }
1883 1888
1884 1889
1885 Handle<JSDataView> Factory::NewJSDataView(Handle<JSArrayBuffer> buffer, 1890 Handle<JSDataView> Factory::NewJSDataView(Handle<JSArrayBuffer> buffer,
1886 size_t byte_offset, 1891 size_t byte_offset,
1887 size_t byte_length) { 1892 size_t byte_length) {
1888 Handle<JSDataView> obj = NewJSDataView(); 1893 Handle<JSDataView> obj = NewJSDataView();
1889 SetupArrayBufferView(isolate(), obj, buffer, byte_offset, byte_length); 1894 SetupArrayBufferView(isolate(), obj, buffer, byte_offset, byte_length);
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after
2361 } 2366 }
2362 2367
2363 2368
2364 Handle<Object> Factory::ToBoolean(bool value) { 2369 Handle<Object> Factory::ToBoolean(bool value) {
2365 return value ? true_value() : false_value(); 2370 return value ? true_value() : false_value();
2366 } 2371 }
2367 2372
2368 2373
2369 } // namespace internal 2374 } // namespace internal
2370 } // namespace v8 2375 } // namespace v8
OLDNEW
« no previous file with comments | « src/factory.h ('k') | src/runtime/runtime.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698