| 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 2381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2392 // Write out the array elements as floats. | 2392 // Write out the array elements as floats. |
| 2393 intptr_t len = Smi::Value(length)*4; | 2393 intptr_t len = Smi::Value(length)*4; |
| 2394 for (intptr_t i = 0; i < len; i++) { | 2394 for (intptr_t i = 0; i < len; i++) { |
| 2395 writer->Write(data[i]); | 2395 writer->Write(data[i]); |
| 2396 } | 2396 } |
| 2397 } | 2397 } |
| 2398 | 2398 |
| 2399 #undef BYTEARRAY_TYPE_LIST | 2399 #undef BYTEARRAY_TYPE_LIST |
| 2400 | 2400 |
| 2401 | 2401 |
| 2402 #define TYPED_DATA_READ(setter, type) \ |
| 2403 for (intptr_t i = 0; i < lengthInBytes; i += element_size) { \ |
| 2404 result.Set##setter(i, reader->Read<type>()); \ |
| 2405 } \ |
| 2406 |
| 2407 RawTypedData* TypedData::ReadFrom(SnapshotReader* reader, |
| 2408 intptr_t object_id, |
| 2409 intptr_t tags, |
| 2410 Snapshot::Kind kind) { |
| 2411 ASSERT(reader != NULL); |
| 2412 |
| 2413 intptr_t cid = RawObject::ClassIdTag::decode(tags); |
| 2414 intptr_t len = reader->ReadSmiValue(); |
| 2415 TypedData& result = TypedData::ZoneHandle( |
| 2416 reader->isolate(), TypedData::New(cid, len, HEAP_SPACE(kind))); |
| 2417 reader->AddBackRef(object_id, &result, kIsDeserialized); |
| 2418 |
| 2419 // Set the object tags. |
| 2420 result.set_tags(tags); |
| 2421 |
| 2422 // Setup the array elements. |
| 2423 intptr_t element_size = ElementSizeInBytes(cid); |
| 2424 intptr_t lengthInBytes = len * element_size; |
| 2425 switch (cid) { |
| 2426 case kTypedDataInt8ArrayCid: |
| 2427 TYPED_DATA_READ(Int8, int8_t); |
| 2428 break; |
| 2429 case kTypedDataUint8ArrayCid: |
| 2430 TYPED_DATA_READ(Uint8, uint8_t); |
| 2431 break; |
| 2432 case kTypedDataUint8ClampedArrayCid: |
| 2433 TYPED_DATA_READ(Uint8, uint8_t); |
| 2434 break; |
| 2435 case kTypedDataInt16ArrayCid: |
| 2436 TYPED_DATA_READ(Int16, int16_t); |
| 2437 break; |
| 2438 case kTypedDataUint16ArrayCid: |
| 2439 TYPED_DATA_READ(Uint16, uint16_t); |
| 2440 break; |
| 2441 case kTypedDataInt32ArrayCid: |
| 2442 TYPED_DATA_READ(Int32, int32_t); |
| 2443 break; |
| 2444 case kTypedDataUint32ArrayCid: |
| 2445 TYPED_DATA_READ(Uint32, uint32_t); |
| 2446 break; |
| 2447 case kTypedDataInt64ArrayCid: |
| 2448 TYPED_DATA_READ(Int64, int64_t); |
| 2449 break; |
| 2450 case kTypedDataUint64ArrayCid: |
| 2451 TYPED_DATA_READ(Uint64, uint64_t); |
| 2452 break; |
| 2453 case kTypedDataFloat32ArrayCid: |
| 2454 TYPED_DATA_READ(Float32, float); |
| 2455 break; |
| 2456 case kTypedDataFloat64ArrayCid: |
| 2457 TYPED_DATA_READ(Float64, double); |
| 2458 break; |
| 2459 default: |
| 2460 UNREACHABLE(); |
| 2461 } |
| 2462 return result.raw(); |
| 2463 } |
| 2464 #undef TYPED_DATA_READ |
| 2465 |
| 2466 |
| 2467 RawExternalTypedData* ExternalTypedData::ReadFrom(SnapshotReader* reader, |
| 2468 intptr_t object_id, |
| 2469 intptr_t tags, |
| 2470 Snapshot::Kind kind) { |
| 2471 UNIMPLEMENTED(); |
| 2472 return ExternalTypedData::null(); |
| 2473 } |
| 2474 |
| 2475 |
| 2476 #define TYPED_DATA_WRITE(type) \ |
| 2477 { \ |
| 2478 type* data = reinterpret_cast<type*>(ptr()->data_); \ |
| 2479 for (intptr_t i = 0; i < len; i++) { \ |
| 2480 writer->Write(data[i]); \ |
| 2481 } \ |
| 2482 } \ |
| 2483 |
| 2484 |
| 2485 void RawTypedData::WriteTo(SnapshotWriter* writer, |
| 2486 intptr_t object_id, |
| 2487 Snapshot::Kind kind) { |
| 2488 ASSERT(writer != NULL); |
| 2489 intptr_t tags = writer->GetObjectTags(this); |
| 2490 intptr_t cid = ClassIdTag::decode(tags); |
| 2491 intptr_t len = Smi::Value(ptr()->length_); |
| 2492 |
| 2493 // Write out the serialization header value for this object. |
| 2494 writer->WriteInlinedObjectHeader(object_id); |
| 2495 |
| 2496 // Write out the class and tags information. |
| 2497 writer->WriteIndexedObject(cid); |
| 2498 writer->WriteIntptrValue(tags); |
| 2499 |
| 2500 // Write out the length field. |
| 2501 writer->Write<RawObject*>(ptr()->length_); |
| 2502 |
| 2503 // Write out the array elements. |
| 2504 switch (cid) { |
| 2505 case kTypedDataInt8ArrayCid: |
| 2506 TYPED_DATA_WRITE(int8_t); |
| 2507 break; |
| 2508 case kTypedDataUint8ArrayCid: |
| 2509 TYPED_DATA_WRITE(uint8_t); |
| 2510 break; |
| 2511 case kTypedDataUint8ClampedArrayCid: |
| 2512 TYPED_DATA_WRITE(uint8_t); |
| 2513 break; |
| 2514 case kTypedDataInt16ArrayCid: |
| 2515 TYPED_DATA_WRITE(int16_t); |
| 2516 break; |
| 2517 case kTypedDataUint16ArrayCid: |
| 2518 TYPED_DATA_WRITE(uint16_t); |
| 2519 break; |
| 2520 case kTypedDataInt32ArrayCid: |
| 2521 TYPED_DATA_WRITE(int32_t); |
| 2522 break; |
| 2523 case kTypedDataUint32ArrayCid: |
| 2524 TYPED_DATA_WRITE(uint32_t); |
| 2525 break; |
| 2526 case kTypedDataInt64ArrayCid: |
| 2527 TYPED_DATA_WRITE(int64_t); |
| 2528 break; |
| 2529 case kTypedDataUint64ArrayCid: |
| 2530 TYPED_DATA_WRITE(uint64_t); |
| 2531 break; |
| 2532 case kTypedDataFloat32ArrayCid: |
| 2533 TYPED_DATA_WRITE(float); // NOLINT. |
| 2534 break; |
| 2535 case kTypedDataFloat64ArrayCid: |
| 2536 TYPED_DATA_WRITE(double); // NOLINT. |
| 2537 break; |
| 2538 default: |
| 2539 UNREACHABLE(); |
| 2540 } |
| 2541 } |
| 2542 |
| 2543 |
| 2544 void RawExternalTypedData::WriteTo(SnapshotWriter* writer, |
| 2545 intptr_t object_id, |
| 2546 Snapshot::Kind kind) { |
| 2547 ASSERT(writer != NULL); |
| 2548 intptr_t tags = writer->GetObjectTags(this); |
| 2549 intptr_t cid = ClassIdTag::decode(tags); |
| 2550 intptr_t len = Smi::Value(ptr()->length_); |
| 2551 |
| 2552 // Write out the serialization header value for this object. |
| 2553 writer->WriteInlinedObjectHeader(object_id); |
| 2554 |
| 2555 // Write out the class and tags information. |
| 2556 writer->WriteIndexedObject(cid); |
| 2557 writer->WriteIntptrValue(tags); |
| 2558 |
| 2559 // Write out the length field. |
| 2560 writer->Write<RawObject*>(ptr()->length_); |
| 2561 |
| 2562 switch (cid) { |
| 2563 case kExternalTypedDataInt8ArrayCid: |
| 2564 TYPED_DATA_WRITE(int8_t); |
| 2565 break; |
| 2566 case kExternalTypedDataUint8ArrayCid: |
| 2567 TYPED_DATA_WRITE(uint8_t); |
| 2568 break; |
| 2569 case kExternalTypedDataUint8ClampedArrayCid: |
| 2570 TYPED_DATA_WRITE(uint8_t); |
| 2571 break; |
| 2572 case kExternalTypedDataInt16ArrayCid: |
| 2573 TYPED_DATA_WRITE(int16_t); |
| 2574 break; |
| 2575 case kExternalTypedDataUint16ArrayCid: |
| 2576 TYPED_DATA_WRITE(uint16_t); |
| 2577 break; |
| 2578 case kExternalTypedDataInt32ArrayCid: |
| 2579 TYPED_DATA_WRITE(int32_t); |
| 2580 break; |
| 2581 case kExternalTypedDataUint32ArrayCid: |
| 2582 TYPED_DATA_WRITE(uint32_t); |
| 2583 break; |
| 2584 case kExternalTypedDataInt64ArrayCid: |
| 2585 TYPED_DATA_WRITE(int64_t); |
| 2586 break; |
| 2587 case kExternalTypedDataUint64ArrayCid: |
| 2588 TYPED_DATA_WRITE(uint64_t); |
| 2589 break; |
| 2590 case kExternalTypedDataFloat32ArrayCid: |
| 2591 TYPED_DATA_WRITE(float); // NOLINT. |
| 2592 break; |
| 2593 case kExternalTypedDataFloat64ArrayCid: |
| 2594 TYPED_DATA_WRITE(double); // NOLINT. |
| 2595 break; |
| 2596 default: |
| 2597 UNREACHABLE(); |
| 2598 } |
| 2599 } |
| 2600 #undef TYPED_DATA_WRITE |
| 2601 |
| 2602 |
| 2402 RawDartFunction* DartFunction::ReadFrom(SnapshotReader* reader, | 2603 RawDartFunction* DartFunction::ReadFrom(SnapshotReader* reader, |
| 2403 intptr_t object_id, | 2604 intptr_t object_id, |
| 2404 intptr_t tags, | 2605 intptr_t tags, |
| 2405 Snapshot::Kind kind) { | 2606 Snapshot::Kind kind) { |
| 2406 UNREACHABLE(); // DartFunction is an abstract class. | 2607 UNREACHABLE(); // DartFunction is an abstract class. |
| 2407 return DartFunction::null(); | 2608 return DartFunction::null(); |
| 2408 } | 2609 } |
| 2409 | 2610 |
| 2410 | 2611 |
| 2411 void RawDartFunction::WriteTo(SnapshotWriter* writer, | 2612 void RawDartFunction::WriteTo(SnapshotWriter* writer, |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2565 // Write out the class and tags information. | 2766 // Write out the class and tags information. |
| 2566 writer->WriteIndexedObject(kWeakPropertyCid); | 2767 writer->WriteIndexedObject(kWeakPropertyCid); |
| 2567 writer->WriteIntptrValue(writer->GetObjectTags(this)); | 2768 writer->WriteIntptrValue(writer->GetObjectTags(this)); |
| 2568 | 2769 |
| 2569 // Write out all the other fields. | 2770 // Write out all the other fields. |
| 2570 writer->Write<RawObject*>(ptr()->key_); | 2771 writer->Write<RawObject*>(ptr()->key_); |
| 2571 writer->Write<RawObject*>(ptr()->value_); | 2772 writer->Write<RawObject*>(ptr()->value_); |
| 2572 } | 2773 } |
| 2573 | 2774 |
| 2574 } // namespace dart | 2775 } // namespace dart |
| OLD | NEW |