Chromium Code Reviews| 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 VM_SNAPSHOT_H_ | 5 #ifndef VM_SNAPSHOT_H_ |
| 6 #define VM_SNAPSHOT_H_ | 6 #define 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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 122 // header anymore. This is pending on making the embedder pass in the | 122 // header anymore. This is pending on making the embedder pass in the |
| 123 // length of their snapshot. | 123 // length of their snapshot. |
| 124 class Snapshot { | 124 class Snapshot { |
| 125 public: | 125 public: |
| 126 enum Kind { | 126 enum Kind { |
| 127 kFull = 0, // Full snapshot of the current dart heap. | 127 kFull = 0, // Full snapshot of the current dart heap. |
| 128 kScript, // A partial snapshot of only the application script. | 128 kScript, // A partial snapshot of only the application script. |
| 129 kMessage, // A partial snapshot used only for isolate messaging. | 129 kMessage, // A partial snapshot used only for isolate messaging. |
| 130 }; | 130 }; |
| 131 | 131 |
| 132 static const int kHeaderSize = 2 * sizeof(int32_t); | 132 static const int kHeaderSize = 2 * sizeof(int64_t); |
|
Anders Johnsen
2014/02/18 10:02:34
this will assign a size_t to int?
| |
| 133 static const int kLengthIndex = 0; | 133 static const int kLengthIndex = 0; |
| 134 static const int kSnapshotFlagIndex = 1; | 134 static const int kSnapshotFlagIndex = 1; |
| 135 | 135 |
| 136 static const Snapshot* SetupFromBuffer(const void* raw_memory); | 136 static const Snapshot* SetupFromBuffer(const void* raw_memory); |
| 137 | 137 |
| 138 // Getters. | 138 // Getters. |
| 139 const uint8_t* content() const { return content_; } | 139 const uint8_t* content() const { return content_; } |
| 140 int32_t length() const { return length_; } | 140 int64_t length() const { return length_; } |
| 141 Kind kind() const { return static_cast<Kind>(kind_); } | 141 Kind kind() const { return static_cast<Kind>(kind_); } |
| 142 | 142 |
| 143 bool IsMessageSnapshot() const { return kind_ == kMessage; } | 143 bool IsMessageSnapshot() const { return kind_ == kMessage; } |
| 144 bool IsScriptSnapshot() const { return kind_ == kScript; } | 144 bool IsScriptSnapshot() const { return kind_ == kScript; } |
| 145 bool IsFullSnapshot() const { return kind_ == kFull; } | 145 bool IsFullSnapshot() const { return kind_ == kFull; } |
| 146 uint8_t* Addr() { return reinterpret_cast<uint8_t*>(this); } | 146 uint8_t* Addr() { return reinterpret_cast<uint8_t*>(this); } |
| 147 | 147 |
| 148 static intptr_t length_offset() { return OFFSET_OF(Snapshot, length_); } | 148 static intptr_t length_offset() { return OFFSET_OF(Snapshot, length_); } |
| 149 static intptr_t kind_offset() { | 149 static intptr_t kind_offset() { |
| 150 return OFFSET_OF(Snapshot, kind_); | 150 return OFFSET_OF(Snapshot, kind_); |
| 151 } | 151 } |
| 152 | 152 |
| 153 private: | 153 private: |
| 154 Snapshot() : length_(0), kind_(kFull) {} | 154 Snapshot() : length_(0), kind_(kFull) {} |
| 155 | 155 |
| 156 int32_t length_; // Stream length. | 156 int64_t length_; // Stream length. |
| 157 int32_t kind_; // Kind of snapshot. | 157 int64_t kind_; // Kind of snapshot. |
|
Anders Johnsen
2014/02/18 10:02:34
Why is kind int64?
Ivan Posva
2014/02/19 04:04:23
So that it is easier to deal with and that you do
| |
| 158 uint8_t content_[]; // Stream content. | 158 uint8_t content_[]; // Stream content. |
| 159 | 159 |
| 160 DISALLOW_COPY_AND_ASSIGN(Snapshot); | 160 DISALLOW_COPY_AND_ASSIGN(Snapshot); |
| 161 }; | 161 }; |
| 162 | 162 |
| 163 | 163 |
| 164 class BaseReader { | 164 class BaseReader { |
| 165 public: | 165 public: |
| 166 BaseReader(const uint8_t* buffer, intptr_t size) : stream_(buffer, size) {} | 166 BaseReader(const uint8_t* buffer, intptr_t size) : stream_(buffer, size) {} |
| 167 // Reads raw data (for basic types). | 167 // Reads raw data (for basic types). |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 429 ASSERT(alloc != NULL); | 429 ASSERT(alloc != NULL); |
| 430 } | 430 } |
| 431 ~BaseWriter() { } | 431 ~BaseWriter() { } |
| 432 | 432 |
| 433 void ReserveHeader() { | 433 void ReserveHeader() { |
| 434 // Make room for recording snapshot buffer size. | 434 // Make room for recording snapshot buffer size. |
| 435 stream_.set_current(stream_.buffer() + Snapshot::kHeaderSize); | 435 stream_.set_current(stream_.buffer() + Snapshot::kHeaderSize); |
| 436 } | 436 } |
| 437 | 437 |
| 438 void FillHeader(Snapshot::Kind kind) { | 438 void FillHeader(Snapshot::Kind kind) { |
| 439 int32_t* data = reinterpret_cast<int32_t*>(stream_.buffer()); | 439 int64_t* data = reinterpret_cast<int64_t*>(stream_.buffer()); |
| 440 data[Snapshot::kLengthIndex] = stream_.bytes_written(); | 440 data[Snapshot::kLengthIndex] = stream_.bytes_written(); |
| 441 data[Snapshot::kSnapshotFlagIndex] = kind; | 441 data[Snapshot::kSnapshotFlagIndex] = kind; |
| 442 } | 442 } |
| 443 | 443 |
| 444 private: | 444 private: |
| 445 WriteStream stream_; | 445 WriteStream stream_; |
| 446 | 446 |
| 447 DISALLOW_IMPLICIT_CONSTRUCTORS(BaseWriter); | 447 DISALLOW_IMPLICIT_CONSTRUCTORS(BaseWriter); |
| 448 }; | 448 }; |
| 449 | 449 |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 619 private: | 619 private: |
| 620 SnapshotWriter* writer_; | 620 SnapshotWriter* writer_; |
| 621 bool as_references_; | 621 bool as_references_; |
| 622 | 622 |
| 623 DISALLOW_COPY_AND_ASSIGN(SnapshotWriterVisitor); | 623 DISALLOW_COPY_AND_ASSIGN(SnapshotWriterVisitor); |
| 624 }; | 624 }; |
| 625 | 625 |
| 626 } // namespace dart | 626 } // namespace dart |
| 627 | 627 |
| 628 #endif // VM_SNAPSHOT_H_ | 628 #endif // VM_SNAPSHOT_H_ |
| OLD | NEW |