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

Side by Side Diff: src/serialize.h

Issue 556243005: Serialize code stubs using stub key. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 3 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/flag-definitions.h ('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 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 void set_reservation(int space_number, int reservation) { 250 void set_reservation(int space_number, int reservation) {
251 DCHECK(space_number >= 0); 251 DCHECK(space_number >= 0);
252 DCHECK(space_number <= LAST_SPACE); 252 DCHECK(space_number <= LAST_SPACE);
253 reservations_[space_number] = reservation; 253 reservations_[space_number] = reservation;
254 } 254 }
255 255
256 void FlushICacheForNewCodeObjects(); 256 void FlushICacheForNewCodeObjects();
257 257
258 // Serialized user code reference certain objects that are provided in a list 258 // Serialized user code reference certain objects that are provided in a list
259 // By calling this method, we assume that we are deserializing user code. 259 // By calling this method, we assume that we are deserializing user code.
260 void SetAttachedObjects(Vector<Object*>* attached_objects) { 260 void SetAttachedObjects(Vector<Handle<Object> >* attached_objects) {
261 attached_objects_ = attached_objects; 261 attached_objects_ = attached_objects;
262 } 262 }
263 263
264 bool deserializing_user_code() { return attached_objects_ != NULL; } 264 bool deserializing_user_code() { return attached_objects_ != NULL; }
265 265
266 private: 266 private:
267 virtual void VisitPointers(Object** start, Object** end); 267 virtual void VisitPointers(Object** start, Object** end);
268 268
269 virtual void VisitRuntimeEntry(RelocInfo* rinfo) { 269 virtual void VisitRuntimeEntry(RelocInfo* rinfo) {
270 UNREACHABLE(); 270 UNREACHABLE();
(...skipping 30 matching lines...) Expand all
301 HeapObject* GetAddressFromEnd(int space) { 301 HeapObject* GetAddressFromEnd(int space) {
302 int offset = source_->GetInt(); 302 int offset = source_->GetInt();
303 offset <<= kObjectAlignmentBits; 303 offset <<= kObjectAlignmentBits;
304 return HeapObject::FromAddress(high_water_[space] - offset); 304 return HeapObject::FromAddress(high_water_[space] - offset);
305 } 305 }
306 306
307 // Cached current isolate. 307 // Cached current isolate.
308 Isolate* isolate_; 308 Isolate* isolate_;
309 309
310 // Objects from the attached object descriptions in the serialized user code. 310 // Objects from the attached object descriptions in the serialized user code.
311 Vector<Object*>* attached_objects_; 311 Vector<Handle<Object> >* attached_objects_;
312 312
313 SnapshotByteSource* source_; 313 SnapshotByteSource* source_;
314 // This is the address of the next object that will be allocated in each 314 // This is the address of the next object that will be allocated in each
315 // space. It is used to calculate the addresses of back-references. 315 // space. It is used to calculate the addresses of back-references.
316 Address high_water_[LAST_SPACE + 1]; 316 Address high_water_[LAST_SPACE + 1];
317 317
318 int reservations_[LAST_SPACE + 1]; 318 int reservations_[LAST_SPACE + 1];
319 static const intptr_t kUninitializedReservation = -1; 319 static const intptr_t kUninitializedReservation = -1;
320 320
321 ExternalReferenceDecoder* external_reference_decoder_; 321 ExternalReferenceDecoder* external_reference_decoder_;
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 int reference_representation_; 452 int reference_representation_;
453 int bytes_processed_so_far_; 453 int bytes_processed_so_far_;
454 bool code_object_; 454 bool code_object_;
455 bool code_has_been_output_; 455 bool code_has_been_output_;
456 }; 456 };
457 457
458 virtual void SerializeObject(Object* o, 458 virtual void SerializeObject(Object* o,
459 HowToCode how_to_code, 459 HowToCode how_to_code,
460 WhereToPoint where_to_point, 460 WhereToPoint where_to_point,
461 int skip) = 0; 461 int skip) = 0;
462 void SerializeReferenceToPreviousObject( 462 void SerializeReferenceToPreviousObject(HeapObject* heap_object,
463 int space, 463 HowToCode how_to_code,
464 int address, 464 WhereToPoint where_to_point,
465 HowToCode how_to_code, 465 int skip);
466 WhereToPoint where_to_point,
467 int skip);
468 void InitializeAllocators(); 466 void InitializeAllocators();
469 // This will return the space for an object. 467 // This will return the space for an object.
470 static int SpaceOfObject(HeapObject* object); 468 static int SpaceOfObject(HeapObject* object);
471 int Allocate(int space, int size); 469 int Allocate(int space, int size);
472 int EncodeExternalReference(Address addr) { 470 int EncodeExternalReference(Address addr) {
473 return external_reference_encoder_->Encode(addr); 471 return external_reference_encoder_->Encode(addr);
474 } 472 }
475 473
476 int SpaceAreaSize(int space); 474 int SpaceAreaSize(int space);
477 475
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
587 Handle<String> source); 585 Handle<String> source);
588 586
589 virtual void SerializeObject(Object* o, HowToCode how_to_code, 587 virtual void SerializeObject(Object* o, HowToCode how_to_code,
590 WhereToPoint where_to_point, int skip); 588 WhereToPoint where_to_point, int skip);
591 589
592 static Handle<SharedFunctionInfo> Deserialize(Isolate* isolate, 590 static Handle<SharedFunctionInfo> Deserialize(Isolate* isolate,
593 ScriptData* data, 591 ScriptData* data,
594 Handle<String> source); 592 Handle<String> source);
595 593
596 static const int kSourceObjectIndex = 0; 594 static const int kSourceObjectIndex = 0;
595 static const int kCodeStubsBaseIndex = 1;
597 596
598 String* source() { 597 String* source() {
599 DCHECK(!AllowHeapAllocation::IsAllowed()); 598 DCHECK(!AllowHeapAllocation::IsAllowed());
600 return source_; 599 return source_;
601 } 600 }
602 601
602 List<uint32_t>* stub_keys() { return &stub_keys_; }
603
603 private: 604 private:
604 void SerializeBuiltin(Code* builtin, HowToCode how_to_code, 605 void SerializeBuiltin(Code* builtin, HowToCode how_to_code,
605 WhereToPoint where_to_point, int skip); 606 WhereToPoint where_to_point, int skip);
607 void SerializeCodeStub(Code* code, HowToCode how_to_code,
608 WhereToPoint where_to_point, int skip);
606 void SerializeSourceObject(HowToCode how_to_code, WhereToPoint where_to_point, 609 void SerializeSourceObject(HowToCode how_to_code, WhereToPoint where_to_point,
607 int skip); 610 int skip);
611 void SerializeHeapObject(HeapObject* heap_object, HowToCode how_to_code,
612 WhereToPoint where_to_point, int skip);
613 int AddCodeStubKey(uint32_t stub_key);
608 614
609 DisallowHeapAllocation no_gc_; 615 DisallowHeapAllocation no_gc_;
610 String* source_; 616 String* source_;
617 List<uint32_t> stub_keys_;
611 DISALLOW_COPY_AND_ASSIGN(CodeSerializer); 618 DISALLOW_COPY_AND_ASSIGN(CodeSerializer);
612 }; 619 };
613 620
614 621
615 // Wrapper around ScriptData to provide code-serializer-specific functionality. 622 // Wrapper around ScriptData to provide code-serializer-specific functionality.
616 class SerializedCodeData { 623 class SerializedCodeData {
617 public: 624 public:
618 // Used by when consuming. 625 // Used by when consuming.
619 explicit SerializedCodeData(ScriptData* data, String* source) 626 explicit SerializedCodeData(ScriptData* data, String* source)
620 : script_data_(data), owns_script_data_(false) { 627 : script_data_(data), owns_script_data_(false) {
(...skipping 10 matching lines...) Expand all
631 638
632 // Return ScriptData object and relinquish ownership over it to the caller. 639 // Return ScriptData object and relinquish ownership over it to the caller.
633 ScriptData* GetScriptData() { 640 ScriptData* GetScriptData() {
634 ScriptData* result = script_data_; 641 ScriptData* result = script_data_;
635 script_data_ = NULL; 642 script_data_ = NULL;
636 DCHECK(owns_script_data_); 643 DCHECK(owns_script_data_);
637 owns_script_data_ = false; 644 owns_script_data_ = false;
638 return result; 645 return result;
639 } 646 }
640 647
648 Vector<const uint32_t> CodeStubKeys() const {
649 return Vector<const uint32_t>(
650 reinterpret_cast<const uint32_t*>(script_data_->data() + kHeaderSize),
651 GetHeaderValue(kNumCodeStubKeysOffset));
652 }
653
641 const byte* Payload() const { 654 const byte* Payload() const {
642 return script_data_->data() + kHeaderEntries * kIntSize; 655 int code_stubs_size = GetHeaderValue(kNumCodeStubKeysOffset) * kInt32Size;
656 return script_data_->data() + kHeaderSize + code_stubs_size;
643 } 657 }
644 658
645 int PayloadLength() const { 659 int PayloadLength() const {
646 return script_data_->length() - kHeaderEntries * kIntSize; 660 int payload_length = GetHeaderValue(kPayloadLengthOffset);
661 DCHECK_EQ(script_data_->data() + script_data_->length(),
662 Payload() + payload_length);
663 return payload_length;
647 } 664 }
648 665
649 int GetReservation(int space) const { 666 int GetReservation(int space) const {
650 return GetHeaderValue(kReservationsOffset + space); 667 return GetHeaderValue(kReservationsOffset + space);
651 } 668 }
652 669
653 private: 670 private:
654 void SetHeaderValue(int offset, int value) { 671 void SetHeaderValue(int offset, int value) {
655 reinterpret_cast<int*>(const_cast<byte*>(script_data_->data()))[offset] = 672 reinterpret_cast<int*>(const_cast<byte*>(script_data_->data()))[offset] =
656 value; 673 value;
657 } 674 }
658 675
659 int GetHeaderValue(int offset) const { 676 int GetHeaderValue(int offset) const {
660 return reinterpret_cast<const int*>(script_data_->data())[offset]; 677 return reinterpret_cast<const int*>(script_data_->data())[offset];
661 } 678 }
662 679
663 bool IsSane(String* source); 680 bool IsSane(String* source);
664 681
665 int CheckSum(String* source); 682 int CheckSum(String* source);
666 683
667 // The data header consists of int-sized entries: 684 // The data header consists of int-sized entries:
668 // [0] version hash 685 // [0] version hash
669 // [1..7] reservation sizes for spaces from NEW_SPACE to PROPERTY_CELL_SPACE. 686 // [1] number of code stub keys
687 // [2] payload length
688 // [3..9] reservation sizes for spaces from NEW_SPACE to PROPERTY_CELL_SPACE.
670 static const int kCheckSumOffset = 0; 689 static const int kCheckSumOffset = 0;
671 static const int kReservationsOffset = 1; 690 static const int kNumCodeStubKeysOffset = 1;
672 static const int kHeaderEntries = 8; 691 static const int kPayloadLengthOffset = 2;
692 static const int kReservationsOffset = 3;
693
694 static const int kNumSpaces = PROPERTY_CELL_SPACE - NEW_SPACE + 1;
695 static const int kHeaderEntries = kReservationsOffset + kNumSpaces;
696 static const int kHeaderSize = kHeaderEntries * kIntSize;
697
698 // Following the header, we store, in sequential order
699 // - code stub keys
700 // - serialization payload
673 701
674 ScriptData* script_data_; 702 ScriptData* script_data_;
675 bool owns_script_data_; 703 bool owns_script_data_;
676 }; 704 };
677 } } // namespace v8::internal 705 } } // namespace v8::internal
678 706
679 #endif // V8_SERIALIZE_H_ 707 #endif // V8_SERIALIZE_H_
OLDNEW
« no previous file with comments | « src/flag-definitions.h ('k') | src/serialize.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698