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/snapshot.h" | 5 #include "vm/snapshot.h" |
6 | 6 |
7 #include "platform/assert.h" | 7 #include "platform/assert.h" |
8 #include "vm/bigint_operations.h" | |
9 #include "vm/bootstrap.h" | 8 #include "vm/bootstrap.h" |
10 #include "vm/class_finalizer.h" | 9 #include "vm/class_finalizer.h" |
11 #include "vm/exceptions.h" | 10 #include "vm/exceptions.h" |
12 #include "vm/heap.h" | 11 #include "vm/heap.h" |
13 #include "vm/lockers.h" | 12 #include "vm/lockers.h" |
14 #include "vm/longjump.h" | 13 #include "vm/longjump.h" |
15 #include "vm/object.h" | 14 #include "vm/object.h" |
16 #include "vm/object_store.h" | 15 #include "vm/object_store.h" |
17 #include "vm/snapshot_ids.h" | 16 #include "vm/snapshot_ids.h" |
18 #include "vm/symbols.h" | 17 #include "vm/symbols.h" |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 | 148 |
150 | 149 |
151 RawSmi* BaseReader::ReadAsSmi() { | 150 RawSmi* BaseReader::ReadAsSmi() { |
152 intptr_t value = ReadIntptrValue(); | 151 intptr_t value = ReadIntptrValue(); |
153 ASSERT((value & kSmiTagMask) == kSmiTag); | 152 ASSERT((value & kSmiTagMask) == kSmiTag); |
154 return reinterpret_cast<RawSmi*>(value); | 153 return reinterpret_cast<RawSmi*>(value); |
155 } | 154 } |
156 | 155 |
157 | 156 |
158 intptr_t BaseReader::ReadSmiValue() { | 157 intptr_t BaseReader::ReadSmiValue() { |
159 return Smi::Value(ReadAsSmi()); | 158 return Smi::Value(ReadAsSmi()); |
160 } | 159 } |
161 | 160 |
162 | 161 |
163 SnapshotReader::SnapshotReader(const uint8_t* buffer, | 162 SnapshotReader::SnapshotReader(const uint8_t* buffer, |
164 intptr_t size, | 163 intptr_t size, |
165 Snapshot::Kind kind, | 164 Snapshot::Kind kind, |
166 Isolate* isolate) | 165 Isolate* isolate) |
167 : BaseReader(buffer, size), | 166 : BaseReader(buffer, size), |
168 kind_(kind), | 167 kind_(kind), |
169 isolate_(isolate), | 168 isolate_(isolate), |
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
610 RawMint* SnapshotReader::NewMint(int64_t value) { | 609 RawMint* SnapshotReader::NewMint(int64_t value) { |
611 ASSERT(kind_ == Snapshot::kFull); | 610 ASSERT(kind_ == Snapshot::kFull); |
612 ASSERT(isolate()->no_gc_scope_depth() != 0); | 611 ASSERT(isolate()->no_gc_scope_depth() != 0); |
613 RawMint* obj = reinterpret_cast<RawMint*>( | 612 RawMint* obj = reinterpret_cast<RawMint*>( |
614 AllocateUninitialized(kMintCid, Mint::InstanceSize())); | 613 AllocateUninitialized(kMintCid, Mint::InstanceSize())); |
615 obj->ptr()->value_ = value; | 614 obj->ptr()->value_ = value; |
616 return obj; | 615 return obj; |
617 } | 616 } |
618 | 617 |
619 | 618 |
620 RawBigint* SnapshotReader::NewBigint(const char* hex_string) { | |
621 ASSERT(kind_ == Snapshot::kFull); | |
622 ASSERT(isolate()->no_gc_scope_depth() != 0); | |
623 intptr_t bigint_length = BigintOperations::ComputeChunkLength(hex_string); | |
624 RawBigint* obj = reinterpret_cast<RawBigint*>( | |
625 AllocateUninitialized(kBigintCid, Bigint::InstanceSize(bigint_length))); | |
626 obj->ptr()->allocated_length_ = bigint_length; | |
627 obj->ptr()->signed_length_ = bigint_length; | |
628 BigintOperations::FromHexCString(hex_string, Bigint::Handle(obj)); | |
629 return obj; | |
630 } | |
631 | |
632 | |
633 RawDouble* SnapshotReader::NewDouble(double value) { | 619 RawDouble* SnapshotReader::NewDouble(double value) { |
634 ASSERT(kind_ == Snapshot::kFull); | 620 ASSERT(kind_ == Snapshot::kFull); |
635 ASSERT(isolate()->no_gc_scope_depth() != 0); | 621 ASSERT(isolate()->no_gc_scope_depth() != 0); |
636 RawDouble* obj = reinterpret_cast<RawDouble*>( | 622 RawDouble* obj = reinterpret_cast<RawDouble*>( |
637 AllocateUninitialized(kDoubleCid, Double::InstanceSize())); | 623 AllocateUninitialized(kDoubleCid, Double::InstanceSize())); |
638 obj->ptr()->value_ = value; | 624 obj->ptr()->value_ = value; |
639 return obj; | 625 return obj; |
640 } | 626 } |
641 | 627 |
642 | 628 |
643 RawTypedData* SnapshotReader::NewTypedData(intptr_t class_id, intptr_t len) { | 629 RawTypedData* SnapshotReader::NewTypedData(intptr_t class_id, intptr_t len) { |
644 ASSERT(kind_ == Snapshot::kFull); | 630 ASSERT(kind_ == Snapshot::kFull); |
645 ASSERT(isolate()->no_gc_scope_depth() != 0); | 631 ASSERT(isolate()->no_gc_scope_depth() != 0); |
646 const intptr_t lengthInBytes = len * TypedData::ElementSizeInBytes(class_id); | 632 const intptr_t lengthInBytes = len * TypedData::ElementSizeInBytes(class_id); |
647 RawTypedData* obj = reinterpret_cast<RawTypedData*>( | 633 RawTypedData* obj = reinterpret_cast<RawTypedData*>( |
648 AllocateUninitialized(class_id, TypedData::InstanceSize(lengthInBytes))); | 634 AllocateUninitialized(class_id, TypedData::InstanceSize(lengthInBytes))); |
649 obj->ptr()->length_ = Smi::New(len); | 635 obj->ptr()->length_ = Smi::New(len); |
650 return obj; | 636 return obj; |
651 } | 637 } |
652 | 638 |
653 | 639 |
654 #define ALLOC_NEW_OBJECT(type) \ | 640 #define ALLOC_NEW_OBJECT(type) \ |
655 ASSERT(kind_ == Snapshot::kFull); \ | 641 ASSERT(kind_ == Snapshot::kFull); \ |
656 ASSERT(isolate()->no_gc_scope_depth() != 0); \ | 642 ASSERT(isolate()->no_gc_scope_depth() != 0); \ |
657 return reinterpret_cast<Raw##type*>( \ | 643 return reinterpret_cast<Raw##type*>( \ |
658 AllocateUninitialized(k##type##Cid, type::InstanceSize())); \ | 644 AllocateUninitialized(k##type##Cid, type::InstanceSize())); \ |
659 | 645 |
660 | 646 |
| 647 RawBigint* SnapshotReader::NewBigint() { |
| 648 ALLOC_NEW_OBJECT(Bigint); |
| 649 } |
| 650 |
| 651 |
661 RawUnresolvedClass* SnapshotReader::NewUnresolvedClass() { | 652 RawUnresolvedClass* SnapshotReader::NewUnresolvedClass() { |
662 ALLOC_NEW_OBJECT(UnresolvedClass); | 653 ALLOC_NEW_OBJECT(UnresolvedClass); |
663 } | 654 } |
664 | 655 |
665 | 656 |
666 RawType* SnapshotReader::NewType() { | 657 RawType* SnapshotReader::NewType() { |
667 ALLOC_NEW_OBJECT(Type); | 658 ALLOC_NEW_OBJECT(Type); |
668 } | 659 } |
669 | 660 |
670 | 661 |
(...skipping 1103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1774 NoGCScope no_gc; | 1765 NoGCScope no_gc; |
1775 WriteObject(obj.raw()); | 1766 WriteObject(obj.raw()); |
1776 UnmarkAll(); | 1767 UnmarkAll(); |
1777 } else { | 1768 } else { |
1778 ThrowException(exception_type(), exception_msg()); | 1769 ThrowException(exception_type(), exception_msg()); |
1779 } | 1770 } |
1780 } | 1771 } |
1781 | 1772 |
1782 | 1773 |
1783 } // namespace dart | 1774 } // namespace dart |
OLD | NEW |