V8 Project
safepoint-table.h
Go to the documentation of this file.
1 // Copyright 2011 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_SAFEPOINT_TABLE_H_
6 #define V8_SAFEPOINT_TABLE_H_
7 
8 #include "src/allocation.h"
9 #include "src/heap/heap.h"
10 #include "src/v8memory.h"
11 #include "src/zone.h"
12 
13 namespace v8 {
14 namespace internal {
15 
16 struct Register;
17 
18 class SafepointEntry BASE_EMBEDDED {
19  public:
20  SafepointEntry() : info_(0), bits_(NULL) {}
21 
22  SafepointEntry(unsigned info, uint8_t* bits) : info_(info), bits_(bits) {
23  DCHECK(is_valid());
24  }
25 
26  bool is_valid() const { return bits_ != NULL; }
27 
28  bool Equals(const SafepointEntry& other) const {
29  return info_ == other.info_ && bits_ == other.bits_;
30  }
31 
32  void Reset() {
33  info_ = 0;
34  bits_ = NULL;
35  }
36 
37  int deoptimization_index() const {
38  DCHECK(is_valid());
39  return DeoptimizationIndexField::decode(info_);
40  }
41 
42  static const int kArgumentsFieldBits = 3;
43  static const int kSaveDoublesFieldBits = 1;
44  static const int kDeoptIndexBits =
45  32 - kArgumentsFieldBits - kSaveDoublesFieldBits;
47  public BitField<int, 0, kDeoptIndexBits> {}; // NOLINT
49  public BitField<unsigned,
50  kDeoptIndexBits,
51  kArgumentsFieldBits> {}; // NOLINT
53  public BitField<bool,
54  kDeoptIndexBits + kArgumentsFieldBits,
55  kSaveDoublesFieldBits> { }; // NOLINT
56 
57  int argument_count() const {
58  DCHECK(is_valid());
59  return ArgumentsField::decode(info_);
60  }
61 
62  bool has_doubles() const {
63  DCHECK(is_valid());
64  return SaveDoublesField::decode(info_);
65  }
66 
67  uint8_t* bits() {
68  DCHECK(is_valid());
69  return bits_;
70  }
71 
72  bool HasRegisters() const;
73  bool HasRegisterAt(int reg_index) const;
74 
75  private:
76  unsigned info_;
77  uint8_t* bits_;
78 };
79 
80 
81 class SafepointTable BASE_EMBEDDED {
82  public:
83  explicit SafepointTable(Code* code);
84 
85  int size() const {
86  return kHeaderSize +
87  (length_ * (kPcAndDeoptimizationIndexSize + entry_size_));
88  }
89  unsigned length() const { return length_; }
90  unsigned entry_size() const { return entry_size_; }
91 
92  unsigned GetPcOffset(unsigned index) const {
93  DCHECK(index < length_);
94  return Memory::uint32_at(GetPcOffsetLocation(index));
95  }
96 
97  SafepointEntry GetEntry(unsigned index) const {
98  DCHECK(index < length_);
99  unsigned info = Memory::uint32_at(GetInfoLocation(index));
100  uint8_t* bits = &Memory::uint8_at(entries_ + (index * entry_size_));
101  return SafepointEntry(info, bits);
102  }
103 
104  // Returns the entry for the given pc.
105  SafepointEntry FindEntry(Address pc) const;
106 
107  void PrintEntry(unsigned index, OStream& os) const; // NOLINT
108 
109  private:
110  static const uint8_t kNoRegisters = 0xFF;
111 
112  static const int kLengthOffset = 0;
113  static const int kEntrySizeOffset = kLengthOffset + kIntSize;
114  static const int kHeaderSize = kEntrySizeOffset + kIntSize;
115 
116  static const int kPcSize = kIntSize;
117  static const int kDeoptimizationIndexSize = kIntSize;
118  static const int kPcAndDeoptimizationIndexSize =
119  kPcSize + kDeoptimizationIndexSize;
120 
121  Address GetPcOffsetLocation(unsigned index) const {
122  return pc_and_deoptimization_indexes_ +
123  (index * kPcAndDeoptimizationIndexSize);
124  }
125 
126  Address GetInfoLocation(unsigned index) const {
127  return GetPcOffsetLocation(index) + kPcSize;
128  }
129 
130  static void PrintBits(OStream& os, // NOLINT
131  uint8_t byte, int digits);
132 
135  unsigned length_;
136  unsigned entry_size_;
137 
140 
141  friend class SafepointTableBuilder;
142  friend class SafepointEntry;
143 
144  DISALLOW_COPY_AND_ASSIGN(SafepointTable);
145 };
146 
147 
148 class Safepoint BASE_EMBEDDED {
149  public:
150  typedef enum {
151  kSimple = 0,
152  kWithRegisters = 1 << 0,
153  kWithDoubles = 1 << 1,
154  kWithRegistersAndDoubles = kWithRegisters | kWithDoubles
155  } Kind;
156 
157  enum DeoptMode {
159  kLazyDeopt
160  };
161 
162  static const int kNoDeoptimizationIndex =
163  (1 << (SafepointEntry::kDeoptIndexBits)) - 1;
164 
165  void DefinePointerSlot(int index, Zone* zone) { indexes_->Add(index, zone); }
167 
168  private:
169  Safepoint(ZoneList<int>* indexes, ZoneList<int>* registers)
170  : indexes_(indexes), registers_(registers) {}
173 
174  friend class SafepointTableBuilder;
175 };
176 
177 
178 class SafepointTableBuilder BASE_EMBEDDED {
179  public:
180  explicit SafepointTableBuilder(Zone* zone)
181  : deoptimization_info_(32, zone),
182  deopt_index_list_(32, zone),
183  indexes_(32, zone),
184  registers_(32, zone),
185  emitted_(false),
186  last_lazy_safepoint_(0),
187  zone_(zone) { }
188 
189  // Get the offset of the emitted safepoint table in the code.
190  unsigned GetCodeOffset() const;
191 
192  // Define a new safepoint for the current position in the body.
193  Safepoint DefineSafepoint(Assembler* assembler,
194  Safepoint::Kind kind,
195  int arguments,
196  Safepoint::DeoptMode mode);
197 
198  // Record deoptimization index for lazy deoptimization for the last
199  // outstanding safepoints.
202  last_lazy_safepoint_ = deopt_index_list_.length();
203  }
204 
205  // Emit the safepoint table after the body. The number of bits per
206  // entry must be enough to hold all the pointer indexes.
207  void Emit(Assembler* assembler, int bits_per_entry);
208 
209 
210  private:
212  unsigned pc;
213  unsigned arguments;
215  };
216 
217  uint32_t EncodeExceptPC(const DeoptimizationInfo& info, unsigned index);
218 
223 
224  unsigned offset_;
225  bool emitted_;
227 
228  Zone* zone_;
229 
230  DISALLOW_COPY_AND_ASSIGN(SafepointTableBuilder);
231 };
232 
233 } } // namespace v8::internal
234 
235 #endif // V8_SAFEPOINT_TABLE_H_
#define BASE_EMBEDDED
Definition: allocation.h:45
Safepoint(ZoneList< int > *indexes, ZoneList< int > *registers)
Safepoint DefineSafepoint(Assembler *assembler, Safepoint::Kind kind, int arguments, Safepoint::DeoptMode mode)
DISALLOW_COPY_AND_ASSIGN(SafepointTable)
SafepointEntry GetEntry(unsigned index) const
ZoneList< DeoptimizationInfo > deoptimization_info_
Address GetInfoLocation(unsigned index) const
unsigned GetPcOffset(unsigned index) const
ZoneList< ZoneList< int > * > indexes_
uint32_t EncodeExceptPC(const DeoptimizationInfo &info, unsigned index)
DISALLOW_COPY_AND_ASSIGN(SafepointTableBuilder)
unsigned GetCodeOffset() const
ZoneList< unsigned > deopt_index_list_
SafepointEntry(unsigned info, uint8_t *bits)
bool Equals(const SafepointEntry &other) const
ZoneList< ZoneList< int > * > registers_
void PrintEntry(unsigned index, OStream &os) const
ZoneList< int > * registers_
Address GetPcOffsetLocation(unsigned index) const
bool HasRegisterAt(int reg_index) const
DisallowHeapAllocation no_allocation_
SafepointEntry FindEntry(Address pc) const
void DefinePointerSlot(int index, Zone *zone)
static void PrintBits(OStream &os, uint8_t byte, int digits)
void RecordLazyDeoptimizationIndex(int index)
void DefinePointerRegister(Register reg, Zone *zone)
void Emit(Assembler *assembler, int bits_per_entry)
static uint8_t & uint8_at(Address addr)
Definition: v8memory.h:16
static uint32_t & uint32_at(Address addr)
Definition: v8memory.h:24
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 mode(MIPS only)") DEFINE_BOOL(enable_always_align_csp
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
#define DCHECK(condition)
Definition: logging.h:205
const Register pc
byte * Address
Definition: globals.h:101
const int kIntSize
Definition: globals.h:124
Debugger support for the V8 JavaScript engine.
Definition: accessors.cc:20