jkummerow@chromium.org | 05ed9dd | 2012-01-23 14:42:48 +0000 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
| 28 | #ifndef V8_SERIALIZE_H_ |
| 29 | #define V8_SERIALIZE_H_ |
| 30 | |
| 31 | #include "hashmap.h" |
| 32 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 33 | namespace v8 { |
| 34 | namespace internal { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 35 | |
| 36 | // A TypeCode is used to distinguish different kinds of external reference. |
| 37 | // It is a single bit to make testing for types easy. |
| 38 | enum TypeCode { |
| 39 | UNCLASSIFIED, // One-of-a-kind references. |
| 40 | BUILTIN, |
| 41 | RUNTIME_FUNCTION, |
| 42 | IC_UTILITY, |
| 43 | DEBUG_ADDRESS, |
| 44 | STATS_COUNTER, |
| 45 | TOP_ADDRESS, |
| 46 | C_BUILTIN, |
| 47 | EXTENSION, |
| 48 | ACCESSOR, |
| 49 | RUNTIME_ENTRY, |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 50 | STUB_CACHE_TABLE, |
| 51 | LAZY_DEOPTIMIZATION |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 52 | }; |
| 53 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 54 | const int kTypeCodeCount = LAZY_DEOPTIMIZATION + 1; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 55 | const int kFirstTypeCode = UNCLASSIFIED; |
| 56 | |
| 57 | const int kReferenceIdBits = 16; |
| 58 | const int kReferenceIdMask = (1 << kReferenceIdBits) - 1; |
| 59 | const int kReferenceTypeShift = kReferenceIdBits; |
| 60 | const int kDebugRegisterBits = 4; |
| 61 | const int kDebugIdShift = kDebugRegisterBits; |
| 62 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 63 | const int kDeoptTableSerializeEntryCount = 8; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 64 | |
danno@chromium.org | b645116 | 2011-08-17 14:33:23 +0000 | [diff] [blame] | 65 | // ExternalReferenceTable is a helper class that defines the relationship |
| 66 | // between external references and their encodings. It is used to build |
| 67 | // hashmaps in ExternalReferenceEncoder and ExternalReferenceDecoder. |
| 68 | class ExternalReferenceTable { |
| 69 | public: |
| 70 | static ExternalReferenceTable* instance(Isolate* isolate); |
| 71 | |
| 72 | ~ExternalReferenceTable() { } |
| 73 | |
| 74 | int size() const { return refs_.length(); } |
| 75 | |
| 76 | Address address(int i) { return refs_[i].address; } |
| 77 | |
| 78 | uint32_t code(int i) { return refs_[i].code; } |
| 79 | |
| 80 | const char* name(int i) { return refs_[i].name; } |
| 81 | |
| 82 | int max_id(int code) { return max_id_[code]; } |
| 83 | |
| 84 | private: |
| 85 | explicit ExternalReferenceTable(Isolate* isolate) : refs_(64) { |
| 86 | PopulateTable(isolate); |
| 87 | } |
| 88 | |
| 89 | struct ExternalReferenceEntry { |
| 90 | Address address; |
| 91 | uint32_t code; |
| 92 | const char* name; |
| 93 | }; |
| 94 | |
| 95 | void PopulateTable(Isolate* isolate); |
| 96 | |
| 97 | // For a few types of references, we can get their address from their id. |
| 98 | void AddFromId(TypeCode type, |
| 99 | uint16_t id, |
| 100 | const char* name, |
| 101 | Isolate* isolate); |
| 102 | |
| 103 | // For other types of references, the caller will figure out the address. |
| 104 | void Add(Address address, TypeCode type, uint16_t id, const char* name); |
| 105 | |
| 106 | List<ExternalReferenceEntry> refs_; |
| 107 | int max_id_[kTypeCodeCount]; |
| 108 | }; |
| 109 | |
| 110 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 111 | class ExternalReferenceEncoder { |
| 112 | public: |
| 113 | ExternalReferenceEncoder(); |
| 114 | |
| 115 | uint32_t Encode(Address key) const; |
| 116 | |
| 117 | const char* NameOfAddress(Address key) const; |
| 118 | |
| 119 | private: |
| 120 | HashMap encodings_; |
| 121 | static uint32_t Hash(Address key) { |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 122 | return static_cast<uint32_t>(reinterpret_cast<uintptr_t>(key) >> 2); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | int IndexOf(Address key) const; |
| 126 | |
| 127 | static bool Match(void* key1, void* key2) { return key1 == key2; } |
| 128 | |
| 129 | void Put(Address key, int index); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 130 | |
| 131 | Isolate* isolate_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 132 | }; |
| 133 | |
| 134 | |
| 135 | class ExternalReferenceDecoder { |
| 136 | public: |
| 137 | ExternalReferenceDecoder(); |
| 138 | ~ExternalReferenceDecoder(); |
| 139 | |
| 140 | Address Decode(uint32_t key) const { |
| 141 | if (key == 0) return NULL; |
| 142 | return *Lookup(key); |
| 143 | } |
| 144 | |
| 145 | private: |
| 146 | Address** encodings_; |
| 147 | |
| 148 | Address* Lookup(uint32_t key) const { |
| 149 | int type = key >> kReferenceTypeShift; |
| 150 | ASSERT(kFirstTypeCode <= type && type < kTypeCodeCount); |
| 151 | int id = key & kReferenceIdMask; |
| 152 | return &encodings_[type][id]; |
| 153 | } |
| 154 | |
| 155 | void Put(uint32_t key, Address value) { |
| 156 | *Lookup(key) = value; |
| 157 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 158 | |
| 159 | Isolate* isolate_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 160 | }; |
| 161 | |
| 162 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 163 | class SnapshotByteSource { |
| 164 | public: |
| 165 | SnapshotByteSource(const byte* array, int length) |
| 166 | : data_(array), length_(length), position_(0) { } |
| 167 | |
| 168 | bool HasMore() { return position_ < length_; } |
| 169 | |
| 170 | int Get() { |
| 171 | ASSERT(position_ < length_); |
| 172 | return data_[position_++]; |
| 173 | } |
| 174 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 175 | int32_t GetUnalignedInt() { |
| 176 | #if defined(V8_HOST_CAN_READ_UNALIGNED) && __BYTE_ORDER == __LITTLE_ENDIAN |
| 177 | int32_t answer; |
| 178 | ASSERT(position_ + sizeof(answer) <= length_ + 0u); |
| 179 | answer = *reinterpret_cast<const int32_t*>(data_ + position_); |
| 180 | #else |
| 181 | int32_t answer = data_[position_]; |
| 182 | answer |= data_[position_ + 1] << 8; |
| 183 | answer |= data_[position_ + 2] << 16; |
| 184 | answer |= data_[position_ + 3] << 24; |
| 185 | #endif |
| 186 | return answer; |
| 187 | } |
| 188 | |
| 189 | void Advance(int by) { position_ += by; } |
| 190 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 191 | inline void CopyRaw(byte* to, int number_of_bytes); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 192 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 193 | inline int GetInt(); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 194 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 195 | bool AtEOF(); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 196 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 197 | int position() { return position_; } |
| 198 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 199 | private: |
| 200 | const byte* data_; |
| 201 | int length_; |
| 202 | int position_; |
| 203 | }; |
| 204 | |
| 205 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 206 | // The Serializer/Deserializer class is a common superclass for Serializer and |
| 207 | // Deserializer which is used to store common constants and methods used by |
| 208 | // both. |
| 209 | class SerializerDeserializer: public ObjectVisitor { |
| 210 | public: |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 211 | static void Iterate(ObjectVisitor* visitor); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 212 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 213 | static int nop() { return kNop; } |
| 214 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 215 | protected: |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 216 | // Where the pointed-to object can be found: |
| 217 | enum Where { |
| 218 | kNewObject = 0, // Object is next in snapshot. |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 219 | // 1-6 One per space. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 220 | kRootArray = 0x9, // Object is found in root array. |
| 221 | kPartialSnapshotCache = 0xa, // Object is in the cache. |
| 222 | kExternalReference = 0xb, // Pointer to an external reference. |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 223 | kSkip = 0xc, // Skip n bytes. |
| 224 | kNop = 0xd, // Does nothing, used to pad. |
| 225 | // 0xe-0xf Free. |
| 226 | kBackref = 0x10, // Object is described relative to end. |
| 227 | // 0x11-0x16 One per space. |
| 228 | kBackrefWithSkip = 0x18, // Object is described relative to end. |
| 229 | // 0x19-0x1e One per space. |
| 230 | // 0x20-0x3f Used by misc. tags below. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 231 | kPointedToMask = 0x3f |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 232 | }; |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 233 | |
| 234 | // How to code the pointer to the object. |
| 235 | enum HowToCode { |
| 236 | kPlain = 0, // Straight pointer. |
| 237 | // What this means depends on the architecture: |
| 238 | kFromCode = 0x40, // A pointer inlined in code. |
| 239 | kHowToCodeMask = 0x40 |
| 240 | }; |
| 241 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 242 | // For kRootArrayConstants |
| 243 | enum WithSkip { |
| 244 | kNoSkipDistance = 0, |
| 245 | kHasSkipDistance = 0x40, |
| 246 | kWithSkipMask = 0x40 |
| 247 | }; |
| 248 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 249 | // Where to point within the object. |
| 250 | enum WhereToPoint { |
| 251 | kStartOfObject = 0, |
jkummerow@chromium.org | 000f7fb | 2012-08-01 11:14:42 +0000 | [diff] [blame] | 252 | kInnerPointer = 0x80, // First insn in code object or payload of cell. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 253 | kWhereToPointMask = 0x80 |
| 254 | }; |
| 255 | |
| 256 | // Misc. |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 257 | // Raw data to be copied from the snapshot. This byte code does not advance |
| 258 | // the current pointer, which is used for code objects, where we write the |
| 259 | // entire code in one memcpy, then fix up stuff with kSkip and other byte |
| 260 | // codes that overwrite data. |
| 261 | static const int kRawData = 0x20; |
| 262 | // Some common raw lengths: 0x21-0x3f. These autoadvance the current pointer. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 263 | // A tag emitted at strategic points in the snapshot to delineate sections. |
| 264 | // If the deserializer does not find these at the expected moments then it |
| 265 | // is an indication that the snapshot and the VM do not fit together. |
| 266 | // Examine the build process for architecture, version or configuration |
| 267 | // mismatches. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 268 | static const int kSynchronize = 0x70; |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 269 | // Used for the source code of the natives, which is in the executable, but |
| 270 | // is referred to from external strings in the snapshot. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 271 | static const int kNativesStringResource = 0x71; |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 272 | static const int kRepeat = 0x72; |
| 273 | static const int kConstantRepeat = 0x73; |
| 274 | // 0x73-0x7f Repeat last word (subtract 0x72 to get the count). |
| 275 | static const int kMaxRepeats = 0x7f - 0x72; |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 276 | static int CodeForRepeats(int repeats) { |
| 277 | ASSERT(repeats >= 1 && repeats <= kMaxRepeats); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 278 | return 0x72 + repeats; |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 279 | } |
| 280 | static int RepeatsForCode(int byte_code) { |
| 281 | ASSERT(byte_code >= kConstantRepeat && byte_code <= 0x7f); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 282 | return byte_code - 0x72; |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 283 | } |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 284 | static const int kRootArrayConstants = 0xa0; |
| 285 | // 0xa0-0xbf Things from the first 32 elements of the root array. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 286 | static const int kRootArrayNumberOfConstantEncodings = 0x20; |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 287 | static int RootArrayConstantFromByteCode(int byte_code) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 288 | return byte_code & 0x1f; |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 289 | } |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 290 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 291 | static const int kNumberOfSpaces = LO_SPACE; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 292 | static const int kAnyOldSpace = -1; |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 293 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 294 | // A bitmask for getting the space out of an instruction. |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 295 | static const int kSpaceMask = 7; |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 296 | }; |
| 297 | |
| 298 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 299 | int SnapshotByteSource::GetInt() { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 300 | // This way of variable-length encoding integers does not suffer from branch |
| 301 | // mispredictions. |
| 302 | uint32_t answer = GetUnalignedInt(); |
| 303 | int bytes = answer & 3; |
| 304 | Advance(bytes); |
| 305 | uint32_t mask = 0xffffffffu; |
| 306 | mask >>= 32 - (bytes << 3); |
| 307 | answer &= mask; |
| 308 | answer >>= 2; |
| 309 | return answer; |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | |
| 313 | void SnapshotByteSource::CopyRaw(byte* to, int number_of_bytes) { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 314 | OS::MemCopy(to, data_ + position_, number_of_bytes); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 315 | position_ += number_of_bytes; |
| 316 | } |
| 317 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 318 | |
| 319 | // A Deserializer reads a snapshot and reconstructs the Object graph it defines. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 320 | class Deserializer: public SerializerDeserializer { |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 321 | public: |
| 322 | // Create a deserializer from a snapshot byte source. |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 323 | explicit Deserializer(SnapshotByteSource* source); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 324 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 325 | virtual ~Deserializer(); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 326 | |
| 327 | // Deserialize the snapshot into an empty heap. |
| 328 | void Deserialize(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 329 | |
| 330 | // Deserialize a single object and the objects reachable from it. |
| 331 | void DeserializePartial(Object** root); |
| 332 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 333 | void set_reservation(int space_number, int reservation) { |
| 334 | ASSERT(space_number >= 0); |
| 335 | ASSERT(space_number <= LAST_SPACE); |
| 336 | reservations_[space_number] = reservation; |
| 337 | } |
| 338 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 339 | private: |
| 340 | virtual void VisitPointers(Object** start, Object** end); |
| 341 | |
| 342 | virtual void VisitExternalReferences(Address* start, Address* end) { |
| 343 | UNREACHABLE(); |
| 344 | } |
| 345 | |
| 346 | virtual void VisitRuntimeEntry(RelocInfo* rinfo) { |
| 347 | UNREACHABLE(); |
| 348 | } |
| 349 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 350 | // Fills in some heap data in an area from start to end (non-inclusive). The |
| 351 | // space id is used for the write barrier. The object_address is the address |
| 352 | // of the object we are writing into, or NULL if we are not writing into an |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 353 | // object, i.e. if we are writing a series of tagged values that are not on |
| 354 | // the heap. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 355 | void ReadChunk( |
| 356 | Object** start, Object** end, int space, Address object_address); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 357 | void ReadObject(int space_number, Object** write_back); |
| 358 | |
| 359 | // This routine both allocates a new object, and also keeps |
| 360 | // track of where objects have been allocated so that we can |
| 361 | // fix back references when deserializing. |
| 362 | Address Allocate(int space_index, int size) { |
| 363 | Address address = high_water_[space_index]; |
| 364 | high_water_[space_index] = address + size; |
| 365 | return address; |
| 366 | } |
| 367 | |
| 368 | // This returns the address of an object that has been described in the |
| 369 | // snapshot as being offset bytes back in a particular space. |
| 370 | HeapObject* GetAddressFromEnd(int space) { |
| 371 | int offset = source_->GetInt(); |
| 372 | offset <<= kObjectAlignmentBits; |
| 373 | return HeapObject::FromAddress(high_water_[space] - offset); |
| 374 | } |
| 375 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 376 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 377 | // Cached current isolate. |
| 378 | Isolate* isolate_; |
| 379 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 380 | SnapshotByteSource* source_; |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 381 | // This is the address of the next object that will be allocated in each |
| 382 | // space. It is used to calculate the addresses of back-references. |
| 383 | Address high_water_[LAST_SPACE + 1]; |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 384 | |
| 385 | int reservations_[LAST_SPACE + 1]; |
| 386 | static const intptr_t kUninitializedReservation = -1; |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 387 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 388 | ExternalReferenceDecoder* external_reference_decoder_; |
| 389 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 390 | DISALLOW_COPY_AND_ASSIGN(Deserializer); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 391 | }; |
| 392 | |
| 393 | |
| 394 | class SnapshotByteSink { |
| 395 | public: |
| 396 | virtual ~SnapshotByteSink() { } |
| 397 | virtual void Put(int byte, const char* description) = 0; |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 398 | virtual void PutSection(int byte, const char* description) { |
| 399 | Put(byte, description); |
| 400 | } |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 401 | void PutInt(uintptr_t integer, const char* description); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 402 | virtual int Position() = 0; |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 403 | }; |
| 404 | |
| 405 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 406 | // Mapping objects to their location after deserialization. |
| 407 | // This is used during building, but not at runtime by V8. |
| 408 | class SerializationAddressMapper { |
| 409 | public: |
| 410 | SerializationAddressMapper() |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 411 | : no_allocation_(), |
| 412 | serialization_map_(new HashMap(&SerializationMatchFun)) { } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 413 | |
| 414 | ~SerializationAddressMapper() { |
| 415 | delete serialization_map_; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 416 | } |
| 417 | |
| 418 | bool IsMapped(HeapObject* obj) { |
| 419 | return serialization_map_->Lookup(Key(obj), Hash(obj), false) != NULL; |
| 420 | } |
| 421 | |
| 422 | int MappedTo(HeapObject* obj) { |
| 423 | ASSERT(IsMapped(obj)); |
| 424 | return static_cast<int>(reinterpret_cast<intptr_t>( |
| 425 | serialization_map_->Lookup(Key(obj), Hash(obj), false)->value)); |
| 426 | } |
| 427 | |
| 428 | void AddMapping(HeapObject* obj, int to) { |
| 429 | ASSERT(!IsMapped(obj)); |
| 430 | HashMap::Entry* entry = |
| 431 | serialization_map_->Lookup(Key(obj), Hash(obj), true); |
| 432 | entry->value = Value(to); |
| 433 | } |
| 434 | |
| 435 | private: |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 436 | static bool SerializationMatchFun(void* key1, void* key2) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 437 | return key1 == key2; |
| 438 | } |
| 439 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 440 | static uint32_t Hash(HeapObject* obj) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 441 | return static_cast<int32_t>(reinterpret_cast<intptr_t>(obj->address())); |
| 442 | } |
| 443 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 444 | static void* Key(HeapObject* obj) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 445 | return reinterpret_cast<void*>(obj->address()); |
| 446 | } |
| 447 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 448 | static void* Value(int v) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 449 | return reinterpret_cast<void*>(v); |
| 450 | } |
| 451 | |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 452 | DisallowHeapAllocation no_allocation_; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 453 | HashMap* serialization_map_; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 454 | DISALLOW_COPY_AND_ASSIGN(SerializationAddressMapper); |
| 455 | }; |
| 456 | |
| 457 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 458 | // There can be only one serializer per V8 process. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 459 | class Serializer : public SerializerDeserializer { |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 460 | public: |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 461 | explicit Serializer(SnapshotByteSink* sink); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 462 | ~Serializer(); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 463 | void VisitPointers(Object** start, Object** end); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 464 | // You can call this after serialization to find out how much space was used |
| 465 | // in each space. |
| 466 | int CurrentAllocationAddress(int space) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 467 | ASSERT(space < kNumberOfSpaces); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 468 | return fullness_[space]; |
| 469 | } |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 470 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 471 | static void Enable() { |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 472 | if (!serialization_enabled_) { |
| 473 | ASSERT(!too_late_to_enable_now_); |
| 474 | } |
| 475 | serialization_enabled_ = true; |
| 476 | } |
| 477 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 478 | static void Disable() { serialization_enabled_ = false; } |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 479 | // Call this when you have made use of the fact that there is no serialization |
| 480 | // going on. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 481 | static void TooLateToEnableNow() { too_late_to_enable_now_ = true; } |
| 482 | static bool enabled() { return serialization_enabled_; } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 483 | SerializationAddressMapper* address_mapper() { return &address_mapper_; } |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 484 | void PutRoot(int index, |
| 485 | HeapObject* object, |
| 486 | HowToCode how, |
| 487 | WhereToPoint where, |
| 488 | int skip); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 489 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 490 | protected: |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 491 | static const int kInvalidRootIndex = -1; |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 492 | |
danno@chromium.org | 88aa058 | 2012-03-23 15:11:57 +0000 | [diff] [blame] | 493 | int RootIndex(HeapObject* heap_object, HowToCode from); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 494 | virtual bool ShouldBeInThePartialSnapshotCache(HeapObject* o) = 0; |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 495 | intptr_t root_index_wave_front() { return root_index_wave_front_; } |
| 496 | void set_root_index_wave_front(intptr_t value) { |
| 497 | ASSERT(value >= root_index_wave_front_); |
| 498 | root_index_wave_front_ = value; |
| 499 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 500 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 501 | class ObjectSerializer : public ObjectVisitor { |
| 502 | public: |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 503 | ObjectSerializer(Serializer* serializer, |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 504 | Object* o, |
| 505 | SnapshotByteSink* sink, |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 506 | HowToCode how_to_code, |
| 507 | WhereToPoint where_to_point) |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 508 | : serializer_(serializer), |
| 509 | object_(HeapObject::cast(o)), |
| 510 | sink_(sink), |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 511 | reference_representation_(how_to_code + where_to_point), |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 512 | bytes_processed_so_far_(0), |
| 513 | code_object_(o->IsCode()), |
| 514 | code_has_been_output_(false) { } |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 515 | void Serialize(); |
| 516 | void VisitPointers(Object** start, Object** end); |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 517 | void VisitEmbeddedPointer(RelocInfo* target); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 518 | void VisitExternalReferences(Address* start, Address* end); |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 519 | void VisitExternalReference(RelocInfo* rinfo); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 520 | void VisitCodeTarget(RelocInfo* target); |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 521 | void VisitCodeEntry(Address entry_address); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 522 | void VisitCell(RelocInfo* rinfo); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 523 | void VisitRuntimeEntry(RelocInfo* reloc); |
| 524 | // Used for seralizing the external strings that hold the natives source. |
| 525 | void VisitExternalAsciiString( |
| 526 | v8::String::ExternalAsciiStringResource** resource); |
| 527 | // We can't serialize a heap with external two byte strings. |
| 528 | void VisitExternalTwoByteString( |
| 529 | v8::String::ExternalStringResource** resource) { |
| 530 | UNREACHABLE(); |
| 531 | } |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 532 | |
| 533 | private: |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 534 | enum ReturnSkip { kCanReturnSkipInsteadOfSkipping, kIgnoringReturn }; |
| 535 | // This function outputs or skips the raw data between the last pointer and |
| 536 | // up to the current position. It optionally can just return the number of |
| 537 | // bytes to skip instead of performing a skip instruction, in case the skip |
| 538 | // can be merged into the next instruction. |
| 539 | int OutputRawData(Address up_to, ReturnSkip return_skip = kIgnoringReturn); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 540 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 541 | Serializer* serializer_; |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 542 | HeapObject* object_; |
| 543 | SnapshotByteSink* sink_; |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 544 | int reference_representation_; |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 545 | int bytes_processed_so_far_; |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 546 | bool code_object_; |
| 547 | bool code_has_been_output_; |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 548 | }; |
| 549 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 550 | virtual void SerializeObject(Object* o, |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 551 | HowToCode how_to_code, |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 552 | WhereToPoint where_to_point, |
| 553 | int skip) = 0; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 554 | void SerializeReferenceToPreviousObject( |
| 555 | int space, |
| 556 | int address, |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 557 | HowToCode how_to_code, |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 558 | WhereToPoint where_to_point, |
| 559 | int skip); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 560 | void InitializeAllocators(); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 561 | // This will return the space for an object. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 562 | static int SpaceOfObject(HeapObject* object); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 563 | int Allocate(int space, int size); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 564 | int EncodeExternalReference(Address addr) { |
| 565 | return external_reference_encoder_->Encode(addr); |
| 566 | } |
| 567 | |
yangguo@chromium.org | ab30bb8 | 2012-02-24 14:41:46 +0000 | [diff] [blame] | 568 | int SpaceAreaSize(int space); |
| 569 | |
| 570 | Isolate* isolate_; |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 571 | // Keep track of the fullness of each space in order to generate |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 572 | // relative addresses for back references. |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 573 | int fullness_[LAST_SPACE + 1]; |
| 574 | SnapshotByteSink* sink_; |
| 575 | int current_root_index_; |
| 576 | ExternalReferenceEncoder* external_reference_encoder_; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 577 | static bool serialization_enabled_; |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 578 | // Did we already make use of the fact that serialization was not enabled? |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 579 | static bool too_late_to_enable_now_; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 580 | SerializationAddressMapper address_mapper_; |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 581 | intptr_t root_index_wave_front_; |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 582 | void Pad(); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 583 | |
| 584 | friend class ObjectSerializer; |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 585 | friend class Deserializer; |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 586 | |
jkummerow@chromium.org | 05ed9dd | 2012-01-23 14:42:48 +0000 | [diff] [blame] | 587 | private: |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 588 | DISALLOW_COPY_AND_ASSIGN(Serializer); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 589 | }; |
| 590 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 591 | |
| 592 | class PartialSerializer : public Serializer { |
| 593 | public: |
| 594 | PartialSerializer(Serializer* startup_snapshot_serializer, |
| 595 | SnapshotByteSink* sink) |
| 596 | : Serializer(sink), |
| 597 | startup_serializer_(startup_snapshot_serializer) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 598 | set_root_index_wave_front(Heap::kStrongRootListLength); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 599 | } |
| 600 | |
| 601 | // Serialize the objects reachable from a single object pointer. |
| 602 | virtual void Serialize(Object** o); |
| 603 | virtual void SerializeObject(Object* o, |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 604 | HowToCode how_to_code, |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 605 | WhereToPoint where_to_point, |
| 606 | int skip); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 607 | |
| 608 | protected: |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 609 | virtual int PartialSnapshotCacheIndex(HeapObject* o); |
| 610 | virtual bool ShouldBeInThePartialSnapshotCache(HeapObject* o) { |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 611 | // Scripts should be referred only through shared function infos. We can't |
| 612 | // allow them to be part of the partial snapshot because they contain a |
| 613 | // unique ID, and deserializing several partial snapshots containing script |
| 614 | // would cause dupes. |
| 615 | ASSERT(!o->IsScript()); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame^] | 616 | return o->IsName() || o->IsSharedFunctionInfo() || |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 617 | o->IsHeapNumber() || o->IsCode() || |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 618 | o->IsScopeInfo() || |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 619 | o->map() == HEAP->fixed_cow_array_map(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 620 | } |
| 621 | |
| 622 | private: |
| 623 | Serializer* startup_serializer_; |
| 624 | DISALLOW_COPY_AND_ASSIGN(PartialSerializer); |
| 625 | }; |
| 626 | |
| 627 | |
| 628 | class StartupSerializer : public Serializer { |
| 629 | public: |
| 630 | explicit StartupSerializer(SnapshotByteSink* sink) : Serializer(sink) { |
| 631 | // Clear the cache of objects used by the partial snapshot. After the |
| 632 | // strong roots have been serialized we can create a partial snapshot |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 633 | // which will repopulate the cache with objects needed by that partial |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 634 | // snapshot. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 635 | Isolate::Current()->set_serialize_partial_snapshot_cache_length(0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 636 | } |
| 637 | // Serialize the current state of the heap. The order is: |
| 638 | // 1) Strong references. |
| 639 | // 2) Partial snapshot cache. |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 640 | // 3) Weak references (e.g. the string table). |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 641 | virtual void SerializeStrongReferences(); |
| 642 | virtual void SerializeObject(Object* o, |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 643 | HowToCode how_to_code, |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 644 | WhereToPoint where_to_point, |
| 645 | int skip); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 646 | void SerializeWeakReferences(); |
| 647 | void Serialize() { |
| 648 | SerializeStrongReferences(); |
| 649 | SerializeWeakReferences(); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 650 | Pad(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 651 | } |
| 652 | |
| 653 | private: |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 654 | virtual bool ShouldBeInThePartialSnapshotCache(HeapObject* o) { |
| 655 | return false; |
| 656 | } |
| 657 | }; |
| 658 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 659 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 660 | } } // namespace v8::internal |
| 661 | |
| 662 | #endif // V8_SERIALIZE_H_ |