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

Side by Side Diff: runtime/vm/raw_object_snapshot.cc

Issue 9958046: Implement {Int,Uint}{8,16,32,64} and Float{32,64} typed arrays. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: add view classes and their tests Created 8 years, 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/bigint_operations.h" 5 #include "vm/bigint_operations.h"
6 #include "vm/object.h" 6 #include "vm/object.h"
7 #include "vm/object_store.h" 7 #include "vm/object_store.h"
8 #include "vm/snapshot.h" 8 #include "vm/snapshot.h"
9 #include "vm/visitor.h" 9 #include "vm/visitor.h"
10 10
(...skipping 1779 matching lines...) Expand 10 before | Expand all | Expand 10 after
1790 1790
1791 RawByteArray* ByteArray::ReadFrom(SnapshotReader* reader, 1791 RawByteArray* ByteArray::ReadFrom(SnapshotReader* reader,
1792 intptr_t object_id, 1792 intptr_t object_id,
1793 intptr_t tags, 1793 intptr_t tags,
1794 Snapshot::Kind kind) { 1794 Snapshot::Kind kind) {
1795 UNREACHABLE(); // ByteArray is an abstract class. 1795 UNREACHABLE(); // ByteArray is an abstract class.
1796 return ByteArray::null(); 1796 return ByteArray::null();
1797 } 1797 }
1798 1798
1799 1799
1800 RawInternalByteArray* InternalByteArray::ReadFrom(SnapshotReader* reader, 1800 template<typename HandleT, typename RawT, typename ElementT>
1801 RawT* ByteArray::ReadFromImpl(SnapshotReader* reader,
1802 intptr_t object_id,
1803 intptr_t tags,
1804 Snapshot::Kind kind) {
1805 ASSERT(reader != NULL);
1806
1807 intptr_t len = reader->ReadSmiValue();
1808 Heap::Space space = (kind == Snapshot::kFull) ? Heap::kOld : Heap::kNew;
1809 HandleT& result =
1810 HandleT::ZoneHandle(reader->isolate(), HandleT::New(len, space));
1811 reader->AddBackwardReference(object_id, &result);
1812
1813 // Set the object tags.
1814 result.set_tags(tags);
1815
1816 // Setup the array elements.
1817 for (intptr_t i = 0; i < len; ++i) {
1818 result.SetAt(i, reader->Read<ElementT>());
1819 }
1820 return result.raw();
1821 }
1822
1823
1824 RawInt8Array* Int8Array::ReadFrom(SnapshotReader* reader,
1825 intptr_t object_id,
1826 intptr_t tags,
1827 Snapshot::Kind kind) {
1828 return ReadFromImpl<Int8Array, RawInt8Array, int8_t>(reader,
1829 object_id,
1830 tags,
1831 kind);
1832 }
1833
1834
1835 RawUint8Array* Uint8Array::ReadFrom(SnapshotReader* reader,
1836 intptr_t object_id,
1837 intptr_t tags,
1838 Snapshot::Kind kind) {
1839 return ReadFromImpl<Uint8Array, RawUint8Array, uint8_t>(reader,
1840 object_id,
1841 tags,
1842 kind);
1843 }
1844
1845
1846 RawInt16Array* Int16Array::ReadFrom(SnapshotReader* reader,
1847 intptr_t object_id,
1848 intptr_t tags,
1849 Snapshot::Kind kind) {
1850 return ReadFromImpl<Int16Array, RawInt16Array, int16_t>(reader,
1851 object_id,
1852 tags,
1853 kind);
1854 }
1855
1856
1857 RawUint16Array* Uint16Array::ReadFrom(SnapshotReader* reader,
1858 intptr_t object_id,
1859 intptr_t tags,
1860 Snapshot::Kind kind) {
1861 return ReadFromImpl<Uint16Array, RawUint16Array, uint16_t>(reader,
1862 object_id,
1863 tags,
1864 kind);
1865 }
1866
1867
1868 RawInt32Array* Int32Array::ReadFrom(SnapshotReader* reader,
1869 intptr_t object_id,
1870 intptr_t tags,
1871 Snapshot::Kind kind) {
1872 return ReadFromImpl<Int32Array, RawInt32Array, int32_t>(reader,
1873 object_id,
1874 tags,
1875 kind);
1876 }
1877
1878
1879 RawUint32Array* Uint32Array::ReadFrom(SnapshotReader* reader,
1880 intptr_t object_id,
1881 intptr_t tags,
1882 Snapshot::Kind kind) {
1883 return ReadFromImpl<Uint32Array, RawUint32Array, uint32_t>(reader,
1884 object_id,
1885 tags,
1886 kind);
1887 }
1888
1889
1890 RawInt64Array* Int64Array::ReadFrom(SnapshotReader* reader,
1891 intptr_t object_id,
1892 intptr_t tags,
1893 Snapshot::Kind kind) {
1894 return ReadFromImpl<Int64Array, RawInt64Array, int64_t>(reader,
1895 object_id,
1896 tags,
1897 kind);
1898 }
1899
1900
1901 RawUint64Array* Uint64Array::ReadFrom(SnapshotReader* reader,
1902 intptr_t object_id,
1903 intptr_t tags,
1904 Snapshot::Kind kind) {
1905 return ReadFromImpl<Uint64Array, RawUint64Array, uint64_t>(reader,
1906 object_id,
1907 tags,
1908 kind);
1909 }
1910
1911
1912 RawFloat32Array* Float32Array::ReadFrom(SnapshotReader* reader,
1913 intptr_t object_id,
1914 intptr_t tags,
1915 Snapshot::Kind kind) {
1916 return ReadFromImpl<Float32Array, RawFloat32Array, float>(reader,
1917 object_id,
1918 tags,
1919 kind);
1920 }
1921
1922
1923 RawFloat64Array* Float64Array::ReadFrom(SnapshotReader* reader,
1924 intptr_t object_id,
1925 intptr_t tags,
1926 Snapshot::Kind kind) {
1927 return ReadFromImpl<Float64Array, RawFloat64Array, double>(reader,
1928 object_id,
1929 tags,
1930 kind);
1931 }
1932
1933
1934 RawExternalInt8Array* ExternalInt8Array::ReadFrom(SnapshotReader* reader,
1801 intptr_t object_id, 1935 intptr_t object_id,
1802 intptr_t tags, 1936 intptr_t tags,
1803 Snapshot::Kind kind) { 1937 Snapshot::Kind kind) {
1804 ASSERT(reader != NULL); 1938 UNREACHABLE();
1805 1939 return ExternalInt8Array::null();
1806 // Read the length so that we can determine instance size to allocate. 1940 }
1807 intptr_t len = reader->ReadSmiValue(); 1941
1808 Heap::Space space = (kind == Snapshot::kFull) ? Heap::kOld : Heap::kNew; 1942
1809 InternalByteArray& result = 1943 RawExternalUint8Array* ExternalUint8Array::ReadFrom(SnapshotReader* reader,
1810 InternalByteArray::ZoneHandle(reader->isolate(), 1944 intptr_t object_id,
1811 InternalByteArray::New(len, space)); 1945 intptr_t tags,
1812 reader->AddBackwardReference(object_id, &result); 1946 Snapshot::Kind kind) {
1813 1947 UNREACHABLE();
1814 // Set the object tags. 1948 return ExternalUint8Array::null();
1815 result.set_tags(tags); 1949 }
1816 1950
1817 // Setup the array elements. 1951
1818 for (intptr_t i = 0; i < len; i++) { 1952 RawExternalInt16Array* ExternalInt16Array::ReadFrom(SnapshotReader* reader,
1819 result.SetAt<uint8_t>(i, reader->Read<uint8_t>()); 1953 intptr_t object_id,
1820 } 1954 intptr_t tags,
1821 return result.raw(); 1955 Snapshot::Kind kind) {
1822 } 1956 UNREACHABLE();
1823 1957 return ExternalInt16Array::null();
1824 1958 }
1825 RawExternalByteArray* ExternalByteArray::ReadFrom(SnapshotReader* reader, 1959
1826 intptr_t object_id, 1960
1827 intptr_t tags, 1961 RawExternalUint16Array* ExternalUint16Array::ReadFrom(SnapshotReader* reader,
1828 Snapshot::Kind kind) { 1962 intptr_t object_id,
1829 UNREACHABLE(); 1963 intptr_t tags,
1830 return ExternalByteArray::null(); 1964 Snapshot::Kind kind) {
1831 } 1965 UNREACHABLE();
1832 1966 return ExternalUint16Array::null();
1833 1967 }
1968
1969
1970 RawExternalInt32Array* ExternalInt32Array::ReadFrom(SnapshotReader* reader,
1971 intptr_t object_id,
1972 intptr_t tags,
1973 Snapshot::Kind kind) {
1974 UNREACHABLE();
1975 return ExternalInt32Array::null();
1976 }
1977
1978
1979 RawExternalUint32Array* ExternalUint32Array::ReadFrom(SnapshotReader* reader,
1980 intptr_t object_id,
1981 intptr_t tags,
1982 Snapshot::Kind kind) {
1983 UNREACHABLE();
1984 return ExternalUint32Array::null();
1985 }
1986
1987
1988 RawExternalInt64Array* ExternalInt64Array::ReadFrom(SnapshotReader* reader,
1989 intptr_t object_id,
1990 intptr_t tags,
1991 Snapshot::Kind kind) {
1992 UNREACHABLE();
1993 return ExternalInt64Array::null();
1994 }
1995
1996
1997 RawExternalUint64Array* ExternalUint64Array::ReadFrom(SnapshotReader* reader,
1998 intptr_t object_id,
1999 intptr_t tags,
2000 Snapshot::Kind kind) {
2001 UNREACHABLE();
2002 return ExternalUint64Array::null();
2003 }
2004
2005
2006 RawExternalFloat32Array* ExternalFloat32Array::ReadFrom(SnapshotReader* reader,
2007 intptr_t object_id,
2008 intptr_t tags,
2009 Snapshot::Kind kind) {
2010 UNREACHABLE();
2011 return ExternalFloat32Array::null();
2012 }
2013
2014
2015 RawExternalFloat64Array* ExternalFloat64Array::ReadFrom(SnapshotReader* reader,
2016 intptr_t object_id,
2017 intptr_t tags,
2018 Snapshot::Kind kind) {
2019 UNREACHABLE();
2020 return ExternalFloat64Array::null();
2021 }
2022
2023
1834 static void ByteArrayWriteTo(SnapshotWriter* writer, 2024 static void ByteArrayWriteTo(SnapshotWriter* writer,
1835 intptr_t object_id, 2025 intptr_t object_id,
1836 Snapshot::Kind kind, 2026 Snapshot::Kind kind,
1837 intptr_t byte_array_kind, 2027 intptr_t byte_array_kind,
1838 intptr_t tags, 2028 intptr_t tags,
1839 RawSmi* length, 2029 RawSmi* length,
1840 uint8_t* data) { 2030 uint8_t* data) {
1841 ASSERT(writer != NULL); 2031 ASSERT(writer != NULL);
1842 intptr_t len = Smi::Value(length); 2032 intptr_t len = Smi::Value(length);
1843 2033
(...skipping 13 matching lines...) Expand all
1857 } 2047 }
1858 2048
1859 2049
1860 void RawByteArray::WriteTo(SnapshotWriter* writer, 2050 void RawByteArray::WriteTo(SnapshotWriter* writer,
1861 intptr_t object_id, 2051 intptr_t object_id,
1862 Snapshot::Kind kind) { 2052 Snapshot::Kind kind) {
1863 UNREACHABLE(); // ByteArray is an abstract class 2053 UNREACHABLE(); // ByteArray is an abstract class
1864 } 2054 }
1865 2055
1866 2056
1867 void RawInternalByteArray::WriteTo(SnapshotWriter* writer, 2057 void RawInt8Array::WriteTo(SnapshotWriter* writer,
1868 intptr_t object_id, 2058 intptr_t object_id,
1869 Snapshot::Kind kind) { 2059 Snapshot::Kind kind) {
1870 ByteArrayWriteTo(writer, 2060 ByteArrayWriteTo(writer,
1871 object_id, 2061 object_id,
1872 kind, 2062 kind,
1873 ObjectStore::kInternalByteArrayClass, 2063 ObjectStore::kInt8ArrayClass,
1874 ptr()->tags_, 2064 ptr()->tags_,
1875 ptr()->length_, 2065 ptr()->length_,
1876 ptr()->data()); 2066 reinterpret_cast<uint8_t*>(ptr()->data_));
1877 } 2067 }
1878 2068
1879 2069
1880 void RawExternalByteArray::WriteTo(SnapshotWriter* writer, 2070 void RawUint8Array::WriteTo(SnapshotWriter* writer,
1881 intptr_t object_id, 2071 intptr_t object_id,
1882 Snapshot::Kind kind) { 2072 Snapshot::Kind kind) {
1883 // Serialize as an internal byte array. 2073 ByteArrayWriteTo(writer,
1884 ByteArrayWriteTo(writer, 2074 object_id,
1885 object_id, 2075 kind,
1886 kind, 2076 ObjectStore::kUint8ArrayClass,
1887 ObjectStore::kInternalByteArrayClass, 2077 ptr()->tags_,
1888 ptr()->tags_, 2078 ptr()->length_,
1889 ptr()->length_, 2079 reinterpret_cast<uint8_t*>(ptr()->data_));
1890 ptr()->external_data_->data()); 2080 }
1891 } 2081
1892 2082
1893 2083 void RawInt16Array::WriteTo(SnapshotWriter* writer,
2084 intptr_t object_id,
2085 Snapshot::Kind kind) {
2086 ByteArrayWriteTo(writer,
2087 object_id,
2088 kind,
2089 ObjectStore::kInt16ArrayClass,
2090 ptr()->tags_,
2091 ptr()->length_,
2092 reinterpret_cast<uint8_t*>(ptr()->data_));
2093 }
2094
2095
2096 void RawUint16Array::WriteTo(SnapshotWriter* writer,
2097 intptr_t object_id,
2098 Snapshot::Kind kind) {
2099 ByteArrayWriteTo(writer,
2100 object_id,
2101 kind,
2102 ObjectStore::kUint16ArrayClass,
2103 ptr()->tags_,
2104 ptr()->length_,
2105 reinterpret_cast<uint8_t*>(ptr()->data_));
2106 }
2107
2108
2109 void RawInt32Array::WriteTo(SnapshotWriter* writer,
2110 intptr_t object_id,
2111 Snapshot::Kind kind) {
2112 ByteArrayWriteTo(writer,
2113 object_id,
2114 kind,
2115 ObjectStore::kInt32ArrayClass,
2116 ptr()->tags_,
2117 ptr()->length_,
2118 reinterpret_cast<uint8_t*>(ptr()->data_));
2119 }
2120
2121
2122 void RawUint32Array::WriteTo(SnapshotWriter* writer,
2123 intptr_t object_id,
2124 Snapshot::Kind kind) {
2125 ByteArrayWriteTo(writer,
2126 object_id,
2127 kind,
2128 ObjectStore::kUint32ArrayClass,
2129 ptr()->tags_,
2130 ptr()->length_,
2131 reinterpret_cast<uint8_t*>(ptr()->data_));
2132 }
2133
2134
2135 void RawInt64Array::WriteTo(SnapshotWriter* writer,
2136 intptr_t object_id,
2137 Snapshot::Kind kind) {
2138 ByteArrayWriteTo(writer,
2139 object_id,
2140 kind,
2141 ObjectStore::kInt64ArrayClass,
2142 ptr()->tags_,
2143 ptr()->length_,
2144 reinterpret_cast<uint8_t*>(ptr()->data_));
2145 }
2146
2147
2148 void RawUint64Array::WriteTo(SnapshotWriter* writer,
2149 intptr_t object_id,
2150 Snapshot::Kind kind) {
2151 ByteArrayWriteTo(writer,
2152 object_id,
2153 kind,
2154 ObjectStore::kUint64ArrayClass,
2155 ptr()->tags_,
2156 ptr()->length_,
2157 reinterpret_cast<uint8_t*>(ptr()->data_));
2158 }
2159
2160
2161 void RawFloat32Array::WriteTo(SnapshotWriter* writer,
2162 intptr_t object_id,
2163 Snapshot::Kind kind) {
2164 ByteArrayWriteTo(writer,
2165 object_id,
2166 kind,
2167 ObjectStore::kFloat32ArrayClass,
2168 ptr()->tags_,
2169 ptr()->length_,
2170 reinterpret_cast<uint8_t*>(ptr()->data_));
2171 }
2172
2173
2174 void RawFloat64Array::WriteTo(SnapshotWriter* writer,
2175 intptr_t object_id,
2176 Snapshot::Kind kind) {
2177 ByteArrayWriteTo(writer,
2178 object_id,
2179 kind,
2180 ObjectStore::kFloat64ArrayClass,
2181 ptr()->tags_,
2182 ptr()->length_,
2183 reinterpret_cast<uint8_t*>(ptr()->data_));
2184 }
2185
2186
2187 void RawExternalInt8Array::WriteTo(SnapshotWriter* writer,
2188 intptr_t object_id,
2189 Snapshot::Kind kind) {
2190 ByteArrayWriteTo(writer,
2191 object_id,
2192 kind,
2193 ObjectStore::kInt8ArrayClass,
2194 ptr()->tags_,
2195 ptr()->length_,
2196 reinterpret_cast<uint8_t*>(ptr()->external_data_->data()));
2197 }
2198
2199
2200 void RawExternalUint8Array::WriteTo(SnapshotWriter* writer,
2201 intptr_t object_id,
2202 Snapshot::Kind kind) {
2203 // Serialize as a non-external int8 array.
2204 ByteArrayWriteTo(writer,
2205 object_id,
2206 kind,
2207 ObjectStore::kUint8ArrayClass,
2208 ptr()->tags_,
2209 ptr()->length_,
2210 reinterpret_cast<uint8_t*>(ptr()->external_data_->data()));
2211 }
2212
2213
2214 void RawExternalInt16Array::WriteTo(SnapshotWriter* writer,
2215 intptr_t object_id,
2216 Snapshot::Kind kind) {
2217 // Serialize as a non-external int16 array.
2218 ByteArrayWriteTo(writer,
2219 object_id,
2220 kind,
2221 ObjectStore::kInt16ArrayClass,
2222 ptr()->tags_,
2223 ptr()->length_,
2224 reinterpret_cast<uint8_t*>(ptr()->external_data_->data()));
2225 }
2226
2227
2228 void RawExternalUint16Array::WriteTo(SnapshotWriter* writer,
2229 intptr_t object_id,
2230 Snapshot::Kind kind) {
2231 // Serialize as a non-external uint16 array.
2232 ByteArrayWriteTo(writer,
2233 object_id,
2234 kind,
2235 ObjectStore::kUint16ArrayClass,
2236 ptr()->tags_,
2237 ptr()->length_,
2238 reinterpret_cast<uint8_t*>(ptr()->external_data_->data()));
2239 }
2240
2241
2242 void RawExternalInt32Array::WriteTo(SnapshotWriter* writer,
2243 intptr_t object_id,
2244 Snapshot::Kind kind) {
2245 // Serialize as a non-external int32 array.
2246 ByteArrayWriteTo(writer,
2247 object_id,
2248 kind,
2249 ObjectStore::kInt32ArrayClass,
2250 ptr()->tags_,
2251 ptr()->length_,
2252 reinterpret_cast<uint8_t*>(ptr()->external_data_->data()));
2253 }
2254
2255
2256 void RawExternalUint32Array::WriteTo(SnapshotWriter* writer,
2257 intptr_t object_id,
2258 Snapshot::Kind kind) {
2259 // Serialize as a non-external uint32 array.
2260 ByteArrayWriteTo(writer,
2261 object_id,
2262 kind,
2263 ObjectStore::kUint32ArrayClass,
2264 ptr()->tags_,
2265 ptr()->length_,
2266 reinterpret_cast<uint8_t*>(ptr()->external_data_->data()));
2267 }
2268
2269
2270 void RawExternalInt64Array::WriteTo(SnapshotWriter* writer,
2271 intptr_t object_id,
2272 Snapshot::Kind kind) {
2273 // Serialize as a non-external int64 array.
2274 ByteArrayWriteTo(writer,
2275 object_id,
2276 kind,
2277 ObjectStore::kInt64ArrayClass,
2278 ptr()->tags_,
2279 ptr()->length_,
2280 reinterpret_cast<uint8_t*>(ptr()->external_data_->data()));
2281 }
2282
2283
2284 void RawExternalUint64Array::WriteTo(SnapshotWriter* writer,
2285 intptr_t object_id,
2286 Snapshot::Kind kind) {
2287 // Serialize as a non-external uint64 array.
2288 ByteArrayWriteTo(writer,
2289 object_id,
2290 kind,
2291 ObjectStore::kUint64ArrayClass,
2292 ptr()->tags_,
2293 ptr()->length_,
2294 reinterpret_cast<uint8_t*>(ptr()->external_data_->data()));
2295 }
2296
2297
2298 void RawExternalFloat32Array::WriteTo(SnapshotWriter* writer,
2299 intptr_t object_id,
2300 Snapshot::Kind kind) {
2301 // Serialize as a non-external float32 array.
2302 ByteArrayWriteTo(writer,
2303 object_id,
2304 kind,
2305 ObjectStore::kFloat32ArrayClass,
2306 ptr()->tags_,
2307 ptr()->length_,
2308 reinterpret_cast<uint8_t*>(ptr()->external_data_->data()));
2309 }
2310
2311
2312 void RawExternalFloat64Array::WriteTo(SnapshotWriter* writer,
2313 intptr_t object_id,
2314 Snapshot::Kind kind) {
2315 // Serialize as a non-external float64 array.
2316 ByteArrayWriteTo(writer,
2317 object_id,
2318 kind,
2319 ObjectStore::kFloat64ArrayClass,
2320 ptr()->tags_,
2321 ptr()->length_,
2322 reinterpret_cast<uint8_t*>(ptr()->external_data_->data()));
2323 }
2324
2325
1894 RawClosure* Closure::ReadFrom(SnapshotReader* reader, 2326 RawClosure* Closure::ReadFrom(SnapshotReader* reader,
1895 intptr_t object_id, 2327 intptr_t object_id,
1896 intptr_t tags, 2328 intptr_t tags,
1897 Snapshot::Kind kind) { 2329 Snapshot::Kind kind) {
1898 UNIMPLEMENTED(); 2330 UNIMPLEMENTED();
1899 return Closure::null(); 2331 return Closure::null();
1900 } 2332 }
1901 2333
1902 2334
1903 void RawClosure::WriteTo(SnapshotWriter* writer, 2335 void RawClosure::WriteTo(SnapshotWriter* writer,
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
1974 writer->Write<RawObject*>(ptr()->num_bracket_expressions_); 2406 writer->Write<RawObject*>(ptr()->num_bracket_expressions_);
1975 writer->WriteObject(ptr()->pattern_); 2407 writer->WriteObject(ptr()->pattern_);
1976 writer->WriteIntptrValue(ptr()->type_); 2408 writer->WriteIntptrValue(ptr()->type_);
1977 writer->WriteIntptrValue(ptr()->flags_); 2409 writer->WriteIntptrValue(ptr()->flags_);
1978 2410
1979 // Do not write out the data part which is native. 2411 // Do not write out the data part which is native.
1980 } 2412 }
1981 2413
1982 2414
1983 } // namespace dart 2415 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698