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

Side by Side Diff: src/factory.cc

Issue 1094863002: Remove the weak list of views from array buffers (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: updates Created 5 years, 8 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/heap-snapshot-generator.cc » ('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 1807 matching lines...) Expand 10 before | Expand all | Expand 10 after
1818 #undef TYPED_ARRAY_CASE 1818 #undef TYPED_ARRAY_CASE
1819 } 1819 }
1820 1820
1821 1821
1822 size_t GetExternalArrayElementSize(ExternalArrayType type) { 1822 size_t GetExternalArrayElementSize(ExternalArrayType type) {
1823 switch (type) { 1823 switch (type) {
1824 #define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) \ 1824 #define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) \
1825 case kExternal##Type##Array: \ 1825 case kExternal##Type##Array: \
1826 return size; 1826 return size;
1827 TYPED_ARRAYS(TYPED_ARRAY_CASE) 1827 TYPED_ARRAYS(TYPED_ARRAY_CASE)
1828 default:
1829 UNREACHABLE();
1830 return 0;
1828 } 1831 }
1829 UNREACHABLE();
1830 return 0;
1831 #undef TYPED_ARRAY_CASE 1832 #undef TYPED_ARRAY_CASE
1832 } 1833 }
1833 1834
1835
1836 size_t GetFixedTypedArraysElementSize(ElementsKind kind) {
1837 switch (kind) {
1838 #define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) \
1839 case TYPE##_ELEMENTS: \
1840 return size;
1841 TYPED_ARRAYS(TYPED_ARRAY_CASE)
1842 default:
1843 UNREACHABLE();
1844 return 0;
1845 }
1846 #undef TYPED_ARRAY_CASE
1847 }
1848
1849
1850 ExternalArrayType GetArrayTypeFromElementsKind(ElementsKind kind) {
1851 switch (kind) {
1852 #define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) \
1853 case TYPE##_ELEMENTS: \
1854 return kExternal##Type##Array;
1855 TYPED_ARRAYS(TYPED_ARRAY_CASE)
1856 default:
1857 UNREACHABLE();
1858 return kExternalInt8Array;
1859 }
1860 #undef TYPED_ARRAY_CASE
1861 }
1862
1834 1863
1835 JSFunction* GetTypedArrayFun(ExternalArrayType type, Isolate* isolate) { 1864 JSFunction* GetTypedArrayFun(ExternalArrayType type, Isolate* isolate) {
1836 Context* native_context = isolate->context()->native_context(); 1865 Context* native_context = isolate->context()->native_context();
1837 switch (type) { 1866 switch (type) {
1838 #define TYPED_ARRAY_FUN(Type, type, TYPE, ctype, size) \ 1867 #define TYPED_ARRAY_FUN(Type, type, TYPE, ctype, size) \
1839 case kExternal##Type##Array: \ 1868 case kExternal##Type##Array: \
1840 return native_context->type##_array_fun(); 1869 return native_context->type##_array_fun();
1841 1870
1842 TYPED_ARRAYS(TYPED_ARRAY_FUN) 1871 TYPED_ARRAYS(TYPED_ARRAY_FUN)
1843 #undef TYPED_ARRAY_FUN 1872 #undef TYPED_ARRAY_FUN
1844 1873
1845 default: 1874 default:
1846 UNREACHABLE(); 1875 UNREACHABLE();
1847 return NULL; 1876 return NULL;
1848 } 1877 }
1849 } 1878 }
1850 1879
1851 1880
1881 JSFunction* GetTypedArrayFun(ElementsKind elements_kind, Isolate* isolate) {
1882 Context* native_context = isolate->context()->native_context();
1883 switch (elements_kind) {
1884 #define TYPED_ARRAY_FUN(Type, type, TYPE, ctype, size) \
1885 case TYPE##_ELEMENTS: \
1886 return native_context->type##_array_fun();
1887
1888 TYPED_ARRAYS(TYPED_ARRAY_FUN)
1889 #undef TYPED_ARRAY_FUN
1890
1891 default:
1892 UNREACHABLE();
1893 return NULL;
1894 }
1895 }
1896
1897
1852 void SetupArrayBufferView(i::Isolate* isolate, 1898 void SetupArrayBufferView(i::Isolate* isolate,
1853 i::Handle<i::JSArrayBufferView> obj, 1899 i::Handle<i::JSArrayBufferView> obj,
1854 i::Handle<i::JSArrayBuffer> buffer, 1900 i::Handle<i::JSArrayBuffer> buffer,
1855 size_t byte_offset, size_t byte_length) { 1901 size_t byte_offset, size_t byte_length) {
1856 DCHECK(byte_offset + byte_length <= 1902 DCHECK(byte_offset + byte_length <=
1857 static_cast<size_t>(buffer->byte_length()->Number())); 1903 static_cast<size_t>(buffer->byte_length()->Number()));
1858 1904
1859 obj->set_buffer(*buffer); 1905 obj->set_buffer(*buffer);
1860 1906
1861 Heap* heap = isolate->heap();
1862 if (heap->InNewSpace(*obj)) {
1863 obj->set_weak_next(heap->new_array_buffer_views_list());
1864 heap->set_new_array_buffer_views_list(*obj);
1865 } else {
1866 obj->set_weak_next(buffer->weak_first_view());
1867 buffer->set_weak_first_view(*obj);
1868 }
1869
1870 i::Handle<i::Object> byte_offset_object = 1907 i::Handle<i::Object> byte_offset_object =
1871 isolate->factory()->NewNumberFromSize(byte_offset); 1908 isolate->factory()->NewNumberFromSize(byte_offset);
1872 obj->set_byte_offset(*byte_offset_object); 1909 obj->set_byte_offset(*byte_offset_object);
1873 1910
1874 i::Handle<i::Object> byte_length_object = 1911 i::Handle<i::Object> byte_length_object =
1875 isolate->factory()->NewNumberFromSize(byte_length); 1912 isolate->factory()->NewNumberFromSize(byte_length);
1876 obj->set_byte_length(*byte_length_object); 1913 obj->set_byte_length(*byte_length_object);
1877 } 1914 }
1878 1915
1879 1916
1880 } // namespace 1917 } // namespace
1881 1918
1882 1919
1883 Handle<JSTypedArray> Factory::NewJSTypedArray(ExternalArrayType type) { 1920 Handle<JSTypedArray> Factory::NewJSTypedArray(ExternalArrayType type) {
1884 Handle<JSFunction> typed_array_fun_handle(GetTypedArrayFun(type, isolate())); 1921 Handle<JSFunction> typed_array_fun_handle(GetTypedArrayFun(type, isolate()));
1885 1922
1886 CALL_HEAP_FUNCTION( 1923 CALL_HEAP_FUNCTION(
1887 isolate(), 1924 isolate(),
1888 isolate()->heap()->AllocateJSObject(*typed_array_fun_handle), 1925 isolate()->heap()->AllocateJSObject(*typed_array_fun_handle),
1889 JSTypedArray); 1926 JSTypedArray);
1890 } 1927 }
1891 1928
1892 1929
1930 Handle<JSTypedArray> Factory::NewJSTypedArray(ElementsKind elements_kind) {
1931 Handle<JSFunction> typed_array_fun_handle(
1932 GetTypedArrayFun(elements_kind, isolate()));
1933
1934 CALL_HEAP_FUNCTION(
1935 isolate(), isolate()->heap()->AllocateJSObject(*typed_array_fun_handle),
1936 JSTypedArray);
1937 }
1938
1939
1893 Handle<JSTypedArray> Factory::NewJSTypedArray(ExternalArrayType type, 1940 Handle<JSTypedArray> Factory::NewJSTypedArray(ExternalArrayType type,
1894 Handle<JSArrayBuffer> buffer, 1941 Handle<JSArrayBuffer> buffer,
1895 size_t byte_offset, 1942 size_t byte_offset,
1896 size_t length) { 1943 size_t length) {
1897 Handle<JSTypedArray> obj = NewJSTypedArray(type); 1944 Handle<JSTypedArray> obj = NewJSTypedArray(type);
1898 1945
1899 size_t element_size = GetExternalArrayElementSize(type); 1946 size_t element_size = GetExternalArrayElementSize(type);
1900 ElementsKind elements_kind = GetExternalArrayElementsKind(type); 1947 ElementsKind elements_kind = GetExternalArrayElementsKind(type);
1901 1948
1902 CHECK(byte_offset % element_size == 0); 1949 CHECK(byte_offset % element_size == 0);
1903 1950
1904 CHECK(length <= (std::numeric_limits<size_t>::max() / element_size)); 1951 CHECK(length <= (std::numeric_limits<size_t>::max() / element_size));
1905 CHECK(length <= static_cast<size_t>(Smi::kMaxValue)); 1952 CHECK(length <= static_cast<size_t>(Smi::kMaxValue));
1906 size_t byte_length = length * element_size; 1953 size_t byte_length = length * element_size;
1907 SetupArrayBufferView(isolate(), obj, buffer, byte_offset, byte_length); 1954 SetupArrayBufferView(isolate(), obj, buffer, byte_offset, byte_length);
1908 1955
1909 Handle<Object> length_object = NewNumberFromSize(length); 1956 Handle<Object> length_object = NewNumberFromSize(length);
1910 obj->set_length(*length_object); 1957 obj->set_length(*length_object);
1911 1958
1912 Handle<ExternalArray> elements = NewExternalArray( 1959 Handle<ExternalArray> elements = NewExternalArray(
1913 static_cast<int>(length), type, 1960 static_cast<int>(length), type,
1914 static_cast<uint8_t*>(buffer->backing_store()) + byte_offset); 1961 static_cast<uint8_t*>(buffer->backing_store()) + byte_offset);
1915 Handle<Map> map = JSObject::GetElementsTransitionMap(obj, elements_kind); 1962 Handle<Map> map = JSObject::GetElementsTransitionMap(obj, elements_kind);
1916 JSObject::SetMapAndElements(obj, map, elements); 1963 JSObject::SetMapAndElements(obj, map, elements);
1917 return obj; 1964 return obj;
1918 } 1965 }
1919 1966
1920 1967
1968 Handle<JSTypedArray> Factory::NewJSTypedArray(ElementsKind elements_kind,
1969 size_t number_of_elements) {
1970 Handle<JSTypedArray> obj = NewJSTypedArray(elements_kind);
1971
1972 size_t element_size = GetFixedTypedArraysElementSize(elements_kind);
1973 ExternalArrayType array_type = GetArrayTypeFromElementsKind(elements_kind);
1974
1975 CHECK(number_of_elements <=
1976 (std::numeric_limits<size_t>::max() / element_size));
1977 CHECK(number_of_elements <= static_cast<size_t>(Smi::kMaxValue));
1978 size_t byte_length = number_of_elements * element_size;
1979
1980 obj->set_byte_offset(Smi::FromInt(0));
1981 i::Handle<i::Object> byte_length_object =
1982 isolate()->factory()->NewNumberFromSize(byte_length);
1983 obj->set_byte_length(*byte_length_object);
1984 Handle<Object> length_object = NewNumberFromSize(number_of_elements);
1985 obj->set_length(*length_object);
1986
1987 obj->set_buffer(Smi::FromInt(0));
1988 Handle<FixedTypedArrayBase> elements =
1989 isolate()->factory()->NewFixedTypedArray(
1990 static_cast<int>(number_of_elements), array_type);
1991 obj->set_elements(*elements);
1992 return obj;
1993 }
1994
1995
1921 Handle<JSDataView> Factory::NewJSDataView(Handle<JSArrayBuffer> buffer, 1996 Handle<JSDataView> Factory::NewJSDataView(Handle<JSArrayBuffer> buffer,
1922 size_t byte_offset, 1997 size_t byte_offset,
1923 size_t byte_length) { 1998 size_t byte_length) {
1924 Handle<JSDataView> obj = NewJSDataView(); 1999 Handle<JSDataView> obj = NewJSDataView();
1925 SetupArrayBufferView(isolate(), obj, buffer, byte_offset, byte_length); 2000 SetupArrayBufferView(isolate(), obj, buffer, byte_offset, byte_length);
1926 return obj; 2001 return obj;
1927 } 2002 }
1928 2003
1929 2004
1930 Handle<JSProxy> Factory::NewJSProxy(Handle<Object> handler, 2005 Handle<JSProxy> Factory::NewJSProxy(Handle<Object> handler,
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after
2397 return Handle<Object>::null(); 2472 return Handle<Object>::null();
2398 } 2473 }
2399 2474
2400 2475
2401 Handle<Object> Factory::ToBoolean(bool value) { 2476 Handle<Object> Factory::ToBoolean(bool value) {
2402 return value ? true_value() : false_value(); 2477 return value ? true_value() : false_value();
2403 } 2478 }
2404 2479
2405 2480
2406 } } // namespace v8::internal 2481 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/factory.h ('k') | src/heap-snapshot-generator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698