| OLD | NEW | 
|---|
| 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 171 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 182   HashMap* map_; | 182   HashMap* map_; | 
| 183 | 183 | 
| 184   DISALLOW_COPY_AND_ASSIGN(RootIndexMap); | 184   DISALLOW_COPY_AND_ASSIGN(RootIndexMap); | 
| 185 }; | 185 }; | 
| 186 | 186 | 
| 187 | 187 | 
| 188 class BackReference { | 188 class BackReference { | 
| 189  public: | 189  public: | 
| 190   explicit BackReference(uint32_t bitfield) : bitfield_(bitfield) {} | 190   explicit BackReference(uint32_t bitfield) : bitfield_(bitfield) {} | 
| 191 | 191 | 
| 192   BackReference(AllocationSpace space, uint32_t chunk_index, | 192   BackReference() : bitfield_(kInvalidValue) {} | 
| 193                 uint32_t chunk_offset) { | 193 | 
| 194     DCHECK(IsAligned(chunk_offset, kObjectAlignment)); | 194   static BackReference SourceReference() { return BackReference(kSourceValue); } | 
| 195     bitfield_ = SpaceBits::encode(space) | ChunkIndexBits::encode(chunk_index) | | 195 | 
| 196                 ChunkOffsetBits::encode(chunk_offset >> kObjectAlignmentBits); | 196   static BackReference LargeObjectReference(uint32_t index) { | 
|  | 197     return BackReference(SpaceBits::encode(LO_SPACE) | | 
|  | 198                          ChunkOffsetBits::encode(index)); | 
| 197   } | 199   } | 
| 198 | 200 | 
| 199   BackReference() : bitfield_(kInvalidValue) {} | 201   static BackReference Reference(AllocationSpace space, uint32_t chunk_index, | 
|  | 202                                  uint32_t chunk_offset) { | 
|  | 203     DCHECK(IsAligned(chunk_offset, kObjectAlignment)); | 
|  | 204     DCHECK_NE(LO_SPACE, space); | 
|  | 205     return BackReference( | 
|  | 206         SpaceBits::encode(space) | ChunkIndexBits::encode(chunk_index) | | 
|  | 207         ChunkOffsetBits::encode(chunk_offset >> kObjectAlignmentBits)); | 
|  | 208   } | 
| 200 | 209 | 
| 201   bool is_valid() const { return bitfield_ != kInvalidValue; } | 210   bool is_valid() const { return bitfield_ != kInvalidValue; } | 
|  | 211   bool is_source() const { return bitfield_ == kSourceValue; } | 
| 202 | 212 | 
| 203   AllocationSpace space() const { | 213   AllocationSpace space() const { | 
| 204     DCHECK(is_valid()); | 214     DCHECK(is_valid()); | 
| 205     return SpaceBits::decode(bitfield_); | 215     return SpaceBits::decode(bitfield_); | 
| 206   } | 216   } | 
| 207 | 217 | 
| 208   uint32_t chunk_offset() const { | 218   uint32_t chunk_offset() const { | 
| 209     DCHECK(is_valid()); | 219     DCHECK(is_valid()); | 
| 210     return ChunkOffsetBits::decode(bitfield_) << kObjectAlignmentBits; | 220     return ChunkOffsetBits::decode(bitfield_) << kObjectAlignmentBits; | 
| 211   } | 221   } | 
| 212 | 222 | 
| 213   uint32_t chunk_index() const { | 223   uint32_t chunk_index() const { | 
| 214     DCHECK(is_valid()); | 224     DCHECK(is_valid()); | 
| 215     return ChunkIndexBits::decode(bitfield_); | 225     return ChunkIndexBits::decode(bitfield_); | 
| 216   } | 226   } | 
| 217 | 227 | 
| 218   uint32_t reference() const { | 228   uint32_t reference() const { | 
| 219     DCHECK(is_valid()); | 229     DCHECK(is_valid()); | 
| 220     return bitfield_ & (ChunkOffsetBits::kMask | ChunkIndexBits::kMask); | 230     return bitfield_ & (ChunkOffsetBits::kMask | ChunkIndexBits::kMask); | 
| 221   } | 231   } | 
| 222 | 232 | 
| 223   uint32_t bitfield() const { return bitfield_; } | 233   uint32_t bitfield() const { return bitfield_; } | 
| 224 | 234 | 
| 225  private: | 235  private: | 
| 226   static const uint32_t kInvalidValue = 0xFFFFFFFF; | 236   static const uint32_t kInvalidValue = 0xFFFFFFFF; | 
|  | 237   static const uint32_t kSourceValue = 0xFFFFFFFE; | 
| 227   static const int kChunkOffsetSize = kPageSizeBits - kObjectAlignmentBits; | 238   static const int kChunkOffsetSize = kPageSizeBits - kObjectAlignmentBits; | 
| 228   static const int kChunkIndexSize = 32 - kChunkOffsetSize - kSpaceTagSize; | 239   static const int kChunkIndexSize = 32 - kChunkOffsetSize - kSpaceTagSize; | 
| 229 | 240 | 
| 230  public: | 241  public: | 
| 231   static const int kMaxChunkIndex = (1 << kChunkIndexSize) - 1; | 242   static const int kMaxChunkIndex = (1 << kChunkIndexSize) - 1; | 
| 232 | 243 | 
| 233  private: | 244  private: | 
| 234   class ChunkOffsetBits : public BitField<uint32_t, 0, kChunkOffsetSize> {}; | 245   class ChunkOffsetBits : public BitField<uint32_t, 0, kChunkOffsetSize> {}; | 
| 235   class ChunkIndexBits | 246   class ChunkIndexBits | 
| 236       : public BitField<uint32_t, ChunkOffsetBits::kNext, kChunkIndexSize> {}; | 247       : public BitField<uint32_t, ChunkOffsetBits::kNext, kChunkIndexSize> {}; | 
| (...skipping 19 matching lines...) Expand all  Loading... | 
| 256     return entry ? BackReference(GetValue(entry)) : BackReference(); | 267     return entry ? BackReference(GetValue(entry)) : BackReference(); | 
| 257   } | 268   } | 
| 258 | 269 | 
| 259   void Add(HeapObject* obj, BackReference b) { | 270   void Add(HeapObject* obj, BackReference b) { | 
| 260     DCHECK(b.is_valid()); | 271     DCHECK(b.is_valid()); | 
| 261     DCHECK_EQ(NULL, LookupEntry(map_, obj, false)); | 272     DCHECK_EQ(NULL, LookupEntry(map_, obj, false)); | 
| 262     HashMap::Entry* entry = LookupEntry(map_, obj, true); | 273     HashMap::Entry* entry = LookupEntry(map_, obj, true); | 
| 263     SetValue(entry, b.bitfield()); | 274     SetValue(entry, b.bitfield()); | 
| 264   } | 275   } | 
| 265 | 276 | 
|  | 277   void AddSourceString(String* string) { | 
|  | 278     Add(string, BackReference::SourceReference()); | 
|  | 279   } | 
|  | 280 | 
| 266  private: | 281  private: | 
| 267   DisallowHeapAllocation no_allocation_; | 282   DisallowHeapAllocation no_allocation_; | 
| 268   HashMap* map_; | 283   HashMap* map_; | 
| 269   DISALLOW_COPY_AND_ASSIGN(BackReferenceMap); | 284   DISALLOW_COPY_AND_ASSIGN(BackReferenceMap); | 
| 270 }; | 285 }; | 
| 271 | 286 | 
| 272 | 287 | 
| 273 // The Serializer/Deserializer class is a common superclass for Serializer and | 288 // The Serializer/Deserializer class is a common superclass for Serializer and | 
| 274 // Deserializer which is used to store common constants and methods used by | 289 // Deserializer which is used to store common constants and methods used by | 
| 275 // both. | 290 // both. | 
| (...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 693 | 708 | 
| 694   List<uint32_t>* stub_keys() { return &stub_keys_; } | 709   List<uint32_t>* stub_keys() { return &stub_keys_; } | 
| 695   int num_internalized_strings() const { return num_internalized_strings_; } | 710   int num_internalized_strings() const { return num_internalized_strings_; } | 
| 696 | 711 | 
| 697  private: | 712  private: | 
| 698   CodeSerializer(Isolate* isolate, SnapshotByteSink* sink, String* source, | 713   CodeSerializer(Isolate* isolate, SnapshotByteSink* sink, String* source, | 
| 699                  Code* main_code) | 714                  Code* main_code) | 
| 700       : Serializer(isolate, sink), | 715       : Serializer(isolate, sink), | 
| 701         source_(source), | 716         source_(source), | 
| 702         main_code_(main_code), | 717         main_code_(main_code), | 
| 703         num_internalized_strings_(0) {} | 718         num_internalized_strings_(0) { | 
|  | 719     back_reference_map_.AddSourceString(source); | 
|  | 720   } | 
| 704 | 721 | 
| 705   virtual void SerializeObject(HeapObject* o, HowToCode how_to_code, | 722   virtual void SerializeObject(HeapObject* o, HowToCode how_to_code, | 
| 706                                WhereToPoint where_to_point, int skip); | 723                                WhereToPoint where_to_point, int skip); | 
| 707 | 724 | 
| 708   void SerializeBuiltin(int builtin_index, HowToCode how_to_code, | 725   void SerializeBuiltin(int builtin_index, HowToCode how_to_code, | 
| 709                         WhereToPoint where_to_point); | 726                         WhereToPoint where_to_point); | 
| 710   void SerializeIC(Code* ic, HowToCode how_to_code, | 727   void SerializeIC(Code* ic, HowToCode how_to_code, | 
| 711                    WhereToPoint where_to_point); | 728                    WhereToPoint where_to_point); | 
| 712   void SerializeCodeStub(uint32_t stub_key, HowToCode how_to_code, | 729   void SerializeCodeStub(uint32_t stub_key, HowToCode how_to_code, | 
| 713                          WhereToPoint where_to_point); | 730                          WhereToPoint where_to_point); | 
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 827   // Following the header, we store, in sequential order | 844   // Following the header, we store, in sequential order | 
| 828   // - code stub keys | 845   // - code stub keys | 
| 829   // - serialization payload | 846   // - serialization payload | 
| 830 | 847 | 
| 831   ScriptData* script_data_; | 848   ScriptData* script_data_; | 
| 832   bool owns_script_data_; | 849   bool owns_script_data_; | 
| 833 }; | 850 }; | 
| 834 } }  // namespace v8::internal | 851 } }  // namespace v8::internal | 
| 835 | 852 | 
| 836 #endif  // V8_SERIALIZE_H_ | 853 #endif  // V8_SERIALIZE_H_ | 
| OLD | NEW | 
|---|