| 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/native_entry.h" | 5 #include "vm/native_entry.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/stub_code.h" | 9 #include "vm/stub_code.h" |
| 10 #include "vm/symbols.h" | 10 #include "vm/symbols.h" |
| (...skipping 1331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1342 | 1342 |
| 1343 | 1343 |
| 1344 RawObjectPool* ObjectPool::ReadFrom(SnapshotReader* reader, | 1344 RawObjectPool* ObjectPool::ReadFrom(SnapshotReader* reader, |
| 1345 intptr_t object_id, | 1345 intptr_t object_id, |
| 1346 intptr_t tags, | 1346 intptr_t tags, |
| 1347 Snapshot::Kind kind, | 1347 Snapshot::Kind kind, |
| 1348 bool as_reference) { | 1348 bool as_reference) { |
| 1349 ASSERT(reader->snapshot_code()); | 1349 ASSERT(reader->snapshot_code()); |
| 1350 ASSERT(kind == Snapshot::kFull); | 1350 ASSERT(kind == Snapshot::kFull); |
| 1351 | 1351 |
| 1352 intptr_t length = reader->Read<intptr_t>(); | 1352 intptr_t len = reader->Read<intptr_t>(); |
| 1353 ObjectPool* result = NULL; |
| 1354 DeserializeState state; |
| 1355 if (!as_reference) { |
| 1356 result = reinterpret_cast<ObjectPool*>(reader->GetBackRef(object_id)); |
| 1357 state = kIsDeserialized; |
| 1358 } else { |
| 1359 state = kIsNotDeserialized; |
| 1360 } |
| 1361 if (result == NULL) { |
| 1362 result = &(ObjectPool::ZoneHandle( |
| 1363 reader->zone(), NEW_OBJECT_WITH_LEN(ObjectPool, len))); |
| 1364 reader->AddBackRef(object_id, result, state); |
| 1365 } |
| 1366 if (!as_reference) { |
| 1367 // Read all the individual elements for inlined objects. |
| 1368 const TypedData& info_array = |
| 1369 TypedData::Handle(reader->NewTypedData(kTypedDataInt8ArrayCid, len)); |
| 1370 result->set_info_array(info_array); |
| 1353 | 1371 |
| 1354 ObjectPool* result = | 1372 NoSafepointScope no_safepoint; |
| 1355 reinterpret_cast<ObjectPool*>(reader->GetBackRef(object_id)); | 1373 for (intptr_t i = 0; i < len; i++) { |
| 1356 if (result == NULL) { | 1374 ObjectPool::EntryType entry_type = |
| 1357 result = | 1375 static_cast<ObjectPool::EntryType>(reader->Read<int8_t>()); |
| 1358 &(ObjectPool::ZoneHandle(reader->zone(), | 1376 *reinterpret_cast<int8_t*>(info_array.DataAddr(i)) = entry_type; |
| 1359 NEW_OBJECT_WITH_LEN(ObjectPool, length))); | 1377 switch (entry_type) { |
| 1360 reader->AddBackRef(object_id, result, kIsDeserialized); | 1378 case ObjectPool::kTaggedObject: { |
| 1361 } | 1379 (*reader->PassiveObjectHandle()) = |
| 1362 | 1380 reader->ReadObjectImpl(kAsReference); |
| 1363 const TypedData& info_array = | 1381 result->SetObjectAt(i, *(reader->PassiveObjectHandle())); |
| 1364 TypedData::Handle(reader->NewTypedData(kTypedDataInt8ArrayCid, length)); | 1382 break; |
| 1365 result->set_info_array(info_array); | 1383 } |
| 1366 | 1384 case ObjectPool::kImmediate: { |
| 1367 NoSafepointScope no_safepoint; | 1385 intptr_t raw_value = reader->Read<intptr_t>(); |
| 1368 for (intptr_t i = 0; i < length; i++) { | 1386 result->SetRawValueAt(i, raw_value); |
| 1369 ObjectPool::EntryType entry_type = | 1387 break; |
| 1370 static_cast<ObjectPool::EntryType>(reader->Read<int8_t>()); | 1388 } |
| 1371 *reinterpret_cast<int8_t*>(info_array.DataAddr(i)) = entry_type; | 1389 case ObjectPool::kNativeEntry: { |
| 1372 switch (entry_type) { | 1390 // Read nothing. Initialize with the lazy link entry. |
| 1373 case ObjectPool::kTaggedObject: { | 1391 uword new_entry = NativeEntry::LinkNativeCallEntry(); |
| 1374 (*reader->PassiveObjectHandle()) = | 1392 result->SetRawValueAt(i, static_cast<intptr_t>(new_entry)); |
| 1375 reader->ReadObjectImpl(kAsReference); | 1393 break; |
| 1376 result->SetObjectAt(i, *(reader->PassiveObjectHandle())); | 1394 } |
| 1377 break; | 1395 default: |
| 1396 UNREACHABLE(); |
| 1378 } | 1397 } |
| 1379 case ObjectPool::kImmediate: { | |
| 1380 intptr_t raw_value = reader->Read<intptr_t>(); | |
| 1381 result->SetRawValueAt(i, raw_value); | |
| 1382 break; | |
| 1383 } | |
| 1384 case ObjectPool::kNativeEntry: { | |
| 1385 // Read nothing. Initialize with the lazy link entry. | |
| 1386 uword new_entry = NativeEntry::LinkNativeCallEntry(); | |
| 1387 result->SetRawValueAt(i, static_cast<intptr_t>(new_entry)); | |
| 1388 break; | |
| 1389 } | |
| 1390 default: | |
| 1391 UNREACHABLE(); | |
| 1392 } | 1398 } |
| 1393 } | 1399 } |
| 1394 | |
| 1395 return result->raw(); | 1400 return result->raw(); |
| 1396 } | 1401 } |
| 1397 | 1402 |
| 1398 | 1403 |
| 1399 void RawObjectPool::WriteTo(SnapshotWriter* writer, | 1404 void RawObjectPool::WriteTo(SnapshotWriter* writer, |
| 1400 intptr_t object_id, | 1405 intptr_t object_id, |
| 1401 Snapshot::Kind kind, | 1406 Snapshot::Kind kind, |
| 1402 bool as_reference) { | 1407 bool as_reference) { |
| 1403 ASSERT(writer->snapshot_code()); | 1408 ASSERT(writer->snapshot_code()); |
| 1404 ASSERT(kind == Snapshot::kFull); | 1409 ASSERT(kind == Snapshot::kFull); |
| (...skipping 1151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2556 | 2561 |
| 2557 RawArray* Array::ReadFrom(SnapshotReader* reader, | 2562 RawArray* Array::ReadFrom(SnapshotReader* reader, |
| 2558 intptr_t object_id, | 2563 intptr_t object_id, |
| 2559 intptr_t tags, | 2564 intptr_t tags, |
| 2560 Snapshot::Kind kind, | 2565 Snapshot::Kind kind, |
| 2561 bool as_reference) { | 2566 bool as_reference) { |
| 2562 ASSERT(reader != NULL); | 2567 ASSERT(reader != NULL); |
| 2563 | 2568 |
| 2564 // Read the length so that we can determine instance size to allocate. | 2569 // Read the length so that we can determine instance size to allocate. |
| 2565 intptr_t len = reader->ReadSmiValue(); | 2570 intptr_t len = reader->ReadSmiValue(); |
| 2566 Array* array = reinterpret_cast<Array*>( | 2571 Array* array = NULL; |
| 2567 reader->GetBackRef(object_id)); | 2572 DeserializeState state; |
| 2573 if (!as_reference) { |
| 2574 array = reinterpret_cast<Array*>(reader->GetBackRef(object_id)); |
| 2575 state = kIsDeserialized; |
| 2576 } else { |
| 2577 state = kIsNotDeserialized; |
| 2578 } |
| 2568 if (array == NULL) { | 2579 if (array == NULL) { |
| 2569 array = &(Array::ZoneHandle(reader->zone(), | 2580 array = &(Array::ZoneHandle(reader->zone(), |
| 2570 NEW_OBJECT_WITH_LEN_SPACE(Array, len, kind))); | 2581 NEW_OBJECT_WITH_LEN_SPACE(Array, len, kind))); |
| 2571 reader->AddBackRef(object_id, array, kIsDeserialized); | 2582 reader->AddBackRef(object_id, array, state); |
| 2572 } | 2583 } |
| 2573 ASSERT(!RawObject::IsCanonical(tags)); | 2584 if (!as_reference) { |
| 2574 reader->ArrayReadFrom(object_id, *array, len, tags); | 2585 // Read all the individual elements for inlined objects. |
| 2586 ASSERT(!RawObject::IsCanonical(tags)); |
| 2587 reader->ArrayReadFrom(object_id, *array, len, tags); |
| 2588 } |
| 2575 return array->raw(); | 2589 return array->raw(); |
| 2576 } | 2590 } |
| 2577 | 2591 |
| 2578 | 2592 |
| 2579 RawImmutableArray* ImmutableArray::ReadFrom(SnapshotReader* reader, | 2593 RawImmutableArray* ImmutableArray::ReadFrom(SnapshotReader* reader, |
| 2580 intptr_t object_id, | 2594 intptr_t object_id, |
| 2581 intptr_t tags, | 2595 intptr_t tags, |
| 2582 Snapshot::Kind kind, | 2596 Snapshot::Kind kind, |
| 2583 bool as_reference) { | 2597 bool as_reference) { |
| 2584 ASSERT(reader != NULL); | 2598 ASSERT(reader != NULL); |
| 2585 | 2599 |
| 2586 // Read the length so that we can determine instance size to allocate. | 2600 // Read the length so that we can determine instance size to allocate. |
| 2587 intptr_t len = reader->ReadSmiValue(); | 2601 intptr_t len = reader->ReadSmiValue(); |
| 2588 Array* array = reinterpret_cast<Array*>(reader->GetBackRef(object_id)); | 2602 Array* array = NULL; |
| 2603 DeserializeState state; |
| 2604 if (!as_reference) { |
| 2605 array = reinterpret_cast<Array*>(reader->GetBackRef(object_id)); |
| 2606 state = kIsDeserialized; |
| 2607 } else { |
| 2608 state = kIsNotDeserialized; |
| 2609 } |
| 2589 if (array == NULL) { | 2610 if (array == NULL) { |
| 2590 array = &(Array::ZoneHandle( | 2611 array = &(Array::ZoneHandle( |
| 2591 reader->zone(), | 2612 reader->zone(), |
| 2592 NEW_OBJECT_WITH_LEN_SPACE(ImmutableArray, len, kind))); | 2613 NEW_OBJECT_WITH_LEN_SPACE(ImmutableArray, len, kind))); |
| 2593 reader->AddBackRef(object_id, array, kIsDeserialized); | 2614 reader->AddBackRef(object_id, array, state); |
| 2594 } | 2615 } |
| 2595 reader->ArrayReadFrom(object_id, *array, len, tags); | 2616 if (!as_reference) { |
| 2596 if (RawObject::IsCanonical(tags)) { | 2617 // Read all the individual elements for inlined objects. |
| 2597 if (kind == Snapshot::kFull) { | 2618 reader->ArrayReadFrom(object_id, *array, len, tags); |
| 2598 array->SetCanonical(); | 2619 if (RawObject::IsCanonical(tags)) { |
| 2599 } else { | 2620 if (kind == Snapshot::kFull) { |
| 2600 *array ^= array->CheckAndCanonicalize(NULL); | 2621 array->SetCanonical(); |
| 2622 } else { |
| 2623 *array ^= array->CheckAndCanonicalize(NULL); |
| 2624 } |
| 2601 } | 2625 } |
| 2602 } | 2626 } |
| 2603 return raw(*array); | 2627 return raw(*array); |
| 2604 } | 2628 } |
| 2605 | 2629 |
| 2606 | 2630 |
| 2607 void RawArray::WriteTo(SnapshotWriter* writer, | 2631 void RawArray::WriteTo(SnapshotWriter* writer, |
| 2608 intptr_t object_id, | 2632 intptr_t object_id, |
| 2609 Snapshot::Kind kind, | 2633 Snapshot::Kind kind, |
| 2610 bool as_reference) { | 2634 bool as_reference) { |
| (...skipping 832 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3443 // We do not allow objects with native fields in an isolate message. | 3467 // We do not allow objects with native fields in an isolate message. |
| 3444 writer->SetWriteException(Exceptions::kArgument, | 3468 writer->SetWriteException(Exceptions::kArgument, |
| 3445 "Illegal argument in isolate message" | 3469 "Illegal argument in isolate message" |
| 3446 " : (object is a UserTag)"); | 3470 " : (object is a UserTag)"); |
| 3447 } else { | 3471 } else { |
| 3448 UNREACHABLE(); | 3472 UNREACHABLE(); |
| 3449 } | 3473 } |
| 3450 } | 3474 } |
| 3451 | 3475 |
| 3452 } // namespace dart | 3476 } // namespace dart |
| OLD | NEW |