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

Side by Side Diff: src/serialize.h

Issue 376223002: Refactor ScriptData class for cached compile data. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 5 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 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/hashmap.h" 9 #include "src/hashmap.h"
9 #include "src/heap-profiler.h" 10 #include "src/heap-profiler.h"
10 #include "src/isolate.h" 11 #include "src/isolate.h"
11 #include "src/parser.h"
12 #include "src/snapshot-source-sink.h" 12 #include "src/snapshot-source-sink.h"
13 13
14 namespace v8 { 14 namespace v8 {
15 namespace internal { 15 namespace internal {
16 16
17 // A TypeCode is used to distinguish different kinds of external reference. 17 // A TypeCode is used to distinguish different kinds of external reference.
18 // It is a single bit to make testing for types easy. 18 // It is a single bit to make testing for types easy.
19 enum TypeCode { 19 enum TypeCode {
20 UNCLASSIFIED, // One-of-a-kind references. 20 UNCLASSIFIED, // One-of-a-kind references.
21 BUILTIN, 21 BUILTIN,
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 Isolate* isolate_; 463 Isolate* isolate_;
464 // 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
465 // relative addresses for back references. 465 // relative addresses for back references.
466 int fullness_[LAST_SPACE + 1]; 466 int fullness_[LAST_SPACE + 1];
467 SnapshotByteSink* sink_; 467 SnapshotByteSink* sink_;
468 ExternalReferenceEncoder* external_reference_encoder_; 468 ExternalReferenceEncoder* external_reference_encoder_;
469 469
470 SerializationAddressMapper address_mapper_; 470 SerializationAddressMapper address_mapper_;
471 intptr_t root_index_wave_front_; 471 intptr_t root_index_wave_front_;
472 void Pad(); 472 void Pad();
473 void PadByte();
474 473
475 friend class ObjectSerializer; 474 friend class ObjectSerializer;
476 friend class Deserializer; 475 friend class Deserializer;
477 476
478 // We may not need the code address map for logging for every instance 477 // We may not need the code address map for logging for every instance
479 // of the serializer. Initialize it on demand. 478 // of the serializer. Initialize it on demand.
480 void InitializeCodeAddressMap(); 479 void InitializeCodeAddressMap();
481 480
482 private: 481 private:
483 CodeAddressMap* code_address_map_; 482 CodeAddressMap* code_address_map_;
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 568
570 // The data header consists of int-sized entries: 569 // The data header consists of int-sized entries:
571 // [0] version hash 570 // [0] version hash
572 // [1] length in bytes 571 // [1] length in bytes
573 // [2..8] reservation sizes for spaces from NEW_SPACE to PROPERTY_CELL_SPACE. 572 // [2..8] reservation sizes for spaces from NEW_SPACE to PROPERTY_CELL_SPACE.
574 static const int kHeaderSize = 9; 573 static const int kHeaderSize = 9;
575 static const int kVersionHashOffset = 0; 574 static const int kVersionHashOffset = 0;
576 static const int kPayloadLengthOffset = 1; 575 static const int kPayloadLengthOffset = 1;
577 static const int kReservationsOffset = 2; 576 static const int kReservationsOffset = 2;
578 }; 577 };
578
579
580 // Wrapper around ScriptData to provide code-serializer-specific functionality.
581 class SerializedCodeData {
582 public:
583 // Used by when consuming.
584 explicit SerializedCodeData(ScriptData* data)
585 : script_data_(data), owns_script_data_(false) {
586 CHECK(IsSane());
587 }
588
589 // Used when producing.
590 SerializedCodeData(List<byte>* payload, CodeSerializer* cs);
591
592 ~SerializedCodeData() {
593 if (owns_script_data_) delete script_data_;
594 }
595
596 // Return ScriptData object and relinquish ownership over it to the caller.
597 ScriptData* GetScriptData() {
598 ScriptData* result = script_data_;
599 script_data_ = NULL;
600 ASSERT(owns_script_data_);
601 owns_script_data_ = false;
602 return result;
603 }
604
605 const byte* Payload() const {
606 return script_data_->data() + kHeaderEntries * kIntSize;
607 }
608
609 int PayloadLength() const {
610 return script_data_->length() - kHeaderEntries * kIntSize;
611 }
612
613 int GetReservation(int space) const {
614 return GetHeaderValue(kReservationsOffset + space);
615 }
616
617 private:
618 void SetHeaderValue(int offset, int value) {
619 reinterpret_cast<int*>(const_cast<byte*>(script_data_->data()))[offset] =
620 value;
621 }
622
623 int GetHeaderValue(int offset) const {
624 return reinterpret_cast<const int*>(script_data_->data())[offset];
625 }
626
627 bool IsSane();
628
629 // The data header consists of int-sized entries:
630 // [0] version hash
631 // [1..7] reservation sizes for spaces from NEW_SPACE to PROPERTY_CELL_SPACE.
632 static const int kVersionHashOffset = 0;
633 static const int kReservationsOffset = 1;
634 static const int kHeaderEntries = 8;
635
636 ScriptData* script_data_;
637 bool owns_script_data_;
638 };
579 } } // namespace v8::internal 639 } } // namespace v8::internal
580 640
581 #endif // V8_SERIALIZE_H_ 641 #endif // V8_SERIALIZE_H_
OLDNEW
« src/preparse-data.h ('K') | « src/preparse-data.cc ('k') | src/serialize.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698