V8 Project
snapshot-source-sink.cc
Go to the documentation of this file.
1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 
7 
8 #include "src/base/logging.h"
9 #include "src/handles-inl.h"
10 #include "src/serialize.h" // for SerializerDeserializer::nop() in AtEOF()
11 
12 
13 namespace v8 {
14 namespace internal {
15 
16 
17 SnapshotByteSource::SnapshotByteSource(const byte* array, int length)
18  : data_(array), length_(length), position_(0) {
19 }
20 
21 
22 SnapshotByteSource::~SnapshotByteSource() { }
23 
24 
25 int32_t SnapshotByteSource::GetUnalignedInt() {
26  DCHECK(position_ < length_); // Require at least one byte left.
27  int32_t answer = data_[position_];
28  answer |= data_[position_ + 1] << 8;
29  answer |= data_[position_ + 2] << 16;
30  answer |= data_[position_ + 3] << 24;
31  return answer;
32 }
33 
34 
35 void SnapshotByteSource::CopyRaw(byte* to, int number_of_bytes) {
36  MemCopy(to, data_ + position_, number_of_bytes);
37  position_ += number_of_bytes;
38 }
39 
40 
41 void SnapshotByteSink::PutInt(uintptr_t integer, const char* description) {
42  DCHECK(integer < 1 << 30);
43  integer <<= 2;
44  int bytes = 1;
45  if (integer > 0xff) bytes = 2;
46  if (integer > 0xffff) bytes = 3;
47  if (integer > 0xffffff) bytes = 4;
48  integer |= (bytes - 1);
49  Put(static_cast<int>(integer & 0xff), "IntPart1");
50  if (bytes > 1) Put(static_cast<int>((integer >> 8) & 0xff), "IntPart2");
51  if (bytes > 2) Put(static_cast<int>((integer >> 16) & 0xff), "IntPart3");
52  if (bytes > 3) Put(static_cast<int>((integer >> 24) & 0xff), "IntPart4");
53 }
54 
55 void SnapshotByteSink::PutRaw(byte* data, int number_of_bytes,
56  const char* description) {
57  for (int i = 0; i < number_of_bytes; ++i) {
58  Put(data[i], description);
59  }
60 }
61 
62 void SnapshotByteSink::PutBlob(byte* data, int number_of_bytes,
63  const char* description) {
64  PutInt(number_of_bytes, description);
65  PutRaw(data, number_of_bytes, description);
66 }
67 
68 
69 bool SnapshotByteSource::AtEOF() {
70  if (0u + length_ - position_ > 2 * sizeof(uint32_t)) return false;
71  for (int x = position_; x < length_; x++) {
72  if (data_[x] != SerializerDeserializer::nop()) return false;
73  }
74  return true;
75 }
76 
77 
78 bool SnapshotByteSource::GetBlob(const byte** data, int* number_of_bytes) {
79  int size = GetInt();
80  *number_of_bytes = size;
81 
82  if (position_ + size < length_) {
83  *data = &data_[position_];
84  Advance(size);
85  return true;
86  } else {
87  Advance(length_ - position_); // proceed until end.
88  return false;
89  }
90 }
91 
92 
93 void DebugSnapshotSink::Put(byte b, const char* description) {
94  PrintF("%24s: %x\n", description, b);
95  sink_->Put(b, description);
96 }
97 
98 } // namespace v8::internal
99 } // namespace v8
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 only print modified registers Trace simulator debug messages Implied by trace sim abort randomize hashes to avoid predictable hash Fixed seed to use to hash property Print the time it takes to deserialize the snapshot A filename with extra code to be included in the A file to write the raw snapshot bytes to(mksnapshot only)") DEFINE_STRING(raw_context_file
enable harmony numeric enable harmony object literal extensions Optimize object size
#define DCHECK(condition)
Definition: logging.h:205
int int32_t
Definition: unicode.cc:24
void PrintF(const char *format,...)
Definition: utils.cc:80
void MemCopy(void *dest, const void *src, size_t size)
Definition: utils.h:350
Debugger support for the V8 JavaScript engine.
Definition: accessors.cc:20