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 #ifndef RUNTIME_VM_SNAPSHOT_H_ | 5 #ifndef RUNTIME_VM_SNAPSHOT_H_ |
6 #define RUNTIME_VM_SNAPSHOT_H_ | 6 #define RUNTIME_VM_SNAPSHOT_H_ |
7 | 7 |
8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
9 #include "vm/allocation.h" | 9 #include "vm/allocation.h" |
10 #include "vm/bitfield.h" | 10 #include "vm/bitfield.h" |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 // - Smi: the Smi value is written as is (last bit is not tagged). | 102 // - Smi: the Smi value is written as is (last bit is not tagged). |
103 // - VM object (from VM isolate): (object id in vm isolate | 0x3) | 103 // - VM object (from VM isolate): (object id in vm isolate | 0x3) |
104 // This valus is serialized as a negative number. | 104 // This valus is serialized as a negative number. |
105 // (note VM objects are never serialized they are expected to be found | 105 // (note VM objects are never serialized they are expected to be found |
106 // using ths unique ID assigned to them). | 106 // using ths unique ID assigned to them). |
107 // - Reference to object that has already been written: (object id | 0x3) | 107 // - Reference to object that has already been written: (object id | 0x3) |
108 // This valus is serialized as a positive number. | 108 // This valus is serialized as a positive number. |
109 // - Object that is seen for the first time (inlined in the stream): | 109 // - Object that is seen for the first time (inlined in the stream): |
110 // (a unique id for this object | 0x1) | 110 // (a unique id for this object | 0x1) |
111 enum SerializedHeaderType { | 111 enum SerializedHeaderType { |
112 kInlined = 0x1, | 112 kInlined = 0x1, |
113 kObjectId = 0x3, | 113 kObjectId = 0x3, |
114 }; | 114 }; |
115 static const int8_t kHeaderTagBits = 2; | 115 static const int8_t kHeaderTagBits = 2; |
116 static const int8_t kObjectIdBits = (kBitsPerInt32 - (kHeaderTagBits + 1)); | 116 static const int8_t kObjectIdBits = (kBitsPerInt32 - (kHeaderTagBits + 1)); |
117 static const intptr_t kMaxObjectId = (kMaxUint32 >> (kHeaderTagBits + 1)); | 117 static const intptr_t kMaxObjectId = (kMaxUint32 >> (kHeaderTagBits + 1)); |
118 static const bool kAsReference = true; | 118 static const bool kAsReference = true; |
119 static const bool kAsInlinedObject = false; | 119 static const bool kAsInlinedObject = false; |
120 static const intptr_t kInvalidPatchIndex = -1; | 120 static const intptr_t kInvalidPatchIndex = -1; |
121 | 121 |
122 | 122 |
123 class SerializedHeaderTag : | 123 class SerializedHeaderTag |
124 public BitField<intptr_t, enum SerializedHeaderType, 0, kHeaderTagBits> {}; | 124 : public BitField<intptr_t, enum SerializedHeaderType, 0, kHeaderTagBits> { |
| 125 }; |
125 | 126 |
126 | 127 |
127 class SerializedHeaderData : | 128 class SerializedHeaderData |
128 public BitField<intptr_t, intptr_t, kHeaderTagBits, kObjectIdBits> {}; | 129 : public BitField<intptr_t, intptr_t, kHeaderTagBits, kObjectIdBits> {}; |
129 | 130 |
130 | 131 |
131 enum DeserializeState { | 132 enum DeserializeState { |
132 kIsDeserialized = 0, | 133 kIsDeserialized = 0, |
133 kIsNotDeserialized = 1, | 134 kIsNotDeserialized = 1, |
134 }; | 135 }; |
135 | 136 |
136 | 137 |
137 enum SerializeState { | 138 enum SerializeState { |
138 kIsSerialized = 0, | 139 kIsSerialized = 0, |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 } | 186 } |
186 static bool IncludesCode(Kind kind) { | 187 static bool IncludesCode(Kind kind) { |
187 return (kind == kAppWithJIT) || (kind == kAppNoJIT); | 188 return (kind == kAppWithJIT) || (kind == kAppNoJIT); |
188 } | 189 } |
189 | 190 |
190 uint8_t* Addr() { return reinterpret_cast<uint8_t*>(this); } | 191 uint8_t* Addr() { return reinterpret_cast<uint8_t*>(this); } |
191 | 192 |
192 static intptr_t length_offset() { | 193 static intptr_t length_offset() { |
193 return OFFSET_OF(Snapshot, unaligned_length_); | 194 return OFFSET_OF(Snapshot, unaligned_length_); |
194 } | 195 } |
195 static intptr_t kind_offset() { | 196 static intptr_t kind_offset() { return OFFSET_OF(Snapshot, unaligned_kind_); } |
196 return OFFSET_OF(Snapshot, unaligned_kind_); | |
197 } | |
198 | 197 |
199 private: | 198 private: |
200 // Prevent Snapshot from ever being allocated directly. | 199 // Prevent Snapshot from ever being allocated directly. |
201 Snapshot(); | 200 Snapshot(); |
202 | 201 |
203 // The following fields are potentially unaligned. | 202 // The following fields are potentially unaligned. |
204 int64_t unaligned_length_; // Stream length. | 203 int64_t unaligned_length_; // Stream length. |
205 int64_t unaligned_kind_; // Kind of snapshot. | 204 int64_t unaligned_kind_; // Kind of snapshot. |
206 | 205 |
207 // Variable length data follows here. | 206 // Variable length data follows here. |
208 | 207 |
209 DISALLOW_COPY_AND_ASSIGN(Snapshot); | 208 DISALLOW_COPY_AND_ASSIGN(Snapshot); |
210 }; | 209 }; |
211 | 210 |
212 | 211 |
213 class InstructionsSnapshot : ValueObject { | 212 class InstructionsSnapshot : ValueObject { |
214 public: | 213 public: |
215 explicit InstructionsSnapshot(const void* raw_memory) | 214 explicit InstructionsSnapshot(const void* raw_memory) |
216 : raw_memory_(raw_memory) { | 215 : raw_memory_(raw_memory) { |
217 ASSERT(Utils::IsAligned(raw_memory, OS::kMaxPreferredCodeAlignment)); | 216 ASSERT(Utils::IsAligned(raw_memory, OS::kMaxPreferredCodeAlignment)); |
218 } | 217 } |
219 | 218 |
220 void* instructions_start() { | 219 void* instructions_start() { |
221 return reinterpret_cast<void*>( | 220 return reinterpret_cast<void*>(reinterpret_cast<uword>(raw_memory_) + |
222 reinterpret_cast<uword>(raw_memory_) + kHeaderSize); | 221 kHeaderSize); |
223 } | 222 } |
224 | 223 |
225 uword instructions_size() { | 224 uword instructions_size() { |
226 uword snapshot_size = *reinterpret_cast<const uword*>(raw_memory_); | 225 uword snapshot_size = *reinterpret_cast<const uword*>(raw_memory_); |
227 return snapshot_size - kHeaderSize; | 226 return snapshot_size - kHeaderSize; |
228 } | 227 } |
229 | 228 |
230 static const intptr_t kHeaderSize = OS::kMaxPreferredCodeAlignment; | 229 static const intptr_t kHeaderSize = OS::kMaxPreferredCodeAlignment; |
231 | 230 |
232 private: | 231 private: |
233 const void* raw_memory_; // The symbol kInstructionsSnapshot. | 232 const void* raw_memory_; // The symbol kInstructionsSnapshot. |
234 | 233 |
235 DISALLOW_COPY_AND_ASSIGN(InstructionsSnapshot); | 234 DISALLOW_COPY_AND_ASSIGN(InstructionsSnapshot); |
236 }; | 235 }; |
237 | 236 |
238 | 237 |
239 class DataSnapshot : ValueObject { | 238 class DataSnapshot : ValueObject { |
240 public: | 239 public: |
241 explicit DataSnapshot(const void* raw_memory) | 240 explicit DataSnapshot(const void* raw_memory) : raw_memory_(raw_memory) { |
242 : raw_memory_(raw_memory) { | |
243 ASSERT(Utils::IsAligned(raw_memory, 2 * kWordSize)); // kObjectAlignment | 241 ASSERT(Utils::IsAligned(raw_memory, 2 * kWordSize)); // kObjectAlignment |
244 } | 242 } |
245 | 243 |
246 void* data_start() { | 244 void* data_start() { |
247 return reinterpret_cast<void*>( | 245 return reinterpret_cast<void*>(reinterpret_cast<uword>(raw_memory_) + |
248 reinterpret_cast<uword>(raw_memory_) + kHeaderSize); | 246 kHeaderSize); |
249 } | 247 } |
250 | 248 |
251 uword data_size() { | 249 uword data_size() { |
252 uword snapshot_size = *reinterpret_cast<const uword*>(raw_memory_); | 250 uword snapshot_size = *reinterpret_cast<const uword*>(raw_memory_); |
253 return snapshot_size - kHeaderSize; | 251 return snapshot_size - kHeaderSize; |
254 } | 252 } |
255 | 253 |
256 // Header: data length and padding for alignment. We use the same alignment | 254 // Header: data length and padding for alignment. We use the same alignment |
257 // as for code for now. | 255 // as for code for now. |
258 static const intptr_t kHeaderSize = OS::kMaxPreferredCodeAlignment; | 256 static const intptr_t kHeaderSize = OS::kMaxPreferredCodeAlignment; |
(...skipping 19 matching lines...) Expand all Loading... |
278 int64_t value = Read<int64_t>(); | 276 int64_t value = Read<int64_t>(); |
279 return static_cast<intptr_t>(value); | 277 return static_cast<intptr_t>(value); |
280 } | 278 } |
281 | 279 |
282 classid_t ReadClassIDValue() { | 280 classid_t ReadClassIDValue() { |
283 uint32_t value = Read<uint32_t>(); | 281 uint32_t value = Read<uint32_t>(); |
284 return static_cast<classid_t>(value); | 282 return static_cast<classid_t>(value); |
285 } | 283 } |
286 COMPILE_ASSERT(sizeof(uint32_t) >= sizeof(classid_t)); | 284 COMPILE_ASSERT(sizeof(uint32_t) >= sizeof(classid_t)); |
287 | 285 |
288 void ReadBytes(uint8_t* addr, intptr_t len) { | 286 void ReadBytes(uint8_t* addr, intptr_t len) { stream_.ReadBytes(addr, len); } |
289 stream_.ReadBytes(addr, len); | |
290 } | |
291 | 287 |
292 double ReadDouble() { | 288 double ReadDouble() { |
293 double result; | 289 double result; |
294 stream_.ReadBytes(reinterpret_cast<uint8_t*>(&result), sizeof(result)); | 290 stream_.ReadBytes(reinterpret_cast<uint8_t*>(&result), sizeof(result)); |
295 return result; | 291 return result; |
296 } | 292 } |
297 | 293 |
298 intptr_t ReadTags() { | 294 intptr_t ReadTags() { |
299 const intptr_t tags = static_cast<intptr_t>(Read<int8_t>()) & 0xff; | 295 const intptr_t tags = static_cast<intptr_t>(Read<int8_t>()) & 0xff; |
300 return tags; | 296 return tags; |
301 } | 297 } |
302 | 298 |
303 const uint8_t* CurrentBufferAddress() const { | 299 const uint8_t* CurrentBufferAddress() const { |
304 return stream_.AddressOfCurrentPosition(); | 300 return stream_.AddressOfCurrentPosition(); |
305 } | 301 } |
306 | 302 |
307 void Advance(intptr_t value) { | 303 void Advance(intptr_t value) { stream_.Advance(value); } |
308 stream_.Advance(value); | |
309 } | |
310 | 304 |
311 intptr_t PendingBytes() const { | 305 intptr_t PendingBytes() const { return stream_.PendingBytes(); } |
312 return stream_.PendingBytes(); | |
313 } | |
314 | 306 |
315 RawSmi* ReadAsSmi(); | 307 RawSmi* ReadAsSmi(); |
316 intptr_t ReadSmiValue(); | 308 intptr_t ReadSmiValue(); |
317 | 309 |
318 // Negative header value indicates VM isolate object id. | 310 // Negative header value indicates VM isolate object id. |
319 bool IsVMIsolateObject(intptr_t header_value) { return (header_value < 0); } | 311 bool IsVMIsolateObject(intptr_t header_value) { return (header_value < 0); } |
320 intptr_t GetVMIsolateObjectId(intptr_t header_val) { | 312 intptr_t GetVMIsolateObjectId(intptr_t header_val) { |
321 ASSERT(IsVMIsolateObject(header_val)); | 313 ASSERT(IsVMIsolateObject(header_val)); |
322 intptr_t value = -header_val; // Header is negative for VM isolate objects. | 314 intptr_t value = -header_val; // Header is negative for VM isolate objects. |
323 ASSERT(SerializedHeaderTag::decode(value) == kObjectId); | 315 ASSERT(SerializedHeaderTag::decode(value) == kObjectId); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 DeserializeState state_; | 359 DeserializeState state_; |
368 bool defer_canonicalization_; | 360 bool defer_canonicalization_; |
369 ZoneGrowableArray<intptr_t>* patch_records_; | 361 ZoneGrowableArray<intptr_t>* patch_records_; |
370 }; | 362 }; |
371 | 363 |
372 | 364 |
373 class InstructionsReader : public ZoneAllocated { | 365 class InstructionsReader : public ZoneAllocated { |
374 public: | 366 public: |
375 InstructionsReader(const uint8_t* instructions_buffer, | 367 InstructionsReader(const uint8_t* instructions_buffer, |
376 const uint8_t* data_buffer) | 368 const uint8_t* data_buffer) |
377 : instructions_buffer_(instructions_buffer), | 369 : instructions_buffer_(instructions_buffer), data_buffer_(data_buffer) { |
378 data_buffer_(data_buffer) { | |
379 ASSERT(instructions_buffer != NULL); | 370 ASSERT(instructions_buffer != NULL); |
380 ASSERT(data_buffer != NULL); | 371 ASSERT(data_buffer != NULL); |
381 ASSERT(Utils::IsAligned(reinterpret_cast<uword>(instructions_buffer), | 372 ASSERT(Utils::IsAligned(reinterpret_cast<uword>(instructions_buffer), |
382 OS::PreferredCodeAlignment())); | 373 OS::PreferredCodeAlignment())); |
383 } | 374 } |
384 | 375 |
385 uword GetInstructionsAt(int32_t offset); | 376 uword GetInstructionsAt(int32_t offset); |
386 RawObject* GetObjectAt(int32_t offset); | 377 RawObject* GetObjectAt(int32_t offset); |
387 | 378 |
388 private: | 379 private: |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
434 RawApiError* VerifyVersionAndFeatures(); | 425 RawApiError* VerifyVersionAndFeatures(); |
435 | 426 |
436 RawObject* NewInteger(int64_t value); | 427 RawObject* NewInteger(int64_t value); |
437 | 428 |
438 protected: | 429 protected: |
439 SnapshotReader(const uint8_t* buffer, | 430 SnapshotReader(const uint8_t* buffer, |
440 intptr_t size, | 431 intptr_t size, |
441 Snapshot::Kind kind, | 432 Snapshot::Kind kind, |
442 ZoneGrowableArray<BackRefNode>* backward_references, | 433 ZoneGrowableArray<BackRefNode>* backward_references, |
443 Thread* thread); | 434 Thread* thread); |
444 ~SnapshotReader() { } | 435 ~SnapshotReader() {} |
445 | 436 |
446 ZoneGrowableArray<BackRefNode>* GetBackwardReferenceTable() const { | 437 ZoneGrowableArray<BackRefNode>* GetBackwardReferenceTable() const { |
447 return backward_references_; | 438 return backward_references_; |
448 } | 439 } |
449 void ResetBackwardReferenceTable() { backward_references_ = NULL; } | 440 void ResetBackwardReferenceTable() { backward_references_ = NULL; } |
450 PageSpace* old_space() const { return old_space_; } | 441 PageSpace* old_space() const { return old_space_; } |
451 | 442 |
452 private: | 443 private: |
453 RawClass* ReadClassId(intptr_t object_id); | 444 RawClass* ReadClassId(intptr_t object_id); |
454 RawFunction* ReadFunctionId(intptr_t object_id); | 445 RawFunction* ReadFunctionId(intptr_t object_id); |
455 RawObject* ReadStaticImplicitClosure(intptr_t object_id, intptr_t cls_header); | 446 RawObject* ReadStaticImplicitClosure(intptr_t object_id, intptr_t cls_header); |
456 | 447 |
457 // Implementation to read an object. | 448 // Implementation to read an object. |
458 RawObject* ReadObjectImpl(bool as_reference, | 449 RawObject* ReadObjectImpl(bool as_reference, |
459 intptr_t patch_object_id = kInvalidPatchIndex, | 450 intptr_t patch_object_id = kInvalidPatchIndex, |
460 intptr_t patch_offset = 0); | 451 intptr_t patch_offset = 0); |
461 RawObject* ReadObjectImpl(intptr_t header, | 452 RawObject* ReadObjectImpl(intptr_t header, |
462 bool as_reference, | 453 bool as_reference, |
463 intptr_t patch_object_id, | 454 intptr_t patch_object_id, |
464 intptr_t patch_offset); | 455 intptr_t patch_offset); |
465 | 456 |
466 // Read a Dart Instance object. | 457 // Read a Dart Instance object. |
467 RawObject* ReadInstance(intptr_t object_id, | 458 RawObject* ReadInstance(intptr_t object_id, intptr_t tags, bool as_reference); |
468 intptr_t tags, | |
469 bool as_reference); | |
470 | 459 |
471 // Read a VM isolate object that was serialized as an Id. | 460 // Read a VM isolate object that was serialized as an Id. |
472 RawObject* ReadVMIsolateObject(intptr_t object_id); | 461 RawObject* ReadVMIsolateObject(intptr_t object_id); |
473 | 462 |
474 // Read an object that was serialized as an Id (singleton in object store, | 463 // Read an object that was serialized as an Id (singleton in object store, |
475 // or an object that was already serialized before). | 464 // or an object that was already serialized before). |
476 RawObject* ReadIndexedObject(intptr_t object_id, | 465 RawObject* ReadIndexedObject(intptr_t object_id, |
477 intptr_t patch_object_id, | 466 intptr_t patch_object_id, |
478 intptr_t patch_offset); | 467 intptr_t patch_offset); |
479 | 468 |
(...skipping 15 matching lines...) Expand all Loading... |
495 intptr_t tags); | 484 intptr_t tags); |
496 | 485 |
497 intptr_t NextAvailableObjectId() const; | 486 intptr_t NextAvailableObjectId() const; |
498 | 487 |
499 void SetReadException(const char* msg); | 488 void SetReadException(const char* msg); |
500 | 489 |
501 RawObject* VmIsolateSnapshotObject(intptr_t index) const; | 490 RawObject* VmIsolateSnapshotObject(intptr_t index) const; |
502 | 491 |
503 bool is_vm_isolate() const; | 492 bool is_vm_isolate() const; |
504 | 493 |
505 Snapshot::Kind kind_; // Indicates type of snapshot(full, script, message). | 494 Snapshot::Kind kind_; // Indicates type of snapshot(full, script, message). |
506 Thread* thread_; // Current thread. | 495 Thread* thread_; // Current thread. |
507 Zone* zone_; // Zone for allocations while reading snapshot. | 496 Zone* zone_; // Zone for allocations while reading snapshot. |
508 Heap* heap_; // Heap of the current isolate. | 497 Heap* heap_; // Heap of the current isolate. |
509 PageSpace* old_space_; // Old space of the current isolate. | 498 PageSpace* old_space_; // Old space of the current isolate. |
510 Class& cls_; // Temporary Class handle. | 499 Class& cls_; // Temporary Class handle. |
511 Object& obj_; // Temporary Object handle. | 500 Object& obj_; // Temporary Object handle. |
512 PassiveObject& pobj_; // Temporary PassiveObject handle. | 501 PassiveObject& pobj_; // Temporary PassiveObject handle. |
513 Array& array_; // Temporary Array handle. | 502 Array& array_; // Temporary Array handle. |
514 Field& field_; // Temporary Field handle. | 503 Field& field_; // Temporary Field handle. |
515 String& str_; // Temporary String handle. | 504 String& str_; // Temporary String handle. |
516 Library& library_; // Temporary library handle. | 505 Library& library_; // Temporary library handle. |
517 AbstractType& type_; // Temporary type handle. | 506 AbstractType& type_; // Temporary type handle. |
518 TypeArguments& type_arguments_; // Temporary type argument handle. | 507 TypeArguments& type_arguments_; // Temporary type argument handle. |
519 GrowableObjectArray& tokens_; // Temporary tokens handle. | 508 GrowableObjectArray& tokens_; // Temporary tokens handle. |
520 TokenStream& stream_; // Temporary token stream handle. | 509 TokenStream& stream_; // Temporary token stream handle. |
521 ExternalTypedData& data_; // Temporary stream data handle. | 510 ExternalTypedData& data_; // Temporary stream data handle. |
522 TypedData& typed_data_; // Temporary typed data handle. | 511 TypedData& typed_data_; // Temporary typed data handle. |
523 Function& function_; // Temporary function handle. | 512 Function& function_; // Temporary function handle. |
524 UnhandledException& error_; // Error handle. | 513 UnhandledException& error_; // Error handle. |
525 intptr_t max_vm_isolate_object_id_; | 514 intptr_t max_vm_isolate_object_id_; |
526 ZoneGrowableArray<BackRefNode>* backward_references_; | 515 ZoneGrowableArray<BackRefNode>* backward_references_; |
527 | 516 |
528 friend class ApiError; | 517 friend class ApiError; |
529 friend class Array; | 518 friend class Array; |
530 friend class Bigint; | 519 friend class Bigint; |
531 friend class BoundedType; | 520 friend class BoundedType; |
532 friend class Class; | 521 friend class Class; |
533 friend class Closure; | 522 friend class Closure; |
534 friend class ClosureData; | 523 friend class ClosureData; |
(...skipping 25 matching lines...) Expand all Loading... |
560 friend class TypeRef; | 549 friend class TypeRef; |
561 friend class UnhandledException; | 550 friend class UnhandledException; |
562 friend class UnresolvedClass; | 551 friend class UnresolvedClass; |
563 friend class WeakProperty; | 552 friend class WeakProperty; |
564 DISALLOW_COPY_AND_ASSIGN(SnapshotReader); | 553 DISALLOW_COPY_AND_ASSIGN(SnapshotReader); |
565 }; | 554 }; |
566 | 555 |
567 | 556 |
568 class ScriptSnapshotReader : public SnapshotReader { | 557 class ScriptSnapshotReader : public SnapshotReader { |
569 public: | 558 public: |
570 ScriptSnapshotReader(const uint8_t* buffer, | 559 ScriptSnapshotReader(const uint8_t* buffer, intptr_t size, Thread* thread); |
571 intptr_t size, | |
572 Thread* thread); | |
573 ~ScriptSnapshotReader(); | 560 ~ScriptSnapshotReader(); |
574 | 561 |
575 private: | 562 private: |
576 DISALLOW_COPY_AND_ASSIGN(ScriptSnapshotReader); | 563 DISALLOW_COPY_AND_ASSIGN(ScriptSnapshotReader); |
577 }; | 564 }; |
578 | 565 |
579 | 566 |
580 class MessageSnapshotReader : public SnapshotReader { | 567 class MessageSnapshotReader : public SnapshotReader { |
581 public: | 568 public: |
582 MessageSnapshotReader(const uint8_t* buffer, | 569 MessageSnapshotReader(const uint8_t* buffer, intptr_t size, Thread* thread); |
583 intptr_t size, | |
584 Thread* thread); | |
585 ~MessageSnapshotReader(); | 570 ~MessageSnapshotReader(); |
586 | 571 |
587 private: | 572 private: |
588 DISALLOW_COPY_AND_ASSIGN(MessageSnapshotReader); | 573 DISALLOW_COPY_AND_ASSIGN(MessageSnapshotReader); |
589 }; | 574 }; |
590 | 575 |
591 | 576 |
592 class BaseWriter : public StackResource { | 577 class BaseWriter : public StackResource { |
593 public: | 578 public: |
594 // Size of the snapshot. | 579 // Size of the snapshot. |
595 intptr_t BytesWritten() const { return stream_.bytes_written(); } | 580 intptr_t BytesWritten() const { return stream_.bytes_written(); } |
596 | 581 |
597 // Writes raw data to the stream (basic type). | 582 // Writes raw data to the stream (basic type). |
598 // sizeof(T) must be in {1,2,4,8}. | 583 // sizeof(T) must be in {1,2,4,8}. |
599 template <typename T> | 584 template <typename T> |
600 void Write(T value) { | 585 void Write(T value) { |
601 WriteStream::Raw<sizeof(T), T>::Write(&stream_, value); | 586 WriteStream::Raw<sizeof(T), T>::Write(&stream_, value); |
602 } | 587 } |
603 | 588 |
604 void WriteRawPointerValue(intptr_t value) { | 589 void WriteRawPointerValue(intptr_t value) { Write<int64_t>(value); } |
605 Write<int64_t>(value); | |
606 } | |
607 | 590 |
608 void WriteClassIDValue(classid_t value) { | 591 void WriteClassIDValue(classid_t value) { Write<uint32_t>(value); } |
609 Write<uint32_t>(value); | |
610 } | |
611 COMPILE_ASSERT(sizeof(uint32_t) >= sizeof(classid_t)); | 592 COMPILE_ASSERT(sizeof(uint32_t) >= sizeof(classid_t)); |
612 | 593 |
613 // Write an object that is serialized as an Id (singleton in object store, | 594 // Write an object that is serialized as an Id (singleton in object store, |
614 // or an object that was already serialized before). | 595 // or an object that was already serialized before). |
615 void WriteIndexedObject(intptr_t object_id) { | 596 void WriteIndexedObject(intptr_t object_id) { |
616 ASSERT(object_id <= kMaxObjectId); | 597 ASSERT(object_id <= kMaxObjectId); |
617 intptr_t value = 0; | 598 intptr_t value = 0; |
618 value = SerializedHeaderTag::update(kObjectId, value); | 599 value = SerializedHeaderTag::update(kObjectId, value); |
619 value = SerializedHeaderData::update(object_id, value); | 600 value = SerializedHeaderData::update(object_id, value); |
620 Write<int32_t>(value); | 601 Write<int32_t>(value); |
(...skipping 25 matching lines...) Expand all Loading... |
646 // Write out a buffer of bytes. | 627 // Write out a buffer of bytes. |
647 void WriteBytes(const uint8_t* addr, intptr_t len) { | 628 void WriteBytes(const uint8_t* addr, intptr_t len) { |
648 stream_.WriteBytes(addr, len); | 629 stream_.WriteBytes(addr, len); |
649 } | 630 } |
650 | 631 |
651 void WriteDouble(double value) { | 632 void WriteDouble(double value) { |
652 stream_.WriteBytes(reinterpret_cast<const uint8_t*>(&value), sizeof(value)); | 633 stream_.WriteBytes(reinterpret_cast<const uint8_t*>(&value), sizeof(value)); |
653 } | 634 } |
654 | 635 |
655 protected: | 636 protected: |
656 BaseWriter(uint8_t** buffer, | 637 BaseWriter(uint8_t** buffer, ReAlloc alloc, intptr_t initial_size) |
657 ReAlloc alloc, | 638 : StackResource(Thread::Current()), stream_(buffer, alloc, initial_size) { |
658 intptr_t initial_size) | |
659 : StackResource(Thread::Current()), | |
660 stream_(buffer, alloc, initial_size) { | |
661 ASSERT(buffer != NULL); | 639 ASSERT(buffer != NULL); |
662 ASSERT(alloc != NULL); | 640 ASSERT(alloc != NULL); |
663 } | 641 } |
664 ~BaseWriter() { } | 642 ~BaseWriter() {} |
665 | 643 |
666 void ReserveHeader() { | 644 void ReserveHeader() { |
667 // Make room for recording snapshot buffer size. | 645 // Make room for recording snapshot buffer size. |
668 stream_.set_current(stream_.buffer() + Snapshot::kHeaderSize); | 646 stream_.set_current(stream_.buffer() + Snapshot::kHeaderSize); |
669 } | 647 } |
670 | 648 |
671 void FillHeader(Snapshot::Kind kind) { | 649 void FillHeader(Snapshot::Kind kind) { |
672 int64_t* data = reinterpret_cast<int64_t*>(stream_.buffer()); | 650 int64_t* data = reinterpret_cast<int64_t*>(stream_.buffer()); |
673 data[Snapshot::kLengthIndex] = stream_.bytes_written(); | 651 data[Snapshot::kLengthIndex] = stream_.bytes_written(); |
674 data[Snapshot::kSnapshotFlagIndex] = kind; | 652 data[Snapshot::kSnapshotFlagIndex] = kind; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
732 GrowableArray<Node*> nodes_; | 710 GrowableArray<Node*> nodes_; |
733 intptr_t first_unprocessed_object_id_; | 711 intptr_t first_unprocessed_object_id_; |
734 | 712 |
735 DISALLOW_COPY_AND_ASSIGN(ForwardList); | 713 DISALLOW_COPY_AND_ASSIGN(ForwardList); |
736 }; | 714 }; |
737 | 715 |
738 | 716 |
739 class InstructionsWriter : public ZoneAllocated { | 717 class InstructionsWriter : public ZoneAllocated { |
740 public: | 718 public: |
741 InstructionsWriter() | 719 InstructionsWriter() |
742 : next_offset_(InstructionsSnapshot::kHeaderSize), | 720 : next_offset_(InstructionsSnapshot::kHeaderSize), |
743 next_object_offset_(DataSnapshot::kHeaderSize), | 721 next_object_offset_(DataSnapshot::kHeaderSize), |
744 instructions_(), | 722 instructions_(), |
745 objects_() { | 723 objects_() {} |
746 } | 724 virtual ~InstructionsWriter() {} |
747 virtual ~InstructionsWriter() { } | |
748 | 725 |
749 int32_t GetOffsetFor(RawInstructions* instructions, RawCode* code); | 726 int32_t GetOffsetFor(RawInstructions* instructions, RawCode* code); |
750 | 727 |
751 int32_t GetObjectOffsetFor(RawObject* raw_object); | 728 int32_t GetObjectOffsetFor(RawObject* raw_object); |
752 | 729 |
753 virtual void Write(uint8_t* vmisolate_buffer, | 730 virtual void Write(uint8_t* vmisolate_buffer, |
754 intptr_t vmisolate_length, | 731 intptr_t vmisolate_length, |
755 uint8_t* isolate_buffer, | 732 uint8_t* isolate_buffer, |
756 intptr_t isolate_length) = 0; | 733 intptr_t isolate_length) = 0; |
757 virtual intptr_t text_size() = 0; | 734 virtual intptr_t text_size() = 0; |
758 virtual intptr_t data_size() = 0; | 735 virtual intptr_t data_size() = 0; |
759 | 736 |
760 protected: | 737 protected: |
761 struct InstructionsData { | 738 struct InstructionsData { |
762 explicit InstructionsData(RawInstructions* insns, | 739 explicit InstructionsData(RawInstructions* insns, |
763 RawCode* code, | 740 RawCode* code, |
764 intptr_t offset) | 741 intptr_t offset) |
765 : raw_insns_(insns), raw_code_(code), offset_(offset) { } | 742 : raw_insns_(insns), raw_code_(code), offset_(offset) {} |
766 | 743 |
767 union { | 744 union { |
768 RawInstructions* raw_insns_; | 745 RawInstructions* raw_insns_; |
769 const Instructions* insns_; | 746 const Instructions* insns_; |
770 }; | 747 }; |
771 union { | 748 union { |
772 RawCode* raw_code_; | 749 RawCode* raw_code_; |
773 const Code* code_; | 750 const Code* code_; |
774 }; | 751 }; |
775 intptr_t offset_; | 752 intptr_t offset_; |
776 }; | 753 }; |
777 | 754 |
778 struct ObjectData { | 755 struct ObjectData { |
779 explicit ObjectData(RawObject* raw_obj) | 756 explicit ObjectData(RawObject* raw_obj) : raw_obj_(raw_obj) {} |
780 : raw_obj_(raw_obj) { } | |
781 | 757 |
782 union { | 758 union { |
783 RawObject* raw_obj_; | 759 RawObject* raw_obj_; |
784 const Object* obj_; | 760 const Object* obj_; |
785 }; | 761 }; |
786 }; | 762 }; |
787 | 763 |
788 intptr_t next_offset_; | 764 intptr_t next_offset_; |
789 intptr_t next_object_offset_; | 765 intptr_t next_object_offset_; |
790 GrowableArray<InstructionsData> instructions_; | 766 GrowableArray<InstructionsData> instructions_; |
791 GrowableArray<ObjectData> objects_; | 767 GrowableArray<ObjectData> objects_; |
792 | 768 |
793 private: | 769 private: |
794 DISALLOW_COPY_AND_ASSIGN(InstructionsWriter); | 770 DISALLOW_COPY_AND_ASSIGN(InstructionsWriter); |
795 }; | 771 }; |
796 | 772 |
797 | 773 |
798 class AssemblyInstructionsWriter : public InstructionsWriter { | 774 class AssemblyInstructionsWriter : public InstructionsWriter { |
799 public: | 775 public: |
800 AssemblyInstructionsWriter(uint8_t** assembly_buffer, | 776 AssemblyInstructionsWriter(uint8_t** assembly_buffer, |
801 ReAlloc alloc, | 777 ReAlloc alloc, |
802 intptr_t initial_size) | 778 intptr_t initial_size) |
803 : InstructionsWriter(), | 779 : InstructionsWriter(), |
804 assembly_stream_(assembly_buffer, alloc, initial_size), | 780 assembly_stream_(assembly_buffer, alloc, initial_size), |
805 text_size_(0), | 781 text_size_(0), |
806 data_size_(0) { | 782 data_size_(0) {} |
807 } | |
808 | 783 |
809 virtual void Write(uint8_t* vmisolate_buffer, | 784 virtual void Write(uint8_t* vmisolate_buffer, |
810 intptr_t vmisolate_length, | 785 intptr_t vmisolate_length, |
811 uint8_t* isolate_buffer, | 786 uint8_t* isolate_buffer, |
812 intptr_t isolate_length); | 787 intptr_t isolate_length); |
813 virtual intptr_t text_size() { return text_size_; } | 788 virtual intptr_t text_size() { return text_size_; } |
814 virtual intptr_t data_size() { return data_size_; } | 789 virtual intptr_t data_size() { return data_size_; } |
815 | 790 |
816 intptr_t AssemblySize() const { return assembly_stream_.bytes_written(); } | 791 intptr_t AssemblySize() const { return assembly_stream_.bytes_written(); } |
817 | 792 |
818 private: | 793 private: |
819 void WriteWordLiteralText(uword value) { | 794 void WriteWordLiteralText(uword value) { |
820 // Padding is helpful for comparing the .S with --disassemble. | 795 // Padding is helpful for comparing the .S with --disassemble. |
821 #if defined(ARCH_IS_64_BIT) | 796 #if defined(ARCH_IS_64_BIT) |
822 assembly_stream_.Print(".quad 0x%0.16" Px "\n", value); | 797 assembly_stream_.Print(".quad 0x%0.16" Px "\n", value); |
823 #else | 798 #else |
824 assembly_stream_.Print(".long 0x%0.8" Px "\n", value); | 799 assembly_stream_.Print(".long 0x%0.8" Px "\n", value); |
825 #endif | 800 #endif |
826 text_size_ += sizeof(value); | 801 text_size_ += sizeof(value); |
827 } | 802 } |
828 | 803 |
829 void WriteWordLiteralData(uword value) { | 804 void WriteWordLiteralData(uword value) { |
830 // Padding is helpful for comparing the .S with --disassemble. | 805 // Padding is helpful for comparing the .S with --disassemble. |
831 #if defined(ARCH_IS_64_BIT) | 806 #if defined(ARCH_IS_64_BIT) |
832 assembly_stream_.Print(".quad 0x%0.16" Px "\n", value); | 807 assembly_stream_.Print(".quad 0x%0.16" Px "\n", value); |
833 #else | 808 #else |
834 assembly_stream_.Print(".long 0x%0.8" Px "\n", value); | 809 assembly_stream_.Print(".long 0x%0.8" Px "\n", value); |
835 #endif | 810 #endif |
836 data_size_ += sizeof(value); | 811 data_size_ += sizeof(value); |
837 } | 812 } |
838 | 813 |
839 WriteStream assembly_stream_; | 814 WriteStream assembly_stream_; |
840 intptr_t text_size_; | 815 intptr_t text_size_; |
841 intptr_t data_size_; | 816 intptr_t data_size_; |
842 | 817 |
843 DISALLOW_COPY_AND_ASSIGN(AssemblyInstructionsWriter); | 818 DISALLOW_COPY_AND_ASSIGN(AssemblyInstructionsWriter); |
844 }; | 819 }; |
845 | 820 |
846 | 821 |
847 class BlobInstructionsWriter : public InstructionsWriter { | 822 class BlobInstructionsWriter : public InstructionsWriter { |
848 public: | 823 public: |
849 BlobInstructionsWriter(uint8_t** instructions_blob_buffer, | 824 BlobInstructionsWriter(uint8_t** instructions_blob_buffer, |
850 uint8_t** rodata_blob_buffer, | 825 uint8_t** rodata_blob_buffer, |
851 ReAlloc alloc, | 826 ReAlloc alloc, |
852 intptr_t initial_size) | 827 intptr_t initial_size) |
853 : InstructionsWriter(), | 828 : InstructionsWriter(), |
854 instructions_blob_stream_(instructions_blob_buffer, alloc, initial_size), | 829 instructions_blob_stream_(instructions_blob_buffer, |
855 rodata_blob_stream_(rodata_blob_buffer, alloc, initial_size) { | 830 alloc, |
856 } | 831 initial_size), |
| 832 rodata_blob_stream_(rodata_blob_buffer, alloc, initial_size) {} |
857 | 833 |
858 virtual void Write(uint8_t* vmisolate_buffer, | 834 virtual void Write(uint8_t* vmisolate_buffer, |
859 intptr_t vmisolate_length, | 835 intptr_t vmisolate_length, |
860 uint8_t* isolate_buffer, | 836 uint8_t* isolate_buffer, |
861 intptr_t isolate_length); | 837 intptr_t isolate_length); |
862 virtual intptr_t text_size() { return InstructionsBlobSize(); } | 838 virtual intptr_t text_size() { return InstructionsBlobSize(); } |
863 virtual intptr_t data_size() { return RodataBlobSize(); } | 839 virtual intptr_t data_size() { return RodataBlobSize(); } |
864 | 840 |
865 intptr_t InstructionsBlobSize() const { | 841 intptr_t InstructionsBlobSize() const { |
866 return instructions_blob_stream_.bytes_written(); | 842 return instructions_blob_stream_.bytes_written(); |
(...skipping 26 matching lines...) Expand all Loading... |
893 Thread* thread() const { return thread_; } | 869 Thread* thread() const { return thread_; } |
894 Zone* zone() const { return thread_->zone(); } | 870 Zone* zone() const { return thread_->zone(); } |
895 Isolate* isolate() const { return thread_->isolate(); } | 871 Isolate* isolate() const { return thread_->isolate(); } |
896 Heap* heap() const { return isolate()->heap(); } | 872 Heap* heap() const { return isolate()->heap(); } |
897 | 873 |
898 // Serialize an object into the buffer. | 874 // Serialize an object into the buffer. |
899 void WriteObject(RawObject* raw); | 875 void WriteObject(RawObject* raw); |
900 | 876 |
901 uword GetObjectTags(RawObject* raw); | 877 uword GetObjectTags(RawObject* raw); |
902 | 878 |
903 Exceptions::ExceptionType exception_type() const { | 879 Exceptions::ExceptionType exception_type() const { return exception_type_; } |
904 return exception_type_; | |
905 } | |
906 void set_exception_type(Exceptions::ExceptionType type) { | 880 void set_exception_type(Exceptions::ExceptionType type) { |
907 exception_type_ = type; | 881 exception_type_ = type; |
908 } | 882 } |
909 const char* exception_msg() const { return exception_msg_; } | 883 const char* exception_msg() const { return exception_msg_; } |
910 void set_exception_msg(const char* msg) { | 884 void set_exception_msg(const char* msg) { exception_msg_ = msg; } |
911 exception_msg_ = msg; | |
912 } | |
913 bool can_send_any_object() const { return can_send_any_object_; } | 885 bool can_send_any_object() const { return can_send_any_object_; } |
914 void ThrowException(Exceptions::ExceptionType type, const char* msg); | 886 void ThrowException(Exceptions::ExceptionType type, const char* msg); |
915 | 887 |
916 // Write a version string for the snapshot. | 888 // Write a version string for the snapshot. |
917 void WriteVersionAndFeatures(); | 889 void WriteVersionAndFeatures(); |
918 | 890 |
919 void WriteFunctionId(RawFunction* func, bool owner_is_class); | 891 void WriteFunctionId(RawFunction* func, bool owner_is_class); |
920 | 892 |
921 RawFunction* IsSerializableClosure(RawClosure* closure); | 893 RawFunction* IsSerializableClosure(RawClosure* closure); |
922 | 894 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
956 ObjectStore* object_store() const { return object_store_; } | 928 ObjectStore* object_store() const { return object_store_; } |
957 | 929 |
958 private: | 930 private: |
959 Thread* thread_; | 931 Thread* thread_; |
960 Snapshot::Kind kind_; | 932 Snapshot::Kind kind_; |
961 ObjectStore* object_store_; // Object store for common classes. | 933 ObjectStore* object_store_; // Object store for common classes. |
962 ClassTable* class_table_; // Class table for the class index to class lookup. | 934 ClassTable* class_table_; // Class table for the class index to class lookup. |
963 ForwardList* forward_list_; | 935 ForwardList* forward_list_; |
964 Exceptions::ExceptionType exception_type_; // Exception type. | 936 Exceptions::ExceptionType exception_type_; // Exception type. |
965 const char* exception_msg_; // Message associated with exception. | 937 const char* exception_msg_; // Message associated with exception. |
966 bool can_send_any_object_; // True if any Dart instance can be sent. | 938 bool can_send_any_object_; // True if any Dart instance can be sent. |
967 | 939 |
968 friend class RawArray; | 940 friend class RawArray; |
969 friend class RawClass; | 941 friend class RawClass; |
970 friend class RawClosureData; | 942 friend class RawClosureData; |
971 friend class RawCode; | 943 friend class RawCode; |
972 friend class RawContextScope; | 944 friend class RawContextScope; |
973 friend class RawExceptionHandlers; | 945 friend class RawExceptionHandlers; |
974 friend class RawField; | 946 friend class RawField; |
975 friend class RawFunction; | 947 friend class RawFunction; |
976 friend class RawGrowableObjectArray; | 948 friend class RawGrowableObjectArray; |
(...skipping 18 matching lines...) Expand all Loading... |
995 friend class SnapshotWriterVisitor; | 967 friend class SnapshotWriterVisitor; |
996 friend class WriteInlinedObjectVisitor; | 968 friend class WriteInlinedObjectVisitor; |
997 DISALLOW_COPY_AND_ASSIGN(SnapshotWriter); | 969 DISALLOW_COPY_AND_ASSIGN(SnapshotWriter); |
998 }; | 970 }; |
999 | 971 |
1000 | 972 |
1001 class ScriptSnapshotWriter : public SnapshotWriter { | 973 class ScriptSnapshotWriter : public SnapshotWriter { |
1002 public: | 974 public: |
1003 static const intptr_t kInitialSize = 64 * KB; | 975 static const intptr_t kInitialSize = 64 * KB; |
1004 ScriptSnapshotWriter(uint8_t** buffer, ReAlloc alloc); | 976 ScriptSnapshotWriter(uint8_t** buffer, ReAlloc alloc); |
1005 ~ScriptSnapshotWriter() { } | 977 ~ScriptSnapshotWriter() {} |
1006 | 978 |
1007 // Writes a partial snapshot of the script. | 979 // Writes a partial snapshot of the script. |
1008 void WriteScriptSnapshot(const Library& lib); | 980 void WriteScriptSnapshot(const Library& lib); |
1009 | 981 |
1010 private: | 982 private: |
1011 ForwardList forward_list_; | 983 ForwardList forward_list_; |
1012 | 984 |
1013 DISALLOW_COPY_AND_ASSIGN(ScriptSnapshotWriter); | 985 DISALLOW_COPY_AND_ASSIGN(ScriptSnapshotWriter); |
1014 }; | 986 }; |
1015 | 987 |
1016 | 988 |
1017 class MessageWriter : public SnapshotWriter { | 989 class MessageWriter : public SnapshotWriter { |
1018 public: | 990 public: |
1019 static const intptr_t kInitialSize = 512; | 991 static const intptr_t kInitialSize = 512; |
1020 MessageWriter(uint8_t** buffer, ReAlloc alloc, bool can_send_any_object); | 992 MessageWriter(uint8_t** buffer, ReAlloc alloc, bool can_send_any_object); |
1021 ~MessageWriter() { } | 993 ~MessageWriter() {} |
1022 | 994 |
1023 void WriteMessage(const Object& obj); | 995 void WriteMessage(const Object& obj); |
1024 | 996 |
1025 private: | 997 private: |
1026 ForwardList forward_list_; | 998 ForwardList forward_list_; |
1027 | 999 |
1028 DISALLOW_COPY_AND_ASSIGN(MessageWriter); | 1000 DISALLOW_COPY_AND_ASSIGN(MessageWriter); |
1029 }; | 1001 }; |
1030 | 1002 |
1031 | 1003 |
(...skipping 11 matching lines...) Expand all Loading... |
1043 private: | 1015 private: |
1044 SnapshotWriter* writer_; | 1016 SnapshotWriter* writer_; |
1045 bool as_references_; | 1017 bool as_references_; |
1046 | 1018 |
1047 DISALLOW_COPY_AND_ASSIGN(SnapshotWriterVisitor); | 1019 DISALLOW_COPY_AND_ASSIGN(SnapshotWriterVisitor); |
1048 }; | 1020 }; |
1049 | 1021 |
1050 } // namespace dart | 1022 } // namespace dart |
1051 | 1023 |
1052 #endif // RUNTIME_VM_SNAPSHOT_H_ | 1024 #endif // RUNTIME_VM_SNAPSHOT_H_ |
OLD | NEW |