| 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 2273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2284 return ReadFromImpl<name##Array, Raw##name##Array, type>(reader, \ | 2284 return ReadFromImpl<name##Array, Raw##name##Array, type>(reader, \ |
| 2285 object_id, \ | 2285 object_id, \ |
| 2286 tags, \ | 2286 tags, \ |
| 2287 kind); \ | 2287 kind); \ |
| 2288 } \ | 2288 } \ |
| 2289 | 2289 |
| 2290 | 2290 |
| 2291 BYTEARRAY_TYPE_LIST(BYTEARRAY_READ_FROM) | 2291 BYTEARRAY_TYPE_LIST(BYTEARRAY_READ_FROM) |
| 2292 #undef BYTEARRAY_READ_FROM | 2292 #undef BYTEARRAY_READ_FROM |
| 2293 | 2293 |
| 2294 RawFloat32x4Array* Float32x4Array::ReadFrom(SnapshotReader* reader, | |
| 2295 intptr_t object_id, | |
| 2296 intptr_t tags, | |
| 2297 Snapshot::Kind kind) { | |
| 2298 ASSERT(reader != NULL); | |
| 2299 | |
| 2300 intptr_t len = reader->ReadSmiValue(); | |
| 2301 Float32x4Array& result = Float32x4Array::ZoneHandle( | |
| 2302 reader->isolate(), Float32x4Array::New(len, HEAP_SPACE(kind))); | |
| 2303 reader->AddBackRef(object_id, &result, kIsDeserialized); | |
| 2304 | |
| 2305 // Set the object tags. | |
| 2306 result.set_tags(tags); | |
| 2307 | |
| 2308 // Setup the array elements. | |
| 2309 simd128_value_t v; | |
| 2310 for (intptr_t i = 0; i < len; ++i) { | |
| 2311 v.storage[0] = reader->Read<float>(); | |
| 2312 v.storage[1] = reader->Read<float>(); | |
| 2313 v.storage[2] = reader->Read<float>(); | |
| 2314 v.storage[3] = reader->Read<float>(); | |
| 2315 result.SetAt(i, v); | |
| 2316 } | |
| 2317 return result.raw(); | |
| 2318 } | |
| 2319 | |
| 2320 | 2294 |
| 2321 #define EXTERNALARRAY_READ_FROM(name, lname, type) \ | 2295 #define EXTERNALARRAY_READ_FROM(name, lname, type) \ |
| 2322 RawExternal##name##Array* External##name##Array::ReadFrom( \ | 2296 RawExternal##name##Array* External##name##Array::ReadFrom( \ |
| 2323 SnapshotReader* reader, \ | 2297 SnapshotReader* reader, \ |
| 2324 intptr_t object_id, \ | 2298 intptr_t object_id, \ |
| 2325 intptr_t tags, \ | 2299 intptr_t tags, \ |
| 2326 Snapshot::Kind kind) { \ | 2300 Snapshot::Kind kind) { \ |
| 2327 ASSERT(kind != Snapshot::kFull); \ | 2301 ASSERT(kind != Snapshot::kFull); \ |
| 2328 intptr_t length = reader->ReadSmiValue(); \ | 2302 intptr_t length = reader->ReadSmiValue(); \ |
| 2329 type* data = reinterpret_cast<type*>(reader->ReadIntptrValue()); \ | 2303 type* data = reinterpret_cast<type*>(reader->ReadIntptrValue()); \ |
| 2330 const External##name##Array& obj = External##name##Array::Handle( \ | 2304 const External##name##Array& obj = External##name##Array::Handle( \ |
| 2331 External##name##Array::New(data, length)); \ | 2305 External##name##Array::New(data, length)); \ |
| 2332 void* peer = reinterpret_cast<void*>(reader->ReadIntptrValue()); \ | 2306 void* peer = reinterpret_cast<void*>(reader->ReadIntptrValue()); \ |
| 2333 Dart_WeakPersistentHandleFinalizer callback = \ | 2307 Dart_WeakPersistentHandleFinalizer callback = \ |
| 2334 reinterpret_cast<Dart_WeakPersistentHandleFinalizer>( \ | 2308 reinterpret_cast<Dart_WeakPersistentHandleFinalizer>( \ |
| 2335 reader->ReadIntptrValue()); \ | 2309 reader->ReadIntptrValue()); \ |
| 2336 obj.AddFinalizer(peer, callback); \ | 2310 obj.AddFinalizer(peer, callback); \ |
| 2337 return obj.raw(); \ | 2311 return obj.raw(); \ |
| 2338 } \ | 2312 } \ |
| 2339 | 2313 |
| 2340 BYTEARRAY_TYPE_LIST(EXTERNALARRAY_READ_FROM) | 2314 BYTEARRAY_TYPE_LIST(EXTERNALARRAY_READ_FROM) |
| 2341 EXTERNALARRAY_READ_FROM(Float32x4, Float32x4, simd128_value_t) | |
| 2342 #undef EXTERNALARRAY_READ_FROM | 2315 #undef EXTERNALARRAY_READ_FROM |
| 2343 | 2316 |
| 2344 | 2317 |
| 2345 template<typename ElementT> | 2318 template<typename ElementT> |
| 2346 static void ByteArrayWriteTo(SnapshotWriter* writer, | 2319 static void ByteArrayWriteTo(SnapshotWriter* writer, |
| 2347 intptr_t object_id, | 2320 intptr_t object_id, |
| 2348 Snapshot::Kind kind, | 2321 Snapshot::Kind kind, |
| 2349 intptr_t byte_array_kind, | 2322 intptr_t byte_array_kind, |
| 2350 intptr_t tags, | 2323 intptr_t tags, |
| 2351 RawSmi* length, | 2324 RawSmi* length, |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2387 k##name##ArrayCid, \ | 2360 k##name##ArrayCid, \ |
| 2388 writer->GetObjectTags(this), \ | 2361 writer->GetObjectTags(this), \ |
| 2389 ptr()->length_, \ | 2362 ptr()->length_, \ |
| 2390 ptr()->data_); \ | 2363 ptr()->data_); \ |
| 2391 } \ | 2364 } \ |
| 2392 | 2365 |
| 2393 | 2366 |
| 2394 BYTEARRAY_TYPE_LIST(BYTEARRAY_WRITE_TO) | 2367 BYTEARRAY_TYPE_LIST(BYTEARRAY_WRITE_TO) |
| 2395 #undef BYTEARRAY_WRITE_TO | 2368 #undef BYTEARRAY_WRITE_TO |
| 2396 | 2369 |
| 2397 void RawFloat32x4Array::WriteTo(SnapshotWriter* writer, intptr_t object_id, | |
| 2398 Snapshot::Kind kind) { | |
| 2399 ASSERT(writer != NULL); | |
| 2400 RawSmi* length = ptr()->length_; | |
| 2401 float* data = reinterpret_cast<float*>(&ptr()->data_[0]); | |
| 2402 | |
| 2403 // Write out the serialization header value for this object. | |
| 2404 writer->WriteInlinedObjectHeader(object_id); | |
| 2405 | |
| 2406 // Write out the class and tags information. | |
| 2407 writer->WriteIndexedObject(kFloat32x4ArrayCid); | |
| 2408 writer->WriteIntptrValue(writer->GetObjectTags(this)); | |
| 2409 | |
| 2410 // Write out the length field. | |
| 2411 writer->Write<RawObject*>(length); | |
| 2412 | |
| 2413 // Write out the array elements as floats. | |
| 2414 intptr_t len = Smi::Value(length)*4; | |
| 2415 for (intptr_t i = 0; i < len; i++) { | |
| 2416 writer->Write(data[i]); | |
| 2417 } | |
| 2418 } | |
| 2419 | 2370 |
| 2420 #define EXTERNALARRAY_WRITE_TO(name, lname, type) \ | 2371 #define EXTERNALARRAY_WRITE_TO(name, lname, type) \ |
| 2421 void RawExternal##name##Array::WriteTo(SnapshotWriter* writer, \ | 2372 void RawExternal##name##Array::WriteTo(SnapshotWriter* writer, \ |
| 2422 intptr_t object_id, \ | 2373 intptr_t object_id, \ |
| 2423 Snapshot::Kind kind) { \ | 2374 Snapshot::Kind kind) { \ |
| 2424 ByteArrayWriteTo(writer, \ | 2375 ByteArrayWriteTo(writer, \ |
| 2425 object_id, \ | 2376 object_id, \ |
| 2426 kind, \ | 2377 kind, \ |
| 2427 k##name##ArrayCid, \ | 2378 k##name##ArrayCid, \ |
| 2428 writer->GetObjectTags(this), \ | 2379 writer->GetObjectTags(this), \ |
| 2429 ptr()->length_, \ | 2380 ptr()->length_, \ |
| 2430 ptr()->data_); \ | 2381 ptr()->data_); \ |
| 2431 } \ | 2382 } \ |
| 2432 | 2383 |
| 2433 | 2384 |
| 2434 BYTEARRAY_TYPE_LIST(EXTERNALARRAY_WRITE_TO) | 2385 BYTEARRAY_TYPE_LIST(EXTERNALARRAY_WRITE_TO) |
| 2435 #undef BYTEARRAY_WRITE_TO | 2386 #undef BYTEARRAY_WRITE_TO |
| 2436 void RawExternalFloat32x4Array::WriteTo(SnapshotWriter* writer, | |
| 2437 intptr_t object_id, | |
| 2438 Snapshot::Kind kind) { | |
| 2439 ASSERT(writer != NULL); | |
| 2440 RawSmi* length = ptr()->length_; | |
| 2441 float* data = reinterpret_cast<float*>(&ptr()->data_[0]); | |
| 2442 | |
| 2443 // Write out the serialization header value for this object. | |
| 2444 writer->WriteInlinedObjectHeader(object_id); | |
| 2445 | |
| 2446 // Write out the class and tags information. | |
| 2447 writer->WriteIndexedObject(kExternalFloat32x4ArrayCid); | |
| 2448 writer->WriteIntptrValue(writer->GetObjectTags(this)); | |
| 2449 | |
| 2450 // Write out the length field. | |
| 2451 writer->Write<RawObject*>(length); | |
| 2452 | |
| 2453 // Write out the array elements as floats. | |
| 2454 intptr_t len = Smi::Value(length)*4; | |
| 2455 for (intptr_t i = 0; i < len; i++) { | |
| 2456 writer->Write(data[i]); | |
| 2457 } | |
| 2458 } | |
| 2459 | 2387 |
| 2460 #undef BYTEARRAY_TYPE_LIST | 2388 #undef BYTEARRAY_TYPE_LIST |
| 2461 | 2389 |
| 2462 | 2390 |
| 2463 #define TYPED_DATA_READ(setter, type) \ | 2391 #define TYPED_DATA_READ(setter, type) \ |
| 2464 for (intptr_t i = 0; i < lengthInBytes; i += element_size) { \ | 2392 for (intptr_t i = 0; i < lengthInBytes; i += element_size) { \ |
| 2465 result.Set##setter(i, reader->Read<type>()); \ | 2393 result.Set##setter(i, reader->Read<type>()); \ |
| 2466 } \ | 2394 } \ |
| 2467 | 2395 |
| 2468 RawTypedData* TypedData::ReadFrom(SnapshotReader* reader, | 2396 RawTypedData* TypedData::ReadFrom(SnapshotReader* reader, |
| (...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2838 // Write out the class and tags information. | 2766 // Write out the class and tags information. |
| 2839 writer->WriteIndexedObject(kWeakPropertyCid); | 2767 writer->WriteIndexedObject(kWeakPropertyCid); |
| 2840 writer->WriteIntptrValue(writer->GetObjectTags(this)); | 2768 writer->WriteIntptrValue(writer->GetObjectTags(this)); |
| 2841 | 2769 |
| 2842 // Write out all the other fields. | 2770 // Write out all the other fields. |
| 2843 writer->Write<RawObject*>(ptr()->key_); | 2771 writer->Write<RawObject*>(ptr()->key_); |
| 2844 writer->Write<RawObject*>(ptr()->value_); | 2772 writer->Write<RawObject*>(ptr()->value_); |
| 2845 } | 2773 } |
| 2846 | 2774 |
| 2847 } // namespace dart | 2775 } // namespace dart |
| OLD | NEW |