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

Side by Side Diff: vm/raw_object_snapshot.cc

Issue 10446112: Refactor snapshot writing code in preparation for the change to remove recursive calls to WriteObje… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 6 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
« no previous file with comments | « no previous file | vm/snapshot.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 (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 1801 matching lines...) Expand 10 before | Expand all | Expand 10 after
1812 result.set_tags(tags); 1812 result.set_tags(tags);
1813 1813
1814 // Setup the array elements. 1814 // Setup the array elements.
1815 for (intptr_t i = 0; i < len; ++i) { 1815 for (intptr_t i = 0; i < len; ++i) {
1816 result.SetAt(i, reader->Read<ElementT>()); 1816 result.SetAt(i, reader->Read<ElementT>());
1817 } 1817 }
1818 return result.raw(); 1818 return result.raw();
1819 } 1819 }
1820 1820
1821 1821
1822 RawInt8Array* Int8Array::ReadFrom(SnapshotReader* reader, 1822 #define TYPE_LIST(V) \
cshapiro 2012/05/31 23:53:19 Could be BYTE_ARRAY_TYPE_LIST to avoid potential n
siva 2012/06/01 00:12:50 Done.
1823 intptr_t object_id, 1823 V(Int8, int8_t) \
1824 intptr_t tags, 1824 V(Uint8, uint8_t) \
1825 Snapshot::Kind kind) { 1825 V(Int16, int16_t) \
1826 return ReadFromImpl<Int8Array, RawInt8Array, int8_t>(reader, 1826 V(Uint16, uint16_t) \
1827 object_id, 1827 V(Int32, int32_t) \
1828 tags, 1828 V(Uint32, uint32_t) \
1829 kind); 1829 V(Int64, int64_t) \
1830 } 1830 V(Uint64, uint64_t) \
1831 V(Float32, float) \
1832 V(Float64, double) \
1831 1833
1832 1834
1833 RawUint8Array* Uint8Array::ReadFrom(SnapshotReader* reader, 1835 #define BYTEARRAY_READ_FROM(name, type) \
1834 intptr_t object_id, 1836 Raw##name##Array* name##Array::ReadFrom(SnapshotReader* reader, \
1835 intptr_t tags, 1837 intptr_t object_id, \
1836 Snapshot::Kind kind) { 1838 intptr_t tags, \
1837 return ReadFromImpl<Uint8Array, RawUint8Array, uint8_t>(reader, 1839 Snapshot::Kind kind) { \
1838 object_id, 1840 return ReadFromImpl<name##Array, Raw##name##Array, type>(reader, \
1839 tags, 1841 object_id, \
1840 kind); 1842 tags, \
1841 } 1843 kind); \
1844 } \
1842 1845
1843 1846
1844 RawInt16Array* Int16Array::ReadFrom(SnapshotReader* reader, 1847 TYPE_LIST(BYTEARRAY_READ_FROM)
1845 intptr_t object_id, 1848 #undef BYTEARRAY_READ_FROM
1846 intptr_t tags,
1847 Snapshot::Kind kind) {
1848 return ReadFromImpl<Int16Array, RawInt16Array, int16_t>(reader,
1849 object_id,
1850 tags,
1851 kind);
1852 }
1853 1849
1854 1850
1855 RawUint16Array* Uint16Array::ReadFrom(SnapshotReader* reader, 1851 #define EXTERNALARRAY_READ_FROM(name, type) \
1856 intptr_t object_id, 1852 RawExternal##name##Array* External##name##Array::ReadFrom( \
1857 intptr_t tags, 1853 SnapshotReader* reader, \
1858 Snapshot::Kind kind) { 1854 intptr_t object_id, \
1859 return ReadFromImpl<Uint16Array, RawUint16Array, uint16_t>(reader, 1855 intptr_t tags, \
1860 object_id, 1856 Snapshot::Kind kind) { \
1861 tags, 1857 UNREACHABLE(); \
1862 kind); 1858 return External##name##Array::null(); \
1863 } 1859 } \
1864 1860
1865 1861
1866 RawInt32Array* Int32Array::ReadFrom(SnapshotReader* reader, 1862 TYPE_LIST(EXTERNALARRAY_READ_FROM)
1867 intptr_t object_id, 1863 #undef EXTERNALARRAY_READ_FROM
1868 intptr_t tags,
1869 Snapshot::Kind kind) {
1870 return ReadFromImpl<Int32Array, RawInt32Array, int32_t>(reader,
1871 object_id,
1872 tags,
1873 kind);
1874 }
1875
1876
1877 RawUint32Array* Uint32Array::ReadFrom(SnapshotReader* reader,
1878 intptr_t object_id,
1879 intptr_t tags,
1880 Snapshot::Kind kind) {
1881 return ReadFromImpl<Uint32Array, RawUint32Array, uint32_t>(reader,
1882 object_id,
1883 tags,
1884 kind);
1885 }
1886
1887
1888 RawInt64Array* Int64Array::ReadFrom(SnapshotReader* reader,
1889 intptr_t object_id,
1890 intptr_t tags,
1891 Snapshot::Kind kind) {
1892 return ReadFromImpl<Int64Array, RawInt64Array, int64_t>(reader,
1893 object_id,
1894 tags,
1895 kind);
1896 }
1897
1898
1899 RawUint64Array* Uint64Array::ReadFrom(SnapshotReader* reader,
1900 intptr_t object_id,
1901 intptr_t tags,
1902 Snapshot::Kind kind) {
1903 return ReadFromImpl<Uint64Array, RawUint64Array, uint64_t>(reader,
1904 object_id,
1905 tags,
1906 kind);
1907 }
1908
1909
1910 RawFloat32Array* Float32Array::ReadFrom(SnapshotReader* reader,
1911 intptr_t object_id,
1912 intptr_t tags,
1913 Snapshot::Kind kind) {
1914 return ReadFromImpl<Float32Array, RawFloat32Array, float>(reader,
1915 object_id,
1916 tags,
1917 kind);
1918 }
1919
1920
1921 RawFloat64Array* Float64Array::ReadFrom(SnapshotReader* reader,
1922 intptr_t object_id,
1923 intptr_t tags,
1924 Snapshot::Kind kind) {
1925 return ReadFromImpl<Float64Array, RawFloat64Array, double>(reader,
1926 object_id,
1927 tags,
1928 kind);
1929 }
1930
1931
1932 RawExternalInt8Array* ExternalInt8Array::ReadFrom(SnapshotReader* reader,
1933 intptr_t object_id,
1934 intptr_t tags,
1935 Snapshot::Kind kind) {
1936 UNREACHABLE();
1937 return ExternalInt8Array::null();
1938 }
1939
1940
1941 RawExternalUint8Array* ExternalUint8Array::ReadFrom(SnapshotReader* reader,
1942 intptr_t object_id,
1943 intptr_t tags,
1944 Snapshot::Kind kind) {
1945 UNREACHABLE();
1946 return ExternalUint8Array::null();
1947 }
1948
1949
1950 RawExternalInt16Array* ExternalInt16Array::ReadFrom(SnapshotReader* reader,
1951 intptr_t object_id,
1952 intptr_t tags,
1953 Snapshot::Kind kind) {
1954 UNREACHABLE();
1955 return ExternalInt16Array::null();
1956 }
1957
1958
1959 RawExternalUint16Array* ExternalUint16Array::ReadFrom(SnapshotReader* reader,
1960 intptr_t object_id,
1961 intptr_t tags,
1962 Snapshot::Kind kind) {
1963 UNREACHABLE();
1964 return ExternalUint16Array::null();
1965 }
1966
1967
1968 RawExternalInt32Array* ExternalInt32Array::ReadFrom(SnapshotReader* reader,
1969 intptr_t object_id,
1970 intptr_t tags,
1971 Snapshot::Kind kind) {
1972 UNREACHABLE();
1973 return ExternalInt32Array::null();
1974 }
1975
1976
1977 RawExternalUint32Array* ExternalUint32Array::ReadFrom(SnapshotReader* reader,
1978 intptr_t object_id,
1979 intptr_t tags,
1980 Snapshot::Kind kind) {
1981 UNREACHABLE();
1982 return ExternalUint32Array::null();
1983 }
1984
1985
1986 RawExternalInt64Array* ExternalInt64Array::ReadFrom(SnapshotReader* reader,
1987 intptr_t object_id,
1988 intptr_t tags,
1989 Snapshot::Kind kind) {
1990 UNREACHABLE();
1991 return ExternalInt64Array::null();
1992 }
1993
1994
1995 RawExternalUint64Array* ExternalUint64Array::ReadFrom(SnapshotReader* reader,
1996 intptr_t object_id,
1997 intptr_t tags,
1998 Snapshot::Kind kind) {
1999 UNREACHABLE();
2000 return ExternalUint64Array::null();
2001 }
2002
2003
2004 RawExternalFloat32Array* ExternalFloat32Array::ReadFrom(SnapshotReader* reader,
2005 intptr_t object_id,
2006 intptr_t tags,
2007 Snapshot::Kind kind) {
2008 UNREACHABLE();
2009 return ExternalFloat32Array::null();
2010 }
2011
2012
2013 RawExternalFloat64Array* ExternalFloat64Array::ReadFrom(SnapshotReader* reader,
2014 intptr_t object_id,
2015 intptr_t tags,
2016 Snapshot::Kind kind) {
2017 UNREACHABLE();
2018 return ExternalFloat64Array::null();
2019 }
2020 1864
2021 1865
2022 static void ByteArrayWriteTo(SnapshotWriter* writer, 1866 static void ByteArrayWriteTo(SnapshotWriter* writer,
2023 intptr_t object_id, 1867 intptr_t object_id,
2024 Snapshot::Kind kind, 1868 Snapshot::Kind kind,
2025 intptr_t byte_array_kind, 1869 intptr_t byte_array_kind,
2026 intptr_t tags, 1870 intptr_t tags,
2027 RawSmi* length, 1871 RawSmi* length,
2028 uint8_t* data) { 1872 uint8_t* data) {
2029 ASSERT(writer != NULL); 1873 ASSERT(writer != NULL);
(...skipping 15 matching lines...) Expand all
2045 } 1889 }
2046 1890
2047 1891
2048 void RawByteArray::WriteTo(SnapshotWriter* writer, 1892 void RawByteArray::WriteTo(SnapshotWriter* writer,
2049 intptr_t object_id, 1893 intptr_t object_id,
2050 Snapshot::Kind kind) { 1894 Snapshot::Kind kind) {
2051 UNREACHABLE(); // ByteArray is an abstract class 1895 UNREACHABLE(); // ByteArray is an abstract class
2052 } 1896 }
2053 1897
2054 1898
2055 void RawInt8Array::WriteTo(SnapshotWriter* writer, 1899 #define BYTEARRAY_WRITE_TO(name, type) \
2056 intptr_t object_id, 1900 void Raw##name##Array::WriteTo(SnapshotWriter* writer, \
2057 Snapshot::Kind kind) { 1901 intptr_t object_id, \
2058 ByteArrayWriteTo(writer, 1902 Snapshot::Kind kind) { \
2059 object_id, 1903 ByteArrayWriteTo(writer, \
2060 kind, 1904 object_id, \
2061 ObjectStore::kInt8ArrayClass, 1905 kind, \
2062 writer->GetObjectTags(this), 1906 ObjectStore::k##name##ArrayClass, \
2063 ptr()->length_, 1907 writer->GetObjectTags(this), \
2064 reinterpret_cast<uint8_t*>(ptr()->data_)); 1908 ptr()->length_, \
2065 } 1909 reinterpret_cast<uint8_t*>(ptr()->data_)); \
1910 } \
2066 1911
2067 1912
2068 void RawUint8Array::WriteTo(SnapshotWriter* writer, 1913 TYPE_LIST(BYTEARRAY_WRITE_TO)
2069 intptr_t object_id, 1914 #undef BYTEARRAY_WRITE_TO
2070 Snapshot::Kind kind) {
2071 ByteArrayWriteTo(writer,
2072 object_id,
2073 kind,
2074 ObjectStore::kUint8ArrayClass,
2075 writer->GetObjectTags(this),
2076 ptr()->length_,
2077 reinterpret_cast<uint8_t*>(ptr()->data_));
2078 }
2079 1915
2080 1916
2081 void RawInt16Array::WriteTo(SnapshotWriter* writer, 1917 #define EXTERNALARRAY_WRITE_TO(name, type) \
2082 intptr_t object_id, 1918 void RawExternal##name##Array::WriteTo(SnapshotWriter* writer, \
2083 Snapshot::Kind kind) { 1919 intptr_t object_id, \
2084 ByteArrayWriteTo(writer, 1920 Snapshot::Kind kind) { \
2085 object_id, 1921 ByteArrayWriteTo(writer, \
2086 kind, 1922 object_id, \
2087 ObjectStore::kInt16ArrayClass, 1923 kind, \
2088 writer->GetObjectTags(this), 1924 ObjectStore::k##name##ArrayClass, \
2089 ptr()->length_, 1925 writer->GetObjectTags(this), \
2090 reinterpret_cast<uint8_t*>(ptr()->data_)); 1926 ptr()->length_, \
2091 } 1927 reinterpret_cast<uint8_t*>(ptr()->external_data_->data())); \
1928 } \
2092 1929
2093 1930
2094 void RawUint16Array::WriteTo(SnapshotWriter* writer, 1931 TYPE_LIST(EXTERNALARRAY_WRITE_TO)
2095 intptr_t object_id, 1932 #undef BYTEARRAY_WRITE_TO
2096 Snapshot::Kind kind) { 1933 #undef TYPE_LIST
2097 ByteArrayWriteTo(writer,
2098 object_id,
2099 kind,
2100 ObjectStore::kUint16ArrayClass,
2101 writer->GetObjectTags(this),
2102 ptr()->length_,
2103 reinterpret_cast<uint8_t*>(ptr()->data_));
2104 }
2105
2106
2107 void RawInt32Array::WriteTo(SnapshotWriter* writer,
2108 intptr_t object_id,
2109 Snapshot::Kind kind) {
2110 ByteArrayWriteTo(writer,
2111 object_id,
2112 kind,
2113 ObjectStore::kInt32ArrayClass,
2114 writer->GetObjectTags(this),
2115 ptr()->length_,
2116 reinterpret_cast<uint8_t*>(ptr()->data_));
2117 }
2118
2119
2120 void RawUint32Array::WriteTo(SnapshotWriter* writer,
2121 intptr_t object_id,
2122 Snapshot::Kind kind) {
2123 ByteArrayWriteTo(writer,
2124 object_id,
2125 kind,
2126 ObjectStore::kUint32ArrayClass,
2127 writer->GetObjectTags(this),
2128 ptr()->length_,
2129 reinterpret_cast<uint8_t*>(ptr()->data_));
2130 }
2131
2132
2133 void RawInt64Array::WriteTo(SnapshotWriter* writer,
2134 intptr_t object_id,
2135 Snapshot::Kind kind) {
2136 ByteArrayWriteTo(writer,
2137 object_id,
2138 kind,
2139 ObjectStore::kInt64ArrayClass,
2140 writer->GetObjectTags(this),
2141 ptr()->length_,
2142 reinterpret_cast<uint8_t*>(ptr()->data_));
2143 }
2144
2145
2146 void RawUint64Array::WriteTo(SnapshotWriter* writer,
2147 intptr_t object_id,
2148 Snapshot::Kind kind) {
2149 ByteArrayWriteTo(writer,
2150 object_id,
2151 kind,
2152 ObjectStore::kUint64ArrayClass,
2153 writer->GetObjectTags(this),
2154 ptr()->length_,
2155 reinterpret_cast<uint8_t*>(ptr()->data_));
2156 }
2157
2158
2159 void RawFloat32Array::WriteTo(SnapshotWriter* writer,
2160 intptr_t object_id,
2161 Snapshot::Kind kind) {
2162 ByteArrayWriteTo(writer,
2163 object_id,
2164 kind,
2165 ObjectStore::kFloat32ArrayClass,
2166 writer->GetObjectTags(this),
2167 ptr()->length_,
2168 reinterpret_cast<uint8_t*>(ptr()->data_));
2169 }
2170
2171
2172 void RawFloat64Array::WriteTo(SnapshotWriter* writer,
2173 intptr_t object_id,
2174 Snapshot::Kind kind) {
2175 ByteArrayWriteTo(writer,
2176 object_id,
2177 kind,
2178 ObjectStore::kFloat64ArrayClass,
2179 writer->GetObjectTags(this),
2180 ptr()->length_,
2181 reinterpret_cast<uint8_t*>(ptr()->data_));
2182 }
2183
2184
2185 void RawExternalInt8Array::WriteTo(SnapshotWriter* writer,
2186 intptr_t object_id,
2187 Snapshot::Kind kind) {
2188 ByteArrayWriteTo(writer,
2189 object_id,
2190 kind,
2191 ObjectStore::kInt8ArrayClass,
2192 writer->GetObjectTags(this),
2193 ptr()->length_,
2194 reinterpret_cast<uint8_t*>(ptr()->external_data_->data()));
2195 }
2196
2197
2198 void RawExternalUint8Array::WriteTo(SnapshotWriter* writer,
2199 intptr_t object_id,
2200 Snapshot::Kind kind) {
2201 // Serialize as a non-external int8 array.
2202 ByteArrayWriteTo(writer,
2203 object_id,
2204 kind,
2205 ObjectStore::kUint8ArrayClass,
2206 writer->GetObjectTags(this),
2207 ptr()->length_,
2208 reinterpret_cast<uint8_t*>(ptr()->external_data_->data()));
2209 }
2210
2211
2212 void RawExternalInt16Array::WriteTo(SnapshotWriter* writer,
2213 intptr_t object_id,
2214 Snapshot::Kind kind) {
2215 // Serialize as a non-external int16 array.
2216 ByteArrayWriteTo(writer,
2217 object_id,
2218 kind,
2219 ObjectStore::kInt16ArrayClass,
2220 writer->GetObjectTags(this),
2221 ptr()->length_,
2222 reinterpret_cast<uint8_t*>(ptr()->external_data_->data()));
2223 }
2224
2225
2226 void RawExternalUint16Array::WriteTo(SnapshotWriter* writer,
2227 intptr_t object_id,
2228 Snapshot::Kind kind) {
2229 // Serialize as a non-external uint16 array.
2230 ByteArrayWriteTo(writer,
2231 object_id,
2232 kind,
2233 ObjectStore::kUint16ArrayClass,
2234 writer->GetObjectTags(this),
2235 ptr()->length_,
2236 reinterpret_cast<uint8_t*>(ptr()->external_data_->data()));
2237 }
2238
2239
2240 void RawExternalInt32Array::WriteTo(SnapshotWriter* writer,
2241 intptr_t object_id,
2242 Snapshot::Kind kind) {
2243 // Serialize as a non-external int32 array.
2244 ByteArrayWriteTo(writer,
2245 object_id,
2246 kind,
2247 ObjectStore::kInt32ArrayClass,
2248 writer->GetObjectTags(this),
2249 ptr()->length_,
2250 reinterpret_cast<uint8_t*>(ptr()->external_data_->data()));
2251 }
2252
2253
2254 void RawExternalUint32Array::WriteTo(SnapshotWriter* writer,
2255 intptr_t object_id,
2256 Snapshot::Kind kind) {
2257 // Serialize as a non-external uint32 array.
2258 ByteArrayWriteTo(writer,
2259 object_id,
2260 kind,
2261 ObjectStore::kUint32ArrayClass,
2262 writer->GetObjectTags(this),
2263 ptr()->length_,
2264 reinterpret_cast<uint8_t*>(ptr()->external_data_->data()));
2265 }
2266
2267
2268 void RawExternalInt64Array::WriteTo(SnapshotWriter* writer,
2269 intptr_t object_id,
2270 Snapshot::Kind kind) {
2271 // Serialize as a non-external int64 array.
2272 ByteArrayWriteTo(writer,
2273 object_id,
2274 kind,
2275 ObjectStore::kInt64ArrayClass,
2276 writer->GetObjectTags(this),
2277 ptr()->length_,
2278 reinterpret_cast<uint8_t*>(ptr()->external_data_->data()));
2279 }
2280
2281
2282 void RawExternalUint64Array::WriteTo(SnapshotWriter* writer,
2283 intptr_t object_id,
2284 Snapshot::Kind kind) {
2285 // Serialize as a non-external uint64 array.
2286 ByteArrayWriteTo(writer,
2287 object_id,
2288 kind,
2289 ObjectStore::kUint64ArrayClass,
2290 writer->GetObjectTags(this),
2291 ptr()->length_,
2292 reinterpret_cast<uint8_t*>(ptr()->external_data_->data()));
2293 }
2294
2295
2296 void RawExternalFloat32Array::WriteTo(SnapshotWriter* writer,
2297 intptr_t object_id,
2298 Snapshot::Kind kind) {
2299 // Serialize as a non-external float32 array.
2300 ByteArrayWriteTo(writer,
2301 object_id,
2302 kind,
2303 ObjectStore::kFloat32ArrayClass,
2304 writer->GetObjectTags(this),
2305 ptr()->length_,
2306 reinterpret_cast<uint8_t*>(ptr()->external_data_->data()));
2307 }
2308
2309
2310 void RawExternalFloat64Array::WriteTo(SnapshotWriter* writer,
2311 intptr_t object_id,
2312 Snapshot::Kind kind) {
2313 // Serialize as a non-external float64 array.
2314 ByteArrayWriteTo(writer,
2315 object_id,
2316 kind,
2317 ObjectStore::kFloat64ArrayClass,
2318 writer->GetObjectTags(this),
2319 ptr()->length_,
2320 reinterpret_cast<uint8_t*>(ptr()->external_data_->data()));
2321 }
2322 1934
2323 1935
2324 RawClosure* Closure::ReadFrom(SnapshotReader* reader, 1936 RawClosure* Closure::ReadFrom(SnapshotReader* reader,
2325 intptr_t object_id, 1937 intptr_t object_id,
2326 intptr_t tags, 1938 intptr_t tags,
2327 Snapshot::Kind kind) { 1939 Snapshot::Kind kind) {
2328 UNIMPLEMENTED(); 1940 UNIMPLEMENTED();
2329 return Closure::null(); 1941 return Closure::null();
2330 } 1942 }
2331 1943
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
2405 writer->Write<RawObject*>(ptr()->num_bracket_expressions_); 2017 writer->Write<RawObject*>(ptr()->num_bracket_expressions_);
2406 writer->WriteObject(ptr()->pattern_); 2018 writer->WriteObject(ptr()->pattern_);
2407 writer->WriteIntptrValue(ptr()->type_); 2019 writer->WriteIntptrValue(ptr()->type_);
2408 writer->WriteIntptrValue(ptr()->flags_); 2020 writer->WriteIntptrValue(ptr()->flags_);
2409 2021
2410 // Do not write out the data part which is native. 2022 // Do not write out the data part which is native.
2411 } 2023 }
2412 2024
2413 2025
2414 } // namespace dart 2026 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | vm/snapshot.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698