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

Side by Side Diff: vm/snapshot.h

Issue 10535066: 1. Remove recursion during snapshot writing and reading (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 6 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 | Annotate | Revision Log
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"
11 #include "vm/globals.h" 11 #include "vm/globals.h"
12 #include "vm/growable_array.h" 12 #include "vm/growable_array.h"
13 #include "vm/isolate.h" 13 #include "vm/isolate.h"
14 #include "vm/visitor.h" 14 #include "vm/visitor.h"
15 15
16 namespace dart { 16 namespace dart {
17 17
18 // Forward declarations. 18 // Forward declarations.
19 class AbstractType; 19 class AbstractType;
20 class AbstractTypeArguments; 20 class AbstractTypeArguments;
21 class Array;
21 class Class; 22 class Class;
22 class Heap; 23 class Heap;
23 class Library; 24 class Library;
24 class Object; 25 class Object;
25 class ObjectStore; 26 class ObjectStore;
27 class RawAbstractTypeArguments;
26 class RawArray; 28 class RawArray;
27 class RawBigint; 29 class RawBigint;
28 class RawClass; 30 class RawClass;
29 class RawContext; 31 class RawContext;
30 class RawDouble; 32 class RawDouble;
31 class RawField; 33 class RawField;
32 class RawFourByteString; 34 class RawFourByteString;
33 class RawFunction; 35 class RawFunction;
34 class RawGrowableObjectArray; 36 class RawGrowableObjectArray;
35 class RawImmutableArray; 37 class RawImmutableArray;
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 Heap* heap() const { return isolate_->heap(); } 350 Heap* heap() const { return isolate_->heap(); }
349 ObjectStore* object_store() const { return isolate_->object_store(); } 351 ObjectStore* object_store() const { return isolate_->object_store(); }
350 Object* ObjectHandle() { return &obj_; } 352 Object* ObjectHandle() { return &obj_; }
351 String* StringHandle() { return &str_; } 353 String* StringHandle() { return &str_; }
352 AbstractType* TypeHandle() { return &type_; } 354 AbstractType* TypeHandle() { return &type_; }
353 AbstractTypeArguments* TypeArgumentsHandle() { return &type_arguments_; } 355 AbstractTypeArguments* TypeArgumentsHandle() { return &type_arguments_; }
354 356
355 // Reads an object. 357 // Reads an object.
356 RawObject* ReadObject(); 358 RawObject* ReadObject();
357 359
358 RawClass* ReadClassId(intptr_t object_id); 360 // Add object to backward references.
361 void AddBackwardReference(intptr_t id, Object* obj, bool is_deserialized);
cshapiro 2012/06/08 22:04:39 Can we make this an enum instead of a bool?
siva 2012/06/11 20:49:06 Done.
359 362
360 // Add object to backward references. 363 // Get an object from the backward references list.
361 void AddBackwardReference(intptr_t id, Object* obj); 364 Object* GetBackwardReference(intptr_t id);
362 365
363 // Read a full snap shot. 366 // Read a full snap shot.
364 void ReadFullSnapshot(); 367 void ReadFullSnapshot();
365 368
366 // Helper functions for creating uninitialized versions 369 // Helper functions for creating uninitialized versions
367 // of various object types. These are used when reading a 370 // of various object types. These are used when reading a
368 // full snapshot. 371 // full snapshot.
369 RawArray* NewArray(intptr_t len); 372 RawArray* NewArray(intptr_t len);
370 RawImmutableArray* NewImmutableArray(intptr_t len); 373 RawImmutableArray* NewImmutableArray(intptr_t len);
371 RawOneByteString* NewOneByteString(intptr_t len); 374 RawOneByteString* NewOneByteString(intptr_t len);
(...skipping 11 matching lines...) Expand all
383 RawTypeParameter* NewTypeParameter(); 386 RawTypeParameter* NewTypeParameter();
384 RawFunction* NewFunction(); 387 RawFunction* NewFunction();
385 RawField* NewField(); 388 RawField* NewField();
386 RawLibrary* NewLibrary(); 389 RawLibrary* NewLibrary();
387 RawLibraryPrefix* NewLibraryPrefix(); 390 RawLibraryPrefix* NewLibraryPrefix();
388 RawScript* NewScript(); 391 RawScript* NewScript();
389 RawLiteralToken* NewLiteralToken(); 392 RawLiteralToken* NewLiteralToken();
390 RawGrowableObjectArray* NewGrowableObjectArray(); 393 RawGrowableObjectArray* NewGrowableObjectArray();
391 394
392 private: 395 private:
396 class BackwardReferenceNode : public ZoneAllocated {
397 public:
398 BackwardReferenceNode(Object* reference, bool is_deserialized)
cshapiro 2012/06/08 22:04:39 same here
siva 2012/06/11 20:49:06 Done.
399 : reference_(reference), is_deserialized_(is_deserialized) {}
400 Object* reference() const { return reference_; }
401 bool is_deserialized() const { return is_deserialized_; }
402 void set_is_deserialized(bool value) { is_deserialized_ = value; }
403
404 private:
405 Object* reference_;
406 bool is_deserialized_;
407
408 DISALLOW_COPY_AND_ASSIGN(BackwardReferenceNode);
409 };
410
393 // Allocate uninitialized objects, this is used when reading a full snapshot. 411 // Allocate uninitialized objects, this is used when reading a full snapshot.
394 RawObject* AllocateUninitialized(const Class& cls, intptr_t size); 412 RawObject* AllocateUninitialized(const Class& cls, intptr_t size);
395 413
396 // Internal implementation of ReadObject once the header value is read. 414 RawClass* ReadClassId(intptr_t object_id);
415 RawObject* ReadObjectImpl();
397 RawObject* ReadObjectImpl(intptr_t header); 416 RawObject* ReadObjectImpl(intptr_t header);
417 RawObject* ReadObjectRef();
398 418
399 // Read an object that was serialized as an Id (singleton, object store, 419 // Read an object that was serialized as an Id (singleton, object store,
400 // or an object that was already serialized before). 420 // or an object that was already serialized before).
401 RawObject* ReadIndexedObject(intptr_t object_id); 421 RawObject* ReadIndexedObject(intptr_t object_id);
402 422
403 // Read an inlined object from the stream. 423 // Read an inlined object from the stream.
404 RawObject* ReadInlinedObject(intptr_t object_id); 424 RawObject* ReadInlinedObject(intptr_t object_id);
405 425
406 // Based on header field check to see if it is an internal VM class. 426 // Based on header field check to see if it is an internal VM class.
407 RawClass* LookupInternalClass(intptr_t class_header); 427 RawClass* LookupInternalClass(intptr_t class_header);
408 428
429 void ArrayReadFrom(const Array& result, intptr_t len, intptr_t tags);
430
409 Snapshot::Kind kind_; // Indicates type of snapshot(full, script, message). 431 Snapshot::Kind kind_; // Indicates type of snapshot(full, script, message).
410 Isolate* isolate_; // Current isolate. 432 Isolate* isolate_; // Current isolate.
411 Class& cls_; // Temporary Class handle. 433 Class& cls_; // Temporary Class handle.
412 Object& obj_; // Temporary Object handle. 434 Object& obj_; // Temporary Object handle.
413 String& str_; // Temporary String handle. 435 String& str_; // Temporary String handle.
414 Library& library_; // Temporary library handle. 436 Library& library_; // Temporary library handle.
415 AbstractType& type_; // Temporary type handle. 437 AbstractType& type_; // Temporary type handle.
416 AbstractTypeArguments& type_arguments_; // Temporary type argument handle. 438 AbstractTypeArguments& type_arguments_; // Temporary type argument handle.
417 GrowableArray<Object*> backward_references_; 439 GrowableArray<BackwardReferenceNode*> backward_references_;
418 440
441 friend class Array;
442 friend class Class;
443 friend class Context;
444 friend class ContextScope;
445 friend class Field;
446 friend class Function;
447 friend class GrowableObjectArray;
448 friend class ImmutableArray;
449 friend class InstantiatedTypeArguments;
450 friend class JSRegExp;
451 friend class Library;
452 friend class LibraryPrefix;
453 friend class LiteralToken;
454 friend class Script;
455 friend class TokenStream;
456 friend class Type;
457 friend class TypeArguments;
458 friend class TypeParameter;
459 friend class UnresolvedClass;
419 DISALLOW_COPY_AND_ASSIGN(SnapshotReader); 460 DISALLOW_COPY_AND_ASSIGN(SnapshotReader);
420 }; 461 };
421 462
422 463
423 class BaseWriter { 464 class BaseWriter {
424 public: 465 public:
425 // Size of the snapshot. 466 // Size of the snapshot.
426 intptr_t BytesWritten() const { return stream_.bytes_written(); } 467 intptr_t BytesWritten() const { return stream_.bytes_written(); }
427 468
428 // Writes raw data to the stream (basic type). 469 // Writes raw data to the stream (basic type).
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 // which comprises of a flag(full/partial snaphot) and the length of 542 // which comprises of a flag(full/partial snaphot) and the length of
502 // serialzed bytes. 543 // serialzed bytes.
503 void FinalizeBuffer() { 544 void FinalizeBuffer() {
504 BaseWriter::FinalizeBuffer(kind_); 545 BaseWriter::FinalizeBuffer(kind_);
505 UnmarkAll(); 546 UnmarkAll();
506 } 547 }
507 548
508 // Serialize an object into the buffer. 549 // Serialize an object into the buffer.
509 void WriteObject(RawObject* raw); 550 void WriteObject(RawObject* raw);
510 551
511 void WriteClassId(RawClass* cls);
512
513 // Unmark all objects that were marked as forwarded for serializing.
514 void UnmarkAll();
515
516 // Writes a full snapshot of the Isolate. 552 // Writes a full snapshot of the Isolate.
517 void WriteFullSnapshot(); 553 void WriteFullSnapshot();
518 554
519 uword GetObjectTags(RawObject* raw); 555 uword GetObjectTags(RawObject* raw);
520 556
521 private: 557 private:
522 class ForwardObjectNode : public ZoneAllocated { 558 class ForwardObjectNode : public ZoneAllocated {
523 public: 559 public:
524 ForwardObjectNode(RawObject* raw, uword tags) : raw_(raw), tags_(tags) {} 560 ForwardObjectNode(RawObject* raw, uword tags, bool is_serialized)
cshapiro 2012/06/08 22:04:39 same here
siva 2012/06/11 20:49:06 Done.
561 : raw_(raw), tags_(tags), is_serialized_(is_serialized) {}
525 RawObject* raw() const { return raw_; } 562 RawObject* raw() const { return raw_; }
526 uword tags() const { return tags_; } 563 uword tags() const { return tags_; }
564 bool is_serialized() const { return is_serialized_; }
565 void set_is_serialized(bool value) { is_serialized_ = value; }
527 566
528 private: 567 private:
529 RawObject* raw_; 568 RawObject* raw_;
530 uword tags_; 569 uword tags_;
570 bool is_serialized_;
531 571
532 DISALLOW_COPY_AND_ASSIGN(ForwardObjectNode); 572 DISALLOW_COPY_AND_ASSIGN(ForwardObjectNode);
533 }; 573 };
534 574
535 intptr_t MarkObject(RawObject* raw); 575 intptr_t MarkObject(RawObject* raw, bool is_serialized);
cshapiro 2012/06/08 22:04:39 same here
siva 2012/06/11 20:49:06 Done.
576 void UnmarkAll();
536 577
537 bool CheckAndWritePredefinedObject(RawObject* raw); 578 bool CheckAndWritePredefinedObject(RawObject* raw);
538 579
580 void WriteObjectRef(RawObject* raw);
581 void WriteClassId(RawClass* cls);
582 void WriteObjectImpl(RawObject* raw);
539 void WriteInlinedObject(RawObject* raw); 583 void WriteInlinedObject(RawObject* raw);
584 void WriteForwardedObjects();
585 void ArrayWriteTo(intptr_t object_id,
586 intptr_t array_kind,
587 intptr_t tags,
588 RawSmi* length,
589 RawAbstractTypeArguments* type_arguments,
590 RawObject* data[]);
540 591
541 ObjectStore* object_store() const { return object_store_; } 592 ObjectStore* object_store() const { return object_store_; }
542 593
543 Snapshot::Kind kind_; 594 Snapshot::Kind kind_;
544 ObjectStore* object_store_; // Object store for common classes. 595 ObjectStore* object_store_; // Object store for common classes.
545 ClassTable* class_table_; // Class table for the class index to class lookup. 596 ClassTable* class_table_; // Class table for the class index to class lookup.
546 GrowableArray<ForwardObjectNode*> forward_list_; 597 GrowableArray<ForwardObjectNode*> forward_list_;
547 598
599 friend class RawArray;
600 friend class RawClass;
601 friend class RawGrowableObjectArray;
602 friend class RawImmutableArray;
603 friend class RawJSRegExp;
604 friend class RawLibrary;
605 friend class RawLiteralToken;
606 friend class RawScript;
607 friend class RawTokenStream;
608 friend class RawTypeArguments;
609 friend class SnapshotWriterVisitor;
548 DISALLOW_COPY_AND_ASSIGN(SnapshotWriter); 610 DISALLOW_COPY_AND_ASSIGN(SnapshotWriter);
549 }; 611 };
550 612
551 613
552 class ScriptSnapshotWriter : public SnapshotWriter { 614 class ScriptSnapshotWriter : public SnapshotWriter {
553 public: 615 public:
554 ScriptSnapshotWriter(uint8_t** buffer, ReAlloc alloc) 616 ScriptSnapshotWriter(uint8_t** buffer, ReAlloc alloc)
555 : SnapshotWriter(Snapshot::kScript, buffer, alloc) { 617 : SnapshotWriter(Snapshot::kScript, buffer, alloc) {
556 ASSERT(buffer != NULL); 618 ASSERT(buffer != NULL);
557 ASSERT(alloc != NULL); 619 ASSERT(alloc != NULL);
558 } 620 }
559 ~ScriptSnapshotWriter() { } 621 ~ScriptSnapshotWriter() { }
560 622
561 // Writes a partial snapshot of the script. 623 // Writes a partial snapshot of the script.
562 void WriteScriptSnapshot(const Library& lib); 624 void WriteScriptSnapshot(const Library& lib);
563 625
564 private: 626 private:
565 DISALLOW_COPY_AND_ASSIGN(ScriptSnapshotWriter); 627 DISALLOW_COPY_AND_ASSIGN(ScriptSnapshotWriter);
566 }; 628 };
567 629
568 630
569 // An object pointer visitor implementation which writes out 631 // An object pointer visitor implementation which writes out
570 // objects to a snap shot. 632 // objects to a snap shot.
571 class SnapshotWriterVisitor : public ObjectPointerVisitor { 633 class SnapshotWriterVisitor : public ObjectPointerVisitor {
572 public: 634 public:
573 explicit SnapshotWriterVisitor(SnapshotWriter* writer) 635 explicit SnapshotWriterVisitor(SnapshotWriter* writer)
574 : ObjectPointerVisitor(Isolate::Current()), writer_(writer) {} 636 : ObjectPointerVisitor(Isolate::Current()),
637 writer_(writer),
638 as_references_(true) {}
639
640 SnapshotWriterVisitor(SnapshotWriter* writer, bool as_references)
641 : ObjectPointerVisitor(Isolate::Current()),
642 writer_(writer),
643 as_references_(as_references) {}
575 644
576 virtual void VisitPointers(RawObject** first, RawObject** last); 645 virtual void VisitPointers(RawObject** first, RawObject** last);
577 646
578 private: 647 private:
579 SnapshotWriter* writer_; 648 SnapshotWriter* writer_;
649 bool as_references_;
580 650
581 DISALLOW_COPY_AND_ASSIGN(SnapshotWriterVisitor); 651 DISALLOW_COPY_AND_ASSIGN(SnapshotWriterVisitor);
582 }; 652 };
583 653
584 } // namespace dart 654 } // namespace dart
585 655
586 #endif // VM_SNAPSHOT_H_ 656 #endif // VM_SNAPSHOT_H_
OLDNEW
« vm/dart_api_message.cc ('K') | « vm/raw_object_snapshot.cc ('k') | vm/snapshot.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698