OLD | NEW |
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/symbols.h" | 9 #include "vm/symbols.h" |
10 #include "vm/visitor.h" | 10 #include "vm/visitor.h" |
(...skipping 2027 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2038 writer->WriteIntptrValue(writer->GetObjectTags(this)); | 2038 writer->WriteIntptrValue(writer->GetObjectTags(this)); |
2039 | 2039 |
2040 // Write out the used length field. | 2040 // Write out the used length field. |
2041 writer->Write<RawObject*>(ptr()->length_); | 2041 writer->Write<RawObject*>(ptr()->length_); |
2042 | 2042 |
2043 // Write out the Array object. | 2043 // Write out the Array object. |
2044 writer->WriteObjectImpl(ptr()->data_); | 2044 writer->WriteObjectImpl(ptr()->data_); |
2045 } | 2045 } |
2046 | 2046 |
2047 | 2047 |
| 2048 RawFloat32x4* Float32x4::ReadFrom(SnapshotReader* reader, |
| 2049 intptr_t object_id, |
| 2050 intptr_t tags, |
| 2051 Snapshot::Kind kind) { |
| 2052 ASSERT(reader != NULL); |
| 2053 // Read the values. |
| 2054 float value0 = reader->Read<float>(); |
| 2055 float value1 = reader->Read<float>(); |
| 2056 float value2 = reader->Read<float>(); |
| 2057 float value3 = reader->Read<float>(); |
| 2058 |
| 2059 // Create a Float32x4 object. |
| 2060 Float32x4& simd = Float32x4::ZoneHandle(reader->isolate(), |
| 2061 Float32x4::null()); |
| 2062 if (kind == Snapshot::kFull) { |
| 2063 simd = reader->NewFloat32x4(value0, value1, value2, value3); |
| 2064 } else { |
| 2065 simd = Float32x4::New(value0, value1, value2, value3, HEAP_SPACE(kind)); |
| 2066 } |
| 2067 reader->AddBackRef(object_id, &simd, kIsDeserialized); |
| 2068 // Set the object tags. |
| 2069 simd.set_tags(tags); |
| 2070 return simd.raw(); |
| 2071 } |
| 2072 |
| 2073 |
| 2074 void RawFloat32x4::WriteTo(SnapshotWriter* writer, |
| 2075 intptr_t object_id, |
| 2076 Snapshot::Kind kind) { |
| 2077 ASSERT(writer != NULL); |
| 2078 |
| 2079 // Write out the serialization header value for this object. |
| 2080 writer->WriteInlinedObjectHeader(object_id); |
| 2081 |
| 2082 // Write out the class and tags information. |
| 2083 writer->WriteIndexedObject(kFloat32x4Cid); |
| 2084 writer->WriteIntptrValue(writer->GetObjectTags(this)); |
| 2085 |
| 2086 // Write out the float values. |
| 2087 writer->Write<float>(ptr()->value_[0]); |
| 2088 writer->Write<float>(ptr()->value_[1]); |
| 2089 writer->Write<float>(ptr()->value_[2]); |
| 2090 writer->Write<float>(ptr()->value_[3]); |
| 2091 } |
| 2092 |
| 2093 |
| 2094 RawUint32x4* Uint32x4::ReadFrom(SnapshotReader* reader, |
| 2095 intptr_t object_id, |
| 2096 intptr_t tags, |
| 2097 Snapshot::Kind kind) { |
| 2098 ASSERT(reader != NULL); |
| 2099 // Read the values. |
| 2100 uint32_t value0 = reader->Read<uint32_t>(); |
| 2101 uint32_t value1 = reader->Read<uint32_t>(); |
| 2102 uint32_t value2 = reader->Read<uint32_t>(); |
| 2103 uint32_t value3 = reader->Read<uint32_t>(); |
| 2104 |
| 2105 // Create a Float32x4 object. |
| 2106 Uint32x4& simd = Uint32x4::ZoneHandle(reader->isolate(), Uint32x4::null()); |
| 2107 |
| 2108 if (kind == Snapshot::kFull) { |
| 2109 simd = reader->NewUint32x4(value0, value1, value2, value3); |
| 2110 } else { |
| 2111 simd = Uint32x4::New(value0, value1, value2, value3, HEAP_SPACE(kind)); |
| 2112 } |
| 2113 reader->AddBackRef(object_id, &simd, kIsDeserialized); |
| 2114 // Set the object tags. |
| 2115 simd.set_tags(tags); |
| 2116 return simd.raw(); |
| 2117 } |
| 2118 |
| 2119 |
| 2120 void RawUint32x4::WriteTo(SnapshotWriter* writer, |
| 2121 intptr_t object_id, |
| 2122 Snapshot::Kind kind) { |
| 2123 ASSERT(writer != NULL); |
| 2124 |
| 2125 // Write out the serialization header value for this object. |
| 2126 writer->WriteInlinedObjectHeader(object_id); |
| 2127 |
| 2128 // Write out the class and tags information. |
| 2129 writer->WriteIndexedObject(kUint32x4Cid); |
| 2130 writer->WriteIntptrValue(writer->GetObjectTags(this)); |
| 2131 |
| 2132 // Write out the mask values. |
| 2133 writer->Write<uint32_t>(ptr()->value_[0]); |
| 2134 writer->Write<uint32_t>(ptr()->value_[1]); |
| 2135 writer->Write<uint32_t>(ptr()->value_[2]); |
| 2136 writer->Write<uint32_t>(ptr()->value_[3]); |
| 2137 } |
| 2138 |
| 2139 |
2048 RawByteArray* ByteArray::ReadFrom(SnapshotReader* reader, | 2140 RawByteArray* ByteArray::ReadFrom(SnapshotReader* reader, |
2049 intptr_t object_id, | 2141 intptr_t object_id, |
2050 intptr_t tags, | 2142 intptr_t tags, |
2051 Snapshot::Kind kind) { | 2143 Snapshot::Kind kind) { |
2052 UNREACHABLE(); // ByteArray is an abstract class. | 2144 UNREACHABLE(); // ByteArray is an abstract class. |
2053 return ByteArray::null(); | 2145 return ByteArray::null(); |
2054 } | 2146 } |
2055 | 2147 |
2056 | 2148 |
2057 template<typename HandleT, typename RawT, typename ElementT> | 2149 template<typename HandleT, typename RawT, typename ElementT> |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2099 return ReadFromImpl<name##Array, Raw##name##Array, type>(reader, \ | 2191 return ReadFromImpl<name##Array, Raw##name##Array, type>(reader, \ |
2100 object_id, \ | 2192 object_id, \ |
2101 tags, \ | 2193 tags, \ |
2102 kind); \ | 2194 kind); \ |
2103 } \ | 2195 } \ |
2104 | 2196 |
2105 | 2197 |
2106 BYTEARRAY_TYPE_LIST(BYTEARRAY_READ_FROM) | 2198 BYTEARRAY_TYPE_LIST(BYTEARRAY_READ_FROM) |
2107 #undef BYTEARRAY_READ_FROM | 2199 #undef BYTEARRAY_READ_FROM |
2108 | 2200 |
| 2201 RawFloat32x4Array* Float32x4Array::ReadFrom(SnapshotReader* reader, |
| 2202 intptr_t object_id, |
| 2203 intptr_t tags, |
| 2204 Snapshot::Kind kind) { |
| 2205 ASSERT(reader != NULL); |
| 2206 |
| 2207 intptr_t len = reader->ReadSmiValue(); |
| 2208 Float32x4Array& result = Float32x4Array::ZoneHandle( |
| 2209 reader->isolate(), Float32x4Array::New(len, HEAP_SPACE(kind))); |
| 2210 reader->AddBackRef(object_id, &result, kIsDeserialized); |
| 2211 |
| 2212 // Set the object tags. |
| 2213 result.set_tags(tags); |
| 2214 |
| 2215 // Setup the array elements. |
| 2216 float v[4]; |
| 2217 for (intptr_t i = 0; i < len; ++i) { |
| 2218 v[0] = reader->Read<float>(); |
| 2219 v[1] = reader->Read<float>(); |
| 2220 v[2] = reader->Read<float>(); |
| 2221 v[3] = reader->Read<float>(); |
| 2222 result.SetAt(i, simd_value_safe_load(&v[0])); |
| 2223 } |
| 2224 return result.raw(); |
| 2225 } |
| 2226 |
2109 | 2227 |
2110 #define EXTERNALARRAY_READ_FROM(name, lname, type) \ | 2228 #define EXTERNALARRAY_READ_FROM(name, lname, type) \ |
2111 RawExternal##name##Array* External##name##Array::ReadFrom( \ | 2229 RawExternal##name##Array* External##name##Array::ReadFrom( \ |
2112 SnapshotReader* reader, \ | 2230 SnapshotReader* reader, \ |
2113 intptr_t object_id, \ | 2231 intptr_t object_id, \ |
2114 intptr_t tags, \ | 2232 intptr_t tags, \ |
2115 Snapshot::Kind kind) { \ | 2233 Snapshot::Kind kind) { \ |
2116 ASSERT(kind != Snapshot::kFull); \ | 2234 ASSERT(kind != Snapshot::kFull); \ |
2117 intptr_t length = reader->ReadSmiValue(); \ | 2235 intptr_t length = reader->ReadSmiValue(); \ |
2118 type* data = reinterpret_cast<type*>(reader->ReadIntptrValue()); \ | 2236 type* data = reinterpret_cast<type*>(reader->ReadIntptrValue()); \ |
2119 const External##name##Array& obj = External##name##Array::Handle( \ | 2237 const External##name##Array& obj = External##name##Array::Handle( \ |
2120 External##name##Array::New(data, length)); \ | 2238 External##name##Array::New(data, length)); \ |
2121 void* peer = reinterpret_cast<void*>(reader->ReadIntptrValue()); \ | 2239 void* peer = reinterpret_cast<void*>(reader->ReadIntptrValue()); \ |
2122 Dart_WeakPersistentHandleFinalizer callback = \ | 2240 Dart_WeakPersistentHandleFinalizer callback = \ |
2123 reinterpret_cast<Dart_WeakPersistentHandleFinalizer>( \ | 2241 reinterpret_cast<Dart_WeakPersistentHandleFinalizer>( \ |
2124 reader->ReadIntptrValue()); \ | 2242 reader->ReadIntptrValue()); \ |
2125 obj.AddFinalizer(peer, callback); \ | 2243 obj.AddFinalizer(peer, callback); \ |
2126 return obj.raw(); \ | 2244 return obj.raw(); \ |
2127 } \ | 2245 } \ |
2128 | 2246 |
2129 | |
2130 BYTEARRAY_TYPE_LIST(EXTERNALARRAY_READ_FROM) | 2247 BYTEARRAY_TYPE_LIST(EXTERNALARRAY_READ_FROM) |
| 2248 EXTERNALARRAY_READ_FROM(Float32x4, Float32x4, simd_value_t) |
2131 #undef EXTERNALARRAY_READ_FROM | 2249 #undef EXTERNALARRAY_READ_FROM |
2132 | 2250 |
2133 | 2251 |
2134 template<typename ElementT> | 2252 template<typename ElementT> |
2135 static void ByteArrayWriteTo(SnapshotWriter* writer, | 2253 static void ByteArrayWriteTo(SnapshotWriter* writer, |
2136 intptr_t object_id, | 2254 intptr_t object_id, |
2137 Snapshot::Kind kind, | 2255 Snapshot::Kind kind, |
2138 intptr_t byte_array_kind, | 2256 intptr_t byte_array_kind, |
2139 intptr_t tags, | 2257 intptr_t tags, |
2140 RawSmi* length, | 2258 RawSmi* length, |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2176 k##name##ArrayCid, \ | 2294 k##name##ArrayCid, \ |
2177 writer->GetObjectTags(this), \ | 2295 writer->GetObjectTags(this), \ |
2178 ptr()->length_, \ | 2296 ptr()->length_, \ |
2179 ptr()->data_); \ | 2297 ptr()->data_); \ |
2180 } \ | 2298 } \ |
2181 | 2299 |
2182 | 2300 |
2183 BYTEARRAY_TYPE_LIST(BYTEARRAY_WRITE_TO) | 2301 BYTEARRAY_TYPE_LIST(BYTEARRAY_WRITE_TO) |
2184 #undef BYTEARRAY_WRITE_TO | 2302 #undef BYTEARRAY_WRITE_TO |
2185 | 2303 |
| 2304 void RawFloat32x4Array::WriteTo(SnapshotWriter* writer, intptr_t object_id, |
| 2305 Snapshot::Kind kind) { |
| 2306 ASSERT(writer != NULL); |
| 2307 RawSmi* length = ptr()->length_; |
| 2308 float* data = reinterpret_cast<float*>(&ptr()->data_[0]); |
| 2309 |
| 2310 // Write out the serialization header value for this object. |
| 2311 writer->WriteInlinedObjectHeader(object_id); |
| 2312 |
| 2313 // Write out the class and tags information. |
| 2314 writer->WriteIndexedObject(kFloat32x4ArrayCid); |
| 2315 writer->WriteIntptrValue(writer->GetObjectTags(this)); |
| 2316 |
| 2317 // Write out the length field. |
| 2318 writer->Write<RawObject*>(length); |
| 2319 |
| 2320 // Write out the array elements as floats. |
| 2321 intptr_t len = Smi::Value(length)*4; |
| 2322 for (intptr_t i = 0; i < len; i++) { |
| 2323 writer->Write(data[i]); |
| 2324 } |
| 2325 } |
2186 | 2326 |
2187 #define EXTERNALARRAY_WRITE_TO(name, lname, type) \ | 2327 #define EXTERNALARRAY_WRITE_TO(name, lname, type) \ |
2188 void RawExternal##name##Array::WriteTo(SnapshotWriter* writer, \ | 2328 void RawExternal##name##Array::WriteTo(SnapshotWriter* writer, \ |
2189 intptr_t object_id, \ | 2329 intptr_t object_id, \ |
2190 Snapshot::Kind kind) { \ | 2330 Snapshot::Kind kind) { \ |
2191 ByteArrayWriteTo(writer, \ | 2331 ByteArrayWriteTo(writer, \ |
2192 object_id, \ | 2332 object_id, \ |
2193 kind, \ | 2333 kind, \ |
2194 k##name##ArrayCid, \ | 2334 k##name##ArrayCid, \ |
2195 writer->GetObjectTags(this), \ | 2335 writer->GetObjectTags(this), \ |
2196 ptr()->length_, \ | 2336 ptr()->length_, \ |
2197 ptr()->data_); \ | 2337 ptr()->data_); \ |
2198 } \ | 2338 } \ |
2199 | 2339 |
2200 | 2340 |
2201 BYTEARRAY_TYPE_LIST(EXTERNALARRAY_WRITE_TO) | 2341 BYTEARRAY_TYPE_LIST(EXTERNALARRAY_WRITE_TO) |
2202 #undef BYTEARRAY_WRITE_TO | 2342 #undef BYTEARRAY_WRITE_TO |
| 2343 void RawExternalFloat32x4Array::WriteTo(SnapshotWriter* writer, |
| 2344 intptr_t object_id, |
| 2345 Snapshot::Kind kind) { |
| 2346 ASSERT(writer != NULL); |
| 2347 RawSmi* length = ptr()->length_; |
| 2348 float* data = reinterpret_cast<float*>(&ptr()->data_[0]); |
| 2349 |
| 2350 // Write out the serialization header value for this object. |
| 2351 writer->WriteInlinedObjectHeader(object_id); |
| 2352 |
| 2353 // Write out the class and tags information. |
| 2354 writer->WriteIndexedObject(kExternalFloat32x4ArrayCid); |
| 2355 writer->WriteIntptrValue(writer->GetObjectTags(this)); |
| 2356 |
| 2357 // Write out the length field. |
| 2358 writer->Write<RawObject*>(length); |
| 2359 |
| 2360 // Write out the array elements as floats. |
| 2361 intptr_t len = Smi::Value(length)*4; |
| 2362 for (intptr_t i = 0; i < len; i++) { |
| 2363 writer->Write(data[i]); |
| 2364 } |
| 2365 } |
| 2366 |
2203 #undef BYTEARRAY_TYPE_LIST | 2367 #undef BYTEARRAY_TYPE_LIST |
2204 | 2368 |
2205 | 2369 |
2206 RawDartFunction* DartFunction::ReadFrom(SnapshotReader* reader, | 2370 RawDartFunction* DartFunction::ReadFrom(SnapshotReader* reader, |
2207 intptr_t object_id, | 2371 intptr_t object_id, |
2208 intptr_t tags, | 2372 intptr_t tags, |
2209 Snapshot::Kind kind) { | 2373 Snapshot::Kind kind) { |
2210 UNREACHABLE(); // DartFunction is an abstract class. | 2374 UNREACHABLE(); // DartFunction is an abstract class. |
2211 return DartFunction::null(); | 2375 return DartFunction::null(); |
2212 } | 2376 } |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2325 // Write out the class and tags information. | 2489 // Write out the class and tags information. |
2326 writer->WriteIndexedObject(kWeakPropertyCid); | 2490 writer->WriteIndexedObject(kWeakPropertyCid); |
2327 writer->WriteIntptrValue(writer->GetObjectTags(this)); | 2491 writer->WriteIntptrValue(writer->GetObjectTags(this)); |
2328 | 2492 |
2329 // Write out all the other fields. | 2493 // Write out all the other fields. |
2330 writer->Write<RawObject*>(ptr()->key_); | 2494 writer->Write<RawObject*>(ptr()->key_); |
2331 writer->Write<RawObject*>(ptr()->value_); | 2495 writer->Write<RawObject*>(ptr()->value_); |
2332 } | 2496 } |
2333 | 2497 |
2334 } // namespace dart | 2498 } // namespace dart |
OLD | NEW |