V8 Project
SnapshotWriter Class Reference
+ Collaboration diagram for SnapshotWriter:

Public Member Functions

 SnapshotWriter (const char *snapshot_file)
 
 ~SnapshotWriter ()
 
void SetCompressor (Compressor *compressor)
 
void SetRawFiles (const char *raw_file, const char *raw_context_file)
 
void SetStartupBlobFile (const char *startup_blob_file)
 
void WriteSnapshot (const i::List< i::byte > &snapshot_data, const i::Serializer &serializer, const i::List< i::byte > &context_snapshot_data, const i::Serializer &context_serializer) const
 

Private Member Functions

void MaybeWriteStartupBlob (const i::List< i::byte > &snapshot_data, const i::Serializer &serializer, const i::List< i::byte > &context_snapshot_data, const i::Serializer &context_serializer) const
 
void WriteSnapshotFile (const i::List< i::byte > &snapshot_data, const i::Serializer &serializer, const i::List< i::byte > &context_snapshot_data, const i::Serializer &context_serializer) const
 
void WriteFilePrefix () const
 
void WriteFileSuffix () const
 
void WriteData (const char *prefix, const i::List< i::byte > &source_data, FILE *raw_file) const
 
void MaybeWriteRawFile (const i::List< i::byte > *data, FILE *raw_file) const
 
void WriteData (const char *prefix, const i::List< i::byte > &source_data, const i::List< i::byte > *data_to_be_written) const
 
void WriteMeta (const char *prefix, const i::Serializer &ser) const
 
void WriteSizeVar (const i::Serializer &ser, const char *prefix, const char *name, int space) const
 
void WriteSnapshotData (const i::List< i::byte > *data) const
 
FILE * GetFileDescriptorOrDie (const char *filename)
 

Private Attributes

FILE * fp_
 
FILE * raw_file_
 
FILE * raw_context_file_
 
FILE * startup_blob_file_
 
Compressorcompressor_
 

Detailed Description

Definition at line 35 of file mksnapshot.cc.

Constructor & Destructor Documentation

◆ SnapshotWriter()

SnapshotWriter::SnapshotWriter ( const char *  snapshot_file)
inlineexplicit

Definition at line 37 of file mksnapshot.cc.

38  : fp_(GetFileDescriptorOrDie(snapshot_file))
39  , raw_file_(NULL)
42  , compressor_(NULL) {
43  }
FILE * GetFileDescriptorOrDie(const char *filename)
Definition: mksnapshot.cc:221
FILE * startup_blob_file_
Definition: mksnapshot.cc:233
FILE * raw_context_file_
Definition: mksnapshot.cc:232
FILE * raw_file_
Definition: mksnapshot.cc:231
Compressor * compressor_
Definition: mksnapshot.cc:234
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 NULL

◆ ~SnapshotWriter()

SnapshotWriter::~SnapshotWriter ( )
inline

Definition at line 45 of file mksnapshot.cc.

45  {
46  fclose(fp_);
47  if (raw_file_) fclose(raw_file_);
50  }

Member Function Documentation

◆ GetFileDescriptorOrDie()

FILE* SnapshotWriter::GetFileDescriptorOrDie ( const char *  filename)
inlineprivate

Definition at line 221 of file mksnapshot.cc.

221  {
222  FILE* fp = base::OS::FOpen(filename, "wb");
223  if (fp == NULL) {
224  i::PrintF("Unable to open file \"%s\" for writing.\n", filename);
225  exit(1);
226  }
227  return fp;
228  }
const Register fp
void PrintF(const char *format,...)
Definition: utils.cc:80
static FILE * FOpen(const char *path, const char *mode)
Definition: d8.cc:1056

References v8::base::OS::FOpen(), v8::internal::fp, NULL, and v8::internal::PrintF().

+ Here is the call graph for this function:

◆ MaybeWriteRawFile()

void SnapshotWriter::MaybeWriteRawFile ( const i::List< i::byte > *  data,
FILE *  raw_file 
) const
inlineprivate

Definition at line 156 of file mksnapshot.cc.

156  {
157  if (!data || !raw_file)
158  return;
159 
160  // Sanity check, whether i::List iterators truly return pointers to an
161  // internal array.
162  DCHECK(data->end() - data->begin() == data->length());
163 
164  size_t written = fwrite(data->begin(), 1, data->length(), raw_file);
165  if (written != (size_t)data->length()) {
166  i::PrintF("Writing raw file failed.. Aborting.\n");
167  exit(1);
168  }
169  }
iterator end() const
Definition: list.h:75
iterator begin() const
Definition: list.h:74
#define DCHECK(condition)
Definition: logging.h:205

References v8::internal::List< T, AllocationPolicy >::begin(), DCHECK, v8::internal::List< T, AllocationPolicy >::end(), and v8::internal::PrintF().

+ Here is the call graph for this function:

◆ MaybeWriteStartupBlob()

void SnapshotWriter::MaybeWriteStartupBlob ( const i::List< i::byte > &  snapshot_data,
const i::Serializer serializer,
const i::List< i::byte > &  context_snapshot_data,
const i::Serializer context_serializer 
) const
inlineprivate

Definition at line 77 of file mksnapshot.cc.

80  {
81  if (!startup_blob_file_)
82  return;
83 
84  i::List<i::byte> startup_blob;
85  i::ListSnapshotSink sink(&startup_blob);
86 
87  int spaces[] = {i::NEW_SPACE, i::OLD_POINTER_SPACE,
91 
92  i::byte* snapshot_bytes = snapshot_data.begin();
93  sink.PutBlob(snapshot_bytes, snapshot_data.length(), "snapshot");
94  for (size_t i = 0; i < arraysize(spaces); ++i)
95  sink.PutInt(serializer.CurrentAllocationAddress(spaces[i]), "spaces");
96 
97  i::byte* context_bytes = context_snapshot_data.begin();
98  sink.PutBlob(context_bytes, context_snapshot_data.length(), "context");
99  for (size_t i = 0; i < arraysize(spaces); ++i)
100  sink.PutInt(context_serializer.CurrentAllocationAddress(spaces[i]),
101  "spaces");
102 
103  size_t written = fwrite(startup_blob.begin(), 1, startup_blob.length(),
105  if (written != (size_t)startup_blob.length()) {
106  i::PrintF("Writing snapshot file failed.. Aborting.\n");
107  exit(1);
108  }
109  }
int CurrentAllocationAddress(int space) const
Definition: serialize.h:385
#define arraysize(array)
Definition: macros.h:86
@ OLD_DATA_SPACE
Definition: globals.h:361
@ PROPERTY_CELL_SPACE
Definition: globals.h:365
@ OLD_POINTER_SPACE
Definition: globals.h:360
uint8_t byte
Definition: globals.h:100

References arraysize, v8::internal::List< T, AllocationPolicy >::begin(), v8::internal::CELL_SPACE, v8::internal::CODE_SPACE, v8::internal::Serializer::CurrentAllocationAddress(), v8::internal::LO_SPACE, v8::internal::MAP_SPACE, v8::internal::NEW_SPACE, v8::internal::OLD_DATA_SPACE, v8::internal::OLD_POINTER_SPACE, v8::internal::PrintF(), v8::internal::PROPERTY_CELL_SPACE, v8::internal::SnapshotByteSink::PutBlob(), and v8::internal::SnapshotByteSink::PutInt().

+ Here is the call graph for this function:

◆ SetCompressor()

void SnapshotWriter::SetCompressor ( Compressor compressor)
inline

Definition at line 52 of file mksnapshot.cc.

52  {
53  compressor_ = compressor;
54  }

Referenced by main().

+ Here is the caller graph for this function:

◆ SetRawFiles()

void SnapshotWriter::SetRawFiles ( const char *  raw_file,
const char *  raw_context_file 
)
inline

Definition at line 56 of file mksnapshot.cc.

56  {
58  raw_context_file_ = GetFileDescriptorOrDie(raw_context_file);
59  }

Referenced by main().

+ Here is the caller graph for this function:

◆ SetStartupBlobFile()

void SnapshotWriter::SetStartupBlobFile ( const char *  startup_blob_file)
inline

Definition at line 61 of file mksnapshot.cc.

61  {
62  if (startup_blob_file != NULL)
63  startup_blob_file_ = GetFileDescriptorOrDie(startup_blob_file);
64  }

References NULL.

Referenced by main().

+ Here is the caller graph for this function:

◆ WriteData() [1/2]

void SnapshotWriter::WriteData ( const char *  prefix,
const i::List< i::byte > &  source_data,
const i::List< i::byte > *  data_to_be_written 
) const
inlineprivate

Definition at line 171 of file mksnapshot.cc.

172  {
173  fprintf(fp_, "const byte Snapshot::%sdata_[] = {\n", prefix);
174  WriteSnapshotData(data_to_be_written);
175  fprintf(fp_, "};\n");
176  fprintf(fp_, "const int Snapshot::%ssize_ = %d;\n", prefix,
177  data_to_be_written->length());
178 
179  if (data_to_be_written == &source_data) {
180  fprintf(fp_, "const byte* Snapshot::%sraw_data_ = Snapshot::%sdata_;\n",
181  prefix, prefix);
182  fprintf(fp_, "const int Snapshot::%sraw_size_ = Snapshot::%ssize_;\n",
183  prefix, prefix);
184  } else {
185  fprintf(fp_, "const byte* Snapshot::%sraw_data_ = NULL;\n", prefix);
186  fprintf(fp_, "const int Snapshot::%sraw_size_ = %d;\n",
187  prefix, source_data.length());
188  }
189  fprintf(fp_, "\n");
190  }
void WriteSnapshotData(const i::List< i::byte > *data) const
Definition: mksnapshot.cc:210

◆ WriteData() [2/2]

void SnapshotWriter::WriteData ( const char *  prefix,
const i::List< i::byte > &  source_data,
FILE *  raw_file 
) const
inlineprivate

Definition at line 137 of file mksnapshot.cc.

138  {
139  const i::List<i::byte>* data_to_be_written = NULL;
140  i::List<i::byte> compressed_data;
141  if (!compressor_) {
142  data_to_be_written = &source_data;
143  } else if (compressor_->Compress(source_data.ToVector())) {
144  compressed_data.AddAll(*compressor_->output());
145  data_to_be_written = &compressed_data;
146  } else {
147  i::PrintF("Compression failed. Aborting.\n");
148  exit(1);
149  }
150 
151  DCHECK(data_to_be_written);
152  MaybeWriteRawFile(data_to_be_written, raw_file);
153  WriteData(prefix, source_data, data_to_be_written);
154  }
virtual i::Vector< i::byte > * output()=0
virtual bool Compress(i::Vector< i::byte > input)=0
void WriteData(const char *prefix, const i::List< i::byte > &source_data, FILE *raw_file) const
Definition: mksnapshot.cc:137
void MaybeWriteRawFile(const i::List< i::byte > *data, FILE *raw_file) const
Definition: mksnapshot.cc:156
void AddAll(const List< T, AllocationPolicy > &other, AllocationPolicy allocator=AllocationPolicy())
Vector< T > ToVector() const
Definition: list.h:81

References v8::internal::List< T, AllocationPolicy >::AddAll(), DCHECK, NULL, v8::internal::PrintF(), and v8::internal::List< T, AllocationPolicy >::ToVector().

+ Here is the call graph for this function:

◆ WriteFilePrefix()

void SnapshotWriter::WriteFilePrefix ( ) const
inlineprivate

Definition at line 123 of file mksnapshot.cc.

123  {
124  fprintf(fp_, "// Autogenerated snapshot file. Do not edit.\n\n");
125  fprintf(fp_, "#include \"src/v8.h\"\n");
126  fprintf(fp_, "#include \"src/base/platform/platform.h\"\n\n");
127  fprintf(fp_, "#include \"src/snapshot.h\"\n\n");
128  fprintf(fp_, "namespace v8 {\n");
129  fprintf(fp_, "namespace internal {\n\n");
130  }

◆ WriteFileSuffix()

void SnapshotWriter::WriteFileSuffix ( ) const
inlineprivate

Definition at line 132 of file mksnapshot.cc.

132  {
133  fprintf(fp_, "} // namespace internal\n");
134  fprintf(fp_, "} // namespace v8\n");
135  }

◆ WriteMeta()

void SnapshotWriter::WriteMeta ( const char *  prefix,
const i::Serializer ser 
) const
inlineprivate

Definition at line 192 of file mksnapshot.cc.

192  {
193  WriteSizeVar(ser, prefix, "new", i::NEW_SPACE);
194  WriteSizeVar(ser, prefix, "pointer", i::OLD_POINTER_SPACE);
195  WriteSizeVar(ser, prefix, "data", i::OLD_DATA_SPACE);
196  WriteSizeVar(ser, prefix, "code", i::CODE_SPACE);
197  WriteSizeVar(ser, prefix, "map", i::MAP_SPACE);
198  WriteSizeVar(ser, prefix, "cell", i::CELL_SPACE);
199  WriteSizeVar(ser, prefix, "property_cell", i::PROPERTY_CELL_SPACE);
200  WriteSizeVar(ser, prefix, "lo", i::LO_SPACE);
201  fprintf(fp_, "\n");
202  }
void WriteSizeVar(const i::Serializer &ser, const char *prefix, const char *name, int space) const
Definition: mksnapshot.cc:204

References v8::internal::CELL_SPACE, v8::internal::CODE_SPACE, v8::internal::LO_SPACE, v8::internal::MAP_SPACE, v8::internal::NEW_SPACE, v8::internal::OLD_DATA_SPACE, v8::internal::OLD_POINTER_SPACE, and v8::internal::PROPERTY_CELL_SPACE.

◆ WriteSizeVar()

void SnapshotWriter::WriteSizeVar ( const i::Serializer ser,
const char *  prefix,
const char *  name,
int  space 
) const
inlineprivate

Definition at line 204 of file mksnapshot.cc.

205  {
206  fprintf(fp_, "const int Snapshot::%s%s_space_used_ = %d;\n",
207  prefix, name, ser.CurrentAllocationAddress(space));
208  }
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 the new space consists of two semi spaces print one trace line following each garbage collection do not print trace line after scavenger collection print cumulative GC statistics in name
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)

References v8::internal::Serializer::CurrentAllocationAddress(), name, and space().

+ Here is the call graph for this function:

◆ WriteSnapshot()

void SnapshotWriter::WriteSnapshot ( const i::List< i::byte > &  snapshot_data,
const i::Serializer serializer,
const i::List< i::byte > &  context_snapshot_data,
const i::Serializer context_serializer 
) const
inline

Definition at line 66 of file mksnapshot.cc.

69  {
70  WriteSnapshotFile(snapshot_data, serializer,
71  context_snapshot_data, context_serializer);
72  MaybeWriteStartupBlob(snapshot_data, serializer,
73  context_snapshot_data, context_serializer);
74  }
void WriteSnapshotFile(const i::List< i::byte > &snapshot_data, const i::Serializer &serializer, const i::List< i::byte > &context_snapshot_data, const i::Serializer &context_serializer) const
Definition: mksnapshot.cc:111
void MaybeWriteStartupBlob(const i::List< i::byte > &snapshot_data, const i::Serializer &serializer, const i::List< i::byte > &context_snapshot_data, const i::Serializer &context_serializer) const
Definition: mksnapshot.cc:77

Referenced by main().

+ Here is the caller graph for this function:

◆ WriteSnapshotData()

void SnapshotWriter::WriteSnapshotData ( const i::List< i::byte > *  data) const
inlineprivate

Definition at line 210 of file mksnapshot.cc.

210  {
211  for (int i = 0; i < data->length(); i++) {
212  if ((i & 0x1f) == 0x1f)
213  fprintf(fp_, "\n");
214  if (i > 0)
215  fprintf(fp_, ",");
216  fprintf(fp_, "%u", static_cast<unsigned char>(data->at(i)));
217  }
218  fprintf(fp_, "\n");
219  }
T & at(int i) const
Definition: list.h:69

References v8::internal::List< T, AllocationPolicy >::at().

+ Here is the call graph for this function:

◆ WriteSnapshotFile()

void SnapshotWriter::WriteSnapshotFile ( const i::List< i::byte > &  snapshot_data,
const i::Serializer serializer,
const i::List< i::byte > &  context_snapshot_data,
const i::Serializer context_serializer 
) const
inlineprivate

Definition at line 111 of file mksnapshot.cc.

114  {
115  WriteFilePrefix();
116  WriteData("", snapshot_data, raw_file_);
117  WriteData("context_", context_snapshot_data, raw_context_file_);
118  WriteMeta("context_", context_serializer);
119  WriteMeta("", serializer);
120  WriteFileSuffix();
121  }
void WriteFilePrefix() const
Definition: mksnapshot.cc:123
void WriteFileSuffix() const
Definition: mksnapshot.cc:132
void WriteMeta(const char *prefix, const i::Serializer &ser) const
Definition: mksnapshot.cc:192

Member Data Documentation

◆ compressor_

Compressor* SnapshotWriter::compressor_
private

Definition at line 234 of file mksnapshot.cc.

◆ fp_

FILE* SnapshotWriter::fp_
private

Definition at line 230 of file mksnapshot.cc.

◆ raw_context_file_

FILE* SnapshotWriter::raw_context_file_
private

Definition at line 232 of file mksnapshot.cc.

◆ raw_file_

FILE* SnapshotWriter::raw_file_
private

Definition at line 231 of file mksnapshot.cc.

◆ startup_blob_file_

FILE* SnapshotWriter::startup_blob_file_
private

Definition at line 233 of file mksnapshot.cc.


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