Chromium Code Reviews| Index: src/serialize.h |
| diff --git a/src/serialize.h b/src/serialize.h |
| index 6cc90eaafc2bb01c65da5b951634a8360e0f89c3..f97dcfae7d0028a8e7d998f640c29717b1fc2993 100644 |
| --- a/src/serialize.h |
| +++ b/src/serialize.h |
| @@ -5,10 +5,10 @@ |
| #ifndef V8_SERIALIZE_H_ |
| #define V8_SERIALIZE_H_ |
| +#include "src/compiler.h" |
| #include "src/hashmap.h" |
| #include "src/heap-profiler.h" |
| #include "src/isolate.h" |
| -#include "src/parser.h" |
| #include "src/snapshot-source-sink.h" |
| namespace v8 { |
| @@ -470,7 +470,6 @@ class Serializer : public SerializerDeserializer { |
| SerializationAddressMapper address_mapper_; |
| intptr_t root_index_wave_front_; |
| void Pad(); |
| - void PadByte(); |
| friend class ObjectSerializer; |
| friend class Deserializer; |
| @@ -576,6 +575,66 @@ class CodeSerializer : public Serializer { |
| static const int kPayloadLengthOffset = 1; |
| static const int kReservationsOffset = 2; |
| }; |
| + |
| + |
| +// Wrapper around ScriptData to provide code-serializer-specific functionality. |
| +class SerializedCodeData { |
| + public: |
| + // Used by when consuming. |
| + explicit SerializedCodeData(ScriptData* data) : script_data_(data) { |
| + CHECK(Sanity()); |
| + 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.
|
| + } |
| + |
| + // Used when producing. |
| + SerializedCodeData(List<byte>* payload, CodeSerializer* cs); |
| + |
| + ~SerializedCodeData() { |
| + if (owns_script_data_) delete script_data_; |
| + } |
| + |
| + // Return ScriptData object and relinquish ownership over it to the caller. |
| + 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.
|
| + ScriptData* result = script_data_; |
| + script_data_ = NULL; |
| + owns_script_data_ = false; |
| + return result; |
| + } |
| + |
| + const byte* Payload() const { |
| + return script_data_->data() + kHeaderEntries * kIntSize; |
| + } |
| + |
| + int PayloadLength() const { |
| + return script_data_->length() - kHeaderEntries * kIntSize; |
| + } |
| + |
| + int GetReservation(int space) const { |
| + return GetHeaderValue(kReservationsOffset + space); |
| + } |
| + |
| + private: |
| + void SetHeaderValue(int offset, int value) { |
| + reinterpret_cast<int*>(const_cast<byte*>(script_data_->data()))[offset] = |
| + value; |
| + } |
| + |
| + int GetHeaderValue(int offset) const { |
| + return reinterpret_cast<const int*>(script_data_->data())[offset]; |
| + } |
| + |
| + bool Sanity(); |
| + |
| + // The data header consists of int-sized entries: |
| + // [0] version hash |
| + // [1..7] reservation sizes for spaces from NEW_SPACE to PROPERTY_CELL_SPACE. |
| + static const int kVersionHashOffset = 0; |
| + static const int kReservationsOffset = 1; |
| + static const int kHeaderEntries = 8; |
| + |
| + ScriptData* script_data_; |
| + bool owns_script_data_; |
| +}; |
| } } // namespace v8::internal |
| #endif // V8_SERIALIZE_H_ |