| OLD | NEW | 
|    1 // Copyright 2006-2009 the V8 project authors. All rights reserved. |    1 // Copyright 2006-2009 the V8 project authors. All rights reserved. | 
|    2 // Redistribution and use in source and binary forms, with or without |    2 // Redistribution and use in source and binary forms, with or without | 
|    3 // modification, are permitted provided that the following conditions are |    3 // modification, are permitted provided that the following conditions are | 
|    4 // met: |    4 // met: | 
|    5 // |    5 // | 
|    6 //     * Redistributions of source code must retain the above copyright |    6 //     * Redistributions of source code must retain the above copyright | 
|    7 //       notice, this list of conditions and the following disclaimer. |    7 //       notice, this list of conditions and the following disclaimer. | 
|    8 //     * Redistributions in binary form must reproduce the above |    8 //     * Redistributions in binary form must reproduce the above | 
|    9 //       copyright notice, this list of conditions and the following |    9 //       copyright notice, this list of conditions and the following | 
|   10 //       disclaimer in the documentation and/or other materials provided |   10 //       disclaimer in the documentation and/or other materials provided | 
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   72   HashMap encodings_; |   72   HashMap encodings_; | 
|   73   static uint32_t Hash(Address key) { |   73   static uint32_t Hash(Address key) { | 
|   74     return static_cast<uint32_t>(reinterpret_cast<uintptr_t>(key) >> 2); |   74     return static_cast<uint32_t>(reinterpret_cast<uintptr_t>(key) >> 2); | 
|   75   } |   75   } | 
|   76  |   76  | 
|   77   int IndexOf(Address key) const; |   77   int IndexOf(Address key) const; | 
|   78  |   78  | 
|   79   static bool Match(void* key1, void* key2) { return key1 == key2; } |   79   static bool Match(void* key1, void* key2) { return key1 == key2; } | 
|   80  |   80  | 
|   81   void Put(Address key, int index); |   81   void Put(Address key, int index); | 
 |   82  | 
 |   83   Isolate* isolate_; | 
|   82 }; |   84 }; | 
|   83  |   85  | 
|   84  |   86  | 
|   85 class ExternalReferenceDecoder { |   87 class ExternalReferenceDecoder { | 
|   86  public: |   88  public: | 
|   87   ExternalReferenceDecoder(); |   89   ExternalReferenceDecoder(); | 
|   88   ~ExternalReferenceDecoder(); |   90   ~ExternalReferenceDecoder(); | 
|   89  |   91  | 
|   90   Address Decode(uint32_t key) const { |   92   Address Decode(uint32_t key) const { | 
|   91     if (key == 0) return NULL; |   93     if (key == 0) return NULL; | 
|   92     return *Lookup(key); |   94     return *Lookup(key); | 
|   93   } |   95   } | 
|   94  |   96  | 
|   95  private: |   97  private: | 
|   96   Address** encodings_; |   98   Address** encodings_; | 
|   97  |   99  | 
|   98   Address* Lookup(uint32_t key) const { |  100   Address* Lookup(uint32_t key) const { | 
|   99     int type = key >> kReferenceTypeShift; |  101     int type = key >> kReferenceTypeShift; | 
|  100     ASSERT(kFirstTypeCode <= type && type < kTypeCodeCount); |  102     ASSERT(kFirstTypeCode <= type && type < kTypeCodeCount); | 
|  101     int id = key & kReferenceIdMask; |  103     int id = key & kReferenceIdMask; | 
|  102     return &encodings_[type][id]; |  104     return &encodings_[type][id]; | 
|  103   } |  105   } | 
|  104  |  106  | 
|  105   void Put(uint32_t key, Address value) { |  107   void Put(uint32_t key, Address value) { | 
|  106     *Lookup(key) = value; |  108     *Lookup(key) = value; | 
|  107   } |  109   } | 
 |  110  | 
 |  111   Isolate* isolate_; | 
|  108 }; |  112 }; | 
|  109  |  113  | 
|  110  |  114  | 
|  111 class SnapshotByteSource { |  115 class SnapshotByteSource { | 
|  112  public: |  116  public: | 
|  113   SnapshotByteSource(const byte* array, int length) |  117   SnapshotByteSource(const byte* array, int length) | 
|  114     : data_(array), length_(length), position_(0) { } |  118     : data_(array), length_(length), position_(0) { } | 
|  115  |  119  | 
|  116   bool HasMore() { return position_ < length_; } |  120   bool HasMore() { return position_ < length_; } | 
|  117  |  121  | 
| (...skipping 19 matching lines...) Expand all  Loading... | 
|  137 }; |  141 }; | 
|  138  |  142  | 
|  139  |  143  | 
|  140 // It is very common to have a reference to objects at certain offsets in the |  144 // It is very common to have a reference to objects at certain offsets in the | 
|  141 // heap.  These offsets have been determined experimentally.  We code |  145 // heap.  These offsets have been determined experimentally.  We code | 
|  142 // references to such objects in a single byte that encodes the way the pointer |  146 // references to such objects in a single byte that encodes the way the pointer | 
|  143 // is written (only plain pointers allowed), the space number and the offset. |  147 // is written (only plain pointers allowed), the space number and the offset. | 
|  144 // This only works for objects in the first page of a space.  Don't use this for |  148 // This only works for objects in the first page of a space.  Don't use this for | 
|  145 // things in newspace since it bypasses the write barrier. |  149 // things in newspace since it bypasses the write barrier. | 
|  146  |  150  | 
|  147 static const int k64 = (sizeof(uintptr_t) - 4) / 4; |  151 RLYSTC const int k64 = (sizeof(uintptr_t) - 4) / 4; | 
|  148  |  152  | 
|  149 #define COMMON_REFERENCE_PATTERNS(f)                               \ |  153 #define COMMON_REFERENCE_PATTERNS(f)                               \ | 
|  150   f(kNumberOfSpaces, 2, (11 - k64))                                \ |  154   f(kNumberOfSpaces, 2, (11 - k64))                                \ | 
|  151   f((kNumberOfSpaces + 1), 2, 0)                                   \ |  155   f((kNumberOfSpaces + 1), 2, 0)                                   \ | 
|  152   f((kNumberOfSpaces + 2), 2, (142 - 16 * k64))                    \ |  156   f((kNumberOfSpaces + 2), 2, (142 - 16 * k64))                    \ | 
|  153   f((kNumberOfSpaces + 3), 2, (74 - 15 * k64))                     \ |  157   f((kNumberOfSpaces + 3), 2, (74 - 15 * k64))                     \ | 
|  154   f((kNumberOfSpaces + 4), 2, 5)                                   \ |  158   f((kNumberOfSpaces + 4), 2, 5)                                   \ | 
|  155   f((kNumberOfSpaces + 5), 1, 135)                                 \ |  159   f((kNumberOfSpaces + 5), 1, 135)                                 \ | 
|  156   f((kNumberOfSpaces + 6), 2, (228 - 39 * k64)) |  160   f((kNumberOfSpaces + 6), 2, (228 - 39 * k64)) | 
|  157  |  161  | 
| (...skipping 12 matching lines...) Expand all  Loading... | 
|  170   f(12, 24) \ |  174   f(12, 24) \ | 
|  171   f(13, 28) \ |  175   f(13, 28) \ | 
|  172   f(14, 32) \ |  176   f(14, 32) \ | 
|  173   f(15, 36) |  177   f(15, 36) | 
|  174  |  178  | 
|  175 // The Serializer/Deserializer class is a common superclass for Serializer and |  179 // The Serializer/Deserializer class is a common superclass for Serializer and | 
|  176 // Deserializer which is used to store common constants and methods used by |  180 // Deserializer which is used to store common constants and methods used by | 
|  177 // both. |  181 // both. | 
|  178 class SerializerDeserializer: public ObjectVisitor { |  182 class SerializerDeserializer: public ObjectVisitor { | 
|  179  public: |  183  public: | 
|  180   static void Iterate(ObjectVisitor* visitor); |  184   RLYSTC void Iterate(ObjectVisitor* visitor); | 
|  181   static void SetSnapshotCacheSize(int size); |  185   RLYSTC void SetSnapshotCacheSize(int size); | 
|  182  |  186  | 
|  183  protected: |  187  protected: | 
|  184   // Where the pointed-to object can be found: |  188   // Where the pointed-to object can be found: | 
|  185   enum Where { |  189   enum Where { | 
|  186     kNewObject = 0,                 // Object is next in snapshot. |  190     kNewObject = 0,                 // Object is next in snapshot. | 
|  187     // 1-8                             One per space. |  191     // 1-8                             One per space. | 
|  188     kRootArray = 0x9,               // Object is found in root array. |  192     kRootArray = 0x9,               // Object is found in root array. | 
|  189     kPartialSnapshotCache = 0xa,    // Object is in the cache. |  193     kPartialSnapshotCache = 0xa,    // Object is in the cache. | 
|  190     kExternalReference = 0xb,       // Pointer to an external reference. |  194     kExternalReference = 0xb,       // Pointer to an external reference. | 
|  191     // 0xc-0xf                         Free. |  195     // 0xc-0xf                         Free. | 
| (...skipping 17 matching lines...) Expand all  Loading... | 
|  209  |  213  | 
|  210   // Where to point within the object. |  214   // Where to point within the object. | 
|  211   enum WhereToPoint { |  215   enum WhereToPoint { | 
|  212     kStartOfObject = 0, |  216     kStartOfObject = 0, | 
|  213     kFirstInstruction = 0x80, |  217     kFirstInstruction = 0x80, | 
|  214     kWhereToPointMask = 0x80 |  218     kWhereToPointMask = 0x80 | 
|  215   }; |  219   }; | 
|  216  |  220  | 
|  217   // Misc. |  221   // Misc. | 
|  218   // Raw data to be copied from the snapshot. |  222   // Raw data to be copied from the snapshot. | 
|  219   static const int kRawData = 0x30; |  223   RLYSTC const int kRawData = 0x30; | 
|  220   // Some common raw lengths: 0x31-0x3f |  224   // Some common raw lengths: 0x31-0x3f | 
|  221   // A tag emitted at strategic points in the snapshot to delineate sections. |  225   // A tag emitted at strategic points in the snapshot to delineate sections. | 
|  222   // If the deserializer does not find these at the expected moments then it |  226   // If the deserializer does not find these at the expected moments then it | 
|  223   // is an indication that the snapshot and the VM do not fit together. |  227   // is an indication that the snapshot and the VM do not fit together. | 
|  224   // Examine the build process for architecture, version or configuration |  228   // Examine the build process for architecture, version or configuration | 
|  225   // mismatches. |  229   // mismatches. | 
|  226   static const int kSynchronize = 0x70; |  230   RLYSTC const int kSynchronize = 0x70; | 
|  227   // Used for the source code of the natives, which is in the executable, but |  231   // Used for the source code of the natives, which is in the executable, but | 
|  228   // is referred to from external strings in the snapshot. |  232   // is referred to from external strings in the snapshot. | 
|  229   static const int kNativesStringResource = 0x71; |  233   RLYSTC const int kNativesStringResource = 0x71; | 
|  230   static const int kNewPage = 0x72; |  234   RLYSTC const int kNewPage = 0x72; | 
|  231   // 0x73-0x7f                            Free. |  235   // 0x73-0x7f                            Free. | 
|  232   // 0xb0-0xbf                            Free. |  236   // 0xb0-0xbf                            Free. | 
|  233   // 0xf0-0xff                            Free. |  237   // 0xf0-0xff                            Free. | 
|  234  |  238  | 
|  235  |  239  | 
|  236   static const int kLargeData = LAST_SPACE; |  240   RLYSTC const int kLargeData = LAST_SPACE; | 
|  237   static const int kLargeCode = kLargeData + 1; |  241   RLYSTC const int kLargeCode = kLargeData + 1; | 
|  238   static const int kLargeFixedArray = kLargeCode + 1; |  242   RLYSTC const int kLargeFixedArray = kLargeCode + 1; | 
|  239   static const int kNumberOfSpaces = kLargeFixedArray + 1; |  243   RLYSTC const int kNumberOfSpaces = kLargeFixedArray + 1; | 
|  240   static const int kAnyOldSpace = -1; |  244   RLYSTC const int kAnyOldSpace = -1; | 
|  241  |  245  | 
|  242   // A bitmask for getting the space out of an instruction. |  246   // A bitmask for getting the space out of an instruction. | 
|  243   static const int kSpaceMask = 15; |  247   RLYSTC const int kSpaceMask = 15; | 
|  244  |  248  | 
|  245   static inline bool SpaceIsLarge(int space) { return space >= kLargeData; } |  249   RLYSTC inline bool SpaceIsLarge(int space) { return space >= kLargeData; } | 
|  246   static inline bool SpaceIsPaged(int space) { |  250   RLYSTC inline bool SpaceIsPaged(int space) { | 
|  247     return space >= FIRST_PAGED_SPACE && space <= LAST_PAGED_SPACE; |  251     return space >= FIRST_PAGED_SPACE && space <= LAST_PAGED_SPACE; | 
|  248   } |  252   } | 
|  249  |  | 
|  250   static int partial_snapshot_cache_length_; |  | 
|  251   static const int kPartialSnapshotCacheCapacity = 1400; |  | 
|  252   static Object* partial_snapshot_cache_[]; |  | 
|  253 }; |  253 }; | 
|  254  |  254  | 
|  255  |  255  | 
|  256 int SnapshotByteSource::GetInt() { |  256 int SnapshotByteSource::GetInt() { | 
|  257   // A little unwind to catch the really small ints. |  257   // A little unwind to catch the really small ints. | 
|  258   int snapshot_byte = Get(); |  258   int snapshot_byte = Get(); | 
|  259   if ((snapshot_byte & 0x80) == 0) { |  259   if ((snapshot_byte & 0x80) == 0) { | 
|  260     return snapshot_byte; |  260     return snapshot_byte; | 
|  261   } |  261   } | 
|  262   int accumulator = (snapshot_byte & 0x7f) << 7; |  262   int accumulator = (snapshot_byte & 0x7f) << 7; | 
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  306   virtual void VisitRuntimeEntry(RelocInfo* rinfo) { |  306   virtual void VisitRuntimeEntry(RelocInfo* rinfo) { | 
|  307     UNREACHABLE(); |  307     UNREACHABLE(); | 
|  308   } |  308   } | 
|  309  |  309  | 
|  310   void ReadChunk(Object** start, Object** end, int space, Address address); |  310   void ReadChunk(Object** start, Object** end, int space, Address address); | 
|  311   HeapObject* GetAddressFromStart(int space); |  311   HeapObject* GetAddressFromStart(int space); | 
|  312   inline HeapObject* GetAddressFromEnd(int space); |  312   inline HeapObject* GetAddressFromEnd(int space); | 
|  313   Address Allocate(int space_number, Space* space, int size); |  313   Address Allocate(int space_number, Space* space, int size); | 
|  314   void ReadObject(int space_number, Space* space, Object** write_back); |  314   void ReadObject(int space_number, Space* space, Object** write_back); | 
|  315  |  315  | 
 |  316   // Cached current isolate. | 
 |  317   Isolate* isolate_; | 
 |  318  | 
|  316   // Keep track of the pages in the paged spaces. |  319   // Keep track of the pages in the paged spaces. | 
|  317   // (In large object space we are keeping track of individual objects |  320   // (In large object space we are keeping track of individual objects | 
|  318   // rather than pages.)  In new space we just need the address of the |  321   // rather than pages.)  In new space we just need the address of the | 
|  319   // first object and the others will flow from that. |  322   // first object and the others will flow from that. | 
|  320   List<Address> pages_[SerializerDeserializer::kNumberOfSpaces]; |  323   List<Address> pages_[SerializerDeserializer::kNumberOfSpaces]; | 
|  321  |  324  | 
|  322   SnapshotByteSource* source_; |  325   SnapshotByteSource* source_; | 
|  323   static ExternalReferenceDecoder* external_reference_decoder_; |  | 
|  324   // This is the address of the next object that will be allocated in each |  326   // This is the address of the next object that will be allocated in each | 
|  325   // space.  It is used to calculate the addresses of back-references. |  327   // space.  It is used to calculate the addresses of back-references. | 
|  326   Address high_water_[LAST_SPACE + 1]; |  328   Address high_water_[LAST_SPACE + 1]; | 
|  327   // This is the address of the most recent object that was allocated.  It |  329   // This is the address of the most recent object that was allocated.  It | 
|  328   // is used to set the location of the new page when we encounter a |  330   // is used to set the location of the new page when we encounter a | 
|  329   // START_NEW_PAGE_SERIALIZATION tag. |  331   // START_NEW_PAGE_SERIALIZATION tag. | 
|  330   Address last_object_address_; |  332   Address last_object_address_; | 
|  331  |  333  | 
 |  334   ExternalReferenceDecoder* external_reference_decoder_; | 
 |  335  | 
|  332   DISALLOW_COPY_AND_ASSIGN(Deserializer); |  336   DISALLOW_COPY_AND_ASSIGN(Deserializer); | 
|  333 }; |  337 }; | 
|  334  |  338  | 
|  335  |  339  | 
|  336 class SnapshotByteSink { |  340 class SnapshotByteSink { | 
|  337  public: |  341  public: | 
|  338   virtual ~SnapshotByteSink() { } |  342   virtual ~SnapshotByteSink() { } | 
|  339   virtual void Put(int byte, const char* description) = 0; |  343   virtual void Put(int byte, const char* description) = 0; | 
|  340   virtual void PutSection(int byte, const char* description) { |  344   virtual void PutSection(int byte, const char* description) { | 
|  341     Put(byte, description); |  345     Put(byte, description); | 
| (...skipping 27 matching lines...) Expand all  Loading... | 
|  369   } |  373   } | 
|  370  |  374  | 
|  371   void AddMapping(HeapObject* obj, int to) { |  375   void AddMapping(HeapObject* obj, int to) { | 
|  372     ASSERT(!IsMapped(obj)); |  376     ASSERT(!IsMapped(obj)); | 
|  373     HashMap::Entry* entry = |  377     HashMap::Entry* entry = | 
|  374         serialization_map_->Lookup(Key(obj), Hash(obj), true); |  378         serialization_map_->Lookup(Key(obj), Hash(obj), true); | 
|  375     entry->value = Value(to); |  379     entry->value = Value(to); | 
|  376   } |  380   } | 
|  377  |  381  | 
|  378  private: |  382  private: | 
|  379   static bool SerializationMatchFun(void* key1, void* key2) { |  383   RLYSTC bool SerializationMatchFun(void* key1, void* key2) { | 
|  380     return key1 == key2; |  384     return key1 == key2; | 
|  381   } |  385   } | 
|  382  |  386  | 
|  383   static uint32_t Hash(HeapObject* obj) { |  387   RLYSTC uint32_t Hash(HeapObject* obj) { | 
|  384     return static_cast<int32_t>(reinterpret_cast<intptr_t>(obj->address())); |  388     return static_cast<int32_t>(reinterpret_cast<intptr_t>(obj->address())); | 
|  385   } |  389   } | 
|  386  |  390  | 
|  387   static void* Key(HeapObject* obj) { |  391   RLYSTC void* Key(HeapObject* obj) { | 
|  388     return reinterpret_cast<void*>(obj->address()); |  392     return reinterpret_cast<void*>(obj->address()); | 
|  389   } |  393   } | 
|  390  |  394  | 
|  391   static void* Value(int v) { |  395   RLYSTC void* Value(int v) { | 
|  392     return reinterpret_cast<void*>(v); |  396     return reinterpret_cast<void*>(v); | 
|  393   } |  397   } | 
|  394  |  398  | 
|  395   HashMap* serialization_map_; |  399   HashMap* serialization_map_; | 
|  396   AssertNoAllocation* no_allocation_; |  400   AssertNoAllocation* no_allocation_; | 
|  397   DISALLOW_COPY_AND_ASSIGN(SerializationAddressMapper); |  401   DISALLOW_COPY_AND_ASSIGN(SerializationAddressMapper); | 
|  398 }; |  402 }; | 
|  399  |  403  | 
|  400  |  404  | 
|  401 class Serializer : public SerializerDeserializer { |  405 // There can be only one serializer per V8 process. | 
 |  406 STATIC_CLASS Serializer : public SerializerDeserializer { | 
|  402  public: |  407  public: | 
|  403   explicit Serializer(SnapshotByteSink* sink); |  408   explicit Serializer(SnapshotByteSink* sink); | 
|  404   ~Serializer(); |  409   ~Serializer(); | 
|  405   void VisitPointers(Object** start, Object** end); |  410   void VisitPointers(Object** start, Object** end); | 
|  406   // You can call this after serialization to find out how much space was used |  411   // You can call this after serialization to find out how much space was used | 
|  407   // in each space. |  412   // in each space. | 
|  408   int CurrentAllocationAddress(int space) { |  413   int CurrentAllocationAddress(int space) { | 
|  409     if (SpaceIsLarge(space)) return large_object_total_; |  414     if (SpaceIsLarge(space)) return large_object_total_; | 
|  410     return fullness_[space]; |  415     return fullness_[space]; | 
|  411   } |  416   } | 
|  412  |  417  | 
|  413   static void Enable() { |  418   RLYSTC void Enable() { | 
|  414     if (!serialization_enabled_) { |  419     if (!serialization_enabled_) { | 
|  415       ASSERT(!too_late_to_enable_now_); |  420       ASSERT(!too_late_to_enable_now_); | 
|  416     } |  421     } | 
|  417     serialization_enabled_ = true; |  422     serialization_enabled_ = true; | 
|  418   } |  423   } | 
|  419  |  424  | 
|  420   static void Disable() { serialization_enabled_ = false; } |  425   RLYSTC void Disable() { serialization_enabled_ = false; } | 
|  421   // Call this when you have made use of the fact that there is no serialization |  426   // Call this when you have made use of the fact that there is no serialization | 
|  422   // going on. |  427   // going on. | 
|  423   static void TooLateToEnableNow() { too_late_to_enable_now_ = true; } |  428   RLYSTC void TooLateToEnableNow() { too_late_to_enable_now_ = true; } | 
|  424   static bool enabled() { return serialization_enabled_; } |  429   RLYSTC bool enabled() { return serialization_enabled_; } | 
|  425   SerializationAddressMapper* address_mapper() { return &address_mapper_; } |  430   SerializationAddressMapper* address_mapper() { return &address_mapper_; } | 
|  426 #ifdef DEBUG |  431 #ifdef DEBUG | 
|  427   virtual void Synchronize(const char* tag); |  432   virtual void Synchronize(const char* tag); | 
|  428 #endif |  433 #endif | 
|  429  |  434  | 
|  430  protected: |  435  protected: | 
|  431   static const int kInvalidRootIndex = -1; |  436   RLYSTC const int kInvalidRootIndex = -1; | 
|  432   virtual int RootIndex(HeapObject* heap_object) = 0; |  437   virtual int RootIndex(HeapObject* heap_object) = 0; | 
|  433   virtual bool ShouldBeInThePartialSnapshotCache(HeapObject* o) = 0; |  438   virtual bool ShouldBeInThePartialSnapshotCache(HeapObject* o) = 0; | 
|  434  |  439  | 
|  435   class ObjectSerializer : public ObjectVisitor { |  440   class ObjectSerializer : public ObjectVisitor { | 
|  436    public: |  441    public: | 
|  437     ObjectSerializer(Serializer* serializer, |  442     ObjectSerializer(Serializer* serializer, | 
|  438                      Object* o, |  443                      Object* o, | 
|  439                      SnapshotByteSink* sink, |  444                      SnapshotByteSink* sink, | 
|  440                      HowToCode how_to_code, |  445                      HowToCode how_to_code, | 
|  441                      WhereToPoint where_to_point) |  446                      WhereToPoint where_to_point) | 
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  476   void SerializeReferenceToPreviousObject( |  481   void SerializeReferenceToPreviousObject( | 
|  477       int space, |  482       int space, | 
|  478       int address, |  483       int address, | 
|  479       HowToCode how_to_code, |  484       HowToCode how_to_code, | 
|  480       WhereToPoint where_to_point); |  485       WhereToPoint where_to_point); | 
|  481   void InitializeAllocators(); |  486   void InitializeAllocators(); | 
|  482   // This will return the space for an object.  If the object is in large |  487   // This will return the space for an object.  If the object is in large | 
|  483   // object space it may return kLargeCode or kLargeFixedArray in order |  488   // object space it may return kLargeCode or kLargeFixedArray in order | 
|  484   // to indicate to the deserializer what kind of large object allocation |  489   // to indicate to the deserializer what kind of large object allocation | 
|  485   // to make. |  490   // to make. | 
|  486   static int SpaceOfObject(HeapObject* object); |  491   RLYSTC int SpaceOfObject(HeapObject* object); | 
|  487   // This just returns the space of the object.  It will return LO_SPACE |  492   // This just returns the space of the object.  It will return LO_SPACE | 
|  488   // for all large objects since you can't check the type of the object |  493   // for all large objects since you can't check the type of the object | 
|  489   // once the map has been used for the serialization address. |  494   // once the map has been used for the serialization address. | 
|  490   static int SpaceOfAlreadySerializedObject(HeapObject* object); |  495   RLYSTC int SpaceOfAlreadySerializedObject(HeapObject* object); | 
|  491   int Allocate(int space, int size, bool* new_page_started); |  496   int Allocate(int space, int size, bool* new_page_started); | 
|  492   int EncodeExternalReference(Address addr) { |  497   int EncodeExternalReference(Address addr) { | 
|  493     return external_reference_encoder_->Encode(addr); |  498     return external_reference_encoder_->Encode(addr); | 
|  494   } |  499   } | 
|  495  |  500  | 
|  496   // Keep track of the fullness of each space in order to generate |  501   // Keep track of the fullness of each space in order to generate | 
|  497   // relative addresses for back references.  Large objects are |  502   // relative addresses for back references.  Large objects are | 
|  498   // just numbered sequentially since relative addresses make no |  503   // just numbered sequentially since relative addresses make no | 
|  499   // sense in large object space. |  504   // sense in large object space. | 
|  500   int fullness_[LAST_SPACE + 1]; |  505   int fullness_[LAST_SPACE + 1]; | 
|  501   SnapshotByteSink* sink_; |  506   SnapshotByteSink* sink_; | 
|  502   int current_root_index_; |  507   int current_root_index_; | 
|  503   ExternalReferenceEncoder* external_reference_encoder_; |  508   ExternalReferenceEncoder* external_reference_encoder_; | 
|  504   static bool serialization_enabled_; |  509   RLYSTC bool serialization_enabled_; | 
|  505   // Did we already make use of the fact that serialization was not enabled? |  510   // Did we already make use of the fact that serialization was not enabled? | 
|  506   static bool too_late_to_enable_now_; |  511   RLYSTC bool too_late_to_enable_now_; | 
|  507   int large_object_total_; |  512   int large_object_total_; | 
|  508   SerializationAddressMapper address_mapper_; |  513   SerializationAddressMapper address_mapper_; | 
|  509  |  514  | 
|  510   friend class ObjectSerializer; |  515   friend class ObjectSerializer; | 
|  511   friend class Deserializer; |  516   friend class Deserializer; | 
|  512  |  517  | 
|  513   DISALLOW_COPY_AND_ASSIGN(Serializer); |  518   DISALLOW_COPY_AND_ASSIGN(Serializer); | 
|  514 }; |  519 }; | 
|  515  |  520  | 
|  516  |  521  | 
| (...skipping 15 matching lines...) Expand all  Loading... | 
|  532   virtual int RootIndex(HeapObject* o); |  537   virtual int RootIndex(HeapObject* o); | 
|  533   virtual int PartialSnapshotCacheIndex(HeapObject* o); |  538   virtual int PartialSnapshotCacheIndex(HeapObject* o); | 
|  534   virtual bool ShouldBeInThePartialSnapshotCache(HeapObject* o) { |  539   virtual bool ShouldBeInThePartialSnapshotCache(HeapObject* o) { | 
|  535     // Scripts should be referred only through shared function infos.  We can't |  540     // Scripts should be referred only through shared function infos.  We can't | 
|  536     // allow them to be part of the partial snapshot because they contain a |  541     // allow them to be part of the partial snapshot because they contain a | 
|  537     // unique ID, and deserializing several partial snapshots containing script |  542     // unique ID, and deserializing several partial snapshots containing script | 
|  538     // would cause dupes. |  543     // would cause dupes. | 
|  539     ASSERT(!o->IsScript()); |  544     ASSERT(!o->IsScript()); | 
|  540     return o->IsString() || o->IsSharedFunctionInfo() || |  545     return o->IsString() || o->IsSharedFunctionInfo() || | 
|  541            o->IsHeapNumber() || o->IsCode() || |  546            o->IsHeapNumber() || o->IsCode() || | 
|  542            o->map() == Heap::fixed_cow_array_map(); |  547            o->map() == HEAP->fixed_cow_array_map(); | 
|  543   } |  548   } | 
|  544  |  549  | 
|  545  private: |  550  private: | 
|  546   Serializer* startup_serializer_; |  551   Serializer* startup_serializer_; | 
|  547   DISALLOW_COPY_AND_ASSIGN(PartialSerializer); |  552   DISALLOW_COPY_AND_ASSIGN(PartialSerializer); | 
|  548 }; |  553 }; | 
|  549  |  554  | 
|  550  |  555  | 
|  551 class StartupSerializer : public Serializer { |  556 class StartupSerializer : public Serializer { | 
|  552  public: |  557  public: | 
|  553   explicit StartupSerializer(SnapshotByteSink* sink) : Serializer(sink) { |  558   explicit StartupSerializer(SnapshotByteSink* sink) : Serializer(sink) { | 
|  554     // Clear the cache of objects used by the partial snapshot.  After the |  559     // Clear the cache of objects used by the partial snapshot.  After the | 
|  555     // strong roots have been serialized we can create a partial snapshot |  560     // strong roots have been serialized we can create a partial snapshot | 
|  556     // which will repopulate the cache with objects neede by that partial |  561     // which will repopulate the cache with objects neede by that partial | 
|  557     // snapshot. |  562     // snapshot. | 
|  558     partial_snapshot_cache_length_ = 0; |  563     Isolate::Current()->set_serialize_partial_snapshot_cache_length(0); | 
|  559   } |  564   } | 
|  560   // Serialize the current state of the heap.  The order is: |  565   // Serialize the current state of the heap.  The order is: | 
|  561   // 1) Strong references. |  566   // 1) Strong references. | 
|  562   // 2) Partial snapshot cache. |  567   // 2) Partial snapshot cache. | 
|  563   // 3) Weak references (eg the symbol table). |  568   // 3) Weak references (eg the symbol table). | 
|  564   virtual void SerializeStrongReferences(); |  569   virtual void SerializeStrongReferences(); | 
|  565   virtual void SerializeObject(Object* o, |  570   virtual void SerializeObject(Object* o, | 
|  566                                HowToCode how_to_code, |  571                                HowToCode how_to_code, | 
|  567                                WhereToPoint where_to_point); |  572                                WhereToPoint where_to_point); | 
|  568   void SerializeWeakReferences(); |  573   void SerializeWeakReferences(); | 
|  569   void Serialize() { |  574   void Serialize() { | 
|  570     SerializeStrongReferences(); |  575     SerializeStrongReferences(); | 
|  571     SerializeWeakReferences(); |  576     SerializeWeakReferences(); | 
|  572   } |  577   } | 
|  573  |  578  | 
|  574  private: |  579  private: | 
|  575   virtual int RootIndex(HeapObject* o) { return kInvalidRootIndex; } |  580   virtual int RootIndex(HeapObject* o) { return kInvalidRootIndex; } | 
|  576   virtual bool ShouldBeInThePartialSnapshotCache(HeapObject* o) { |  581   virtual bool ShouldBeInThePartialSnapshotCache(HeapObject* o) { | 
|  577     return false; |  582     return false; | 
|  578   } |  583   } | 
|  579 }; |  584 }; | 
|  580  |  585  | 
|  581  |  586  | 
|  582 } }  // namespace v8::internal |  587 } }  // namespace v8::internal | 
|  583  |  588  | 
|  584 #endif  // V8_SERIALIZE_H_ |  589 #endif  // V8_SERIALIZE_H_ | 
| OLD | NEW |