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 2212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2223 writer->WriteIntptrValue(writer->GetObjectTags(this)); | 2223 writer->WriteIntptrValue(writer->GetObjectTags(this)); |
2224 | 2224 |
2225 // Write out the mask values. | 2225 // Write out the mask values. |
2226 writer->Write<uint32_t>(ptr()->value_[0]); | 2226 writer->Write<uint32_t>(ptr()->value_[0]); |
2227 writer->Write<uint32_t>(ptr()->value_[1]); | 2227 writer->Write<uint32_t>(ptr()->value_[1]); |
2228 writer->Write<uint32_t>(ptr()->value_[2]); | 2228 writer->Write<uint32_t>(ptr()->value_[2]); |
2229 writer->Write<uint32_t>(ptr()->value_[3]); | 2229 writer->Write<uint32_t>(ptr()->value_[3]); |
2230 } | 2230 } |
2231 | 2231 |
2232 | 2232 |
2233 RawByteArray* ByteArray::ReadFrom(SnapshotReader* reader, | |
2234 intptr_t object_id, | |
2235 intptr_t tags, | |
2236 Snapshot::Kind kind) { | |
2237 UNREACHABLE(); // ByteArray is an abstract class. | |
2238 return ByteArray::null(); | |
2239 } | |
2240 | |
2241 | |
2242 template<typename HandleT, typename RawT, typename ElementT> | |
2243 RawT* ByteArray::ReadFromImpl(SnapshotReader* reader, | |
2244 intptr_t object_id, | |
2245 intptr_t tags, | |
2246 Snapshot::Kind kind) { | |
2247 ASSERT(reader != NULL); | |
2248 | |
2249 intptr_t len = reader->ReadSmiValue(); | |
2250 HandleT& result = HandleT::ZoneHandle( | |
2251 reader->isolate(), HandleT::New(len, HEAP_SPACE(kind))); | |
2252 reader->AddBackRef(object_id, &result, kIsDeserialized); | |
2253 | |
2254 // Set the object tags. | |
2255 result.set_tags(tags); | |
2256 | |
2257 // Setup the array elements. | |
2258 for (intptr_t i = 0; i < len; ++i) { | |
2259 result.SetAt(i, reader->Read<ElementT>()); | |
2260 } | |
2261 return result.raw(); | |
2262 } | |
2263 | |
2264 | |
2265 #define BYTEARRAY_TYPE_LIST(V) \ | |
2266 V(Int8, int8, int8_t) \ | |
2267 V(Uint8, uint8, uint8_t) \ | |
2268 V(Uint8Clamped, uint8, uint8_t) \ | |
2269 V(Int16, int16, int16_t) \ | |
2270 V(Uint16, uint16, uint16_t) \ | |
2271 V(Int32, int32, int32_t) \ | |
2272 V(Uint32, uint32, uint32_t) \ | |
2273 V(Int64, int64, int64_t) \ | |
2274 V(Uint64, uint64, uint64_t) \ | |
2275 V(Float32, float32, float) \ | |
2276 V(Float64, float64, double) \ | |
2277 | |
2278 | |
2279 #define BYTEARRAY_READ_FROM(name, lname, type) \ | |
2280 Raw##name##Array* name##Array::ReadFrom(SnapshotReader* reader, \ | |
2281 intptr_t object_id, \ | |
2282 intptr_t tags, \ | |
2283 Snapshot::Kind kind) { \ | |
2284 return ReadFromImpl<name##Array, Raw##name##Array, type>(reader, \ | |
2285 object_id, \ | |
2286 tags, \ | |
2287 kind); \ | |
2288 } \ | |
2289 | |
2290 | |
2291 BYTEARRAY_TYPE_LIST(BYTEARRAY_READ_FROM) | |
2292 #undef BYTEARRAY_READ_FROM | |
2293 | |
2294 | |
2295 #define EXTERNALARRAY_READ_FROM(name, lname, type) \ | |
2296 RawExternal##name##Array* External##name##Array::ReadFrom( \ | |
2297 SnapshotReader* reader, \ | |
2298 intptr_t object_id, \ | |
2299 intptr_t tags, \ | |
2300 Snapshot::Kind kind) { \ | |
2301 ASSERT(kind != Snapshot::kFull); \ | |
2302 intptr_t length = reader->ReadSmiValue(); \ | |
2303 type* data = reinterpret_cast<type*>(reader->ReadIntptrValue()); \ | |
2304 const External##name##Array& obj = External##name##Array::Handle( \ | |
2305 External##name##Array::New(data, length)); \ | |
2306 void* peer = reinterpret_cast<void*>(reader->ReadIntptrValue()); \ | |
2307 Dart_WeakPersistentHandleFinalizer callback = \ | |
2308 reinterpret_cast<Dart_WeakPersistentHandleFinalizer>( \ | |
2309 reader->ReadIntptrValue()); \ | |
2310 obj.AddFinalizer(peer, callback); \ | |
2311 return obj.raw(); \ | |
2312 } \ | |
2313 | |
2314 BYTEARRAY_TYPE_LIST(EXTERNALARRAY_READ_FROM) | |
2315 #undef EXTERNALARRAY_READ_FROM | |
2316 | |
2317 | |
2318 template<typename ElementT> | |
2319 static void ByteArrayWriteTo(SnapshotWriter* writer, | |
2320 intptr_t object_id, | |
2321 Snapshot::Kind kind, | |
2322 intptr_t byte_array_kind, | |
2323 intptr_t tags, | |
2324 RawSmi* length, | |
2325 ElementT* data) { | |
2326 ASSERT(writer != NULL); | |
2327 intptr_t len = Smi::Value(length); | |
2328 | |
2329 // Write out the serialization header value for this object. | |
2330 writer->WriteInlinedObjectHeader(object_id); | |
2331 | |
2332 // Write out the class and tags information. | |
2333 writer->WriteIndexedObject(byte_array_kind); | |
2334 writer->WriteIntptrValue(tags); | |
2335 | |
2336 // Write out the length field. | |
2337 writer->Write<RawObject*>(length); | |
2338 | |
2339 // Write out the array elements. | |
2340 for (intptr_t i = 0; i < len; i++) { | |
2341 writer->Write(data[i]); | |
2342 } | |
2343 } | |
2344 | |
2345 | |
2346 void RawByteArray::WriteTo(SnapshotWriter* writer, | |
2347 intptr_t object_id, | |
2348 Snapshot::Kind kind) { | |
2349 UNREACHABLE(); // ByteArray is an abstract class | |
2350 } | |
2351 | |
2352 | |
2353 #define BYTEARRAY_WRITE_TO(name, lname, type) \ | |
2354 void Raw##name##Array::WriteTo(SnapshotWriter* writer, \ | |
2355 intptr_t object_id, \ | |
2356 Snapshot::Kind kind) { \ | |
2357 ByteArrayWriteTo(writer, \ | |
2358 object_id, \ | |
2359 kind, \ | |
2360 k##name##ArrayCid, \ | |
2361 writer->GetObjectTags(this), \ | |
2362 ptr()->length_, \ | |
2363 ptr()->data_); \ | |
2364 } \ | |
2365 | |
2366 | |
2367 BYTEARRAY_TYPE_LIST(BYTEARRAY_WRITE_TO) | |
2368 #undef BYTEARRAY_WRITE_TO | |
2369 | |
2370 | |
2371 #define EXTERNALARRAY_WRITE_TO(name, lname, type) \ | |
2372 void RawExternal##name##Array::WriteTo(SnapshotWriter* writer, \ | |
2373 intptr_t object_id, \ | |
2374 Snapshot::Kind kind) { \ | |
2375 ByteArrayWriteTo(writer, \ | |
2376 object_id, \ | |
2377 kind, \ | |
2378 k##name##ArrayCid, \ | |
2379 writer->GetObjectTags(this), \ | |
2380 ptr()->length_, \ | |
2381 ptr()->data_); \ | |
2382 } \ | |
2383 | |
2384 | |
2385 BYTEARRAY_TYPE_LIST(EXTERNALARRAY_WRITE_TO) | |
2386 #undef BYTEARRAY_WRITE_TO | |
2387 | |
2388 #undef BYTEARRAY_TYPE_LIST | |
2389 | |
2390 | |
2391 #define TYPED_DATA_READ(setter, type) \ | 2233 #define TYPED_DATA_READ(setter, type) \ |
2392 for (intptr_t i = 0; i < lengthInBytes; i += element_size) { \ | 2234 for (intptr_t i = 0; i < lengthInBytes; i += element_size) { \ |
2393 result.Set##setter(i, reader->Read<type>()); \ | 2235 result.Set##setter(i, reader->Read<type>()); \ |
2394 } \ | 2236 } \ |
2395 | 2237 |
| 2238 |
2396 RawTypedData* TypedData::ReadFrom(SnapshotReader* reader, | 2239 RawTypedData* TypedData::ReadFrom(SnapshotReader* reader, |
2397 intptr_t object_id, | 2240 intptr_t object_id, |
2398 intptr_t tags, | 2241 intptr_t tags, |
2399 Snapshot::Kind kind) { | 2242 Snapshot::Kind kind) { |
2400 ASSERT(reader != NULL); | 2243 ASSERT(reader != NULL); |
2401 | 2244 |
2402 intptr_t cid = RawObject::ClassIdTag::decode(tags); | 2245 intptr_t cid = RawObject::ClassIdTag::decode(tags); |
2403 intptr_t len = reader->ReadSmiValue(); | 2246 intptr_t len = reader->ReadSmiValue(); |
2404 TypedData& result = TypedData::ZoneHandle( | 2247 TypedData& result = TypedData::ZoneHandle( |
2405 reader->isolate(), TypedData::New(cid, len, HEAP_SPACE(kind))); | 2248 reader->isolate(), TypedData::New(cid, len, HEAP_SPACE(kind))); |
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2766 // Write out the class and tags information. | 2609 // Write out the class and tags information. |
2767 writer->WriteIndexedObject(kWeakPropertyCid); | 2610 writer->WriteIndexedObject(kWeakPropertyCid); |
2768 writer->WriteIntptrValue(writer->GetObjectTags(this)); | 2611 writer->WriteIntptrValue(writer->GetObjectTags(this)); |
2769 | 2612 |
2770 // Write out all the other fields. | 2613 // Write out all the other fields. |
2771 writer->Write<RawObject*>(ptr()->key_); | 2614 writer->Write<RawObject*>(ptr()->key_); |
2772 writer->Write<RawObject*>(ptr()->value_); | 2615 writer->Write<RawObject*>(ptr()->value_); |
2773 } | 2616 } |
2774 | 2617 |
2775 } // namespace dart | 2618 } // namespace dart |
OLD | NEW |