| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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_CLUSTERED_SNAPSHOT_H_ | 5 #ifndef RUNTIME_VM_CLUSTERED_SNAPSHOT_H_ |
| 6 #define RUNTIME_VM_CLUSTERED_SNAPSHOT_H_ | 6 #define RUNTIME_VM_CLUSTERED_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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 public: | 116 public: |
| 117 Serializer(Thread* thread, | 117 Serializer(Thread* thread, |
| 118 Snapshot::Kind kind, | 118 Snapshot::Kind kind, |
| 119 uint8_t** buffer, | 119 uint8_t** buffer, |
| 120 ReAlloc alloc, | 120 ReAlloc alloc, |
| 121 intptr_t initial_size, | 121 intptr_t initial_size, |
| 122 InstructionsWriter* instructions_writer_); | 122 InstructionsWriter* instructions_writer_); |
| 123 ~Serializer(); | 123 ~Serializer(); |
| 124 | 124 |
| 125 intptr_t WriteVMSnapshot(const Array& symbols, const Array& scripts); | 125 intptr_t WriteVMSnapshot(const Array& symbols, const Array& scripts); |
| 126 void WriteFullSnapshot(intptr_t num_base_objects, ObjectStore* object_store); | 126 void WriteIsolateSnapshot(intptr_t num_base_objects, |
| 127 ObjectStore* object_store); |
| 127 | 128 |
| 128 void AddVMIsolateBaseObjects(); | 129 void AddVMIsolateBaseObjects(); |
| 129 | 130 |
| 130 void AddBaseObject(RawObject* base_object) { | 131 void AddBaseObject(RawObject* base_object) { |
| 131 AssignRef(base_object); | 132 AssignRef(base_object); |
| 132 num_base_objects_++; | 133 num_base_objects_++; |
| 133 } | 134 } |
| 134 | 135 |
| 135 void AssignRef(RawObject* object) { | 136 void AssignRef(RawObject* object) { |
| 136 ASSERT(next_ref_index_ != 0); | 137 ASSERT(next_ref_index_ != 0); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 | 200 |
| 200 void FillHeader(Snapshot::Kind kind) { | 201 void FillHeader(Snapshot::Kind kind) { |
| 201 int64_t* data = reinterpret_cast<int64_t*>(stream_.buffer()); | 202 int64_t* data = reinterpret_cast<int64_t*>(stream_.buffer()); |
| 202 data[Snapshot::kLengthIndex] = stream_.bytes_written(); | 203 data[Snapshot::kLengthIndex] = stream_.bytes_written(); |
| 203 data[Snapshot::kSnapshotFlagIndex] = kind; | 204 data[Snapshot::kSnapshotFlagIndex] = kind; |
| 204 } | 205 } |
| 205 | 206 |
| 206 void WriteVersionAndFeatures(); | 207 void WriteVersionAndFeatures(); |
| 207 | 208 |
| 208 void Serialize(); | 209 void Serialize(); |
| 210 WriteStream* stream() { return &stream_; } |
| 209 intptr_t bytes_written() { return stream_.bytes_written(); } | 211 intptr_t bytes_written() { return stream_.bytes_written(); } |
| 210 | 212 |
| 211 // Writes raw data to the stream (basic type). | 213 // Writes raw data to the stream (basic type). |
| 212 // sizeof(T) must be in {1,2,4,8}. | 214 // sizeof(T) must be in {1,2,4,8}. |
| 213 template <typename T> | 215 template <typename T> |
| 214 void Write(T value) { | 216 void Write(T value) { |
| 215 WriteStream::Raw<sizeof(T), T>::Write(&stream_, value); | 217 WriteStream::Raw<sizeof(T), T>::Write(&stream_, value); |
| 216 } | 218 } |
| 217 | 219 |
| 218 void WriteBytes(const uint8_t* addr, intptr_t len) { | 220 void WriteBytes(const uint8_t* addr, intptr_t len) { |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 class Deserializer : public StackResource { | 289 class Deserializer : public StackResource { |
| 288 public: | 290 public: |
| 289 Deserializer(Thread* thread, | 291 Deserializer(Thread* thread, |
| 290 Snapshot::Kind kind, | 292 Snapshot::Kind kind, |
| 291 const uint8_t* buffer, | 293 const uint8_t* buffer, |
| 292 intptr_t size, | 294 intptr_t size, |
| 293 const uint8_t* instructions_buffer, | 295 const uint8_t* instructions_buffer, |
| 294 const uint8_t* data_buffer); | 296 const uint8_t* data_buffer); |
| 295 ~Deserializer(); | 297 ~Deserializer(); |
| 296 | 298 |
| 297 void ReadFullSnapshot(ObjectStore* object_store); | 299 void ReadIsolateSnapshot(ObjectStore* object_store); |
| 298 void ReadVMSnapshot(); | 300 void ReadVMSnapshot(); |
| 299 | 301 |
| 300 void AddVMIsolateBaseObjects(); | 302 void AddVMIsolateBaseObjects(); |
| 301 | 303 |
| 302 static void InitializeHeader(RawObject* raw, | 304 static void InitializeHeader(RawObject* raw, |
| 303 intptr_t cid, | 305 intptr_t cid, |
| 304 intptr_t size, | 306 intptr_t size, |
| 305 bool is_vm_isolate, | 307 bool is_vm_isolate, |
| 306 bool is_canonical = false); | 308 bool is_canonical = false); |
| 307 | 309 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 | 345 |
| 344 TokenPosition ReadTokenPosition() { | 346 TokenPosition ReadTokenPosition() { |
| 345 return TokenPosition::SnapshotDecode(Read<int32_t>()); | 347 return TokenPosition::SnapshotDecode(Read<int32_t>()); |
| 346 } | 348 } |
| 347 | 349 |
| 348 intptr_t ReadCid() { | 350 intptr_t ReadCid() { |
| 349 COMPILE_ASSERT(RawObject::kClassIdTagSize <= 32); | 351 COMPILE_ASSERT(RawObject::kClassIdTagSize <= 32); |
| 350 return Read<int32_t>(); | 352 return Read<int32_t>(); |
| 351 } | 353 } |
| 352 | 354 |
| 353 uword GetInstructionsAt(int32_t offset) { | 355 RawInstructions* GetInstructionsAt(int32_t offset) { |
| 354 return instructions_reader_->GetInstructionsAt(offset); | 356 return instructions_reader_->GetInstructionsAt(offset); |
| 355 } | 357 } |
| 356 | 358 |
| 357 RawObject* GetObjectAt(int32_t offset) { | 359 RawObject* GetObjectAt(int32_t offset) { |
| 358 return instructions_reader_->GetObjectAt(offset); | 360 return instructions_reader_->GetObjectAt(offset); |
| 359 } | 361 } |
| 360 | 362 |
| 361 RawApiError* VerifyVersionAndFeatures(); | 363 RawApiError* VerifyVersionAndFeatures(); |
| 362 | 364 |
| 363 void Prepare(); | 365 void Prepare(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 380 RawArray* refs_; | 382 RawArray* refs_; |
| 381 intptr_t next_ref_index_; | 383 intptr_t next_ref_index_; |
| 382 DeserializationCluster** clusters_; | 384 DeserializationCluster** clusters_; |
| 383 }; | 385 }; |
| 384 | 386 |
| 385 | 387 |
| 386 class FullSnapshotWriter { | 388 class FullSnapshotWriter { |
| 387 public: | 389 public: |
| 388 static const intptr_t kInitialSize = 64 * KB; | 390 static const intptr_t kInitialSize = 64 * KB; |
| 389 FullSnapshotWriter(Snapshot::Kind kind, | 391 FullSnapshotWriter(Snapshot::Kind kind, |
| 390 uint8_t** vm_isolate_snapshot_buffer, | 392 uint8_t** vm_snapshot_data_buffer, |
| 391 uint8_t** isolate_snapshot_buffer, | 393 uint8_t** isolate_snapshot_data_buffer, |
| 392 ReAlloc alloc, | 394 ReAlloc alloc, |
| 393 InstructionsWriter* instructions_writer); | 395 InstructionsWriter* vm_instructions_writer, |
| 396 InstructionsWriter* iso_instructions_writer); |
| 394 ~FullSnapshotWriter(); | 397 ~FullSnapshotWriter(); |
| 395 | 398 |
| 396 uint8_t** vm_isolate_snapshot_buffer() const { | 399 uint8_t** vm_snapshot_data_buffer() const { return vm_snapshot_data_buffer_; } |
| 397 return vm_isolate_snapshot_buffer_; | 400 |
| 401 uint8_t** isolate_snapshot_data_buffer() const { |
| 402 return isolate_snapshot_data_buffer_; |
| 398 } | 403 } |
| 399 | 404 |
| 400 uint8_t** isolate_snapshot_buffer() const { return isolate_snapshot_buffer_; } | |
| 401 | |
| 402 Thread* thread() const { return thread_; } | 405 Thread* thread() const { return thread_; } |
| 403 Zone* zone() const { return thread_->zone(); } | 406 Zone* zone() const { return thread_->zone(); } |
| 404 Isolate* isolate() const { return thread_->isolate(); } | 407 Isolate* isolate() const { return thread_->isolate(); } |
| 405 Heap* heap() const { return isolate()->heap(); } | 408 Heap* heap() const { return isolate()->heap(); } |
| 406 | 409 |
| 407 // Writes a full snapshot of the Isolate. | 410 // Writes a full snapshot of the Isolate. |
| 408 void WriteFullSnapshot(); | 411 void WriteFullSnapshot(); |
| 409 | 412 |
| 410 intptr_t VmIsolateSnapshotSize() const { return vm_isolate_snapshot_size_; } | 413 intptr_t VmIsolateSnapshotSize() const { return vm_isolate_snapshot_size_; } |
| 411 intptr_t IsolateSnapshotSize() const { return isolate_snapshot_size_; } | 414 intptr_t IsolateSnapshotSize() const { return isolate_snapshot_size_; } |
| 412 | 415 |
| 413 private: | 416 private: |
| 414 // Writes a snapshot of the VM Isolate. | 417 // Writes a snapshot of the VM Isolate. |
| 415 intptr_t WriteVmIsolateSnapshot(); | 418 intptr_t WriteVMSnapshot(); |
| 416 | 419 |
| 417 // Writes a full snapshot of a regular Dart Isolate. | 420 // Writes a full snapshot of a regular Dart Isolate. |
| 418 void WriteIsolateFullSnapshot(intptr_t num_base_objects); | 421 void WriteIsolateSnapshot(intptr_t num_base_objects); |
| 419 | 422 |
| 420 Thread* thread_; | 423 Thread* thread_; |
| 421 Snapshot::Kind kind_; | 424 Snapshot::Kind kind_; |
| 422 uint8_t** vm_isolate_snapshot_buffer_; | 425 uint8_t** vm_snapshot_data_buffer_; |
| 423 uint8_t** isolate_snapshot_buffer_; | 426 uint8_t** isolate_snapshot_data_buffer_; |
| 424 ReAlloc alloc_; | 427 ReAlloc alloc_; |
| 425 intptr_t vm_isolate_snapshot_size_; | 428 intptr_t vm_isolate_snapshot_size_; |
| 426 intptr_t isolate_snapshot_size_; | 429 intptr_t isolate_snapshot_size_; |
| 427 ForwardList* forward_list_; | 430 ForwardList* forward_list_; |
| 428 InstructionsWriter* instructions_writer_; | 431 InstructionsWriter* vm_instructions_writer_; |
| 432 InstructionsWriter* isolate_instructions_writer_; |
| 429 Array& token_streams_; | 433 Array& token_streams_; |
| 430 Array& saved_symbol_table_; | 434 Array& saved_symbol_table_; |
| 431 Array& new_vm_symbol_table_; | 435 Array& new_vm_symbol_table_; |
| 432 | 436 |
| 437 // Stats for benchmarking. |
| 438 intptr_t clustered_vm_size_; |
| 439 intptr_t clustered_isolate_size_; |
| 440 intptr_t mapped_data_size_; |
| 441 intptr_t mapped_instructions_size_; |
| 442 |
| 433 DISALLOW_COPY_AND_ASSIGN(FullSnapshotWriter); | 443 DISALLOW_COPY_AND_ASSIGN(FullSnapshotWriter); |
| 434 }; | 444 }; |
| 435 | 445 |
| 436 | 446 |
| 437 class VmIsolateSnapshotReader { | 447 class FullSnapshotReader { |
| 438 public: | 448 public: |
| 439 VmIsolateSnapshotReader(Snapshot::Kind kind, | 449 FullSnapshotReader(const Snapshot* snapshot, |
| 440 const uint8_t* buffer, | 450 const uint8_t* instructions_buffer, |
| 441 intptr_t size, | 451 Thread* thread); |
| 442 const uint8_t* instructions_buffer, | 452 ~FullSnapshotReader() {} |
| 443 const uint8_t* data_buffer, | |
| 444 Thread* thread) | |
| 445 : kind_(kind), | |
| 446 thread_(thread), | |
| 447 buffer_(buffer), | |
| 448 size_(size), | |
| 449 instructions_buffer_(instructions_buffer), | |
| 450 data_buffer_(data_buffer) { | |
| 451 thread->isolate()->set_compilation_allowed(kind != Snapshot::kAppAOT); | |
| 452 } | |
| 453 | 453 |
| 454 ~VmIsolateSnapshotReader() {} | 454 RawApiError* ReadVMSnapshot(); |
| 455 | 455 RawApiError* ReadIsolateSnapshot(); |
| 456 RawApiError* ReadVmIsolateSnapshot(); | |
| 457 | 456 |
| 458 private: | 457 private: |
| 459 Snapshot::Kind kind_; | 458 Snapshot::Kind kind_; |
| 460 Thread* thread_; | |
| 461 const uint8_t* buffer_; | |
| 462 intptr_t size_; | |
| 463 const uint8_t* instructions_buffer_; | |
| 464 const uint8_t* data_buffer_; | |
| 465 | |
| 466 DISALLOW_COPY_AND_ASSIGN(VmIsolateSnapshotReader); | |
| 467 }; | |
| 468 | |
| 469 | |
| 470 class IsolateSnapshotReader { | |
| 471 public: | |
| 472 IsolateSnapshotReader(Snapshot::Kind kind, | |
| 473 const uint8_t* buffer, | |
| 474 intptr_t size, | |
| 475 const uint8_t* instructions_buffer, | |
| 476 const uint8_t* data_buffer, | |
| 477 Thread* thread) | |
| 478 : kind_(kind), | |
| 479 thread_(thread), | |
| 480 buffer_(buffer), | |
| 481 size_(size), | |
| 482 instructions_buffer_(instructions_buffer), | |
| 483 data_buffer_(data_buffer) { | |
| 484 thread->isolate()->set_compilation_allowed(kind != Snapshot::kAppAOT); | |
| 485 } | |
| 486 | |
| 487 ~IsolateSnapshotReader() {} | |
| 488 | |
| 489 RawApiError* ReadFullSnapshot(); | |
| 490 | |
| 491 private: | |
| 492 Snapshot::Kind kind_; | |
| 493 Thread* thread_; | 459 Thread* thread_; |
| 494 const uint8_t* buffer_; | 460 const uint8_t* buffer_; |
| 495 intptr_t size_; | 461 intptr_t size_; |
| 496 const uint8_t* instructions_buffer_; | 462 const uint8_t* instructions_buffer_; |
| 497 const uint8_t* data_buffer_; | 463 const uint8_t* data_buffer_; |
| 498 | 464 |
| 499 DISALLOW_COPY_AND_ASSIGN(IsolateSnapshotReader); | 465 DISALLOW_COPY_AND_ASSIGN(FullSnapshotReader); |
| 500 }; | 466 }; |
| 501 | 467 |
| 502 } // namespace dart | 468 } // namespace dart |
| 503 | 469 |
| 504 #endif // RUNTIME_VM_CLUSTERED_SNAPSHOT_H_ | 470 #endif // RUNTIME_VM_CLUSTERED_SNAPSHOT_H_ |
| OLD | NEW |