Chromium Code Reviews| 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" |
| 11 #include "src/parser.h" | |
|
vogelheim
2014/07/07 15:20:01
parser.h draws in a rather large amount of headers
Yang
2014/07/08 09:01:05
Yup. Doing this later.
| |
| 11 #include "src/snapshot-source-sink.h" | 12 #include "src/snapshot-source-sink.h" |
| 12 | 13 |
| 13 namespace v8 { | 14 namespace v8 { |
| 14 namespace internal { | 15 namespace internal { |
| 15 | 16 |
| 16 // A TypeCode is used to distinguish different kinds of external reference. | 17 // A TypeCode is used to distinguish different kinds of external reference. |
| 17 // It is a single bit to make testing for types easy. | 18 // It is a single bit to make testing for types easy. |
| 18 enum TypeCode { | 19 enum TypeCode { |
| 19 UNCLASSIFIED, // One-of-a-kind references. | 20 UNCLASSIFIED, // One-of-a-kind references. |
| 20 BUILTIN, | 21 BUILTIN, |
| (...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 462 Isolate* isolate_; | 463 Isolate* isolate_; |
| 463 // Keep track of the fullness of each space in order to generate | 464 // Keep track of the fullness of each space in order to generate |
| 464 // relative addresses for back references. | 465 // relative addresses for back references. |
| 465 int fullness_[LAST_SPACE + 1]; | 466 int fullness_[LAST_SPACE + 1]; |
| 466 SnapshotByteSink* sink_; | 467 SnapshotByteSink* sink_; |
| 467 ExternalReferenceEncoder* external_reference_encoder_; | 468 ExternalReferenceEncoder* external_reference_encoder_; |
| 468 | 469 |
| 469 SerializationAddressMapper address_mapper_; | 470 SerializationAddressMapper address_mapper_; |
| 470 intptr_t root_index_wave_front_; | 471 intptr_t root_index_wave_front_; |
| 471 void Pad(); | 472 void Pad(); |
| 473 void PadByte(); | |
| 472 | 474 |
| 473 friend class ObjectSerializer; | 475 friend class ObjectSerializer; |
| 474 friend class Deserializer; | 476 friend class Deserializer; |
| 475 | 477 |
| 476 // We may not need the code address map for logging for every instance | 478 // We may not need the code address map for logging for every instance |
| 477 // of the serializer. Initialize it on demand. | 479 // of the serializer. Initialize it on demand. |
| 478 void InitializeCodeAddressMap(); | 480 void InitializeCodeAddressMap(); |
| 479 | 481 |
| 480 private: | 482 private: |
| 481 CodeAddressMap* code_address_map_; | 483 CodeAddressMap* code_address_map_; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 544 int skip); | 546 int skip); |
| 545 void SerializeWeakReferences(); | 547 void SerializeWeakReferences(); |
| 546 void Serialize() { | 548 void Serialize() { |
| 547 SerializeStrongReferences(); | 549 SerializeStrongReferences(); |
| 548 SerializeWeakReferences(); | 550 SerializeWeakReferences(); |
| 549 Pad(); | 551 Pad(); |
| 550 } | 552 } |
| 551 }; | 553 }; |
| 552 | 554 |
| 553 | 555 |
| 556 class CodeSerializer : public Serializer { | |
| 557 public: | |
| 558 CodeSerializer(Isolate* isolate, SnapshotByteSink* sink) | |
| 559 : Serializer(isolate, sink) { | |
| 560 set_root_index_wave_front(Heap::kStrongRootListLength); | |
| 561 InitializeCodeAddressMap(); | |
| 562 } | |
| 563 | |
| 564 static ScriptData* Serialize(Handle<SharedFunctionInfo> info); | |
| 565 virtual void SerializeObject(Object* o, HowToCode how_to_code, | |
| 566 WhereToPoint where_to_point, int skip); | |
| 567 | |
| 568 static Object* Deserialize(Isolate* isolate, ScriptData* data); | |
| 569 | |
| 570 // The data header consists of | |
| 571 // [0] version hash | |
|
vogelheim
2014/07/07 15:20:01
nitpick: It took me a while to understand these ar
Yang
2014/07/08 09:01:05
Done.
| |
| 572 // [1] length in bytes | |
| 573 // [2..8] reservation sizes for spaces from NEW_SPACE to PROPERTY_CELL_SPACE. | |
| 574 static const int kHeaderSize = 9; | |
| 575 static const int kVersionHashOffset = 0; | |
| 576 static const int kPayloadLengthOffset = 1; | |
| 577 static const int kReservationsOffset = 2; | |
| 578 }; | |
| 579 | |
| 580 | |
| 581 class DummySnapshotSink : public SnapshotByteSink { | |
|
vogelheim
2014/07/07 15:20:01
If these (and the following) *Sinks are of general
Yang
2014/07/08 09:01:05
Done.
| |
| 582 public: | |
| 583 DummySnapshotSink() : length_(0) {} | |
| 584 virtual ~DummySnapshotSink() {} | |
| 585 virtual void Put(int byte, const char* description) { length_++; } | |
| 586 virtual int Position() { return length_; } | |
| 587 | |
| 588 private: | |
| 589 int length_; | |
| 590 }; | |
| 591 | |
| 592 | |
| 593 // Wrap a SnapshotByteSink into a DebugSnapshotSink to get debugging output. | |
| 594 class DebugSnapshotSink : public SnapshotByteSink { | |
| 595 public: | |
| 596 explicit DebugSnapshotSink(SnapshotByteSink* chained) : sink_(chained) {} | |
| 597 virtual ~DebugSnapshotSink() {} | |
| 598 virtual void Put(int byte, const char* description) { | |
| 599 printf("%24s: %x\n", description, byte); | |
|
vogelheim
2014/07/07 15:20:01
nitpick: This header does not include stdio.h (and
Yang
2014/07/08 09:01:05
Using PrintF instead.
| |
| 600 sink_->Put(byte, description); | |
| 601 } | |
| 602 virtual int Position() { return sink_->Position(); } | |
| 603 | |
| 604 private: | |
| 605 SnapshotByteSink* sink_; | |
| 606 }; | |
| 607 | |
| 608 | |
| 609 class ListSnapshotSink : public i::SnapshotByteSink { | |
| 610 public: | |
| 611 explicit ListSnapshotSink(i::List<char>* data) : data_(data) {} | |
| 612 virtual ~ListSnapshotSink() {} | |
| 613 virtual void Put(int byte, const char* description) { data_->Add(byte); } | |
| 614 virtual int Position() { return data_->length(); } | |
| 615 | |
| 616 private: | |
| 617 i::List<char>* data_; | |
| 618 }; | |
| 554 } } // namespace v8::internal | 619 } } // namespace v8::internal |
| 555 | 620 |
| 556 #endif // V8_SERIALIZE_H_ | 621 #endif // V8_SERIALIZE_H_ |
| OLD | NEW |