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

Side by Side Diff: src/serialize.h

Issue 671843003: Small fixes for the code serializer. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: rebased and addressed nit Created 6 years, 2 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
« no previous file with comments | « src/objects.cc ('k') | src/serialize.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/compiler.h" 8 #include "src/compiler.h"
9 #include "src/hashmap.h" 9 #include "src/hashmap.h"
10 #include "src/heap-profiler.h" 10 #include "src/heap-profiler.h"
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 257
258 // Deserialize a single object and the objects reachable from it. 258 // Deserialize a single object and the objects reachable from it.
259 // We may want to abort gracefully even if deserialization fails. 259 // We may want to abort gracefully even if deserialization fails.
260 void DeserializePartial(Isolate* isolate, Object** root, 260 void DeserializePartial(Isolate* isolate, Object** root,
261 OnOOM on_oom = FATAL_ON_OOM); 261 OnOOM on_oom = FATAL_ON_OOM);
262 262
263 void AddReservation(int space, uint32_t chunk) { 263 void AddReservation(int space, uint32_t chunk) {
264 DCHECK(space >= 0); 264 DCHECK(space >= 0);
265 DCHECK(space < kNumberOfSpaces); 265 DCHECK(space < kNumberOfSpaces);
266 DCHECK(space == LO_SPACE || 266 DCHECK(space == LO_SPACE ||
267 chunk < static_cast<uint32_t>(Page::kMaxRegularHeapObjectSize)); 267 chunk <= static_cast<uint32_t>(Page::kMaxRegularHeapObjectSize));
268 reservations_[space].Add({chunk, NULL, NULL}); 268 reservations_[space].Add({chunk, NULL, NULL});
269 } 269 }
270 270
271 void FlushICacheForNewCodeObjects(); 271 void FlushICacheForNewCodeObjects();
272 272
273 // Serialized user code reference certain objects that are provided in a list 273 // Serialized user code reference certain objects that are provided in a list
274 // By calling this method, we assume that we are deserializing user code. 274 // By calling this method, we assume that we are deserializing user code.
275 void SetAttachedObjects(Vector<Handle<Object> >* attached_objects) { 275 void SetAttachedObjects(Vector<Handle<Object> >* attached_objects) {
276 attached_objects_ = attached_objects; 276 attached_objects_ = attached_objects;
277 } 277 }
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
612 static ScriptData* Serialize(Isolate* isolate, 612 static ScriptData* Serialize(Isolate* isolate,
613 Handle<SharedFunctionInfo> info, 613 Handle<SharedFunctionInfo> info,
614 Handle<String> source); 614 Handle<String> source);
615 615
616 MUST_USE_RESULT static MaybeHandle<SharedFunctionInfo> Deserialize( 616 MUST_USE_RESULT static MaybeHandle<SharedFunctionInfo> Deserialize(
617 Isolate* isolate, ScriptData* data, Handle<String> source); 617 Isolate* isolate, ScriptData* data, Handle<String> source);
618 618
619 static const int kSourceObjectIndex = 0; 619 static const int kSourceObjectIndex = 0;
620 static const int kCodeStubsBaseIndex = 1; 620 static const int kCodeStubsBaseIndex = 1;
621 621
622 String* source() { 622 String* source() const {
623 DCHECK(!AllowHeapAllocation::IsAllowed()); 623 DCHECK(!AllowHeapAllocation::IsAllowed());
624 return source_; 624 return source_;
625 } 625 }
626 626
627 List<uint32_t>* stub_keys() { return &stub_keys_; } 627 List<uint32_t>* stub_keys() { return &stub_keys_; }
628 int num_internalized_strings() const { return num_internalized_strings_; }
628 629
629 private: 630 private:
630 CodeSerializer(Isolate* isolate, SnapshotByteSink* sink, String* source, 631 CodeSerializer(Isolate* isolate, SnapshotByteSink* sink, String* source,
631 Code* main_code) 632 Code* main_code)
632 : Serializer(isolate, sink), source_(source), main_code_(main_code) { 633 : Serializer(isolate, sink),
634 source_(source),
635 main_code_(main_code),
636 num_internalized_strings_(0) {
633 set_root_index_wave_front(Heap::kStrongRootListLength); 637 set_root_index_wave_front(Heap::kStrongRootListLength);
634 InitializeCodeAddressMap(); 638 InitializeCodeAddressMap();
635 } 639 }
636 640
637 virtual void SerializeObject(Object* o, HowToCode how_to_code, 641 virtual void SerializeObject(Object* o, HowToCode how_to_code,
638 WhereToPoint where_to_point, int skip); 642 WhereToPoint where_to_point, int skip);
639 643
640 void SerializeBuiltin(int builtin_index, HowToCode how_to_code, 644 void SerializeBuiltin(int builtin_index, HowToCode how_to_code,
641 WhereToPoint where_to_point); 645 WhereToPoint where_to_point);
642 void SerializeIC(Code* ic, HowToCode how_to_code, 646 void SerializeIC(Code* ic, HowToCode how_to_code,
643 WhereToPoint where_to_point); 647 WhereToPoint where_to_point);
644 void SerializeCodeStub(uint32_t stub_key, HowToCode how_to_code, 648 void SerializeCodeStub(uint32_t stub_key, HowToCode how_to_code,
645 WhereToPoint where_to_point); 649 WhereToPoint where_to_point);
646 void SerializeSourceObject(HowToCode how_to_code, 650 void SerializeSourceObject(HowToCode how_to_code,
647 WhereToPoint where_to_point); 651 WhereToPoint where_to_point);
648 void SerializeHeapObject(HeapObject* heap_object, HowToCode how_to_code, 652 void SerializeHeapObject(HeapObject* heap_object, HowToCode how_to_code,
649 WhereToPoint where_to_point); 653 WhereToPoint where_to_point);
650 int AddCodeStubKey(uint32_t stub_key); 654 int AddCodeStubKey(uint32_t stub_key);
651 655
652 DisallowHeapAllocation no_gc_; 656 DisallowHeapAllocation no_gc_;
653 String* source_; 657 String* source_;
654 Code* main_code_; 658 Code* main_code_;
659 int num_internalized_strings_;
655 List<uint32_t> stub_keys_; 660 List<uint32_t> stub_keys_;
656 DISALLOW_COPY_AND_ASSIGN(CodeSerializer); 661 DISALLOW_COPY_AND_ASSIGN(CodeSerializer);
657 }; 662 };
658 663
659 664
660 // Wrapper around ScriptData to provide code-serializer-specific functionality. 665 // Wrapper around ScriptData to provide code-serializer-specific functionality.
661 class SerializedCodeData { 666 class SerializedCodeData {
662 public: 667 public:
663 // Used by when consuming. 668 // Used by when consuming.
664 explicit SerializedCodeData(ScriptData* data, String* source) 669 explicit SerializedCodeData(ScriptData* data, String* source)
(...skipping 22 matching lines...) Expand all
687 public: 692 public:
688 uint32_t chunk_size() const { return ChunkSizeBits::decode(reservation); } 693 uint32_t chunk_size() const { return ChunkSizeBits::decode(reservation); }
689 bool is_last_chunk() const { return IsLastChunkBits::decode(reservation); } 694 bool is_last_chunk() const { return IsLastChunkBits::decode(reservation); }
690 695
691 private: 696 private:
692 uint32_t reservation; 697 uint32_t reservation;
693 698
694 DISALLOW_COPY_AND_ASSIGN(Reservation); 699 DISALLOW_COPY_AND_ASSIGN(Reservation);
695 }; 700 };
696 701
702 int NumInternalizedStrings() const {
703 return GetHeaderValue(kNumInternalizedStringsOffset);
704 }
705
697 Vector<const Reservation> Reservations() const { 706 Vector<const Reservation> Reservations() const {
698 return Vector<const Reservation>(reinterpret_cast<const Reservation*>( 707 return Vector<const Reservation>(reinterpret_cast<const Reservation*>(
699 script_data_->data() + kHeaderSize), 708 script_data_->data() + kHeaderSize),
700 GetHeaderValue(kReservationsOffset)); 709 GetHeaderValue(kReservationsOffset));
701 } 710 }
702 711
703 Vector<const uint32_t> CodeStubKeys() const { 712 Vector<const uint32_t> CodeStubKeys() const {
704 int reservations_size = GetHeaderValue(kReservationsOffset) * kInt32Size; 713 int reservations_size = GetHeaderValue(kReservationsOffset) * kInt32Size;
705 const byte* start = script_data_->data() + kHeaderSize + reservations_size; 714 const byte* start = script_data_->data() + kHeaderSize + reservations_size;
706 return Vector<const uint32_t>(reinterpret_cast<const uint32_t*>(start), 715 return Vector<const uint32_t>(reinterpret_cast<const uint32_t*>(start),
(...skipping 23 matching lines...) Expand all
730 int GetHeaderValue(int offset) const { 739 int GetHeaderValue(int offset) const {
731 return reinterpret_cast<const int*>(script_data_->data())[offset]; 740 return reinterpret_cast<const int*>(script_data_->data())[offset];
732 } 741 }
733 742
734 bool IsSane(String* source); 743 bool IsSane(String* source);
735 744
736 int CheckSum(String* source); 745 int CheckSum(String* source);
737 746
738 // The data header consists of int-sized entries: 747 // The data header consists of int-sized entries:
739 // [0] version hash 748 // [0] version hash
740 // [1] number of code stub keys 749 // [1] number of internalized strings
741 // [2] payload length 750 // [2] number of code stub keys
742 // [3..9] reservation sizes for spaces from NEW_SPACE to PROPERTY_CELL_SPACE. 751 // [3] payload length
752 // [4..10] reservation sizes for spaces from NEW_SPACE to PROPERTY_CELL_SPACE.
743 static const int kCheckSumOffset = 0; 753 static const int kCheckSumOffset = 0;
744 static const int kReservationsOffset = 1; 754 static const int kNumInternalizedStringsOffset = 1;
745 static const int kNumCodeStubKeysOffset = 2; 755 static const int kReservationsOffset = 2;
746 static const int kPayloadLengthOffset = 3; 756 static const int kNumCodeStubKeysOffset = 3;
757 static const int kPayloadLengthOffset = 4;
747 static const int kHeaderSize = (kPayloadLengthOffset + 1) * kIntSize; 758 static const int kHeaderSize = (kPayloadLengthOffset + 1) * kIntSize;
748 759
749 class ChunkSizeBits : public BitField<uint32_t, 0, 31> {}; 760 class ChunkSizeBits : public BitField<uint32_t, 0, 31> {};
750 class IsLastChunkBits : public BitField<bool, 31, 1> {}; 761 class IsLastChunkBits : public BitField<bool, 31, 1> {};
751 762
752 // Following the header, we store, in sequential order 763 // Following the header, we store, in sequential order
753 // - code stub keys 764 // - code stub keys
754 // - serialization payload 765 // - serialization payload
755 766
756 ScriptData* script_data_; 767 ScriptData* script_data_;
757 bool owns_script_data_; 768 bool owns_script_data_;
758 }; 769 };
759 } } // namespace v8::internal 770 } } // namespace v8::internal
760 771
761 #endif // V8_SERIALIZE_H_ 772 #endif // V8_SERIALIZE_H_
OLDNEW
« no previous file with comments | « src/objects.cc ('k') | src/serialize.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698