OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 void Reset() { | 55 void Reset() { |
56 info_ = 0; | 56 info_ = 0; |
57 bits_ = NULL; | 57 bits_ = NULL; |
58 } | 58 } |
59 | 59 |
60 int deoptimization_index() const { | 60 int deoptimization_index() const { |
61 ASSERT(is_valid()); | 61 ASSERT(is_valid()); |
62 return DeoptimizationIndexField::decode(info_); | 62 return DeoptimizationIndexField::decode(info_); |
63 } | 63 } |
64 | 64 |
65 int gap_code_size() const { | 65 static const int kArgumentsFieldBits = 3; |
66 ASSERT(is_valid()); | 66 static const int kSaveDoublesFieldBits = 1; |
67 return GapCodeSizeField::decode(info_); | 67 static const int kDeoptIndexBits = |
68 } | 68 32 - kArgumentsFieldBits - kSaveDoublesFieldBits; |
| 69 class DeoptimizationIndexField: |
| 70 public BitField<int, 0, kDeoptIndexBits> {}; // NOLINT |
| 71 class ArgumentsField: |
| 72 public BitField<unsigned, |
| 73 kDeoptIndexBits, |
| 74 kArgumentsFieldBits> {}; // NOLINT |
| 75 class SaveDoublesField: |
| 76 public BitField<bool, |
| 77 kDeoptIndexBits + kArgumentsFieldBits, |
| 78 kSaveDoublesFieldBits> { }; // NOLINT |
69 | 79 |
70 int argument_count() const { | 80 int argument_count() const { |
71 ASSERT(is_valid()); | 81 ASSERT(is_valid()); |
72 return ArgumentsField::decode(info_); | 82 return ArgumentsField::decode(info_); |
73 } | 83 } |
74 | 84 |
75 bool has_doubles() const { | 85 bool has_doubles() const { |
76 ASSERT(is_valid()); | 86 ASSERT(is_valid()); |
77 return SaveDoublesField::decode(info_); | 87 return SaveDoublesField::decode(info_); |
78 } | 88 } |
79 | 89 |
80 uint8_t* bits() { | 90 uint8_t* bits() { |
81 ASSERT(is_valid()); | 91 ASSERT(is_valid()); |
82 return bits_; | 92 return bits_; |
83 } | 93 } |
84 | 94 |
85 bool HasRegisters() const; | 95 bool HasRegisters() const; |
86 bool HasRegisterAt(int reg_index) const; | 96 bool HasRegisterAt(int reg_index) const; |
87 | 97 |
88 // Reserve 13 bits for the gap code size. On ARM a constant pool can be | |
89 // emitted when generating the gap code. The size of the const pool is less | |
90 // than what can be represented in 12 bits, so 13 bits gives room for having | |
91 // instructions before potentially emitting a constant pool. | |
92 static const int kGapCodeSizeBits = 13; | |
93 static const int kArgumentsFieldBits = 3; | |
94 static const int kSaveDoublesFieldBits = 1; | |
95 static const int kDeoptIndexBits = | |
96 32 - kGapCodeSizeBits - kArgumentsFieldBits - kSaveDoublesFieldBits; | |
97 class GapCodeSizeField: public BitField<unsigned, 0, kGapCodeSizeBits> {}; | |
98 class DeoptimizationIndexField: public BitField<int, | |
99 kGapCodeSizeBits, | |
100 kDeoptIndexBits> {}; // NOLIN
T | |
101 class ArgumentsField: public BitField<unsigned, | |
102 kGapCodeSizeBits + kDeoptIndexBits, | |
103 kArgumentsFieldBits> {}; // NOLINT | |
104 class SaveDoublesField: public BitField<bool, | |
105 kGapCodeSizeBits + kDeoptIndexBits + | |
106 kArgumentsFieldBits, | |
107 kSaveDoublesFieldBits> { }; // NOLINT | |
108 | |
109 private: | 98 private: |
110 unsigned info_; | 99 unsigned info_; |
111 uint8_t* bits_; | 100 uint8_t* bits_; |
112 }; | 101 }; |
113 | 102 |
114 | 103 |
115 class SafepointTable BASE_EMBEDDED { | 104 class SafepointTable BASE_EMBEDDED { |
116 public: | 105 public: |
117 explicit SafepointTable(Code* code); | 106 explicit SafepointTable(Code* code); |
118 | 107 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 | 168 |
180 class Safepoint BASE_EMBEDDED { | 169 class Safepoint BASE_EMBEDDED { |
181 public: | 170 public: |
182 typedef enum { | 171 typedef enum { |
183 kSimple = 0, | 172 kSimple = 0, |
184 kWithRegisters = 1 << 0, | 173 kWithRegisters = 1 << 0, |
185 kWithDoubles = 1 << 1, | 174 kWithDoubles = 1 << 1, |
186 kWithRegistersAndDoubles = kWithRegisters | kWithDoubles | 175 kWithRegistersAndDoubles = kWithRegisters | kWithDoubles |
187 } Kind; | 176 } Kind; |
188 | 177 |
| 178 enum DeoptMode { |
| 179 kNoLazyDeopt, |
| 180 kLazyDeopt |
| 181 }; |
| 182 |
189 static const int kNoDeoptimizationIndex = | 183 static const int kNoDeoptimizationIndex = |
190 (1 << (SafepointEntry::kDeoptIndexBits)) - 1; | 184 (1 << (SafepointEntry::kDeoptIndexBits)) - 1; |
191 | 185 |
192 void DefinePointerSlot(int index) { indexes_->Add(index); } | 186 void DefinePointerSlot(int index) { indexes_->Add(index); } |
193 void DefinePointerRegister(Register reg); | 187 void DefinePointerRegister(Register reg); |
194 | 188 |
195 private: | 189 private: |
196 Safepoint(ZoneList<int>* indexes, ZoneList<int>* registers) : | 190 Safepoint(ZoneList<int>* indexes, ZoneList<int>* registers) : |
197 indexes_(indexes), registers_(registers) { } | 191 indexes_(indexes), registers_(registers) { } |
198 ZoneList<int>* indexes_; | 192 ZoneList<int>* indexes_; |
199 ZoneList<int>* registers_; | 193 ZoneList<int>* registers_; |
200 | 194 |
201 friend class SafepointTableBuilder; | 195 friend class SafepointTableBuilder; |
202 }; | 196 }; |
203 | 197 |
204 | 198 |
205 class SafepointTableBuilder BASE_EMBEDDED { | 199 class SafepointTableBuilder BASE_EMBEDDED { |
206 public: | 200 public: |
207 SafepointTableBuilder() | 201 SafepointTableBuilder() |
208 : deoptimization_info_(32), | 202 : deoptimization_info_(32), |
| 203 deopt_index_list_(32), |
209 indexes_(32), | 204 indexes_(32), |
210 registers_(32), | 205 registers_(32), |
211 emitted_(false) { } | 206 emitted_(false), |
| 207 last_lazy_safepoint_(0) { } |
212 | 208 |
213 // Get the offset of the emitted safepoint table in the code. | 209 // Get the offset of the emitted safepoint table in the code. |
214 unsigned GetCodeOffset() const; | 210 unsigned GetCodeOffset() const; |
215 | 211 |
216 // Define a new safepoint for the current position in the body. | 212 // Define a new safepoint for the current position in the body. |
217 Safepoint DefineSafepoint(Assembler* assembler, | 213 Safepoint DefineSafepoint(Assembler* assembler, |
218 Safepoint::Kind kind, | 214 Safepoint::Kind kind, |
219 int arguments, | 215 int arguments, |
220 int deoptimization_index); | 216 Safepoint::DeoptMode mode); |
221 | 217 |
222 // Update the last safepoint with the size of the code generated until the | 218 // Record deoptimization index for lazy deoptimization for the last |
223 // end of the gap following it. | 219 // outstanding safepoints. |
224 void SetPcAfterGap(int pc) { | 220 void RecordLazyDeoptimizationIndex(int index); |
225 ASSERT(!deoptimization_info_.is_empty()); | |
226 int index = deoptimization_info_.length() - 1; | |
227 deoptimization_info_[index].pc_after_gap = pc; | |
228 } | |
229 | |
230 // Get the end pc offset of the last safepoint, including the code generated | |
231 // until the end of the gap following it. | |
232 unsigned GetPcAfterGap() { | |
233 int index = deoptimization_info_.length(); | |
234 if (index == 0) return 0; | |
235 return deoptimization_info_[index - 1].pc_after_gap; | |
236 } | |
237 | 221 |
238 // Emit the safepoint table after the body. The number of bits per | 222 // Emit the safepoint table after the body. The number of bits per |
239 // entry must be enough to hold all the pointer indexes. | 223 // entry must be enough to hold all the pointer indexes. |
240 void Emit(Assembler* assembler, int bits_per_entry); | 224 void Emit(Assembler* assembler, int bits_per_entry); |
241 | 225 |
242 // Count the number of deoptimization points where the next | |
243 // following deoptimization point comes less than limit bytes | |
244 // after the end of this point's gap. | |
245 int CountShortDeoptimizationIntervals(unsigned limit); | |
246 | 226 |
247 private: | 227 private: |
248 struct DeoptimizationInfo { | 228 struct DeoptimizationInfo { |
249 unsigned pc; | 229 unsigned pc; |
250 unsigned deoptimization_index; | |
251 unsigned pc_after_gap; | |
252 unsigned arguments; | 230 unsigned arguments; |
253 bool has_doubles; | 231 bool has_doubles; |
254 }; | 232 }; |
255 | 233 |
256 uint32_t EncodeExceptPC(const DeoptimizationInfo& info); | 234 uint32_t EncodeExceptPC(const DeoptimizationInfo& info, unsigned index); |
257 | 235 |
258 ZoneList<DeoptimizationInfo> deoptimization_info_; | 236 ZoneList<DeoptimizationInfo> deoptimization_info_; |
| 237 ZoneList<unsigned> deopt_index_list_; |
259 ZoneList<ZoneList<int>*> indexes_; | 238 ZoneList<ZoneList<int>*> indexes_; |
260 ZoneList<ZoneList<int>*> registers_; | 239 ZoneList<ZoneList<int>*> registers_; |
261 | 240 |
262 unsigned offset_; | 241 unsigned offset_; |
263 bool emitted_; | 242 bool emitted_; |
| 243 int last_lazy_safepoint_; |
264 | 244 |
265 DISALLOW_COPY_AND_ASSIGN(SafepointTableBuilder); | 245 DISALLOW_COPY_AND_ASSIGN(SafepointTableBuilder); |
266 }; | 246 }; |
267 | 247 |
268 } } // namespace v8::internal | 248 } } // namespace v8::internal |
269 | 249 |
270 #endif // V8_SAFEPOINT_TABLE_H_ | 250 #endif // V8_SAFEPOINT_TABLE_H_ |
OLD | NEW |