OLD | NEW |
1 // Copyright (c) 2014, the Dartino project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dartino 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.md file. | 3 // BSD-style license that can be found in the LICENSE.md file. |
4 | 4 |
5 #include "src/vm/snapshot.h" | 5 #include "src/vm/snapshot.h" |
6 | 6 |
7 #include <stdio.h> | 7 #include <stdio.h> |
8 #include <stdlib.h> | 8 #include <stdlib.h> |
9 #include <stdarg.h> | 9 #include <stdarg.h> |
10 #include <string.h> | 10 #include <string.h> |
11 | 11 |
12 #include "src/shared/assert.h" | 12 #include "src/shared/assert.h" |
13 #include "src/shared/bytecodes.h" | 13 #include "src/shared/bytecodes.h" |
14 #include "src/shared/utils.h" | 14 #include "src/shared/utils.h" |
15 #include "src/shared/version.h" | 15 #include "src/shared/version.h" |
16 | 16 |
17 #include "src/vm/object.h" | 17 #include "src/vm/object.h" |
18 #include "src/vm/program.h" | 18 #include "src/vm/program.h" |
19 | 19 |
20 namespace fletch { | 20 namespace dartino { |
21 | 21 |
22 static const int kSupportedSizeOfDouble = 8; | 22 static const int kSupportedSizeOfDouble = 8; |
23 static const int kReferenceTableSizeBytes = 4; | 23 static const int kReferenceTableSizeBytes = 4; |
24 static const int kHeapSizeBytes = 4; | 24 static const int kHeapSizeBytes = 4; |
25 | 25 |
26 class Header { | 26 class Header { |
27 public: | 27 public: |
28 explicit Header(int64 value) : value_(value) {} | 28 explicit Header(int64 value) : value_(value) {} |
29 | 29 |
30 static Header FromSmi(Smi* value) { | 30 static Header FromSmi(Smi* value) { |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 // Read the required backward reference table size. | 306 // Read the required backward reference table size. |
307 int references = 0; | 307 int references = 0; |
308 for (int i = 0; i < kReferenceTableSizeBytes; i++) { | 308 for (int i = 0; i < kReferenceTableSizeBytes; i++) { |
309 references = (references << 8) | ReadByte(); | 309 references = (references << 8) | ReadByte(); |
310 } | 310 } |
311 | 311 |
312 Program* program = new Program(Program::kLoadedFromSnapshot, hashtag); | 312 Program* program = new Program(Program::kLoadedFromSnapshot, hashtag); |
313 | 313 |
314 // Read the heap size and allocate an area for it. | 314 // Read the heap size and allocate an area for it. |
315 int size_position; | 315 int size_position; |
316 if (kPointerSize == 8 && sizeof(fletch_double) == 8) { | 316 if (kPointerSize == 8 && sizeof(dartino_double) == 8) { |
317 size_position = position_ + 0 * kHeapSizeBytes; | 317 size_position = position_ + 0 * kHeapSizeBytes; |
318 } else if (kPointerSize == 8 && sizeof(fletch_double) == 4) { | 318 } else if (kPointerSize == 8 && sizeof(dartino_double) == 4) { |
319 size_position = position_ + 1 * kHeapSizeBytes; | 319 size_position = position_ + 1 * kHeapSizeBytes; |
320 } else if (kPointerSize == 4 && sizeof(fletch_double) == 8) { | 320 } else if (kPointerSize == 4 && sizeof(dartino_double) == 8) { |
321 size_position = position_ + 2 * kHeapSizeBytes; | 321 size_position = position_ + 2 * kHeapSizeBytes; |
322 } else { | 322 } else { |
323 ASSERT(kPointerSize == 4 && sizeof(fletch_double) == 4); | 323 ASSERT(kPointerSize == 4 && sizeof(dartino_double) == 4); |
324 size_position = position_ + 3 * kHeapSizeBytes; | 324 size_position = position_ + 3 * kHeapSizeBytes; |
325 } | 325 } |
326 position_ += 4 * kHeapSizeBytes; | 326 position_ += 4 * kHeapSizeBytes; |
327 int heap_size = ReadHeapSizeFrom(size_position); | 327 int heap_size = ReadHeapSizeFrom(size_position); |
328 // Make sure to make room for the filler at the end of the program space. | 328 // Make sure to make room for the filler at the end of the program space. |
329 memory_ = | 329 memory_ = |
330 ObjectMemory::AllocateChunk(program->heap()->space(), heap_size + 1); | 330 ObjectMemory::AllocateChunk(program->heap()->space(), heap_size + 1); |
331 top_ = memory_->base(); | 331 top_ = memory_->base(); |
332 | 332 |
333 // Allocate space for the backward references. | 333 // Allocate space for the backward references. |
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
736 } | 736 } |
737 } | 737 } |
738 | 738 |
739 void Class::ClassReadFrom(SnapshotReader* reader) { | 739 void Class::ClassReadFrom(SnapshotReader* reader) { |
740 int size = AllocationSize(); | 740 int size = AllocationSize(); |
741 for (int offset = HeapObject::kSize; offset < size; offset += kPointerSize) { | 741 for (int offset = HeapObject::kSize; offset < size; offset += kPointerSize) { |
742 at_put(offset, reader->ReadObject()); | 742 at_put(offset, reader->ReadObject()); |
743 } | 743 } |
744 } | 744 } |
745 | 745 |
746 #ifdef FLETCH_TARGET_X64 | 746 #ifdef DARTINO_TARGET_X64 |
747 void Function::WriteByteCodes(SnapshotWriter* writer) { | 747 void Function::WriteByteCodes(SnapshotWriter* writer) { |
748 ASSERT(kPointerSize == 8); | 748 ASSERT(kPointerSize == 8); |
749 uint8* bcp = bytecode_address_for(0); | 749 uint8* bcp = bytecode_address_for(0); |
750 int i = 0; | 750 int i = 0; |
751 while (i < bytecode_size()) { | 751 while (i < bytecode_size()) { |
752 Opcode opcode = static_cast<Opcode>(bcp[i]); | 752 Opcode opcode = static_cast<Opcode>(bcp[i]); |
753 switch (opcode) { | 753 switch (opcode) { |
754 case kLoadConst: | 754 case kLoadConst: |
755 case kAllocate: | 755 case kAllocate: |
756 case kAllocateImmutable: | 756 case kAllocateImmutable: |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
791 } | 791 } |
792 } | 792 } |
793 } | 793 } |
794 #else | 794 #else |
795 void Function::WriteByteCodes(SnapshotWriter* writer) { | 795 void Function::WriteByteCodes(SnapshotWriter* writer) { |
796 ASSERT(kPointerSize == 4); | 796 ASSERT(kPointerSize == 4); |
797 writer->WriteBytes(bytecode_size(), bytecode_address_for(0)); | 797 writer->WriteBytes(bytecode_size(), bytecode_address_for(0)); |
798 } | 798 } |
799 #endif | 799 #endif |
800 | 800 |
801 #ifdef FLETCH_TARGET_X64 | 801 #ifdef DARTINO_TARGET_X64 |
802 void Function::ReadByteCodes(SnapshotReader* reader) { | 802 void Function::ReadByteCodes(SnapshotReader* reader) { |
803 ASSERT(kPointerSize == 8); | 803 ASSERT(kPointerSize == 8); |
804 uint8* bcp = bytecode_address_for(0); | 804 uint8* bcp = bytecode_address_for(0); |
805 int i = 0; | 805 int i = 0; |
806 while (i < bytecode_size()) { | 806 while (i < bytecode_size()) { |
807 uint8 raw_opcode = reader->ReadByte(); | 807 uint8 raw_opcode = reader->ReadByte(); |
808 Opcode opcode = static_cast<Opcode>(raw_opcode); | 808 Opcode opcode = static_cast<Opcode>(raw_opcode); |
809 switch (opcode) { | 809 switch (opcode) { |
810 case kLoadConst: | 810 case kLoadConst: |
811 case kAllocate: | 811 case kAllocate: |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
939 writer->WriteInt64(selector()); | 939 writer->WriteInt64(selector()); |
940 } | 940 } |
941 | 941 |
942 void DispatchTableEntry::DispatchTableEntryReadFrom(SnapshotReader* reader) { | 942 void DispatchTableEntry::DispatchTableEntryReadFrom(SnapshotReader* reader) { |
943 set_target(Function::cast(reader->ReadObject())); | 943 set_target(Function::cast(reader->ReadObject())); |
944 set_code(NULL); | 944 set_code(NULL); |
945 set_offset(Smi::cast(reader->ReadObject())); | 945 set_offset(Smi::cast(reader->ReadObject())); |
946 set_selector(reader->ReadInt64()); | 946 set_selector(reader->ReadInt64()); |
947 } | 947 } |
948 | 948 |
949 } // namespace fletch | 949 } // namespace dartino |
OLD | NEW |