Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(183)

Side by Side Diff: src/assembler.cc

Issue 5699002: RFC: Switch to ast ids (instead of positions) for type feedback. (Closed)
Patch Set: Cleanup Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 1994-2006 Sun Microsystems Inc. 1 // Copyright (c) 1994-2006 Sun Microsystems Inc.
2 // All Rights Reserved. 2 // All Rights Reserved.
3 // 3 //
4 // Redistribution and use in source and binary forms, with or without 4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are 5 // modification, are permitted provided that the following conditions are
6 // met: 6 // met:
7 // 7 //
8 // - Redistributions of source code must retain the above copyright notice, 8 // - Redistributions of source code must retain the above copyright notice,
9 // this list of conditions and the following disclaimer. 9 // this list of conditions and the following disclaimer.
10 // 10 //
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 82
83 // ----------------------------------------------------------------------------- 83 // -----------------------------------------------------------------------------
84 // Implementation of RelocInfoWriter and RelocIterator 84 // Implementation of RelocInfoWriter and RelocIterator
85 // 85 //
86 // Encoding 86 // Encoding
87 // 87 //
88 // The most common modes are given single-byte encodings. Also, it is 88 // The most common modes are given single-byte encodings. Also, it is
89 // easy to identify the type of reloc info and skip unwanted modes in 89 // easy to identify the type of reloc info and skip unwanted modes in
90 // an iteration. 90 // an iteration.
91 // 91 //
92 // The encoding relies on the fact that there are less than 14 92 // The encoding relies on the fact that there are less than 14
fschneider 2011/02/11 11:28:18 I'm confused by this comment in the existing code
93 // different relocation modes. 93 // different relocation modes.
94 // 94 //
95 // embedded_object: [6 bits pc delta] 00 95 // embedded_object: [6 bits pc delta] 00
96 // 96 //
97 // code_taget: [6 bits pc delta] 01 97 // code_taget: [6 bits pc delta] 01
fschneider 2011/02/11 11:28:18 --> code_target
98 // 98 //
99 // code_taget_with_id: [6 bits pc delta] 10,
fschneider 2011/02/11 11:28:18 --> code_target
100 // [6 bits signed data delta] 00
101 //
99 // position: [6 bits pc delta] 10, 102 // position: [6 bits pc delta] 10,
100 // [7 bits signed data delta] 0 103 // [6 bits signed data delta] 01
101 // 104 //
102 // statement_position: [6 bits pc delta] 10, 105 // statement_position: [6 bits pc delta] 10,
103 // [7 bits signed data delta] 1 106 // [6 bits signed data delta] 10
104 // 107 //
105 // any nondata mode: 00 [4 bits rmode] 11, // rmode: 0..13 only 108 // any nondata mode: 00 [4 bits rmode] 11, // rmode: 0..13 only
106 // 00 [6 bits pc delta] 109 // 00 [6 bits pc delta]
107 // 110 //
108 // pc-jump: 00 1111 11, 111 // pc-jump: 00 1111 11,
109 // 00 [6 bits pc delta] 112 // 00 [6 bits pc delta]
110 // 113 //
111 // pc-jump: 01 1111 11, 114 // pc-jump: 01 1111 11,
112 // (variable length) 7 - 26 bit pc delta, written in chunks of 7 115 // (variable length) 7 - 26 bit pc delta, written in chunks of 7
113 // bits, the lowest 7 bits written first. 116 // bits, the lowest 7 bits written first.
114 // 117 //
115 // data-jump + pos: 00 1110 11, 118 // data-jump + c.id: 00 1110 11,
116 // signed intptr_t, lowest byte written first 119 // signed intptr_t, lowest byte written first
117 // 120 //
118 // data-jump + st.pos: 01 1110 11, 121 // data-jump + pos: 01 1110 11,
119 // signed intptr_t, lowest byte written first 122 // signed intptr_t, lowest byte written first
120 // 123 //
121 // data-jump + comm.: 10 1110 11, 124 // data-jump + st.pos: 10 1110 11,
125 // signed intptr_t, lowest byte written first
126 //
127 // data-jump + comm.: 11 1110 11,
122 // signed intptr_t, lowest byte written first 128 // signed intptr_t, lowest byte written first
123 // 129 //
124 const int kMaxRelocModes = 14; 130 const int kMaxRelocModes = 14;
125 131
126 const int kTagBits = 2; 132 const int kTagBits = 2;
127 const int kTagMask = (1 << kTagBits) - 1; 133 const int kTagMask = (1 << kTagBits) - 1;
128 const int kExtraTagBits = 4; 134 const int kExtraTagBits = 4;
129 const int kPositionTypeTagBits = 1; 135 const int kLocatableTypeTagBits = 2;
130 const int kSmallDataBits = kBitsPerByte - kPositionTypeTagBits; 136 const int kSmallDataBits = kBitsPerByte - kLocatableTypeTagBits;
131 137
132 const int kEmbeddedObjectTag = 0; 138 const int kEmbeddedObjectTag = 0;
133 const int kCodeTargetTag = 1; 139 const int kCodeTargetTag = 1;
134 const int kPositionTag = 2; 140 const int kLocatableTag = 2;
135 const int kDefaultTag = 3; 141 const int kDefaultTag = 3;
136 142
137 const int kPCJumpTag = (1 << kExtraTagBits) - 1; 143 const int kPCJumpTag = (1 << kExtraTagBits) - 1;
138 144
139 const int kSmallPCDeltaBits = kBitsPerByte - kTagBits; 145 const int kSmallPCDeltaBits = kBitsPerByte - kTagBits;
140 const int kSmallPCDeltaMask = (1 << kSmallPCDeltaBits) - 1; 146 const int kSmallPCDeltaMask = (1 << kSmallPCDeltaBits) - 1;
141 147
142 const int kVariableLengthPCJumpTopTag = 1; 148 const int kVariableLengthPCJumpTopTag = 1;
143 const int kChunkBits = 7; 149 const int kChunkBits = 7;
144 const int kChunkMask = (1 << kChunkBits) - 1; 150 const int kChunkMask = (1 << kChunkBits) - 1;
145 const int kLastChunkTagBits = 1; 151 const int kLastChunkTagBits = 1;
146 const int kLastChunkTagMask = 1; 152 const int kLastChunkTagMask = 1;
147 const int kLastChunkTag = 1; 153 const int kLastChunkTag = 1;
148 154
149 155
150 const int kDataJumpTag = kPCJumpTag - 1; 156 const int kDataJumpTag = kPCJumpTag - 1;
151 157
152 const int kNonstatementPositionTag = 0; 158 const int kCodeWithIdTag = 0;
153 const int kStatementPositionTag = 1; 159 const int kNonstatementPositionTag = 1;
154 const int kCommentTag = 2; 160 const int kStatementPositionTag = 2;
161 const int kCommentTag = 3;
155 162
156 163
157 uint32_t RelocInfoWriter::WriteVariableLengthPCJump(uint32_t pc_delta) { 164 uint32_t RelocInfoWriter::WriteVariableLengthPCJump(uint32_t pc_delta) {
158 // Return if the pc_delta can fit in kSmallPCDeltaBits bits. 165 // Return if the pc_delta can fit in kSmallPCDeltaBits bits.
159 // Otherwise write a variable length PC jump for the bits that do 166 // Otherwise write a variable length PC jump for the bits that do
160 // not fit in the kSmallPCDeltaBits bits. 167 // not fit in the kSmallPCDeltaBits bits.
161 if (is_uintn(pc_delta, kSmallPCDeltaBits)) return pc_delta; 168 if (is_uintn(pc_delta, kSmallPCDeltaBits)) return pc_delta;
162 WriteExtraTag(kPCJumpTag, kVariableLengthPCJumpTopTag); 169 WriteExtraTag(kPCJumpTag, kVariableLengthPCJumpTopTag);
163 uint32_t pc_jump = pc_delta >> kSmallPCDeltaBits; 170 uint32_t pc_jump = pc_delta >> kSmallPCDeltaBits;
164 ASSERT(pc_jump > 0); 171 ASSERT(pc_jump > 0);
(...skipping 10 matching lines...) Expand all
175 182
176 183
177 void RelocInfoWriter::WriteTaggedPC(uint32_t pc_delta, int tag) { 184 void RelocInfoWriter::WriteTaggedPC(uint32_t pc_delta, int tag) {
178 // Write a byte of tagged pc-delta, possibly preceded by var. length pc-jump. 185 // Write a byte of tagged pc-delta, possibly preceded by var. length pc-jump.
179 pc_delta = WriteVariableLengthPCJump(pc_delta); 186 pc_delta = WriteVariableLengthPCJump(pc_delta);
180 *--pos_ = pc_delta << kTagBits | tag; 187 *--pos_ = pc_delta << kTagBits | tag;
181 } 188 }
182 189
183 190
184 void RelocInfoWriter::WriteTaggedData(intptr_t data_delta, int tag) { 191 void RelocInfoWriter::WriteTaggedData(intptr_t data_delta, int tag) {
185 *--pos_ = static_cast<byte>(data_delta << kPositionTypeTagBits | tag); 192 *--pos_ = static_cast<byte>(data_delta << kLocatableTypeTagBits | tag);
186 } 193 }
187 194
188 195
189 void RelocInfoWriter::WriteExtraTag(int extra_tag, int top_tag) { 196 void RelocInfoWriter::WriteExtraTag(int extra_tag, int top_tag) {
190 *--pos_ = static_cast<int>(top_tag << (kTagBits + kExtraTagBits) | 197 *--pos_ = static_cast<int>(top_tag << (kTagBits + kExtraTagBits) |
191 extra_tag << kTagBits | 198 extra_tag << kTagBits |
192 kDefaultTag); 199 kDefaultTag);
193 } 200 }
194 201
195 202
196 void RelocInfoWriter::WriteExtraTaggedPC(uint32_t pc_delta, int extra_tag) { 203 void RelocInfoWriter::WriteExtraTaggedPC(uint32_t pc_delta, int extra_tag) {
197 // Write two-byte tagged pc-delta, possibly preceded by var. length pc-jump. 204 // Write two-byte tagged pc-delta, possibly preceded by var. length pc-jump.
198 pc_delta = WriteVariableLengthPCJump(pc_delta); 205 pc_delta = WriteVariableLengthPCJump(pc_delta);
199 WriteExtraTag(extra_tag, 0); 206 WriteExtraTag(extra_tag, 0);
200 *--pos_ = pc_delta; 207 *--pos_ = pc_delta;
201 } 208 }
202 209
203 210
211 void RelocInfoWriter::WriteExtraTaggedIntData(int data_delta, int top_tag) {
212 WriteExtraTag(kDataJumpTag, top_tag);
213 for (int i = 0; i < kIntSize; i++) {
214 *--pos_ = static_cast<byte>(data_delta);
215 // Signed right shift is arithmetic shift. Tested in test-utils.cc.
216 data_delta = data_delta >> kBitsPerByte;
217 }
218 }
219
220
204 void RelocInfoWriter::WriteExtraTaggedData(intptr_t data_delta, int top_tag) { 221 void RelocInfoWriter::WriteExtraTaggedData(intptr_t data_delta, int top_tag) {
205 WriteExtraTag(kDataJumpTag, top_tag); 222 WriteExtraTag(kDataJumpTag, top_tag);
206 for (int i = 0; i < kIntptrSize; i++) { 223 for (int i = 0; i < kIntptrSize; i++) {
207 *--pos_ = static_cast<byte>(data_delta); 224 *--pos_ = static_cast<byte>(data_delta);
208 // Signed right shift is arithmetic shift. Tested in test-utils.cc. 225 // Signed right shift is arithmetic shift. Tested in test-utils.cc.
209 data_delta = data_delta >> kBitsPerByte; 226 data_delta = data_delta >> kBitsPerByte;
210 } 227 }
211 } 228 }
212 229
213 230
214 void RelocInfoWriter::Write(const RelocInfo* rinfo) { 231 void RelocInfoWriter::Write(const RelocInfo* rinfo) {
215 #ifdef DEBUG 232 #ifdef DEBUG
216 byte* begin_pos = pos_; 233 byte* begin_pos = pos_;
217 #endif 234 #endif
218 Counters::reloc_info_count.Increment(); 235 Counters::reloc_info_count.Increment();
219 ASSERT(rinfo->pc() - last_pc_ >= 0); 236 ASSERT(rinfo->pc() - last_pc_ >= 0);
220 ASSERT(RelocInfo::NUMBER_OF_MODES <= kMaxRelocModes); 237 ASSERT(RelocInfo::NUMBER_OF_MODES - RelocInfo::LAST_CODE_ENUM <=
238 kMaxRelocModes);
221 // Use unsigned delta-encoding for pc. 239 // Use unsigned delta-encoding for pc.
222 uint32_t pc_delta = static_cast<uint32_t>(rinfo->pc() - last_pc_); 240 uint32_t pc_delta = static_cast<uint32_t>(rinfo->pc() - last_pc_);
223 RelocInfo::Mode rmode = rinfo->rmode(); 241 RelocInfo::Mode rmode = rinfo->rmode();
224 242
225 // The two most common modes are given small tags, and usually fit in a byte. 243 // The two most common modes are given small tags, and usually fit in a byte.
226 if (rmode == RelocInfo::EMBEDDED_OBJECT) { 244 if (rmode == RelocInfo::EMBEDDED_OBJECT) {
227 WriteTaggedPC(pc_delta, kEmbeddedObjectTag); 245 WriteTaggedPC(pc_delta, kEmbeddedObjectTag);
228 } else if (rmode == RelocInfo::CODE_TARGET) { 246 } else if (rmode == RelocInfo::CODE_TARGET) {
229 WriteTaggedPC(pc_delta, kCodeTargetTag); 247 WriteTaggedPC(pc_delta, kCodeTargetTag);
230 } else if (RelocInfo::IsPosition(rmode)) { 248 } else if (rmode == RelocInfo::CODE_TARGET_WITH_ID) {
231 // Use signed delta-encoding for data. 249 // Use signed delta-encoding for id.
232 intptr_t data_delta = rinfo->data() - last_data_; 250 ASSERT(static_cast<int>(rinfo->data()) == rinfo->data());
233 int pos_type_tag = rmode == RelocInfo::POSITION ? kNonstatementPositionTag 251 int id_delta = static_cast<int>(rinfo->data()) - last_id_;
234 : kStatementPositionTag; 252 // Check if delta is small enough to fit in a tagged byte.
235 // Check if data is small enough to fit in a tagged byte. 253 if (is_intn(id_delta, kSmallDataBits)) {
236 // We cannot use is_intn because data_delta is not an int32_t. 254 WriteTaggedPC(pc_delta, kLocatableTag);
237 if (data_delta >= -(1 << (kSmallDataBits-1)) && 255 WriteTaggedData(id_delta, kCodeWithIdTag);
238 data_delta < 1 << (kSmallDataBits-1)) {
239 WriteTaggedPC(pc_delta, kPositionTag);
240 WriteTaggedData(data_delta, pos_type_tag);
241 last_data_ = rinfo->data();
242 } else { 256 } else {
243 // Otherwise, use costly encoding. 257 // Otherwise, use costly encoding.
244 WriteExtraTaggedPC(pc_delta, kPCJumpTag); 258 WriteExtraTaggedPC(pc_delta, kPCJumpTag);
245 WriteExtraTaggedData(data_delta, pos_type_tag); 259 WriteExtraTaggedIntData(id_delta, kCodeWithIdTag);
246 last_data_ = rinfo->data();
247 } 260 }
261 last_id_ = static_cast<int>(rinfo->data());
262 } else if (RelocInfo::IsPosition(rmode)) {
263 // Use signed delta-encoding for position.
264 ASSERT(static_cast<int>(rinfo->data()) == rinfo->data());
265 int pos_delta = static_cast<int>(rinfo->data()) - last_position_;
266 int pos_type_tag = (rmode == RelocInfo::POSITION) ? kNonstatementPositionTag
267 : kStatementPositionTag;
268 // Check if delta is small enough to fit in a tagged byte.
269 if (is_intn(pos_delta, kSmallDataBits)) {
270 WriteTaggedPC(pc_delta, kLocatableTag);
271 WriteTaggedData(pos_delta, pos_type_tag);
272 } else {
273 // Otherwise, use costly encoding.
274 WriteExtraTaggedPC(pc_delta, kPCJumpTag);
275 WriteExtraTaggedIntData(pos_delta, pos_type_tag);
276 }
277 last_position_ = static_cast<int>(rinfo->data());
248 } else if (RelocInfo::IsComment(rmode)) { 278 } else if (RelocInfo::IsComment(rmode)) {
249 // Comments are normally not generated, so we use the costly encoding. 279 // Comments are normally not generated, so we use the costly encoding.
250 WriteExtraTaggedPC(pc_delta, kPCJumpTag); 280 WriteExtraTaggedPC(pc_delta, kPCJumpTag);
251 WriteExtraTaggedData(rinfo->data() - last_data_, kCommentTag); 281 WriteExtraTaggedData(rinfo->data(), kCommentTag);
252 last_data_ = rinfo->data();
253 } else { 282 } else {
283 ASSERT(rmode > RelocInfo::LAST_COMPACT_ENUM);
284 int saved_mode = rmode - RelocInfo::LAST_COMPACT_ENUM;
254 // For all other modes we simply use the mode as the extra tag. 285 // For all other modes we simply use the mode as the extra tag.
255 // None of these modes need a data component. 286 // None of these modes need a data component.
256 ASSERT(rmode < kPCJumpTag && rmode < kDataJumpTag); 287 ASSERT(saved_mode < kPCJumpTag && saved_mode < kDataJumpTag);
257 WriteExtraTaggedPC(pc_delta, rmode); 288 WriteExtraTaggedPC(pc_delta, saved_mode);
258 } 289 }
259 last_pc_ = rinfo->pc(); 290 last_pc_ = rinfo->pc();
260 #ifdef DEBUG 291 #ifdef DEBUG
261 ASSERT(begin_pos - pos_ <= kMaxSize); 292 ASSERT(begin_pos - pos_ <= kMaxSize);
262 #endif 293 #endif
263 } 294 }
264 295
265 296
266 inline int RelocIterator::AdvanceGetTag() { 297 inline int RelocIterator::AdvanceGetTag() {
267 return *--pos_ & kTagMask; 298 return *--pos_ & kTagMask;
(...skipping 13 matching lines...) Expand all
281 inline void RelocIterator::ReadTaggedPC() { 312 inline void RelocIterator::ReadTaggedPC() {
282 rinfo_.pc_ += *pos_ >> kTagBits; 313 rinfo_.pc_ += *pos_ >> kTagBits;
283 } 314 }
284 315
285 316
286 inline void RelocIterator::AdvanceReadPC() { 317 inline void RelocIterator::AdvanceReadPC() {
287 rinfo_.pc_ += *--pos_; 318 rinfo_.pc_ += *--pos_;
288 } 319 }
289 320
290 321
322 void RelocIterator::AdvanceReadId() {
323 int x = 0;
324 for (int i = 0; i < kIntSize; i++) {
325 x |= static_cast<int>(*--pos_) << i * kBitsPerByte;
326 }
327 last_id_ += x;
328 rinfo_.data_ = last_id_;
329 }
330
331
332 void RelocIterator::AdvanceReadPosition() {
333 int x = 0;
334 for (int i = 0; i < kIntSize; i++) {
335 x |= static_cast<int>(*--pos_) << i * kBitsPerByte;
336 }
337 last_position_ += x;
338 rinfo_.data_ = last_position_;
339 }
340
341
291 void RelocIterator::AdvanceReadData() { 342 void RelocIterator::AdvanceReadData() {
292 intptr_t x = 0; 343 intptr_t x = 0;
293 for (int i = 0; i < kIntptrSize; i++) { 344 for (int i = 0; i < kIntptrSize; i++) {
294 x |= static_cast<intptr_t>(*--pos_) << i * kBitsPerByte; 345 x |= static_cast<intptr_t>(*--pos_) << i * kBitsPerByte;
295 } 346 }
296 rinfo_.data_ += x; 347 rinfo_.data_ = x;
297 } 348 }
298 349
299 350
300 void RelocIterator::AdvanceReadVariableLengthPCJump() { 351 void RelocIterator::AdvanceReadVariableLengthPCJump() {
301 // Read the 32-kSmallPCDeltaBits most significant bits of the 352 // Read the 32-kSmallPCDeltaBits most significant bits of the
302 // pc jump in kChunkBits bit chunks and shift them into place. 353 // pc jump in kChunkBits bit chunks and shift them into place.
303 // Stop when the last chunk is encountered. 354 // Stop when the last chunk is encountered.
304 uint32_t pc_jump = 0; 355 uint32_t pc_jump = 0;
305 for (int i = 0; i < kIntSize; i++) { 356 for (int i = 0; i < kIntSize; i++) {
306 byte pc_jump_part = *--pos_; 357 byte pc_jump_part = *--pos_;
307 pc_jump |= (pc_jump_part >> kLastChunkTagBits) << i * kChunkBits; 358 pc_jump |= (pc_jump_part >> kLastChunkTagBits) << i * kChunkBits;
308 if ((pc_jump_part & kLastChunkTagMask) == 1) break; 359 if ((pc_jump_part & kLastChunkTagMask) == 1) break;
309 } 360 }
310 // The least significant kSmallPCDeltaBits bits will be added 361 // The least significant kSmallPCDeltaBits bits will be added
311 // later. 362 // later.
312 rinfo_.pc_ += pc_jump << kSmallPCDeltaBits; 363 rinfo_.pc_ += pc_jump << kSmallPCDeltaBits;
313 } 364 }
314 365
315 366
316 inline int RelocIterator::GetPositionTypeTag() { 367 inline int RelocIterator::GetLocatableTypeTag() {
317 return *pos_ & ((1 << kPositionTypeTagBits) - 1); 368 return *pos_ & ((1 << kLocatableTypeTagBits) - 1);
318 } 369 }
319 370
320 371
321 inline void RelocIterator::ReadTaggedData() { 372 inline void RelocIterator::ReadTaggedId() {
322 int8_t signed_b = *pos_; 373 int8_t signed_b = *pos_;
323 // Signed right shift is arithmetic shift. Tested in test-utils.cc. 374 // Signed right shift is arithmetic shift. Tested in test-utils.cc.
324 rinfo_.data_ += signed_b >> kPositionTypeTagBits; 375 last_id_ += signed_b >> kLocatableTypeTagBits;
376 rinfo_.data_ = last_id_;
325 } 377 }
326 378
327 379
328 inline RelocInfo::Mode RelocIterator::DebugInfoModeFromTag(int tag) { 380 inline void RelocIterator::ReadTaggedPosition() {
329 if (tag == kStatementPositionTag) { 381 int8_t signed_b = *pos_;
330 return RelocInfo::STATEMENT_POSITION; 382 // Signed right shift is arithmetic shift. Tested in test-utils.cc.
331 } else if (tag == kNonstatementPositionTag) { 383 last_position_ += signed_b >> kLocatableTypeTagBits;
332 return RelocInfo::POSITION; 384 rinfo_.data_ = last_position_;
333 } else {
334 ASSERT(tag == kCommentTag);
335 return RelocInfo::COMMENT;
336 }
337 } 385 }
338 386
339 387
388 static inline RelocInfo::Mode GetPositionModeFromTag(int tag) {
389 ASSERT(tag == kNonstatementPositionTag ||
390 tag == kStatementPositionTag);
391 return (tag == kNonstatementPositionTag)
392 ? RelocInfo::POSITION : RelocInfo::STATEMENT_POSITION;
393 }
394
395
340 void RelocIterator::next() { 396 void RelocIterator::next() {
341 ASSERT(!done()); 397 ASSERT(!done());
342 // Basically, do the opposite of RelocInfoWriter::Write. 398 // Basically, do the opposite of RelocInfoWriter::Write.
343 // Reading of data is as far as possible avoided for unwanted modes, 399 // Reading of data is as far as possible avoided for unwanted modes,
344 // but we must always update the pc. 400 // but we must always update the pc.
345 // 401 //
346 // We exit this loop by returning when we find a mode we want. 402 // We exit this loop by returning when we find a mode we want.
347 while (pos_ > end_) { 403 while (pos_ > end_) {
348 int tag = AdvanceGetTag(); 404 int tag = AdvanceGetTag();
349 if (tag == kEmbeddedObjectTag) { 405 if (tag == kEmbeddedObjectTag) {
350 ReadTaggedPC(); 406 ReadTaggedPC();
351 if (SetMode(RelocInfo::EMBEDDED_OBJECT)) return; 407 if (SetMode(RelocInfo::EMBEDDED_OBJECT)) return;
352 } else if (tag == kCodeTargetTag) { 408 } else if (tag == kCodeTargetTag) {
353 ReadTaggedPC(); 409 ReadTaggedPC();
354 if (SetMode(RelocInfo::CODE_TARGET)) return; 410 if (SetMode(RelocInfo::CODE_TARGET)) return;
355 } else if (tag == kPositionTag) { 411 } else if (tag == kLocatableTag) {
356 ReadTaggedPC(); 412 ReadTaggedPC();
357 Advance(); 413 Advance();
358 // Check if we want source positions. 414 int locatable_tag = GetLocatableTypeTag();
359 if (mode_mask_ & RelocInfo::kPositionMask) { 415 if (locatable_tag == kCodeWithIdTag) {
360 ReadTaggedData(); 416 if (SetMode(RelocInfo::CODE_TARGET_WITH_ID)) {
361 if (SetMode(DebugInfoModeFromTag(GetPositionTypeTag()))) return; 417 ReadTaggedId();
418 return;
419 }
420 } else {
421 // Compact encoding is never used for comments,
422 // so it must be a position.
423 ASSERT(locatable_tag == kNonstatementPositionTag ||
424 locatable_tag == kStatementPositionTag);
425 if (mode_mask_ & RelocInfo::kPositionMask) {
426 ReadTaggedPosition();
427 if (SetMode(GetPositionModeFromTag(locatable_tag))) return;
428 }
362 } 429 }
363 } else { 430 } else {
364 ASSERT(tag == kDefaultTag); 431 ASSERT(tag == kDefaultTag);
365 int extra_tag = GetExtraTag(); 432 int extra_tag = GetExtraTag();
366 if (extra_tag == kPCJumpTag) { 433 if (extra_tag == kPCJumpTag) {
367 int top_tag = GetTopTag(); 434 int top_tag = GetTopTag();
368 if (top_tag == kVariableLengthPCJumpTopTag) { 435 if (top_tag == kVariableLengthPCJumpTopTag) {
369 AdvanceReadVariableLengthPCJump(); 436 AdvanceReadVariableLengthPCJump();
370 } else { 437 } else {
371 AdvanceReadPC(); 438 AdvanceReadPC();
372 } 439 }
373 } else if (extra_tag == kDataJumpTag) { 440 } else if (extra_tag == kDataJumpTag) {
374 // Check if we want debug modes (the only ones with data). 441 int locatable_tag = GetTopTag();
375 if (mode_mask_ & RelocInfo::kDebugMask) { 442 if (locatable_tag == kCodeWithIdTag) {
376 int top_tag = GetTopTag(); 443 if (SetMode(RelocInfo::CODE_TARGET_WITH_ID)) {
377 AdvanceReadData(); 444 AdvanceReadId();
378 if (SetMode(DebugInfoModeFromTag(top_tag))) return; 445 return;
446 }
447 Advance(kIntSize);
448 } else if (locatable_tag != kCommentTag) {
449 ASSERT(locatable_tag == kNonstatementPositionTag ||
450 locatable_tag == kStatementPositionTag);
451 if (mode_mask_ & RelocInfo::kPositionMask) {
452 AdvanceReadPosition();
453 if (SetMode(GetPositionModeFromTag(locatable_tag))) return;
454 } else {
455 Advance(kIntSize);
456 }
379 } else { 457 } else {
380 // Otherwise, just skip over the data. 458 ASSERT(locatable_tag == kCommentTag);
459 if (SetMode(RelocInfo::COMMENT)) {
460 AdvanceReadData();
461 return;
462 }
381 Advance(kIntptrSize); 463 Advance(kIntptrSize);
382 } 464 }
383 } else { 465 } else {
384 AdvanceReadPC(); 466 AdvanceReadPC();
385 if (SetMode(static_cast<RelocInfo::Mode>(extra_tag))) return; 467 int rmode = extra_tag + RelocInfo::LAST_COMPACT_ENUM;
468 if (SetMode(static_cast<RelocInfo::Mode>(rmode))) return;
386 } 469 }
387 } 470 }
388 } 471 }
389 done_ = true; 472 done_ = true;
390 } 473 }
391 474
392 475
393 RelocIterator::RelocIterator(Code* code, int mode_mask) { 476 RelocIterator::RelocIterator(Code* code, int mode_mask) {
394 rinfo_.pc_ = code->instruction_start(); 477 rinfo_.pc_ = code->instruction_start();
395 rinfo_.data_ = 0; 478 rinfo_.data_ = 0;
396 // Relocation info is read backwards. 479 // Relocation info is read backwards.
397 pos_ = code->relocation_start() + code->relocation_size(); 480 pos_ = code->relocation_start() + code->relocation_size();
398 end_ = code->relocation_start(); 481 end_ = code->relocation_start();
399 done_ = false; 482 done_ = false;
400 mode_mask_ = mode_mask; 483 mode_mask_ = mode_mask;
484 last_id_ = 0;
485 last_position_ = 0;
401 if (mode_mask_ == 0) pos_ = end_; 486 if (mode_mask_ == 0) pos_ = end_;
402 next(); 487 next();
403 } 488 }
404 489
405 490
406 RelocIterator::RelocIterator(const CodeDesc& desc, int mode_mask) { 491 RelocIterator::RelocIterator(const CodeDesc& desc, int mode_mask) {
407 rinfo_.pc_ = desc.buffer; 492 rinfo_.pc_ = desc.buffer;
408 rinfo_.data_ = 0; 493 rinfo_.data_ = 0;
409 // Relocation info is read backwards. 494 // Relocation info is read backwards.
410 pos_ = desc.buffer + desc.buffer_size; 495 pos_ = desc.buffer + desc.buffer_size;
411 end_ = pos_ - desc.reloc_size; 496 end_ = pos_ - desc.reloc_size;
412 done_ = false; 497 done_ = false;
413 mode_mask_ = mode_mask; 498 mode_mask_ = mode_mask;
499 last_id_ = 0;
500 last_position_ = 0;
414 if (mode_mask_ == 0) pos_ = end_; 501 if (mode_mask_ == 0) pos_ = end_;
415 next(); 502 next();
416 } 503 }
417 504
418 505
419 // ----------------------------------------------------------------------------- 506 // -----------------------------------------------------------------------------
420 // Implementation of RelocInfo 507 // Implementation of RelocInfo
421 508
422 509
423 #ifdef ENABLE_DISASSEMBLER 510 #ifdef ENABLE_DISASSEMBLER
424 const char* RelocInfo::RelocModeName(RelocInfo::Mode rmode) { 511 const char* RelocInfo::RelocModeName(RelocInfo::Mode rmode) {
425 switch (rmode) { 512 switch (rmode) {
426 case RelocInfo::NONE: 513 case RelocInfo::NONE:
427 return "no reloc"; 514 return "no reloc";
428 case RelocInfo::EMBEDDED_OBJECT: 515 case RelocInfo::EMBEDDED_OBJECT:
429 return "embedded object"; 516 return "embedded object";
430 case RelocInfo::CONSTRUCT_CALL: 517 case RelocInfo::CONSTRUCT_CALL:
431 return "code target (js construct call)"; 518 return "code target (js construct call)";
432 case RelocInfo::CODE_TARGET_CONTEXT: 519 case RelocInfo::CODE_TARGET_CONTEXT:
433 return "code target (context)"; 520 return "code target (context)";
434 case RelocInfo::DEBUG_BREAK: 521 case RelocInfo::DEBUG_BREAK:
435 #ifndef ENABLE_DEBUGGER_SUPPORT 522 #ifndef ENABLE_DEBUGGER_SUPPORT
436 UNREACHABLE(); 523 UNREACHABLE();
437 #endif 524 #endif
438 return "debug break"; 525 return "debug break";
439 case RelocInfo::CODE_TARGET: 526 case RelocInfo::CODE_TARGET:
440 return "code target"; 527 return "code target";
528 case RelocInfo::CODE_TARGET_WITH_ID:
529 return "code target with id";
441 case RelocInfo::GLOBAL_PROPERTY_CELL: 530 case RelocInfo::GLOBAL_PROPERTY_CELL:
442 return "global property cell"; 531 return "global property cell";
443 case RelocInfo::RUNTIME_ENTRY: 532 case RelocInfo::RUNTIME_ENTRY:
444 return "runtime entry"; 533 return "runtime entry";
445 case RelocInfo::JS_RETURN: 534 case RelocInfo::JS_RETURN:
446 return "js return"; 535 return "js return";
447 case RelocInfo::COMMENT: 536 case RelocInfo::COMMENT:
448 return "comment"; 537 return "comment";
449 case RelocInfo::POSITION: 538 case RelocInfo::POSITION:
450 return "position"; 539 return "position";
(...skipping 25 matching lines...) Expand all
476 target_object()->ShortPrint(); 565 target_object()->ShortPrint();
477 PrintF(")"); 566 PrintF(")");
478 } else if (rmode_ == EXTERNAL_REFERENCE) { 567 } else if (rmode_ == EXTERNAL_REFERENCE) {
479 ExternalReferenceEncoder ref_encoder; 568 ExternalReferenceEncoder ref_encoder;
480 PrintF(" (%s) (%p)", 569 PrintF(" (%s) (%p)",
481 ref_encoder.NameOfAddress(*target_reference_address()), 570 ref_encoder.NameOfAddress(*target_reference_address()),
482 *target_reference_address()); 571 *target_reference_address());
483 } else if (IsCodeTarget(rmode_)) { 572 } else if (IsCodeTarget(rmode_)) {
484 Code* code = Code::GetCodeFromTargetAddress(target_address()); 573 Code* code = Code::GetCodeFromTargetAddress(target_address());
485 PrintF(" (%s) (%p)", Code::Kind2String(code->kind()), target_address()); 574 PrintF(" (%s) (%p)", Code::Kind2String(code->kind()), target_address());
575 if (rmode_ == CODE_TARGET_WITH_ID) {
576 PrintF(" (id=%d)", static_cast<int>(data_));
577 }
486 } else if (IsPosition(rmode_)) { 578 } else if (IsPosition(rmode_)) {
487 PrintF(" (%" V8_PTR_PREFIX "d)", data()); 579 PrintF(" (%" V8_PTR_PREFIX "d)", data());
488 } else if (rmode_ == RelocInfo::RUNTIME_ENTRY) { 580 } else if (rmode_ == RelocInfo::RUNTIME_ENTRY) {
489 // Depotimization bailouts are stored as runtime entries. 581 // Depotimization bailouts are stored as runtime entries.
490 int id = Deoptimizer::GetDeoptimizationId( 582 int id = Deoptimizer::GetDeoptimizationId(
491 target_address(), Deoptimizer::EAGER); 583 target_address(), Deoptimizer::EAGER);
492 if (id != Deoptimizer::kNotDeoptimizationEntry) { 584 if (id != Deoptimizer::kNotDeoptimizationEntry) {
493 PrintF(" (deoptimization bailout %d)", id); 585 PrintF(" (deoptimization bailout %d)", id);
494 } 586 }
495 } 587 }
(...skipping 12 matching lines...) Expand all
508 case GLOBAL_PROPERTY_CELL: 600 case GLOBAL_PROPERTY_CELL:
509 Object::VerifyPointer(target_cell()); 601 Object::VerifyPointer(target_cell());
510 break; 602 break;
511 case DEBUG_BREAK: 603 case DEBUG_BREAK:
512 #ifndef ENABLE_DEBUGGER_SUPPORT 604 #ifndef ENABLE_DEBUGGER_SUPPORT
513 UNREACHABLE(); 605 UNREACHABLE();
514 break; 606 break;
515 #endif 607 #endif
516 case CONSTRUCT_CALL: 608 case CONSTRUCT_CALL:
517 case CODE_TARGET_CONTEXT: 609 case CODE_TARGET_CONTEXT:
610 case CODE_TARGET_WITH_ID:
518 case CODE_TARGET: { 611 case CODE_TARGET: {
519 // convert inline target address to code object 612 // convert inline target address to code object
520 Address addr = target_address(); 613 Address addr = target_address();
521 ASSERT(addr != NULL); 614 ASSERT(addr != NULL);
522 // Check that we can find the right code object. 615 // Check that we can find the right code object.
523 Code* code = Code::GetCodeFromTargetAddress(addr); 616 Code* code = Code::GetCodeFromTargetAddress(addr);
524 Object* found = Heap::FindCodeObject(addr); 617 Object* found = Heap::FindCodeObject(addr);
525 ASSERT(found->IsCode()); 618 ASSERT(found->IsCode());
526 ASSERT(code->address() == HeapObject::cast(found)->address()); 619 ASSERT(code->address() == HeapObject::cast(found)->address());
527 break; 620 break;
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after
935 assembler_->RecordRelocInfo(RelocInfo::POSITION, state_.current_position); 1028 assembler_->RecordRelocInfo(RelocInfo::POSITION, state_.current_position);
936 state_.written_position = state_.current_position; 1029 state_.written_position = state_.current_position;
937 written = true; 1030 written = true;
938 } 1031 }
939 1032
940 // Return whether something was written. 1033 // Return whether something was written.
941 return written; 1034 return written;
942 } 1035 }
943 1036
944 } } // namespace v8::internal 1037 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698