V8 Project
v8::internal::Serializer::ObjectSerializer Class Reference

#include <serialize.h>

+ Inheritance diagram for v8::internal::Serializer::ObjectSerializer:
+ Collaboration diagram for v8::internal::Serializer::ObjectSerializer:

Public Member Functions

 ObjectSerializer (Serializer *serializer, Object *o, SnapshotByteSink *sink, HowToCode how_to_code, WhereToPoint where_to_point)
 
void Serialize ()
 
void VisitPointers (Object **start, Object **end)
 
void VisitEmbeddedPointer (RelocInfo *target)
 
void VisitExternalReference (Address *p)
 
void VisitExternalReference (RelocInfo *rinfo)
 
void VisitCodeTarget (RelocInfo *target)
 
void VisitCodeEntry (Address entry_address)
 
void VisitCell (RelocInfo *rinfo)
 
void VisitRuntimeEntry (RelocInfo *reloc)
 
void VisitExternalOneByteString (v8::String::ExternalOneByteStringResource **resource)
 
void VisitExternalTwoByteString (v8::String::ExternalStringResource **resource)
 

Private Types

enum  ReturnSkip { kCanReturnSkipInsteadOfSkipping , kIgnoringReturn }
 

Private Member Functions

int OutputRawData (Address up_to, ReturnSkip return_skip=kIgnoringReturn)
 

Private Attributes

Serializerserializer_
 
HeapObjectobject_
 
SnapshotByteSinksink_
 
int reference_representation_
 
int bytes_processed_so_far_
 
bool code_object_
 
bool code_has_been_output_
 

Detailed Description

Definition at line 409 of file serialize.h.

Member Enumeration Documentation

◆ ReturnSkip

Enumerator
kCanReturnSkipInsteadOfSkipping 
kIgnoringReturn 

Definition at line 442 of file serialize.h.

Constructor & Destructor Documentation

◆ ObjectSerializer()

v8::internal::Serializer::ObjectSerializer::ObjectSerializer ( Serializer serializer,
Object o,
SnapshotByteSink sink,
HowToCode  how_to_code,
WhereToPoint  where_to_point 
)
inline

Definition at line 411 of file serialize.h.

Member Function Documentation

◆ OutputRawData()

int v8::internal::Serializer::ObjectSerializer::OutputRawData ( Address  up_to,
ReturnSkip  return_skip = kIgnoringReturn 
)
private

Definition at line 1726 of file serialize.cc.

1727  {
1728  Address object_start = object_->address();
1729  int base = bytes_processed_so_far_;
1730  int up_to_offset = static_cast<int>(up_to - object_start);
1731  int to_skip = up_to_offset - bytes_processed_so_far_;
1732  int bytes_to_output = to_skip;
1733  bytes_processed_so_far_ += to_skip;
1734  // This assert will fail if the reloc info gives us the target_address_address
1735  // locations in a non-ascending order. Luckily that doesn't happen.
1736  DCHECK(to_skip >= 0);
1737  bool outputting_code = false;
1738  if (to_skip != 0 && code_object_ && !code_has_been_output_) {
1739  // Output the code all at once and fix later.
1740  bytes_to_output = object_->Size() + to_skip - bytes_processed_so_far_;
1741  outputting_code = true;
1742  code_has_been_output_ = true;
1743  }
1744  if (bytes_to_output != 0 &&
1745  (!code_object_ || outputting_code)) {
1746 #define RAW_CASE(index) \
1747  if (!outputting_code && bytes_to_output == index * kPointerSize && \
1748  index * kPointerSize == to_skip) { \
1749  sink_->PutSection(kRawData + index, "RawDataFixed"); \
1750  to_skip = 0; /* This insn already skips. */ \
1751  } else /* NOLINT */
1753 #undef RAW_CASE
1754  { /* NOLINT */
1755  // We always end up here if we are outputting the code of a code object.
1756  sink_->Put(kRawData, "RawData");
1757  sink_->PutInt(bytes_to_output, "length");
1758  }
1759 
1760  // To make snapshots reproducible, we need to wipe out all pointers in code.
1761  if (code_object_) {
1762  Code* code = CloneCodeObject(object_);
1763  WipeOutRelocations(code);
1764  // We need to wipe out the header fields *after* wiping out the
1765  // relocations, because some of these fields are needed for the latter.
1766  code->WipeOutHeader();
1767  object_start = code->address();
1768  }
1769 
1770  const char* description = code_object_ ? "Code" : "Byte";
1771  for (int i = 0; i < bytes_to_output; i++) {
1772  sink_->PutSection(object_start[base + i], description);
1773  }
1774  if (code_object_) delete[] object_start;
1775  }
1776  if (to_skip != 0 && return_skip == kIgnoringReturn) {
1777  sink_->Put(kSkip, "Skip");
1778  sink_->PutInt(to_skip, "SkipDistance");
1779  to_skip = 0;
1780  }
1781  return to_skip;
1782 }
virtual void Put(byte b, const char *description)=0
virtual void PutSection(int b, const char *description)
void PutInt(uintptr_t integer, const char *description)
#define DCHECK(condition)
Definition: logging.h:205
static Code * CloneCodeObject(HeapObject *code)
Definition: serialize.cc:1705
byte * Address
Definition: globals.h:101
static void WipeOutRelocations(Code *code)
Definition: serialize.cc:1712
#define COMMON_RAW_LENGTHS(f)
#define RAW_CASE(index)

References v8::internal::HeapObject::address(), v8::internal::CloneCodeObject(), COMMON_RAW_LENGTHS, DCHECK, v8::internal::SerializerDeserializer::kRawData, v8::internal::SerializerDeserializer::kSkip, v8::internal::SnapshotByteSink::Put(), v8::internal::SnapshotByteSink::PutInt(), v8::internal::SnapshotByteSink::PutSection(), RAW_CASE, v8::internal::Serializer::sink_, v8::internal::Code::WipeOutHeader(), and v8::internal::WipeOutRelocations().

Referenced by Serialize().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Serialize()

void v8::internal::Serializer::ObjectSerializer::Serialize ( )

Definition at line 1517 of file serialize.cc.

1517  {
1519  int size = object_->Size();
1520 
1522  "ObjectSerialization");
1523  sink_->PutInt(size >> kObjectAlignmentBits, "Size in words");
1524 
1526  const char* code_name =
1529  CodeNameEvent(object_->address(), sink_->Position(), code_name));
1531  SnapshotPositionEvent(object_->address(), sink_->Position()));
1532  }
1533 
1534  // Mark this object as already serialized.
1535  if (space == LO_SPACE) {
1536  if (object_->IsCode()) {
1537  sink_->PutInt(EXECUTABLE, "executable large object");
1538  } else {
1539  sink_->PutInt(NOT_EXECUTABLE, "not executable large object");
1540  }
1541  int index = serializer_->AllocateLargeObject(size);
1543  } else {
1544  int offset = serializer_->Allocate(space, size);
1546  }
1547 
1548  // Serialize the map (first word of the object).
1550 
1551  // Serialize the rest of the object.
1556 }
const char * Lookup(Address address)
Definition: serialize.cc:506
void IterateBody(InstanceType type, int object_size, ObjectVisitor *v)
Definition: objects.cc:1538
InstanceType instance_type()
Definition: objects-inl.h:4323
void AddMapping(HeapObject *obj, int to)
Definition: serialize.h:349
int OutputRawData(Address up_to, ReturnSkip return_skip=kIgnoringReturn)
Definition: serialize.cc:1726
virtual void SerializeObject(Object *o, HowToCode how_to_code, WhereToPoint where_to_point, int skip)=0
SerializationAddressMapper * address_mapper()
Definition: serialize.h:392
int Allocate(int space, int size)
Definition: serialize.cc:1804
CodeAddressMap * code_address_map_
Definition: serialize.h:500
int AllocateLargeObject(int size)
Definition: serialize.cc:1798
static int SpaceOfObject(HeapObject *object)
Definition: serialize.cc:1785
enable harmony numeric enable harmony object literal extensions Optimize object size
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be expose gc extension under the specified name show built in functions in stack traces use random jit cookie to mask large constants minimum length for automatic enable preparsing CPU profiler sampling interval in microseconds trace out of bounds accesses to external arrays default size of stack region v8 is allowed to maximum length of function source code printed in a stack trace min size of a semi space(in MBytes)
#define LOG(isolate, Call)
Definition: log.h:69
#define CHECK_EQ(expected, value)
Definition: logging.h:169
const int kPointerSize
Definition: globals.h:129
@ NOT_EXECUTABLE
Definition: globals.h:391
const int kObjectAlignmentBits
Definition: globals.h:225

References v8::internal::SerializationAddressMapper::AddMapping(), v8::internal::HeapObject::address(), v8::internal::Serializer::address_mapper(), v8::internal::Serializer::Allocate(), v8::internal::Serializer::AllocateLargeObject(), bytes_processed_so_far_, CHECK_EQ, v8::internal::Serializer::code_address_map_, v8::internal::EXECUTABLE, v8::internal::Map::instance_type(), v8::internal::Serializer::isolate_, v8::internal::HeapObject::IterateBody(), v8::internal::SerializerDeserializer::kNewObject, v8::internal::kObjectAlignmentBits, v8::internal::SerializerDeserializer::kPlain, v8::internal::kPointerSize, v8::internal::SerializerDeserializer::kStartOfObject, v8::internal::LO_SPACE, LOG, v8::internal::CodeAddressMap::Lookup(), v8::internal::HeapObject::map(), v8::internal::NOT_EXECUTABLE, object_, OutputRawData(), v8::internal::SnapshotByteSink::Position(), v8::internal::SnapshotByteSink::Put(), v8::internal::SnapshotByteSink::PutInt(), reference_representation_, v8::internal::Serializer::SerializeObject(), serializer_, sink_, size, v8::internal::HeapObject::Size(), space(), and v8::internal::Serializer::SpaceOfObject().

Referenced by v8::internal::CodeSerializer::SerializeHeapObject(), v8::internal::PartialSerializer::SerializeObject(), and v8::internal::StartupSerializer::SerializeObject().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ VisitCell()

void v8::internal::Serializer::ObjectSerializer::VisitCell ( RelocInfo rinfo)

Definition at line 1669 of file serialize.cc.

1669  {
1670  // Out-of-line constant pool entries will be visited by the ConstantPoolArray.
1671  if (FLAG_enable_ool_constant_pool && rinfo->IsInConstantPool()) return;
1672 
1673  int skip = OutputRawData(rinfo->pc(), kCanReturnSkipInsteadOfSkipping);
1674  Cell* object = Cell::cast(rinfo->target_cell());
1677 }

References v8::internal::RelocInfo::IsInConstantPool(), v8::internal::SerializerDeserializer::kInnerPointer, v8::internal::SerializerDeserializer::kPlain, v8::internal::kPointerSize, and v8::internal::RelocInfo::pc().

+ Here is the call graph for this function:

◆ VisitCodeEntry()

void v8::internal::Serializer::ObjectSerializer::VisitCodeEntry ( Address  entry_address)

Definition at line 1661 of file serialize.cc.

1661  {
1662  int skip = OutputRawData(entry_address, kCanReturnSkipInsteadOfSkipping);
1663  Code* object = Code::cast(Code::GetObjectFromEntryAddress(entry_address));
1666 }
static Object * GetObjectFromEntryAddress(Address location_of_address)
Definition: objects-inl.h:5029

References v8::internal::Code::GetObjectFromEntryAddress(), v8::internal::SerializerDeserializer::kInnerPointer, v8::internal::SerializerDeserializer::kPlain, and v8::internal::kPointerSize.

+ Here is the call graph for this function:

◆ VisitCodeTarget()

void v8::internal::Serializer::ObjectSerializer::VisitCodeTarget ( RelocInfo target)

Definition at line 1649 of file serialize.cc.

1649  {
1650  // Out-of-line constant pool entries will be visited by the ConstantPoolArray.
1651  if (FLAG_enable_ool_constant_pool && rinfo->IsInConstantPool()) return;
1652 
1653  int skip = OutputRawData(rinfo->target_address_address(),
1655  Code* object = Code::GetCodeFromTargetAddress(rinfo->target_address());
1657  bytes_processed_so_far_ += rinfo->target_address_size();
1658 }
static Code * GetCodeFromTargetAddress(Address address)
Definition: objects-inl.h:5018

References v8::internal::Code::GetCodeFromTargetAddress(), v8::internal::RelocInfo::IsInConstantPool(), v8::internal::SerializerDeserializer::kFromCode, and v8::internal::SerializerDeserializer::kInnerPointer.

+ Here is the call graph for this function:

◆ VisitEmbeddedPointer()

void v8::internal::Serializer::ObjectSerializer::VisitEmbeddedPointer ( RelocInfo target)

Definition at line 1601 of file serialize.cc.

1601  {
1602  // Out-of-line constant pool entries will be visited by the ConstantPoolArray.
1603  if (FLAG_enable_ool_constant_pool && rinfo->IsInConstantPool()) return;
1604 
1605  int skip = OutputRawData(rinfo->target_address_address(),
1607  HowToCode how_to_code = rinfo->IsCodedSpecially() ? kFromCode : kPlain;
1608  Object* object = rinfo->target_object();
1609  serializer_->SerializeObject(object, how_to_code, kStartOfObject, skip);
1610  bytes_processed_so_far_ += rinfo->target_address_size();
1611 }
kSerializedDataOffset Object
Definition: objects-inl.h:5322

References v8::internal::RelocInfo::IsCodedSpecially(), v8::internal::RelocInfo::IsInConstantPool(), v8::internal::SerializerDeserializer::kFromCode, v8::internal::SerializerDeserializer::kPlain, and v8::internal::SerializerDeserializer::kStartOfObject.

+ Here is the call graph for this function:

◆ VisitExternalOneByteString()

void v8::internal::Serializer::ObjectSerializer::VisitExternalOneByteString ( v8::String::ExternalOneByteStringResource **  resource)

Definition at line 1680 of file serialize.cc.

1681  {
1682  Address references_start = reinterpret_cast<Address>(resource_pointer);
1683  OutputRawData(references_start);
1684  for (int i = 0; i < Natives::GetBuiltinsCount(); i++) {
1685  Object* source =
1686  serializer_->isolate()->heap()->natives_source_cache()->get(i);
1687  if (!source->IsUndefined()) {
1688  ExternalOneByteString* string = ExternalOneByteString::cast(source);
1690  const Resource* resource = string->resource();
1691  if (resource == *resource_pointer) {
1692  sink_->Put(kNativesStringResource, "NativesStringResource");
1693  sink_->PutSection(i, "NativesStringResourceEnd");
1694  bytes_processed_so_far_ += sizeof(resource);
1695  return;
1696  }
1697  }
1698  }
1699  // One of the strings in the natives cache should match the resource. We
1700  // can't serialize any other kinds of external strings.
1701  UNREACHABLE();
1702 }
An ExternalOneByteStringResource is a wrapper around an one-byte string buffer that resides outside V...
Definition: v8.h:1918
static const int kNativesStringResource
Definition: serialize.h:212
Isolate * isolate() const
Definition: serialize.h:390
#define UNREACHABLE()
Definition: logging.h:30

References v8::internal::NativesCollection< type >::GetBuiltinsCount(), v8::internal::SerializerDeserializer::kNativesStringResource, v8::internal::SnapshotByteSink::Put(), v8::internal::SnapshotByteSink::PutSection(), v8::internal::Serializer::sink_, and UNREACHABLE.

+ Here is the call graph for this function:

◆ VisitExternalReference() [1/2]

void v8::internal::Serializer::ObjectSerializer::VisitExternalReference ( Address p)

Definition at line 1614 of file serialize.cc.

1614  {
1615  int skip = OutputRawData(reinterpret_cast<Address>(p),
1617  sink_->Put(kExternalReference + kPlain + kStartOfObject, "ExternalRef");
1618  sink_->PutInt(skip, "SkipB4ExternalRef");
1619  Address target = *p;
1620  sink_->PutInt(serializer_->EncodeExternalReference(target), "reference id");
1622 }
int EncodeExternalReference(Address addr)
Definition: serialize.h:471

References v8::internal::SerializerDeserializer::kExternalReference, v8::internal::SerializerDeserializer::kPlain, v8::internal::kPointerSize, v8::internal::SerializerDeserializer::kStartOfObject, v8::internal::SnapshotByteSink::Put(), v8::internal::SnapshotByteSink::PutInt(), and v8::internal::Serializer::sink_.

+ Here is the call graph for this function:

◆ VisitExternalReference() [2/2]

void v8::internal::Serializer::ObjectSerializer::VisitExternalReference ( RelocInfo rinfo)

Definition at line 1625 of file serialize.cc.

1625  {
1626  int skip = OutputRawData(rinfo->target_address_address(),
1628  HowToCode how_to_code = rinfo->IsCodedSpecially() ? kFromCode : kPlain;
1629  sink_->Put(kExternalReference + how_to_code + kStartOfObject, "ExternalRef");
1630  sink_->PutInt(skip, "SkipB4ExternalRef");
1631  Address target = rinfo->target_reference();
1632  sink_->PutInt(serializer_->EncodeExternalReference(target), "reference id");
1633  bytes_processed_so_far_ += rinfo->target_address_size();
1634 }

References v8::internal::RelocInfo::IsCodedSpecially(), v8::internal::SerializerDeserializer::kExternalReference, v8::internal::SerializerDeserializer::kFromCode, v8::internal::SerializerDeserializer::kPlain, v8::internal::SerializerDeserializer::kStartOfObject, v8::internal::SnapshotByteSink::Put(), v8::internal::SnapshotByteSink::PutInt(), and v8::internal::Serializer::sink_.

+ Here is the call graph for this function:

◆ VisitExternalTwoByteString()

void v8::internal::Serializer::ObjectSerializer::VisitExternalTwoByteString ( v8::String::ExternalStringResource **  resource)
inline

Definition at line 436 of file serialize.h.

437  {
438  UNREACHABLE();
439  }

References UNREACHABLE.

◆ VisitPointers()

void v8::internal::Serializer::ObjectSerializer::VisitPointers ( Object **  start,
Object **  end 
)

Definition at line 1559 of file serialize.cc.

1560  {
1561  Object** current = start;
1562  while (current < end) {
1563  while (current < end && (*current)->IsSmi()) current++;
1564  if (current < end) OutputRawData(reinterpret_cast<Address>(current));
1565 
1566  while (current < end && !(*current)->IsSmi()) {
1567  HeapObject* current_contents = HeapObject::cast(*current);
1568  int root_index = serializer_->RootIndex(current_contents, kPlain);
1569  // Repeats are not subject to the write barrier so there are only some
1570  // objects that can be used in a repeat encoding. These are the early
1571  // ones in the root array that are never in new space.
1572  if (current != start &&
1573  root_index != kInvalidRootIndex &&
1574  root_index < kRootArrayNumberOfConstantEncodings &&
1575  current_contents == current[-1]) {
1576  DCHECK(!serializer_->isolate()->heap()->InNewSpace(current_contents));
1577  int repeat_count = 1;
1578  while (&current[repeat_count] < end - 1 &&
1579  current[repeat_count] == current_contents) {
1580  repeat_count++;
1581  }
1582  current += repeat_count;
1583  bytes_processed_so_far_ += repeat_count * kPointerSize;
1584  if (repeat_count > kMaxRepeats) {
1585  sink_->Put(kRepeat, "SerializeRepeats");
1586  sink_->PutInt(repeat_count, "SerializeRepeats");
1587  } else {
1588  sink_->Put(CodeForRepeats(repeat_count), "SerializeRepeats");
1589  }
1590  } else {
1592  current_contents, kPlain, kStartOfObject, 0);
1594  current++;
1595  }
1596  }
1597  }
1598 }
bool InNewSpace(Object *object)
Definition: heap-inl.h:322
static const int kRootArrayNumberOfConstantEncodings
Definition: serialize.h:227
static int CodeForRepeats(int repeats)
Definition: serialize.h:217
int RootIndex(HeapObject *heap_object, HowToCode from)
Definition: serialize.cc:1336
static const int kInvalidRootIndex
Definition: serialize.h:400

References v8::internal::SerializerDeserializer::CodeForRepeats(), DCHECK, v8::internal::Serializer::kInvalidRootIndex, v8::internal::SerializerDeserializer::kMaxRepeats, v8::internal::SerializerDeserializer::kPlain, v8::internal::kPointerSize, v8::internal::SerializerDeserializer::kRepeat, v8::internal::SerializerDeserializer::kRootArrayNumberOfConstantEncodings, v8::internal::SerializerDeserializer::kStartOfObject, v8::internal::SnapshotByteSink::Put(), v8::internal::SnapshotByteSink::PutInt(), and v8::internal::Serializer::sink_.

+ Here is the call graph for this function:

◆ VisitRuntimeEntry()

void v8::internal::Serializer::ObjectSerializer::VisitRuntimeEntry ( RelocInfo reloc)

Definition at line 1637 of file serialize.cc.

1637  {
1638  int skip = OutputRawData(rinfo->target_address_address(),
1640  HowToCode how_to_code = rinfo->IsCodedSpecially() ? kFromCode : kPlain;
1641  sink_->Put(kExternalReference + how_to_code + kStartOfObject, "ExternalRef");
1642  sink_->PutInt(skip, "SkipB4ExternalRef");
1643  Address target = rinfo->target_address();
1644  sink_->PutInt(serializer_->EncodeExternalReference(target), "reference id");
1645  bytes_processed_so_far_ += rinfo->target_address_size();
1646 }

References v8::internal::RelocInfo::IsCodedSpecially(), v8::internal::SerializerDeserializer::kExternalReference, v8::internal::SerializerDeserializer::kFromCode, v8::internal::SerializerDeserializer::kPlain, v8::internal::SerializerDeserializer::kStartOfObject, v8::internal::SnapshotByteSink::Put(), v8::internal::SnapshotByteSink::PutInt(), and v8::internal::Serializer::sink_.

+ Here is the call graph for this function:

Member Data Documentation

◆ bytes_processed_so_far_

int v8::internal::Serializer::ObjectSerializer::bytes_processed_so_far_
private

Definition at line 453 of file serialize.h.

Referenced by Serialize().

◆ code_has_been_output_

bool v8::internal::Serializer::ObjectSerializer::code_has_been_output_
private

Definition at line 455 of file serialize.h.

◆ code_object_

bool v8::internal::Serializer::ObjectSerializer::code_object_
private

Definition at line 454 of file serialize.h.

◆ object_

HeapObject* v8::internal::Serializer::ObjectSerializer::object_
private

Definition at line 450 of file serialize.h.

Referenced by Serialize().

◆ reference_representation_

int v8::internal::Serializer::ObjectSerializer::reference_representation_
private

Definition at line 452 of file serialize.h.

Referenced by Serialize().

◆ serializer_

Serializer* v8::internal::Serializer::ObjectSerializer::serializer_
private

Definition at line 449 of file serialize.h.

Referenced by Serialize().

◆ sink_

SnapshotByteSink* v8::internal::Serializer::ObjectSerializer::sink_
private

Definition at line 451 of file serialize.h.

Referenced by Serialize().


The documentation for this class was generated from the following files: