serialize.h 21.6 KB
Newer Older
1
// Copyright 2012 the V8 project authors. All rights reserved.
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
//     * Redistributions of source code must retain the above copyright
//       notice, this list of conditions and the following disclaimer.
//     * Redistributions in binary form must reproduce the above
//       copyright notice, this list of conditions and the following
//       disclaimer in the documentation and/or other materials provided
//       with the distribution.
//     * Neither the name of Google Inc. nor the names of its
//       contributors may be used to endorse or promote products derived
//       from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#ifndef V8_SERIALIZE_H_
#define V8_SERIALIZE_H_

#include "hashmap.h"

33 34
namespace v8 {
namespace internal {
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49

// A TypeCode is used to distinguish different kinds of external reference.
// It is a single bit to make testing for types easy.
enum TypeCode {
  UNCLASSIFIED,        // One-of-a-kind references.
  BUILTIN,
  RUNTIME_FUNCTION,
  IC_UTILITY,
  DEBUG_ADDRESS,
  STATS_COUNTER,
  TOP_ADDRESS,
  C_BUILTIN,
  EXTENSION,
  ACCESSOR,
  RUNTIME_ENTRY,
50 51
  STUB_CACHE_TABLE,
  LAZY_DEOPTIMIZATION
52 53
};

54
const int kTypeCodeCount = LAZY_DEOPTIMIZATION + 1;
55 56 57 58 59 60 61 62
const int kFirstTypeCode = UNCLASSIFIED;

const int kReferenceIdBits = 16;
const int kReferenceIdMask = (1 << kReferenceIdBits) - 1;
const int kReferenceTypeShift = kReferenceIdBits;
const int kDebugRegisterBits = 4;
const int kDebugIdShift = kDebugRegisterBits;

63
const int kDeoptTableSerializeEntryCount = 8;
64

65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
// ExternalReferenceTable is a helper class that defines the relationship
// between external references and their encodings. It is used to build
// hashmaps in ExternalReferenceEncoder and ExternalReferenceDecoder.
class ExternalReferenceTable {
 public:
  static ExternalReferenceTable* instance(Isolate* isolate);

  ~ExternalReferenceTable() { }

  int size() const { return refs_.length(); }

  Address address(int i) { return refs_[i].address; }

  uint32_t code(int i) { return refs_[i].code; }

  const char* name(int i) { return refs_[i].name; }

  int max_id(int code) { return max_id_[code]; }

 private:
  explicit ExternalReferenceTable(Isolate* isolate) : refs_(64) {
      PopulateTable(isolate);
  }

  struct ExternalReferenceEntry {
    Address address;
    uint32_t code;
    const char* name;
  };

  void PopulateTable(Isolate* isolate);

  // For a few types of references, we can get their address from their id.
  void AddFromId(TypeCode type,
                 uint16_t id,
                 const char* name,
                 Isolate* isolate);

  // For other types of references, the caller will figure out the address.
  void Add(Address address, TypeCode type, uint16_t id, const char* name);

  List<ExternalReferenceEntry> refs_;
  int max_id_[kTypeCodeCount];
};


111 112
class ExternalReferenceEncoder {
 public:
113
  explicit ExternalReferenceEncoder(Isolate* isolate);
114 115 116 117 118 119 120 121

  uint32_t Encode(Address key) const;

  const char* NameOfAddress(Address key) const;

 private:
  HashMap encodings_;
  static uint32_t Hash(Address key) {
122
    return static_cast<uint32_t>(reinterpret_cast<uintptr_t>(key) >> 2);
123 124 125 126 127 128 129
  }

  int IndexOf(Address key) const;

  static bool Match(void* key1, void* key2) { return key1 == key2; }

  void Put(Address key, int index);
130 131

  Isolate* isolate_;
132 133 134 135 136
};


class ExternalReferenceDecoder {
 public:
137
  explicit ExternalReferenceDecoder(Isolate* isolate);
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
  ~ExternalReferenceDecoder();

  Address Decode(uint32_t key) const {
    if (key == 0) return NULL;
    return *Lookup(key);
  }

 private:
  Address** encodings_;

  Address* Lookup(uint32_t key) const {
    int type = key >> kReferenceTypeShift;
    ASSERT(kFirstTypeCode <= type && type < kTypeCodeCount);
    int id = key & kReferenceIdMask;
    return &encodings_[type][id];
  }

  void Put(uint32_t key, Address value) {
    *Lookup(key) = value;
  }
158 159

  Isolate* isolate_;
160 161 162
};


163 164 165 166 167 168 169 170 171 172 173 174
class SnapshotByteSource {
 public:
  SnapshotByteSource(const byte* array, int length)
    : data_(array), length_(length), position_(0) { }

  bool HasMore() { return position_ < length_; }

  int Get() {
    ASSERT(position_ < length_);
    return data_[position_++];
  }

175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
  int32_t GetUnalignedInt() {
#if defined(V8_HOST_CAN_READ_UNALIGNED) &&  __BYTE_ORDER == __LITTLE_ENDIAN
    int32_t answer;
    ASSERT(position_ + sizeof(answer) <= length_ + 0u);
    answer = *reinterpret_cast<const int32_t*>(data_ + position_);
#else
    int32_t answer = data_[position_];
    answer |= data_[position_ + 1] << 8;
    answer |= data_[position_ + 2] << 16;
    answer |= data_[position_ + 3] << 24;
#endif
    return answer;
  }

  void Advance(int by) { position_ += by; }

191
  inline void CopyRaw(byte* to, int number_of_bytes);
192

193
  inline int GetInt();
194

195
  bool AtEOF();
196

197
  int position() { return position_; }
198

199 200 201 202 203 204
 private:
  const byte* data_;
  int length_;
  int position_;
};

205

206 207 208 209 210
// The Serializer/Deserializer class is a common superclass for Serializer and
// Deserializer which is used to store common constants and methods used by
// both.
class SerializerDeserializer: public ObjectVisitor {
 public:
211
  static void Iterate(Isolate* isolate, ObjectVisitor* visitor);
212

213 214
  static int nop() { return kNop; }

215
 protected:
216 217 218
  // Where the pointed-to object can be found:
  enum Where {
    kNewObject = 0,                 // Object is next in snapshot.
219
    // 1-6                             One per space.
220 221 222
    kRootArray = 0x9,               // Object is found in root array.
    kPartialSnapshotCache = 0xa,    // Object is in the cache.
    kExternalReference = 0xb,       // Pointer to an external reference.
223 224 225 226 227 228 229 230
    kSkip = 0xc,                    // Skip n bytes.
    kNop = 0xd,                     // Does nothing, used to pad.
    // 0xe-0xf                         Free.
    kBackref = 0x10,                // Object is described relative to end.
    // 0x11-0x16                       One per space.
    kBackrefWithSkip = 0x18,        // Object is described relative to end.
    // 0x19-0x1e                       One per space.
    // 0x20-0x3f                       Used by misc. tags below.
231
    kPointedToMask = 0x3f
232
  };
233 234 235 236 237 238 239 240 241

  // How to code the pointer to the object.
  enum HowToCode {
    kPlain = 0,                          // Straight pointer.
    // What this means depends on the architecture:
    kFromCode = 0x40,                    // A pointer inlined in code.
    kHowToCodeMask = 0x40
  };

242 243 244 245 246 247 248
  // For kRootArrayConstants
  enum WithSkip {
    kNoSkipDistance = 0,
    kHasSkipDistance = 0x40,
    kWithSkipMask = 0x40
  };

249 250 251
  // Where to point within the object.
  enum WhereToPoint {
    kStartOfObject = 0,
252
    kInnerPointer = 0x80,  // First insn in code object or payload of cell.
253 254 255 256
    kWhereToPointMask = 0x80
  };

  // Misc.
257 258 259 260 261 262
  // Raw data to be copied from the snapshot.  This byte code does not advance
  // the current pointer, which is used for code objects, where we write the
  // entire code in one memcpy, then fix up stuff with kSkip and other byte
  // codes that overwrite data.
  static const int kRawData = 0x20;
  // Some common raw lengths: 0x21-0x3f.  These autoadvance the current pointer.
263 264 265 266 267
  // A tag emitted at strategic points in the snapshot to delineate sections.
  // If the deserializer does not find these at the expected moments then it
  // is an indication that the snapshot and the VM do not fit together.
  // Examine the build process for architecture, version or configuration
  // mismatches.
268
  static const int kSynchronize = 0x70;
269 270
  // Used for the source code of the natives, which is in the executable, but
  // is referred to from external strings in the snapshot.
271
  static const int kNativesStringResource = 0x71;
272 273 274 275
  static const int kRepeat = 0x72;
  static const int kConstantRepeat = 0x73;
  // 0x73-0x7f            Repeat last word (subtract 0x72 to get the count).
  static const int kMaxRepeats = 0x7f - 0x72;
276 277
  static int CodeForRepeats(int repeats) {
    ASSERT(repeats >= 1 && repeats <= kMaxRepeats);
278
    return 0x72 + repeats;
279 280 281
  }
  static int RepeatsForCode(int byte_code) {
    ASSERT(byte_code >= kConstantRepeat && byte_code <= 0x7f);
282
    return byte_code - 0x72;
283
  }
284 285
  static const int kRootArrayConstants = 0xa0;
  // 0xa0-0xbf            Things from the first 32 elements of the root array.
286 287
  static const int kRootArrayNumberOfConstantEncodings = 0x20;
  static int RootArrayConstantFromByteCode(int byte_code) {
288
    return byte_code & 0x1f;
289
  }
290

291
  static const int kNumberOfSpaces = LO_SPACE;
292
  static const int kAnyOldSpace = -1;
293

294
  // A bitmask for getting the space out of an instruction.
295
  static const int kSpaceMask = 7;
296 297 298
};


299
int SnapshotByteSource::GetInt() {
300 301 302 303 304 305 306 307 308 309
  // This way of variable-length encoding integers does not suffer from branch
  // mispredictions.
  uint32_t answer = GetUnalignedInt();
  int bytes = answer & 3;
  Advance(bytes);
  uint32_t mask = 0xffffffffu;
  mask >>= 32 - (bytes << 3);
  answer &= mask;
  answer >>= 2;
  return answer;
310 311 312 313
}


void SnapshotByteSource::CopyRaw(byte* to, int number_of_bytes) {
314
  OS::MemCopy(to, data_ + position_, number_of_bytes);
315 316 317
  position_ += number_of_bytes;
}

318 319

// A Deserializer reads a snapshot and reconstructs the Object graph it defines.
320
class Deserializer: public SerializerDeserializer {
321 322
 public:
  // Create a deserializer from a snapshot byte source.
323
  explicit Deserializer(SnapshotByteSource* source);
324

325
  virtual ~Deserializer();
326 327

  // Deserialize the snapshot into an empty heap.
328
  void Deserialize(Isolate* isolate);
329 330

  // Deserialize a single object and the objects reachable from it.
331
  void DeserializePartial(Isolate* isolate, Object** root);
332

333
  void set_reservation(int space_number, int reservation) {
334 335 336 337 338
    ASSERT(space_number >= 0);
    ASSERT(space_number <= LAST_SPACE);
    reservations_[space_number] = reservation;
  }

339 340 341 342 343 344 345
 private:
  virtual void VisitPointers(Object** start, Object** end);

  virtual void VisitRuntimeEntry(RelocInfo* rinfo) {
    UNREACHABLE();
  }

346 347 348 349
  // Allocation sites are present in the snapshot, and must be linked into
  // a list at deserialization time.
  void RelinkAllocationSite(AllocationSite* site);

350 351 352
  // Fills in some heap data in an area from start to end (non-inclusive).  The
  // space id is used for the write barrier.  The object_address is the address
  // of the object we are writing into, or NULL if we are not writing into an
353 354
  // object, i.e. if we are writing a series of tagged values that are not on
  // the heap.
355 356
  void ReadChunk(
      Object** start, Object** end, int space, Address object_address);
357 358 359 360 361 362 363 364
  void ReadObject(int space_number, Object** write_back);

  // This routine both allocates a new object, and also keeps
  // track of where objects have been allocated so that we can
  // fix back references when deserializing.
  Address Allocate(int space_index, int size) {
    Address address = high_water_[space_index];
    high_water_[space_index] = address + size;
365 366
    HeapProfiler* profiler = isolate_->heap_profiler();
    if (profiler->is_tracking_allocations()) {
367
      profiler->AllocationEvent(address, size);
368
    }
369 370 371 372 373 374 375 376 377 378 379
    return address;
  }

  // This returns the address of an object that has been described in the
  // snapshot as being offset bytes back in a particular space.
  HeapObject* GetAddressFromEnd(int space) {
    int offset = source_->GetInt();
    offset <<= kObjectAlignmentBits;
    return HeapObject::FromAddress(high_water_[space] - offset);
  }

380
  void FlushICacheForNewCodeObjects();
381

382 383 384
  // Cached current isolate.
  Isolate* isolate_;

385
  SnapshotByteSource* source_;
386 387 388
  // This is the address of the next object that will be allocated in each
  // space.  It is used to calculate the addresses of back-references.
  Address high_water_[LAST_SPACE + 1];
389

390
  int reservations_[LAST_SPACE + 1];
391
  static const intptr_t kUninitializedReservation = -1;
392

393 394
  ExternalReferenceDecoder* external_reference_decoder_;

395
  DISALLOW_COPY_AND_ASSIGN(Deserializer);
396 397 398 399 400 401 402
};


class SnapshotByteSink {
 public:
  virtual ~SnapshotByteSink() { }
  virtual void Put(int byte, const char* description) = 0;
403 404 405
  virtual void PutSection(int byte, const char* description) {
    Put(byte, description);
  }
406
  void PutInt(uintptr_t integer, const char* description);
407
  virtual int Position() = 0;
408 409 410
};


411 412 413 414 415
// Mapping objects to their location after deserialization.
// This is used during building, but not at runtime by V8.
class SerializationAddressMapper {
 public:
  SerializationAddressMapper()
416 417
      : no_allocation_(),
        serialization_map_(new HashMap(&SerializationMatchFun)) { }
418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440

  ~SerializationAddressMapper() {
    delete serialization_map_;
  }

  bool IsMapped(HeapObject* obj) {
    return serialization_map_->Lookup(Key(obj), Hash(obj), false) != NULL;
  }

  int MappedTo(HeapObject* obj) {
    ASSERT(IsMapped(obj));
    return static_cast<int>(reinterpret_cast<intptr_t>(
        serialization_map_->Lookup(Key(obj), Hash(obj), false)->value));
  }

  void AddMapping(HeapObject* obj, int to) {
    ASSERT(!IsMapped(obj));
    HashMap::Entry* entry =
        serialization_map_->Lookup(Key(obj), Hash(obj), true);
    entry->value = Value(to);
  }

 private:
441
  static bool SerializationMatchFun(void* key1, void* key2) {
442 443 444
    return key1 == key2;
  }

445
  static uint32_t Hash(HeapObject* obj) {
446 447 448
    return static_cast<int32_t>(reinterpret_cast<intptr_t>(obj->address()));
  }

449
  static void* Key(HeapObject* obj) {
450 451 452
    return reinterpret_cast<void*>(obj->address());
  }

453
  static void* Value(int v) {
454 455 456
    return reinterpret_cast<void*>(v);
  }

457
  DisallowHeapAllocation no_allocation_;
458 459 460 461 462
  HashMap* serialization_map_;
  DISALLOW_COPY_AND_ASSIGN(SerializationAddressMapper);
};


463 464
class CodeAddressMap;

465
// There can be only one serializer per V8 process.
466
class Serializer : public SerializerDeserializer {
467
 public:
468
  Serializer(Isolate* isolate, SnapshotByteSink* sink);
469
  ~Serializer();
470
  void VisitPointers(Object** start, Object** end);
471 472 473
  // You can call this after serialization to find out how much space was used
  // in each space.
  int CurrentAllocationAddress(int space) {
474
    ASSERT(space < kNumberOfSpaces);
475 476
    return fullness_[space];
  }
477

478 479
  Isolate* isolate() const { return isolate_; }
  static void Enable(Isolate* isolate);
480
  static void Disable();
481 482 483

  // Call this when you have made use of the fact that there is no serialization
  // going on.
484 485
  static void TooLateToEnableNow() { too_late_to_enable_now_ = true; }
  static bool enabled() { return serialization_enabled_; }
486
  SerializationAddressMapper* address_mapper() { return &address_mapper_; }
487 488 489 490 491
  void PutRoot(int index,
               HeapObject* object,
               HowToCode how,
               WhereToPoint where,
               int skip);
492

493
 protected:
494
  static const int kInvalidRootIndex = -1;
495

496
  int RootIndex(HeapObject* heap_object, HowToCode from);
497
  virtual bool ShouldBeInThePartialSnapshotCache(HeapObject* o) = 0;
498 499 500 501 502
  intptr_t root_index_wave_front() { return root_index_wave_front_; }
  void set_root_index_wave_front(intptr_t value) {
    ASSERT(value >= root_index_wave_front_);
    root_index_wave_front_ = value;
  }
503

504 505
  class ObjectSerializer : public ObjectVisitor {
   public:
506
    ObjectSerializer(Serializer* serializer,
507 508
                     Object* o,
                     SnapshotByteSink* sink,
509 510
                     HowToCode how_to_code,
                     WhereToPoint where_to_point)
511 512 513
      : serializer_(serializer),
        object_(HeapObject::cast(o)),
        sink_(sink),
514
        reference_representation_(how_to_code + where_to_point),
515 516 517
        bytes_processed_so_far_(0),
        code_object_(o->IsCode()),
        code_has_been_output_(false) { }
518 519
    void Serialize();
    void VisitPointers(Object** start, Object** end);
520
    void VisitEmbeddedPointer(RelocInfo* target);
521
    void VisitExternalReference(Address* p);
522
    void VisitExternalReference(RelocInfo* rinfo);
523
    void VisitCodeTarget(RelocInfo* target);
524
    void VisitCodeEntry(Address entry_address);
525
    void VisitCell(RelocInfo* rinfo);
526
    void VisitRuntimeEntry(RelocInfo* reloc);
527 528 529 530 531 532 533 534
    // Used for seralizing the external strings that hold the natives source.
    void VisitExternalAsciiString(
        v8::String::ExternalAsciiStringResource** resource);
    // We can't serialize a heap with external two byte strings.
    void VisitExternalTwoByteString(
        v8::String::ExternalStringResource** resource) {
      UNREACHABLE();
    }
535 536

   private:
537 538 539 540 541 542
    enum ReturnSkip { kCanReturnSkipInsteadOfSkipping, kIgnoringReturn };
    // This function outputs or skips the raw data between the last pointer and
    // up to the current position.  It optionally can just return the number of
    // bytes to skip instead of performing a skip instruction, in case the skip
    // can be merged into the next instruction.
    int OutputRawData(Address up_to, ReturnSkip return_skip = kIgnoringReturn);
543

544
    Serializer* serializer_;
545 546
    HeapObject* object_;
    SnapshotByteSink* sink_;
547
    int reference_representation_;
548
    int bytes_processed_so_far_;
549 550
    bool code_object_;
    bool code_has_been_output_;
551 552
  };

553
  virtual void SerializeObject(Object* o,
554
                               HowToCode how_to_code,
555 556
                               WhereToPoint where_to_point,
                               int skip) = 0;
557 558 559
  void SerializeReferenceToPreviousObject(
      int space,
      int address,
560
      HowToCode how_to_code,
561 562
      WhereToPoint where_to_point,
      int skip);
563
  void InitializeAllocators();
564
  // This will return the space for an object.
565
  static int SpaceOfObject(HeapObject* object);
566
  int Allocate(int space, int size);
567 568 569 570
  int EncodeExternalReference(Address addr) {
    return external_reference_encoder_->Encode(addr);
  }

571 572
  int SpaceAreaSize(int space);

573 574 575 576
  // Some roots should not be serialized, because their actual value depends on
  // absolute addresses and they are reset after deserialization, anyway.
  bool ShouldBeSkipped(Object** current);

577
  Isolate* isolate_;
578
  // Keep track of the fullness of each space in order to generate
579
  // relative addresses for back references.
580 581 582 583
  int fullness_[LAST_SPACE + 1];
  SnapshotByteSink* sink_;
  int current_root_index_;
  ExternalReferenceEncoder* external_reference_encoder_;
584
  static bool serialization_enabled_;
585
  // Did we already make use of the fact that serialization was not enabled?
586
  static bool too_late_to_enable_now_;
587
  SerializationAddressMapper address_mapper_;
588
  intptr_t root_index_wave_front_;
589
  void Pad();
590 591

  friend class ObjectSerializer;
592
  friend class Deserializer;
593

594
 private:
595
  static CodeAddressMap* code_address_map_;
596
  DISALLOW_COPY_AND_ASSIGN(Serializer);
597 598
};

599 600 601

class PartialSerializer : public Serializer {
 public:
602 603
  PartialSerializer(Isolate* isolate,
                    Serializer* startup_snapshot_serializer,
604
                    SnapshotByteSink* sink)
605
    : Serializer(isolate, sink),
606
      startup_serializer_(startup_snapshot_serializer) {
607
    set_root_index_wave_front(Heap::kStrongRootListLength);
608 609 610 611 612
  }

  // Serialize the objects reachable from a single object pointer.
  virtual void Serialize(Object** o);
  virtual void SerializeObject(Object* o,
613
                               HowToCode how_to_code,
614 615
                               WhereToPoint where_to_point,
                               int skip);
616 617 618 619

 protected:
  virtual int PartialSnapshotCacheIndex(HeapObject* o);
  virtual bool ShouldBeInThePartialSnapshotCache(HeapObject* o) {
620 621 622 623 624
    // Scripts should be referred only through shared function infos.  We can't
    // allow them to be part of the partial snapshot because they contain a
    // unique ID, and deserializing several partial snapshots containing script
    // would cause dupes.
    ASSERT(!o->IsScript());
625
    return o->IsName() || o->IsSharedFunctionInfo() ||
626
           o->IsHeapNumber() || o->IsCode() ||
627
           o->IsScopeInfo() ||
628 629
           o->map() ==
               startup_serializer_->isolate()->heap()->fixed_cow_array_map();
630 631 632 633 634 635 636 637 638 639
  }

 private:
  Serializer* startup_serializer_;
  DISALLOW_COPY_AND_ASSIGN(PartialSerializer);
};


class StartupSerializer : public Serializer {
 public:
640 641
  StartupSerializer(Isolate* isolate, SnapshotByteSink* sink)
    : Serializer(isolate, sink) {
642 643
    // Clear the cache of objects used by the partial snapshot.  After the
    // strong roots have been serialized we can create a partial snapshot
644
    // which will repopulate the cache with objects needed by that partial
645
    // snapshot.
646
    isolate->set_serialize_partial_snapshot_cache_length(0);
647 648 649 650
  }
  // Serialize the current state of the heap.  The order is:
  // 1) Strong references.
  // 2) Partial snapshot cache.
651
  // 3) Weak references (e.g. the string table).
652 653
  virtual void SerializeStrongReferences();
  virtual void SerializeObject(Object* o,
654
                               HowToCode how_to_code,
655 656
                               WhereToPoint where_to_point,
                               int skip);
657 658 659 660
  void SerializeWeakReferences();
  void Serialize() {
    SerializeStrongReferences();
    SerializeWeakReferences();
661
    Pad();
662 663 664 665 666 667 668 669
  }

 private:
  virtual bool ShouldBeInThePartialSnapshotCache(HeapObject* o) {
    return false;
  }
};

670

671 672 673
} }  // namespace v8::internal

#endif  // V8_SERIALIZE_H_