Chromium Code Reviews| 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" |
| 11 #include "vm/datastream.h" | 11 #include "vm/datastream.h" |
| 12 #include "vm/exceptions.h" | 12 #include "vm/exceptions.h" |
| 13 #include "vm/globals.h" | 13 #include "vm/globals.h" |
| 14 #include "vm/growable_array.h" | 14 #include "vm/growable_array.h" |
| 15 #include "vm/hash_map.h" | 15 #include "vm/hash_map.h" |
| 16 #include "vm/heap.h" | 16 #include "vm/heap.h" |
| 17 #include "vm/isolate.h" | 17 #include "vm/isolate.h" |
| 18 #include "vm/object.h" | 18 #include "vm/object.h" |
| 19 #include "vm/snapshot.h" | 19 #include "vm/snapshot.h" |
| 20 #include "vm/version.h" | 20 #include "vm/version.h" |
| 21 #include "vm/visitor.h" | 21 #include "vm/visitor.h" |
| 22 | 22 |
| 23 #if defined(DEBUG) | |
| 24 #define SNAPSHOT_BACKTRACE | |
| 25 #endif | |
|
siva
2017/04/18 21:17:58
If this is going to be always on when DEBUG is def
| |
| 26 | |
| 23 namespace dart { | 27 namespace dart { |
| 24 | 28 |
| 25 // Forward declarations. | 29 // Forward declarations. |
| 26 class Serializer; | 30 class Serializer; |
| 27 class Deserializer; | 31 class Deserializer; |
| 28 class ObjectStore; | 32 class ObjectStore; |
| 29 | 33 |
| 30 // For full snapshots, we use a clustered snapshot format that trades longer | 34 // For full snapshots, we use a clustered snapshot format that trades longer |
| 31 // serialization time for faster deserialization time and smaller snapshots. | 35 // serialization time for faster deserialization time and smaller snapshots. |
| 32 // Objects are clustered by class to allow writing type information once per | 36 // Objects are clustered by class to allow writing type information once per |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 147 } else { | 151 } else { |
| 148 SmiObjectIdPair new_pair; | 152 SmiObjectIdPair new_pair; |
| 149 new_pair.smi_ = smi; | 153 new_pair.smi_ = smi; |
| 150 new_pair.id_ = next_ref_index_; | 154 new_pair.id_ = next_ref_index_; |
| 151 smi_ids_.Insert(new_pair); | 155 smi_ids_.Insert(new_pair); |
| 152 } | 156 } |
| 153 } | 157 } |
| 154 next_ref_index_++; | 158 next_ref_index_++; |
| 155 } | 159 } |
| 156 | 160 |
| 157 void Push(RawObject* object) { | 161 void Push(RawObject* object); |
| 158 if (!object->IsHeapObject()) { | |
| 159 RawSmi* smi = Smi::RawCast(object); | |
| 160 if (smi_ids_.Lookup(smi) == NULL) { | |
| 161 SmiObjectIdPair pair; | |
| 162 pair.smi_ = smi; | |
| 163 pair.id_ = 1; | |
| 164 smi_ids_.Insert(pair); | |
| 165 stack_.Add(object); | |
| 166 num_written_objects_++; | |
| 167 } | |
| 168 return; | |
| 169 } | |
| 170 | |
| 171 if (object->IsCode() && !Snapshot::IncludesCode(kind_)) { | |
| 172 return; // Do not trace, will write null. | |
| 173 } | |
| 174 | |
| 175 if (object->IsSendPort()) { | |
| 176 // TODO(rmacnak): Do a better job of resetting fields in precompilation | |
| 177 // and assert this is unreachable. | |
| 178 return; // Do not trace, will write null. | |
| 179 } | |
| 180 | |
| 181 intptr_t id = heap_->GetObjectId(object); | |
| 182 if (id == 0) { | |
| 183 heap_->SetObjectId(object, 1); | |
| 184 ASSERT(heap_->GetObjectId(object) != 0); | |
| 185 stack_.Add(object); | |
| 186 num_written_objects_++; | |
| 187 } | |
| 188 } | |
| 189 | 162 |
| 190 void AddUntracedRef() { num_written_objects_++; } | 163 void AddUntracedRef() { num_written_objects_++; } |
| 191 | 164 |
| 192 void Trace(RawObject* object); | 165 void Trace(RawObject* object); |
| 193 | 166 |
| 167 void UnexpectedObject(RawObject* object, const char* message); | |
| 168 #if defined(SNAPSHOT_BACKTRACE) | |
| 169 RawObject* ParentOf(const Object& object); | |
| 170 #endif | |
| 171 | |
| 194 SerializationCluster* NewClusterForClass(intptr_t cid); | 172 SerializationCluster* NewClusterForClass(intptr_t cid); |
| 195 | 173 |
| 196 void ReserveHeader() { | 174 void ReserveHeader() { |
| 197 // Make room for recording snapshot buffer size. | 175 // Make room for recording snapshot buffer size. |
| 198 stream_.set_current(stream_.buffer() + Snapshot::kHeaderSize); | 176 stream_.set_current(stream_.buffer() + Snapshot::kHeaderSize); |
| 199 } | 177 } |
| 200 | 178 |
| 201 void FillHeader(Snapshot::Kind kind) { | 179 void FillHeader(Snapshot::Kind kind) { |
| 202 int64_t* data = reinterpret_cast<int64_t*>(stream_.buffer()); | 180 int64_t* data = reinterpret_cast<int64_t*>(stream_.buffer()); |
| 203 data[Snapshot::kLengthIndex] = stream_.bytes_written(); | 181 data[Snapshot::kLengthIndex] = stream_.bytes_written(); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 275 WriteStream stream_; | 253 WriteStream stream_; |
| 276 ImageWriter* image_writer_; | 254 ImageWriter* image_writer_; |
| 277 SerializationCluster** clusters_by_cid_; | 255 SerializationCluster** clusters_by_cid_; |
| 278 GrowableArray<RawObject*> stack_; | 256 GrowableArray<RawObject*> stack_; |
| 279 intptr_t num_cids_; | 257 intptr_t num_cids_; |
| 280 intptr_t num_base_objects_; | 258 intptr_t num_base_objects_; |
| 281 intptr_t num_written_objects_; | 259 intptr_t num_written_objects_; |
| 282 intptr_t next_ref_index_; | 260 intptr_t next_ref_index_; |
| 283 SmiObjectIdMap smi_ids_; | 261 SmiObjectIdMap smi_ids_; |
| 284 | 262 |
| 263 #if defined(SNAPSHOT_BACKTRACE) | |
| 264 RawObject* current_parent_; | |
| 265 GrowableArray<Object*> parent_pairs_; | |
| 266 #endif | |
| 267 | |
| 285 DISALLOW_IMPLICIT_CONSTRUCTORS(Serializer); | 268 DISALLOW_IMPLICIT_CONSTRUCTORS(Serializer); |
| 286 }; | 269 }; |
| 287 | 270 |
| 288 | 271 |
| 289 class Deserializer : public StackResource { | 272 class Deserializer : public StackResource { |
| 290 public: | 273 public: |
| 291 Deserializer(Thread* thread, | 274 Deserializer(Thread* thread, |
| 292 Snapshot::Kind kind, | 275 Snapshot::Kind kind, |
| 293 const uint8_t* buffer, | 276 const uint8_t* buffer, |
| 294 intptr_t size, | 277 intptr_t size, |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 462 intptr_t size_; | 445 intptr_t size_; |
| 463 const uint8_t* instructions_buffer_; | 446 const uint8_t* instructions_buffer_; |
| 464 const uint8_t* data_buffer_; | 447 const uint8_t* data_buffer_; |
| 465 | 448 |
| 466 DISALLOW_COPY_AND_ASSIGN(FullSnapshotReader); | 449 DISALLOW_COPY_AND_ASSIGN(FullSnapshotReader); |
| 467 }; | 450 }; |
| 468 | 451 |
| 469 } // namespace dart | 452 } // namespace dart |
| 470 | 453 |
| 471 #endif // RUNTIME_VM_CLUSTERED_SNAPSHOT_H_ | 454 #endif // RUNTIME_VM_CLUSTERED_SNAPSHOT_H_ |
| OLD | NEW |