Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(236)

Side by Side Diff: runtime/vm/snapshot.h

Issue 1255003004: Implement patch records to patch canonical objects. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: merged-to-tot Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 // This valus is serialized as a positive number. 90 // This valus is serialized as a positive number.
91 // - Object that is seen for the first time (inlined in the stream): 91 // - Object that is seen for the first time (inlined in the stream):
92 // (a unique id for this object | 0x1) 92 // (a unique id for this object | 0x1)
93 enum SerializedHeaderType { 93 enum SerializedHeaderType {
94 kInlined = 0x1, 94 kInlined = 0x1,
95 kObjectId = 0x3, 95 kObjectId = 0x3,
96 }; 96 };
97 static const int8_t kHeaderTagBits = 2; 97 static const int8_t kHeaderTagBits = 2;
98 static const int8_t kObjectIdBits = (kBitsPerInt32 - (kHeaderTagBits + 1)); 98 static const int8_t kObjectIdBits = (kBitsPerInt32 - (kHeaderTagBits + 1));
99 static const intptr_t kMaxObjectId = (kMaxUint32 >> (kHeaderTagBits + 1)); 99 static const intptr_t kMaxObjectId = (kMaxUint32 >> (kHeaderTagBits + 1));
100 static const intptr_t kInvalidPatchIndex = -1;
100 101
101 102
102 class SerializedHeaderTag : public BitField<enum SerializedHeaderType, 103 class SerializedHeaderTag : public BitField<enum SerializedHeaderType,
103 0, 104 0,
104 kHeaderTagBits> { 105 kHeaderTagBits> {
105 }; 106 };
106 107
107 108
108 class SerializedHeaderData : public BitField<intptr_t, 109 class SerializedHeaderData : public BitField<intptr_t,
109 kHeaderTagBits, 110 kHeaderTagBits,
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 return SerializedHeaderData::decode(value); 242 return SerializedHeaderData::decode(value);
242 } 243 }
243 244
244 private: 245 private:
245 ReadStream stream_; // input stream. 246 ReadStream stream_; // input stream.
246 }; 247 };
247 248
248 249
249 class BackRefNode : public ValueObject { 250 class BackRefNode : public ValueObject {
250 public: 251 public:
251 BackRefNode(Object* reference, DeserializeState state) 252 BackRefNode(Object* reference,
252 : reference_(reference), state_(state) {} 253 DeserializeState state,
254 bool defer_canonicalization)
255 : reference_(reference),
256 state_(state),
257 defer_canonicalization_(defer_canonicalization),
258 patch_records_(NULL) {}
253 Object* reference() const { return reference_; } 259 Object* reference() const { return reference_; }
254 bool is_deserialized() const { return state_ == kIsDeserialized; } 260 bool is_deserialized() const { return state_ == kIsDeserialized; }
255 void set_state(DeserializeState state) { state_ = state; } 261 void set_state(DeserializeState state) { state_ = state; }
262 bool defer_canonicalization() const { return defer_canonicalization_; }
263 ZoneGrowableArray<intptr_t>* patch_records() const { return patch_records_; }
256 264
257 BackRefNode& operator=(const BackRefNode& other) { 265 BackRefNode& operator=(const BackRefNode& other) {
258 reference_ = other.reference_; 266 reference_ = other.reference_;
259 state_ = other.state_; 267 state_ = other.state_;
268 defer_canonicalization_ = other.defer_canonicalization_;
269 patch_records_ = other.patch_records_;
260 return *this; 270 return *this;
261 } 271 }
262 272
273 void AddPatchRecord(intptr_t patch_object_id, intptr_t patch_offset) {
274 if (defer_canonicalization_) {
275 if (patch_records_ == NULL) {
276 patch_records_ = new ZoneGrowableArray<intptr_t>();
277 }
278 patch_records_->Add(patch_object_id);
279 patch_records_->Add(patch_offset);
280 }
281 }
282
263 private: 283 private:
264 Object* reference_; 284 Object* reference_;
265 DeserializeState state_; 285 DeserializeState state_;
286 bool defer_canonicalization_;
287 ZoneGrowableArray<intptr_t>* patch_records_;
266 }; 288 };
267 289
268 290
269 // Reads a snapshot into objects. 291 // Reads a snapshot into objects.
270 class SnapshotReader : public BaseReader { 292 class SnapshotReader : public BaseReader {
271 public: 293 public:
272 Zone* zone() const { return zone_; } 294 Zone* zone() const { return zone_; }
273 Isolate* isolate() const { return isolate_; } 295 Isolate* isolate() const { return isolate_; }
274 Heap* heap() const { return heap_; } 296 Heap* heap() const { return heap_; }
275 ObjectStore* object_store() const { return isolate_->object_store(); } 297 ObjectStore* object_store() const { return isolate_->object_store(); }
276 ClassTable* class_table() const { return isolate_->class_table(); } 298 ClassTable* class_table() const { return isolate_->class_table(); }
277 PassiveObject* PassiveObjectHandle() { return &pobj_; } 299 PassiveObject* PassiveObjectHandle() { return &pobj_; }
278 Array* ArrayHandle() { return &array_; } 300 Array* ArrayHandle() { return &array_; }
279 String* StringHandle() { return &str_; } 301 String* StringHandle() { return &str_; }
280 AbstractType* TypeHandle() { return &type_; } 302 AbstractType* TypeHandle() { return &type_; }
281 TypeArguments* TypeArgumentsHandle() { return &type_arguments_; } 303 TypeArguments* TypeArgumentsHandle() { return &type_arguments_; }
282 Array* TokensHandle() { return &tokens_; } 304 Array* TokensHandle() { return &tokens_; }
283 TokenStream* StreamHandle() { return &stream_; } 305 TokenStream* StreamHandle() { return &stream_; }
284 ExternalTypedData* DataHandle() { return &data_; } 306 ExternalTypedData* DataHandle() { return &data_; }
285 TypedData* TypedDataHandle() { return &typed_data_; } 307 TypedData* TypedDataHandle() { return &typed_data_; }
286 Snapshot::Kind kind() const { return kind_; } 308 Snapshot::Kind kind() const { return kind_; }
287 bool allow_code() const { return false; } 309 bool allow_code() const { return false; }
288 310
289 // Reads an object. 311 // Reads an object.
290 RawObject* ReadObject(); 312 RawObject* ReadObject();
291 313
292 // Add object to backward references. 314 // Add object to backward references.
293 void AddBackRef(intptr_t id, Object* obj, DeserializeState state); 315 void AddBackRef(intptr_t id,
316 Object* obj,
317 DeserializeState state,
318 bool defer_canonicalization = false);
294 319
295 // Get an object from the backward references list. 320 // Get an object from the backward references list.
296 Object* GetBackRef(intptr_t id); 321 Object* GetBackRef(intptr_t id);
297 322
298 // Read a full snap shot. 323 // Read a full snap shot.
299 RawApiError* ReadFullSnapshot(); 324 RawApiError* ReadFullSnapshot();
300 325
301 // Read a script snap shot. 326 // Read a script snap shot.
302 RawObject* ReadScriptSnapshot(); 327 RawObject* ReadScriptSnapshot();
303 328
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 } 385 }
361 void ResetBackwardReferenceTable() { backward_references_ = NULL; } 386 void ResetBackwardReferenceTable() { backward_references_ = NULL; }
362 PageSpace* old_space() const { return old_space_; } 387 PageSpace* old_space() const { return old_space_; }
363 388
364 private: 389 private:
365 // Allocate uninitialized objects, this is used when reading a full snapshot. 390 // Allocate uninitialized objects, this is used when reading a full snapshot.
366 RawObject* AllocateUninitialized(intptr_t class_id, intptr_t size); 391 RawObject* AllocateUninitialized(intptr_t class_id, intptr_t size);
367 392
368 RawClass* ReadClassId(intptr_t object_id); 393 RawClass* ReadClassId(intptr_t object_id);
369 RawObject* ReadStaticImplicitClosure(intptr_t object_id, intptr_t cls_header); 394 RawObject* ReadStaticImplicitClosure(intptr_t object_id, intptr_t cls_header);
370 RawObject* ReadObjectImpl(); 395 RawObject* ReadObjectImpl(intptr_t patch_object_id = kInvalidPatchIndex,
371 RawObject* ReadObjectImpl(intptr_t header); 396 intptr_t patch_offset = 0);
372 RawObject* ReadObjectRef(); 397 RawObject* ReadObjectImpl(intptr_t header,
398 intptr_t patch_object_id,
399 intptr_t patch_offset);
400 RawObject* ReadObjectRef(intptr_t patch_object_id = kInvalidPatchIndex,
401 intptr_t patch_offset = 0);
373 402
374 // Read a VM isolate object that was serialized as an Id. 403 // Read a VM isolate object that was serialized as an Id.
375 RawObject* ReadVMIsolateObject(intptr_t object_id); 404 RawObject* ReadVMIsolateObject(intptr_t object_id);
376 405
377 // Read an object that was serialized as an Id (singleton in object store, 406 // Read an object that was serialized as an Id (singleton in object store,
378 // or an object that was already serialized before). 407 // or an object that was already serialized before).
379 RawObject* ReadIndexedObject(intptr_t object_id); 408 RawObject* ReadIndexedObject(intptr_t object_id,
409 intptr_t patch_object_id,
410 intptr_t patch_offset);
380 411
381 // Read an inlined object from the stream. 412 // Read an inlined object from the stream.
382 RawObject* ReadInlinedObject(intptr_t object_id); 413 RawObject* ReadInlinedObject(intptr_t object_id,
414 intptr_t patch_object_id,
415 intptr_t patch_offset);
416
417 // Add a patch record for the object so that objects whose canonicalization
418 // is deferred can be back patched after they are canonicalized.
419 void AddPatchRecord(intptr_t object_id,
420 intptr_t patch_object_id,
421 intptr_t patch_offset);
422
423 // Process all the deferred canonicalization entries and patch all references.
424 void ProcessDeferredCanonicalizations();
383 425
384 // Decode class id from the header field. 426 // Decode class id from the header field.
385 intptr_t LookupInternalClass(intptr_t class_header); 427 intptr_t LookupInternalClass(intptr_t class_header);
386 428
387 void ArrayReadFrom(const Array& result, intptr_t len, intptr_t tags); 429 void ArrayReadFrom(intptr_t object_id,
430 const Array& result,
431 intptr_t len,
432 intptr_t tags);
388 433
389 intptr_t NextAvailableObjectId() const; 434 intptr_t NextAvailableObjectId() const;
390 435
391 void SetReadException(const char* msg); 436 void SetReadException(const char* msg);
392 437
393 RawObject* VmIsolateSnapshotObject(intptr_t index) const; 438 RawObject* VmIsolateSnapshotObject(intptr_t index) const;
394 439
395 Snapshot::Kind kind_; // Indicates type of snapshot(full, script, message). 440 Snapshot::Kind kind_; // Indicates type of snapshot(full, script, message).
396 Isolate* isolate_; // Current isolate. 441 Isolate* isolate_; // Current isolate.
397 Zone* zone_; // Zone for allocations while reading snapshot. 442 Zone* zone_; // Zone for allocations while reading snapshot.
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after
874 private: 919 private:
875 SnapshotWriter* writer_; 920 SnapshotWriter* writer_;
876 bool as_references_; 921 bool as_references_;
877 922
878 DISALLOW_COPY_AND_ASSIGN(SnapshotWriterVisitor); 923 DISALLOW_COPY_AND_ASSIGN(SnapshotWriterVisitor);
879 }; 924 };
880 925
881 } // namespace dart 926 } // namespace dart
882 927
883 #endif // VM_SNAPSHOT_H_ 928 #endif // VM_SNAPSHOT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698