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

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

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

Powered by Google App Engine
This is Rietveld 408576698