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

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) : script_data_(data) {
585 CHECK(Sanity());
586 owns_script_data_ = false;
vogelheim 2014/07/09 17:23:37 nitpick: maybe set owns_script_data_ in initialize
Yang 2014/07/10 08:28:46 Done.
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() {
vogelheim 2014/07/09 17:23:37 What if owns_script_data_ is already false when th
Yang 2014/07/10 08:28:46 I think ASSERT should be sufficient. Add that.
598 ScriptData* result = script_data_;
599 script_data_ = NULL;
600 owns_script_data_ = false;
601 return result;
602 }
603
604 const byte* Payload() const {
605 return script_data_->data() + kHeaderEntries * kIntSize;
606 }
607
608 int PayloadLength() const {
609 return script_data_->length() - kHeaderEntries * kIntSize;
610 }
611
612 int GetReservation(int space) const {
613 return GetHeaderValue(kReservationsOffset + space);
614 }
615
616 private:
617 void SetHeaderValue(int offset, int value) {
618 reinterpret_cast<int*>(const_cast<byte*>(script_data_->data()))[offset] =
619 value;
620 }
621
622 int GetHeaderValue(int offset) const {
623 return reinterpret_cast<const int*>(script_data_->data())[offset];
624 }
625
626 bool Sanity();
627
628 // The data header consists of int-sized entries:
629 // [0] version hash
630 // [1..7] reservation sizes for spaces from NEW_SPACE to PROPERTY_CELL_SPACE.
631 static const int kVersionHashOffset = 0;
632 static const int kReservationsOffset = 1;
633 static const int kHeaderEntries = 8;
634
635 ScriptData* script_data_;
636 bool owns_script_data_;
637 };
579 } } // namespace v8::internal 638 } } // namespace v8::internal
580 639
581 #endif // V8_SERIALIZE_H_ 640 #endif // V8_SERIALIZE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698