V8 Project
snapshot-source-sink.h
Go to the documentation of this file.
1 // Copyright 2012 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 #ifndef V8_SNAPSHOT_SOURCE_SINK_H_
6 #define V8_SNAPSHOT_SOURCE_SINK_H_
7 
8 #include "src/base/logging.h"
9 #include "src/utils.h"
10 
11 namespace v8 {
12 namespace internal {
13 
14 
15 /**
16  * Source to read snapshot and builtins files from.
17  *
18  * Note: Memory ownership remains with callee.
19  */
20 class SnapshotByteSource FINAL {
21  public:
22  SnapshotByteSource(const byte* array, int length);
24 
25  bool HasMore() { return position_ < length_; }
26 
27  int Get() {
28  DCHECK(position_ < length_);
29  return data_[position_++];
30  }
31 
33 
34  void Advance(int by) { position_ += by; }
35 
36  void CopyRaw(byte* to, int number_of_bytes);
37 
38  inline int GetInt() {
39  // This way of variable-length encoding integers does not suffer from branch
40  // mispredictions.
41  uint32_t answer = GetUnalignedInt();
42  int bytes = (answer & 3) + 1;
43  Advance(bytes);
44  uint32_t mask = 0xffffffffu;
45  mask >>= 32 - (bytes << 3);
46  answer &= mask;
47  answer >>= 2;
48  return answer;
49  }
50 
51  bool GetBlob(const byte** data, int* number_of_bytes);
52 
53  bool AtEOF();
54 
55  int position() { return position_; }
56 
57  private:
58  const byte* data_;
59  int length_;
60  int position_;
61 
62  DISALLOW_COPY_AND_ASSIGN(SnapshotByteSource);
63 };
64 
65 
66 /**
67  * Sink to write snapshot files to.
68  *
69  * Subclasses must implement actual storage or i/o.
70  */
72  public:
73  virtual ~SnapshotByteSink() { }
74  virtual void Put(byte b, const char* description) = 0;
75  virtual void PutSection(int b, const char* description) {
76  DCHECK_LE(b, kMaxUInt8);
77  Put(static_cast<byte>(b), description);
78  }
79  void PutInt(uintptr_t integer, const char* description);
80  void PutRaw(byte* data, int number_of_bytes, const char* description);
81  void PutBlob(byte* data, int number_of_bytes, const char* description);
82  virtual int Position() = 0;
83 };
84 
85 
87  public:
89  virtual ~DummySnapshotSink() {}
90  virtual void Put(byte b, const char* description) { length_++; }
91  virtual int Position() { return length_; }
92 
93  private:
94  int length_;
95 };
96 
97 
98 // Wrap a SnapshotByteSink into a DebugSnapshotSink to get debugging output.
100  public:
101  explicit DebugSnapshotSink(SnapshotByteSink* chained) : sink_(chained) {}
102  virtual void Put(byte b, const char* description) OVERRIDE;
103  virtual int Position() OVERRIDE { return sink_->Position(); }
104 
105  private:
107 };
108 
109 
111  public:
112  explicit ListSnapshotSink(i::List<byte>* data) : data_(data) {}
113  virtual void Put(byte b, const char* description) OVERRIDE {
114  data_->Add(b);
115  }
116  virtual int Position() OVERRIDE { return data_->length(); }
117 
118  private:
120 };
121 
122 } // namespace v8::internal
123 } // namespace v8
124 
125 #endif // V8_SNAPSHOT_SOURCE_SINK_H_
virtual void Put(byte b, const char *description) OVERRIDE
DebugSnapshotSink(SnapshotByteSink *chained)
virtual void Put(byte b, const char *description)
void CopyRaw(byte *to, int number_of_bytes)
SnapshotByteSource(const byte *array, int length)
int32_t GetUnalignedInt()
bool GetBlob(const byte **data, int *number_of_bytes)
DISALLOW_COPY_AND_ASSIGN(SnapshotByteSource)
ListSnapshotSink(i::List< byte > *data)
virtual void Put(byte b, const char *description) OVERRIDE
void Add(const T &element, AllocationPolicy allocator=AllocationPolicy())
Definition: list-inl.h:17
Sink to write snapshot files to.
virtual void Put(byte b, const char *description)=0
virtual void PutSection(int b, const char *description)
void PutRaw(byte *data, int number_of_bytes, const char *description)
void PutInt(uintptr_t integer, const char *description)
void PutBlob(byte *data, int number_of_bytes, const char *description)
#define OVERRIDE
#define FINAL
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
#define DCHECK_LE(v1, v2)
Definition: logging.h:210
#define DCHECK(condition)
Definition: logging.h:205
int int32_t
Definition: unicode.cc:24
const int kMaxUInt8
Definition: globals.h:113
Debugger support for the V8 JavaScript engine.
Definition: accessors.cc:20