| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef V8_SERIALIZE_H_ | 5 #ifndef V8_SERIALIZE_H_ |
| 6 #define V8_SERIALIZE_H_ | 6 #define V8_SERIALIZE_H_ |
| 7 | 7 |
| 8 #include "src/hashmap.h" | 8 #include "src/hashmap.h" |
| 9 #include "src/heap-profiler.h" | 9 #include "src/heap-profiler.h" |
| 10 #include "src/isolate.h" | 10 #include "src/isolate.h" |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 }; | 341 }; |
| 342 | 342 |
| 343 // Where to point within the object. | 343 // Where to point within the object. |
| 344 enum WhereToPoint { | 344 enum WhereToPoint { |
| 345 kStartOfObject = 0, | 345 kStartOfObject = 0, |
| 346 kInnerPointer = 0x80, // First insn in code object or payload of cell. | 346 kInnerPointer = 0x80, // First insn in code object or payload of cell. |
| 347 kWhereToPointMask = 0x80 | 347 kWhereToPointMask = 0x80 |
| 348 }; | 348 }; |
| 349 | 349 |
| 350 // Misc. | 350 // Misc. |
| 351 |
| 352 // 0x48, 0x88 and 0xc8 are unused. |
| 353 |
| 351 // Raw data to be copied from the snapshot. This byte code does not advance | 354 // Raw data to be copied from the snapshot. This byte code does not advance |
| 352 // the current pointer, which is used for code objects, where we write the | 355 // the current pointer, which is used for code objects, where we write the |
| 353 // entire code in one memcpy, then fix up stuff with kSkip and other byte | 356 // entire code in one memcpy, then fix up stuff with kSkip and other byte |
| 354 // codes that overwrite data. | 357 // codes that overwrite data. |
| 355 static const int kRawData = 0x20; | 358 static const int kRawData = 0x20; |
| 356 // Some common raw lengths: 0x21-0x3f. | 359 // Some common raw lengths: 0x21-0x3f. |
| 357 // These autoadvance the current pointer. | 360 // These autoadvance the current pointer. |
| 358 static const int kOnePointerRawData = 0x21; | 361 static const int kOnePointerRawData = 0x21; |
| 359 | 362 |
| 363 // Internal reference encoded as offsets of pc and target from code entry. |
| 364 static const int kInternalReference = 0x08; |
| 365 |
| 360 static const int kVariableRepeat = 0x60; | 366 static const int kVariableRepeat = 0x60; |
| 361 // 0x61-0x6f Repeat last word | 367 // 0x61-0x6f Repeat last word |
| 362 static const int kFixedRepeat = 0x61; | 368 static const int kFixedRepeat = 0x61; |
| 363 static const int kFixedRepeatBase = kFixedRepeat - 1; | 369 static const int kFixedRepeatBase = kFixedRepeat - 1; |
| 364 static const int kLastFixedRepeat = 0x6f; | 370 static const int kLastFixedRepeat = 0x6f; |
| 365 static const int kMaxFixedRepeats = kLastFixedRepeat - kFixedRepeatBase; | 371 static const int kMaxFixedRepeats = kLastFixedRepeat - kFixedRepeatBase; |
| 366 static int CodeForRepeats(int repeats) { | 372 static int CodeForRepeats(int repeats) { |
| 367 DCHECK(repeats >= 1 && repeats <= kMaxFixedRepeats); | 373 DCHECK(repeats >= 1 && repeats <= kMaxFixedRepeats); |
| 368 return kFixedRepeatBase + repeats; | 374 return kFixedRepeatBase + repeats; |
| 369 } | 375 } |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 604 void EncodeReservations(List<SerializedData::Reservation>* out) const; | 610 void EncodeReservations(List<SerializedData::Reservation>* out) const; |
| 605 | 611 |
| 606 Isolate* isolate() const { return isolate_; } | 612 Isolate* isolate() const { return isolate_; } |
| 607 | 613 |
| 608 BackReferenceMap* back_reference_map() { return &back_reference_map_; } | 614 BackReferenceMap* back_reference_map() { return &back_reference_map_; } |
| 609 RootIndexMap* root_index_map() { return &root_index_map_; } | 615 RootIndexMap* root_index_map() { return &root_index_map_; } |
| 610 | 616 |
| 611 protected: | 617 protected: |
| 612 class ObjectSerializer : public ObjectVisitor { | 618 class ObjectSerializer : public ObjectVisitor { |
| 613 public: | 619 public: |
| 614 ObjectSerializer(Serializer* serializer, | 620 ObjectSerializer(Serializer* serializer, Object* o, SnapshotByteSink* sink, |
| 615 Object* o, | 621 HowToCode how_to_code, WhereToPoint where_to_point) |
| 616 SnapshotByteSink* sink, | 622 : serializer_(serializer), |
| 617 HowToCode how_to_code, | 623 object_(HeapObject::cast(o)), |
| 618 WhereToPoint where_to_point) | 624 sink_(sink), |
| 619 : serializer_(serializer), | 625 reference_representation_(how_to_code + where_to_point), |
| 620 object_(HeapObject::cast(o)), | 626 bytes_processed_so_far_(0), |
| 621 sink_(sink), | 627 is_code_object_(o->IsCode()), |
| 622 reference_representation_(how_to_code + where_to_point), | 628 code_has_been_output_(false) {} |
| 623 bytes_processed_so_far_(0), | |
| 624 code_object_(o->IsCode()), | |
| 625 code_has_been_output_(false) { } | |
| 626 void Serialize(); | 629 void Serialize(); |
| 627 void VisitPointers(Object** start, Object** end); | 630 void VisitPointers(Object** start, Object** end); |
| 628 void VisitEmbeddedPointer(RelocInfo* target); | 631 void VisitEmbeddedPointer(RelocInfo* target); |
| 629 void VisitExternalReference(Address* p); | 632 void VisitExternalReference(Address* p); |
| 630 void VisitExternalReference(RelocInfo* rinfo); | 633 void VisitExternalReference(RelocInfo* rinfo); |
| 634 void VisitInternalReference(RelocInfo* rinfo); |
| 631 void VisitCodeTarget(RelocInfo* target); | 635 void VisitCodeTarget(RelocInfo* target); |
| 632 void VisitCodeEntry(Address entry_address); | 636 void VisitCodeEntry(Address entry_address); |
| 633 void VisitCell(RelocInfo* rinfo); | 637 void VisitCell(RelocInfo* rinfo); |
| 634 void VisitRuntimeEntry(RelocInfo* reloc); | 638 void VisitRuntimeEntry(RelocInfo* reloc); |
| 635 // Used for seralizing the external strings that hold the natives source. | 639 // Used for seralizing the external strings that hold the natives source. |
| 636 void VisitExternalOneByteString( | 640 void VisitExternalOneByteString( |
| 637 v8::String::ExternalOneByteStringResource** resource); | 641 v8::String::ExternalOneByteStringResource** resource); |
| 638 // We can't serialize a heap with external two byte strings. | 642 // We can't serialize a heap with external two byte strings. |
| 639 void VisitExternalTwoByteString( | 643 void VisitExternalTwoByteString( |
| 640 v8::String::ExternalStringResource** resource) { | 644 v8::String::ExternalStringResource** resource) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 653 // External strings are serialized in a way to resemble sequential strings. | 657 // External strings are serialized in a way to resemble sequential strings. |
| 654 void SerializeExternalString(); | 658 void SerializeExternalString(); |
| 655 | 659 |
| 656 Address PrepareCode(); | 660 Address PrepareCode(); |
| 657 | 661 |
| 658 Serializer* serializer_; | 662 Serializer* serializer_; |
| 659 HeapObject* object_; | 663 HeapObject* object_; |
| 660 SnapshotByteSink* sink_; | 664 SnapshotByteSink* sink_; |
| 661 int reference_representation_; | 665 int reference_representation_; |
| 662 int bytes_processed_so_far_; | 666 int bytes_processed_so_far_; |
| 663 bool code_object_; | 667 bool is_code_object_; |
| 664 bool code_has_been_output_; | 668 bool code_has_been_output_; |
| 665 }; | 669 }; |
| 666 | 670 |
| 667 virtual void SerializeObject(HeapObject* o, HowToCode how_to_code, | 671 virtual void SerializeObject(HeapObject* o, HowToCode how_to_code, |
| 668 WhereToPoint where_to_point, int skip) = 0; | 672 WhereToPoint where_to_point, int skip) = 0; |
| 669 | 673 |
| 670 void PutRoot(int index, HeapObject* object, HowToCode how, WhereToPoint where, | 674 void PutRoot(int index, HeapObject* object, HowToCode how, WhereToPoint where, |
| 671 int skip); | 675 int skip); |
| 672 | 676 |
| 673 // Returns true if the object was successfully serialized. | 677 // Returns true if the object was successfully serialized. |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 971 kNumInternalizedStringsOffset + kInt32Size; | 975 kNumInternalizedStringsOffset + kInt32Size; |
| 972 static const int kNumCodeStubKeysOffset = kNumReservationsOffset + kInt32Size; | 976 static const int kNumCodeStubKeysOffset = kNumReservationsOffset + kInt32Size; |
| 973 static const int kPayloadLengthOffset = kNumCodeStubKeysOffset + kInt32Size; | 977 static const int kPayloadLengthOffset = kNumCodeStubKeysOffset + kInt32Size; |
| 974 static const int kChecksum1Offset = kPayloadLengthOffset + kInt32Size; | 978 static const int kChecksum1Offset = kPayloadLengthOffset + kInt32Size; |
| 975 static const int kChecksum2Offset = kChecksum1Offset + kInt32Size; | 979 static const int kChecksum2Offset = kChecksum1Offset + kInt32Size; |
| 976 static const int kHeaderSize = kChecksum2Offset + kInt32Size; | 980 static const int kHeaderSize = kChecksum2Offset + kInt32Size; |
| 977 }; | 981 }; |
| 978 } } // namespace v8::internal | 982 } } // namespace v8::internal |
| 979 | 983 |
| 980 #endif // V8_SERIALIZE_H_ | 984 #endif // V8_SERIALIZE_H_ |
| OLD | NEW |