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

Side by Side Diff: src/assembler.cc

Issue 1230183002: Change and simplify RelocInfo format. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: fix typo Created 5 years, 5 months 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
« no previous file with comments | « src/assembler.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 // tags. 241 // tags.
242 // 242 //
243 // Low tag: 243 // Low tag:
244 // 00: embedded_object: [6-bit pc delta] 00 244 // 00: embedded_object: [6-bit pc delta] 00
245 // 245 //
246 // 01: code_target: [6-bit pc delta] 01 246 // 01: code_target: [6-bit pc delta] 01
247 // 247 //
248 // 10: short_data_record: [6-bit pc delta] 10 followed by 248 // 10: short_data_record: [6-bit pc delta] 10 followed by
249 // [6-bit data delta] [2-bit data type tag] 249 // [6-bit data delta] [2-bit data type tag]
250 // 250 //
251 // 11: long_record [2-bit high tag][4 bit middle_tag] 11 251 // 11: long_record [6 bit reloc mode] 11
252 // followed by variable data depending on type. 252 // followed by pc delta
253 // followed by optional data depending on type.
253 // 254 //
254 // 2-bit data type tags, used in short_data_record and data_jump long_record: 255 // 2-bit data type tags, used in short_data_record and data_jump long_record:
255 // code_target_with_id: 00 256 // code_target_with_id: 00
256 // position: 01 257 // position: 01
257 // statement_position: 10 258 // statement_position: 10
258 // comment: 11 (not used in short_data_record) 259 // deopt_reason: 11
259 // deopt_reason: 11 (not used in long_data_record)
260 // 260 //
261 // Long record format: 261 // If a pc delta exceeds 6 bits, it is split into a remainder that fits into
262 // 4-bit middle_tag: 262 // 6 bits and a part that does not. The latter is encoded as a long record
263 // 0000 - 1100 : Short record for RelocInfo::Mode middle_tag + 2 263 // with PC_JUMP as pseudo reloc info mode. The former is encoded as part of
264 // (The middle_tag encodes rmode - RelocInfo::LAST_COMPACT_ENUM, 264 // the following record in the usual way. The long pc jump record has variable
265 // and is between 0000 and 1100) 265 // length:
266 // The format is: 266 // pc-jump: [PC_JUMP] 11
267 // 00 [4 bit middle_tag] 11 followed by
268 // 00 [6 bit pc delta]
269 //
270 // 1101: constant or veneer pool. Used only on ARM and ARM64 for now.
271 // The format is: [2-bit sub-type] 1101 11
272 // signed int (size of the pool).
273 // The 2-bit sub-types are:
274 // 00: constant pool
275 // 01: veneer pool
276 // 1110: long_data_record
277 // The format is: [2-bit data_type_tag] 1110 11
278 // signed intptr_t, lowest byte written first
279 // (except data_type code_target_with_id, which
280 // is followed by a signed int, not intptr_t.)
281 //
282 // 1111: long_pc_jump
283 // The format is:
284 // pc-jump: 00 1111 11,
285 // 00 [6 bits pc delta]
286 // or
287 // pc-jump (variable length):
288 // 01 1111 11,
289 // [7 bits data] 0 267 // [7 bits data] 0
290 // ... 268 // ...
291 // [7 bits data] 1 269 // [7 bits data] 1
292 // (Bits 6..31 of pc delta, with leading zeroes 270 // (Bits 6..31 of pc delta, with leading zeroes
293 // dropped, and last non-zero chunk tagged with 1.) 271 // dropped, and last non-zero chunk tagged with 1.)
294 272
295 const int kTagBits = 2; 273 const int kTagBits = 2;
296 const int kTagMask = (1 << kTagBits) - 1; 274 const int kTagMask = (1 << kTagBits) - 1;
297 const int kExtraTagBits = 4; 275 const int kLongTagBits = 6;
298 const int kLocatableTypeTagBits = 2; 276 const int kShortDataTypeTagBits = 2;
299 const int kSmallDataBits = kBitsPerByte - kLocatableTypeTagBits; 277 const int kShortDataBits = kBitsPerByte - kShortDataTypeTagBits;
300 278
301 const int kEmbeddedObjectTag = 0; 279 const int kEmbeddedObjectTag = 0;
302 const int kCodeTargetTag = 1; 280 const int kCodeTargetTag = 1;
303 const int kLocatableTag = 2; 281 const int kLocatableTag = 2;
304 const int kDefaultTag = 3; 282 const int kDefaultTag = 3;
305 283
306 const int kPCJumpExtraTag = (1 << kExtraTagBits) - 1;
307
308 const int kSmallPCDeltaBits = kBitsPerByte - kTagBits; 284 const int kSmallPCDeltaBits = kBitsPerByte - kTagBits;
309 const int kSmallPCDeltaMask = (1 << kSmallPCDeltaBits) - 1; 285 const int kSmallPCDeltaMask = (1 << kSmallPCDeltaBits) - 1;
310 const int RelocInfo::kMaxSmallPCDelta = kSmallPCDeltaMask; 286 const int RelocInfo::kMaxSmallPCDelta = kSmallPCDeltaMask;
311 287
312 const int kVariableLengthPCJumpTopTag = 1;
313 const int kChunkBits = 7; 288 const int kChunkBits = 7;
314 const int kChunkMask = (1 << kChunkBits) - 1; 289 const int kChunkMask = (1 << kChunkBits) - 1;
315 const int kLastChunkTagBits = 1; 290 const int kLastChunkTagBits = 1;
316 const int kLastChunkTagMask = 1; 291 const int kLastChunkTagMask = 1;
317 const int kLastChunkTag = 1; 292 const int kLastChunkTag = 1;
318 293
319
320 const int kDataJumpExtraTag = kPCJumpExtraTag - 1;
321
322 const int kCodeWithIdTag = 0; 294 const int kCodeWithIdTag = 0;
323 const int kNonstatementPositionTag = 1; 295 const int kNonstatementPositionTag = 1;
324 const int kStatementPositionTag = 2; 296 const int kStatementPositionTag = 2;
325 const int kCommentTag = 3;
326
327 // Reuse the same value for deopt reason tag in short record format.
328 // It is possible because we use kCommentTag only for the long record format.
329 const int kDeoptReasonTag = 3; 297 const int kDeoptReasonTag = 3;
330 298
331 const int kPoolExtraTag = kPCJumpExtraTag - 2;
332 const int kConstPoolTag = 0;
333 const int kVeneerPoolTag = 1;
334 299
335 300 uint32_t RelocInfoWriter::WriteLongPCJump(uint32_t pc_delta) {
336 uint32_t RelocInfoWriter::WriteVariableLengthPCJump(uint32_t pc_delta) {
337 // Return if the pc_delta can fit in kSmallPCDeltaBits bits. 301 // Return if the pc_delta can fit in kSmallPCDeltaBits bits.
338 // Otherwise write a variable length PC jump for the bits that do 302 // Otherwise write a variable length PC jump for the bits that do
339 // not fit in the kSmallPCDeltaBits bits. 303 // not fit in the kSmallPCDeltaBits bits.
340 if (is_uintn(pc_delta, kSmallPCDeltaBits)) return pc_delta; 304 if (is_uintn(pc_delta, kSmallPCDeltaBits)) return pc_delta;
341 WriteExtraTag(kPCJumpExtraTag, kVariableLengthPCJumpTopTag); 305 WriteMode(RelocInfo::PC_JUMP);
342 uint32_t pc_jump = pc_delta >> kSmallPCDeltaBits; 306 uint32_t pc_jump = pc_delta >> kSmallPCDeltaBits;
343 DCHECK(pc_jump > 0); 307 DCHECK(pc_jump > 0);
344 // Write kChunkBits size chunks of the pc_jump. 308 // Write kChunkBits size chunks of the pc_jump.
345 for (; pc_jump > 0; pc_jump = pc_jump >> kChunkBits) { 309 for (; pc_jump > 0; pc_jump = pc_jump >> kChunkBits) {
346 byte b = pc_jump & kChunkMask; 310 byte b = pc_jump & kChunkMask;
347 *--pos_ = b << kLastChunkTagBits; 311 *--pos_ = b << kLastChunkTagBits;
348 } 312 }
349 // Tag the last chunk so it can be identified. 313 // Tag the last chunk so it can be identified.
350 *pos_ = *pos_ | kLastChunkTag; 314 *pos_ = *pos_ | kLastChunkTag;
351 // Return the remaining kSmallPCDeltaBits of the pc_delta. 315 // Return the remaining kSmallPCDeltaBits of the pc_delta.
352 return pc_delta & kSmallPCDeltaMask; 316 return pc_delta & kSmallPCDeltaMask;
353 } 317 }
354 318
355 319
356 void RelocInfoWriter::WriteTaggedPC(uint32_t pc_delta, int tag) { 320 void RelocInfoWriter::WriteShortTaggedPC(uint32_t pc_delta, int tag) {
357 // Write a byte of tagged pc-delta, possibly preceded by var. length pc-jump. 321 // Write a byte of tagged pc-delta, possibly preceded by an explicit pc-jump.
358 pc_delta = WriteVariableLengthPCJump(pc_delta); 322 pc_delta = WriteLongPCJump(pc_delta);
359 *--pos_ = pc_delta << kTagBits | tag; 323 *--pos_ = pc_delta << kTagBits | tag;
360 } 324 }
361 325
362 326
363 void RelocInfoWriter::WriteTaggedData(intptr_t data_delta, int tag) { 327 void RelocInfoWriter::WriteShortTaggedData(intptr_t data_delta, int tag) {
364 *--pos_ = static_cast<byte>(data_delta << kLocatableTypeTagBits | tag); 328 *--pos_ = static_cast<byte>(data_delta << kShortDataTypeTagBits | tag);
365 } 329 }
366 330
367 331
368 void RelocInfoWriter::WriteExtraTag(int extra_tag, int top_tag) { 332 void RelocInfoWriter::WriteMode(RelocInfo::Mode rmode) {
369 *--pos_ = static_cast<int>(top_tag << (kTagBits + kExtraTagBits) | 333 STATIC_ASSERT(RelocInfo::NUMBER_OF_MODES <= (1 << kLongTagBits));
370 extra_tag << kTagBits | 334 *--pos_ = static_cast<int>((rmode << kTagBits) | kDefaultTag);
371 kDefaultTag);
372 } 335 }
373 336
374 337
375 void RelocInfoWriter::WriteExtraTaggedPC(uint32_t pc_delta, int extra_tag) { 338 void RelocInfoWriter::WriteModeAndPC(uint32_t pc_delta, RelocInfo::Mode rmode) {
376 // Write two-byte tagged pc-delta, possibly preceded by var. length pc-jump. 339 // Write two-byte tagged pc-delta, possibly preceded by var. length pc-jump.
377 pc_delta = WriteVariableLengthPCJump(pc_delta); 340 pc_delta = WriteLongPCJump(pc_delta);
378 WriteExtraTag(extra_tag, 0); 341 WriteMode(rmode);
379 *--pos_ = pc_delta; 342 *--pos_ = pc_delta;
380 } 343 }
381 344
382 345
383 void RelocInfoWriter::WriteInt(int number) { 346 void RelocInfoWriter::WriteIntData(int number) {
384 for (int i = 0; i < kIntSize; i++) { 347 for (int i = 0; i < kIntSize; i++) {
385 *--pos_ = static_cast<byte>(number); 348 *--pos_ = static_cast<byte>(number);
386 // Signed right shift is arithmetic shift. Tested in test-utils.cc. 349 // Signed right shift is arithmetic shift. Tested in test-utils.cc.
387 number = number >> kBitsPerByte; 350 number = number >> kBitsPerByte;
388 } 351 }
389 } 352 }
390 353
391 354
392 void RelocInfoWriter::WriteDebugBreakSlotData(int data) { WriteInt(data); } 355 void RelocInfoWriter::WriteData(intptr_t data_delta) {
393
394
395 void RelocInfoWriter::WriteExtraTaggedIntData(int data_delta, int top_tag) {
396 WriteExtraTag(kDataJumpExtraTag, top_tag);
397 WriteInt(data_delta);
398 }
399
400
401 void RelocInfoWriter::WriteExtraTaggedPoolData(int data, int pool_type) {
402 WriteExtraTag(kPoolExtraTag, pool_type);
403 WriteInt(data);
404 }
405
406
407 void RelocInfoWriter::WriteExtraTaggedData(intptr_t data_delta, int top_tag) {
408 WriteExtraTag(kDataJumpExtraTag, top_tag);
409 for (int i = 0; i < kIntptrSize; i++) { 356 for (int i = 0; i < kIntptrSize; i++) {
410 *--pos_ = static_cast<byte>(data_delta); 357 *--pos_ = static_cast<byte>(data_delta);
411 // Signed right shift is arithmetic shift. Tested in test-utils.cc. 358 // Signed right shift is arithmetic shift. Tested in test-utils.cc.
412 data_delta = data_delta >> kBitsPerByte; 359 data_delta = data_delta >> kBitsPerByte;
413 } 360 }
414 } 361 }
415 362
416 363
417 void RelocInfoWriter::WritePosition(int pc_delta, int pos_delta, 364 void RelocInfoWriter::WritePosition(int pc_delta, int pos_delta,
418 RelocInfo::Mode rmode) { 365 RelocInfo::Mode rmode) {
419 int pos_type_tag = (rmode == RelocInfo::POSITION) ? kNonstatementPositionTag 366 int pos_type_tag = (rmode == RelocInfo::POSITION) ? kNonstatementPositionTag
420 : kStatementPositionTag; 367 : kStatementPositionTag;
421 // Check if delta is small enough to fit in a tagged byte. 368 // Check if delta is small enough to fit in a tagged byte.
422 if (is_intn(pos_delta, kSmallDataBits)) { 369 if (is_intn(pos_delta, kShortDataBits)) {
423 WriteTaggedPC(pc_delta, kLocatableTag); 370 WriteShortTaggedPC(pc_delta, kLocatableTag);
424 WriteTaggedData(pos_delta, pos_type_tag); 371 WriteShortTaggedData(pos_delta, pos_type_tag);
425 } else { 372 } else {
426 // Otherwise, use costly encoding. 373 // Otherwise, use costly encoding.
427 WriteExtraTaggedPC(pc_delta, kPCJumpExtraTag); 374 WriteModeAndPC(pc_delta, rmode);
428 WriteExtraTaggedIntData(pos_delta, pos_type_tag); 375 WriteIntData(pos_delta);
429 } 376 }
430 } 377 }
431 378
432 379
433 void RelocInfoWriter::FlushPosition() { 380 void RelocInfoWriter::FlushPosition() {
434 if (!next_position_candidate_flushed_) { 381 if (!next_position_candidate_flushed_) {
435 WritePosition(next_position_candidate_pc_delta_, 382 WritePosition(next_position_candidate_pc_delta_,
436 next_position_candidate_pos_delta_, RelocInfo::POSITION); 383 next_position_candidate_pos_delta_, RelocInfo::POSITION);
437 next_position_candidate_pos_delta_ = 0; 384 next_position_candidate_pos_delta_ = 0;
438 next_position_candidate_pc_delta_ = 0; 385 next_position_candidate_pc_delta_ = 0;
(...skipping 10 matching lines...) Expand all
449 #ifdef DEBUG 396 #ifdef DEBUG
450 byte* begin_pos = pos_; 397 byte* begin_pos = pos_;
451 #endif 398 #endif
452 DCHECK(rinfo->rmode() < RelocInfo::NUMBER_OF_MODES); 399 DCHECK(rinfo->rmode() < RelocInfo::NUMBER_OF_MODES);
453 DCHECK(rinfo->pc() - last_pc_ >= 0); 400 DCHECK(rinfo->pc() - last_pc_ >= 0);
454 // Use unsigned delta-encoding for pc. 401 // Use unsigned delta-encoding for pc.
455 uint32_t pc_delta = static_cast<uint32_t>(rinfo->pc() - last_pc_); 402 uint32_t pc_delta = static_cast<uint32_t>(rinfo->pc() - last_pc_);
456 403
457 // The two most common modes are given small tags, and usually fit in a byte. 404 // The two most common modes are given small tags, and usually fit in a byte.
458 if (rmode == RelocInfo::EMBEDDED_OBJECT) { 405 if (rmode == RelocInfo::EMBEDDED_OBJECT) {
459 WriteTaggedPC(pc_delta, kEmbeddedObjectTag); 406 WriteShortTaggedPC(pc_delta, kEmbeddedObjectTag);
460 } else if (rmode == RelocInfo::CODE_TARGET) { 407 } else if (rmode == RelocInfo::CODE_TARGET) {
461 WriteTaggedPC(pc_delta, kCodeTargetTag); 408 WriteShortTaggedPC(pc_delta, kCodeTargetTag);
462 DCHECK(begin_pos - pos_ <= RelocInfo::kMaxCallSize); 409 DCHECK(begin_pos - pos_ <= RelocInfo::kMaxCallSize);
463 } else if (rmode == RelocInfo::CODE_TARGET_WITH_ID) { 410 } else if (rmode == RelocInfo::CODE_TARGET_WITH_ID) {
464 // Use signed delta-encoding for id. 411 // Use signed delta-encoding for id.
465 DCHECK_EQ(static_cast<int>(rinfo->data()), rinfo->data()); 412 DCHECK_EQ(static_cast<int>(rinfo->data()), rinfo->data());
466 int id_delta = static_cast<int>(rinfo->data()) - last_id_; 413 int id_delta = static_cast<int>(rinfo->data()) - last_id_;
467 // Check if delta is small enough to fit in a tagged byte. 414 // Check if delta is small enough to fit in a tagged byte.
468 if (is_intn(id_delta, kSmallDataBits)) { 415 if (is_intn(id_delta, kShortDataBits)) {
469 WriteTaggedPC(pc_delta, kLocatableTag); 416 WriteShortTaggedPC(pc_delta, kLocatableTag);
470 WriteTaggedData(id_delta, kCodeWithIdTag); 417 WriteShortTaggedData(id_delta, kCodeWithIdTag);
471 } else { 418 } else {
472 // Otherwise, use costly encoding. 419 // Otherwise, use costly encoding.
473 WriteExtraTaggedPC(pc_delta, kPCJumpExtraTag); 420 WriteModeAndPC(pc_delta, rmode);
474 WriteExtraTaggedIntData(id_delta, kCodeWithIdTag); 421 WriteIntData(id_delta);
475 } 422 }
476 last_id_ = static_cast<int>(rinfo->data()); 423 last_id_ = static_cast<int>(rinfo->data());
477 } else if (rmode == RelocInfo::DEOPT_REASON) { 424 } else if (rmode == RelocInfo::DEOPT_REASON) {
478 DCHECK(rinfo->data() < (1 << kSmallDataBits)); 425 DCHECK(rinfo->data() < (1 << kShortDataBits));
479 WriteTaggedPC(pc_delta, kLocatableTag); 426 WriteShortTaggedPC(pc_delta, kLocatableTag);
480 WriteTaggedData(rinfo->data(), kDeoptReasonTag); 427 WriteShortTaggedData(rinfo->data(), kDeoptReasonTag);
481 } else if (RelocInfo::IsPosition(rmode)) { 428 } else if (RelocInfo::IsPosition(rmode)) {
482 // Use signed delta-encoding for position. 429 // Use signed delta-encoding for position.
483 DCHECK_EQ(static_cast<int>(rinfo->data()), rinfo->data()); 430 DCHECK_EQ(static_cast<int>(rinfo->data()), rinfo->data());
484 int pos_delta = static_cast<int>(rinfo->data()) - last_position_; 431 int pos_delta = static_cast<int>(rinfo->data()) - last_position_;
485 if (rmode == RelocInfo::STATEMENT_POSITION) { 432 if (rmode == RelocInfo::STATEMENT_POSITION) {
486 WritePosition(pc_delta, pos_delta, rmode); 433 WritePosition(pc_delta, pos_delta, rmode);
487 } else { 434 } else {
488 DCHECK_EQ(rmode, RelocInfo::POSITION); 435 DCHECK_EQ(rmode, RelocInfo::POSITION);
489 if (pc_delta != 0 || last_mode_ != RelocInfo::POSITION) { 436 if (pc_delta != 0 || last_mode_ != RelocInfo::POSITION) {
490 FlushPosition(); 437 FlushPosition();
491 next_position_candidate_pc_delta_ = pc_delta; 438 next_position_candidate_pc_delta_ = pc_delta;
492 next_position_candidate_pos_delta_ = pos_delta; 439 next_position_candidate_pos_delta_ = pos_delta;
493 } else { 440 } else {
494 next_position_candidate_pos_delta_ += pos_delta; 441 next_position_candidate_pos_delta_ += pos_delta;
495 } 442 }
496 next_position_candidate_flushed_ = false; 443 next_position_candidate_flushed_ = false;
497 } 444 }
498 last_position_ = static_cast<int>(rinfo->data()); 445 last_position_ = static_cast<int>(rinfo->data());
499 } else if (RelocInfo::IsComment(rmode)) {
500 // Comments are normally not generated, so we use the costly encoding.
501 WriteExtraTaggedPC(pc_delta, kPCJumpExtraTag);
502 WriteExtraTaggedData(rinfo->data(), kCommentTag);
503 DCHECK(begin_pos - pos_ >= RelocInfo::kMinRelocCommentSize);
504 } else if (RelocInfo::IsConstPool(rmode) || RelocInfo::IsVeneerPool(rmode)) {
505 WriteExtraTaggedPC(pc_delta, kPCJumpExtraTag);
506 WriteExtraTaggedPoolData(
507 static_cast<int>(rinfo->data()),
508 RelocInfo::IsConstPool(rmode) ? kConstPoolTag : kVeneerPoolTag);
509 } else { 446 } else {
510 DCHECK(rmode > RelocInfo::LAST_COMPACT_ENUM); 447 WriteModeAndPC(pc_delta, rmode);
511 DCHECK(rmode <= RelocInfo::LAST_STANDARD_NONCOMPACT_ENUM); 448 if (RelocInfo::IsComment(rmode)) {
512 STATIC_ASSERT(RelocInfo::LAST_STANDARD_NONCOMPACT_ENUM - 449 WriteData(rinfo->data());
513 RelocInfo::LAST_COMPACT_ENUM <= 450 } else if (RelocInfo::IsConstPool(rmode) ||
514 kPoolExtraTag); 451 RelocInfo::IsVeneerPool(rmode) ||
515 int saved_mode = rmode - RelocInfo::LAST_COMPACT_ENUM - 1; 452 RelocInfo::IsDebugBreakSlot(rmode)) {
516 // For all other modes we simply use the mode as the extra tag. 453 WriteIntData(static_cast<int>(rinfo->data()));
517 // None of these modes need a data component.
518 DCHECK(0 <= saved_mode && saved_mode < kPoolExtraTag);
519 WriteExtraTaggedPC(pc_delta, saved_mode);
520 if (RelocInfo::IsDebugBreakSlot(rmode)) {
521 WriteDebugBreakSlotData(static_cast<int>(rinfo->data()));
522 } 454 }
523 } 455 }
524 last_pc_ = rinfo->pc(); 456 last_pc_ = rinfo->pc();
525 last_mode_ = rmode; 457 last_mode_ = rmode;
526 #ifdef DEBUG 458 #ifdef DEBUG
527 DCHECK(begin_pos - pos_ <= kMaxSize); 459 DCHECK(begin_pos - pos_ <= kMaxSize);
528 #endif 460 #endif
529 } 461 }
530 462
531 463
532 inline int RelocIterator::AdvanceGetTag() { 464 inline int RelocIterator::AdvanceGetTag() {
533 return *--pos_ & kTagMask; 465 return *--pos_ & kTagMask;
534 } 466 }
535 467
536 468
537 inline int RelocIterator::GetExtraTag() { 469 inline RelocInfo::Mode RelocIterator::GetMode() {
538 return (*pos_ >> kTagBits) & ((1 << kExtraTagBits) - 1); 470 return static_cast<RelocInfo::Mode>((*pos_ >> kTagBits) &
471 ((1 << kLongTagBits) - 1));
539 } 472 }
540 473
541 474
542 inline int RelocIterator::GetTopTag() { 475 inline void RelocIterator::ReadShortTaggedPC() {
543 return *pos_ >> (kTagBits + kExtraTagBits);
544 }
545
546
547 inline void RelocIterator::ReadTaggedPC() {
548 rinfo_.pc_ += *pos_ >> kTagBits; 476 rinfo_.pc_ += *pos_ >> kTagBits;
549 } 477 }
550 478
551 479
552 inline void RelocIterator::AdvanceReadPC() { 480 inline void RelocIterator::AdvanceReadPC() {
553 rinfo_.pc_ += *--pos_; 481 rinfo_.pc_ += *--pos_;
554 } 482 }
555 483
556 484
557 void RelocIterator::AdvanceReadId() { 485 void RelocIterator::AdvanceReadId() {
558 int x = 0; 486 int x = 0;
559 for (int i = 0; i < kIntSize; i++) { 487 for (int i = 0; i < kIntSize; i++) {
560 x |= static_cast<int>(*--pos_) << i * kBitsPerByte; 488 x |= static_cast<int>(*--pos_) << i * kBitsPerByte;
561 } 489 }
562 last_id_ += x; 490 last_id_ += x;
563 rinfo_.data_ = last_id_; 491 rinfo_.data_ = last_id_;
564 } 492 }
565 493
566 494
567 void RelocIterator::AdvanceReadInt() { 495 void RelocIterator::AdvanceReadInt() {
568 int x = 0; 496 int x = 0;
569 for (int i = 0; i < kIntSize; i++) { 497 for (int i = 0; i < kIntSize; i++) {
570 x |= static_cast<int>(*--pos_) << i * kBitsPerByte; 498 x |= static_cast<int>(*--pos_) << i * kBitsPerByte;
571 } 499 }
572 rinfo_.data_ = x; 500 rinfo_.data_ = x;
573 } 501 }
574 502
575 503
576 void RelocIterator::AdvanceReadPoolData() { AdvanceReadInt(); }
577
578
579 void RelocIterator::AdvanceReadDebugBreakSlotData() { AdvanceReadInt(); }
580
581
582 void RelocIterator::AdvanceReadPosition() { 504 void RelocIterator::AdvanceReadPosition() {
583 int x = 0; 505 int x = 0;
584 for (int i = 0; i < kIntSize; i++) { 506 for (int i = 0; i < kIntSize; i++) {
585 x |= static_cast<int>(*--pos_) << i * kBitsPerByte; 507 x |= static_cast<int>(*--pos_) << i * kBitsPerByte;
586 } 508 }
587 last_position_ += x; 509 last_position_ += x;
588 rinfo_.data_ = last_position_; 510 rinfo_.data_ = last_position_;
589 } 511 }
590 512
591 513
592 void RelocIterator::AdvanceReadData() { 514 void RelocIterator::AdvanceReadData() {
593 intptr_t x = 0; 515 intptr_t x = 0;
594 for (int i = 0; i < kIntptrSize; i++) { 516 for (int i = 0; i < kIntptrSize; i++) {
595 x |= static_cast<intptr_t>(*--pos_) << i * kBitsPerByte; 517 x |= static_cast<intptr_t>(*--pos_) << i * kBitsPerByte;
596 } 518 }
597 rinfo_.data_ = x; 519 rinfo_.data_ = x;
598 } 520 }
599 521
600 522
601 void RelocIterator::AdvanceReadVariableLengthPCJump() { 523 void RelocIterator::AdvanceReadLongPCJump() {
602 // Read the 32-kSmallPCDeltaBits most significant bits of the 524 // Read the 32-kSmallPCDeltaBits most significant bits of the
603 // pc jump in kChunkBits bit chunks and shift them into place. 525 // pc jump in kChunkBits bit chunks and shift them into place.
604 // Stop when the last chunk is encountered. 526 // Stop when the last chunk is encountered.
605 uint32_t pc_jump = 0; 527 uint32_t pc_jump = 0;
606 for (int i = 0; i < kIntSize; i++) { 528 for (int i = 0; i < kIntSize; i++) {
607 byte pc_jump_part = *--pos_; 529 byte pc_jump_part = *--pos_;
608 pc_jump |= (pc_jump_part >> kLastChunkTagBits) << i * kChunkBits; 530 pc_jump |= (pc_jump_part >> kLastChunkTagBits) << i * kChunkBits;
609 if ((pc_jump_part & kLastChunkTagMask) == 1) break; 531 if ((pc_jump_part & kLastChunkTagMask) == 1) break;
610 } 532 }
611 // The least significant kSmallPCDeltaBits bits will be added 533 // The least significant kSmallPCDeltaBits bits will be added
612 // later. 534 // later.
613 rinfo_.pc_ += pc_jump << kSmallPCDeltaBits; 535 rinfo_.pc_ += pc_jump << kSmallPCDeltaBits;
614 } 536 }
615 537
616 538
617 inline int RelocIterator::GetLocatableTypeTag() { 539 inline int RelocIterator::GetShortDataTypeTag() {
618 return *pos_ & ((1 << kLocatableTypeTagBits) - 1); 540 return *pos_ & ((1 << kShortDataTypeTagBits) - 1);
619 } 541 }
620 542
621 543
622 inline void RelocIterator::ReadTaggedId() { 544 inline void RelocIterator::ReadShortTaggedId() {
623 int8_t signed_b = *pos_; 545 int8_t signed_b = *pos_;
624 // Signed right shift is arithmetic shift. Tested in test-utils.cc. 546 // Signed right shift is arithmetic shift. Tested in test-utils.cc.
625 last_id_ += signed_b >> kLocatableTypeTagBits; 547 last_id_ += signed_b >> kShortDataTypeTagBits;
626 rinfo_.data_ = last_id_; 548 rinfo_.data_ = last_id_;
627 } 549 }
628 550
629 551
630 inline void RelocIterator::ReadTaggedPosition() { 552 inline void RelocIterator::ReadShortTaggedPosition() {
631 int8_t signed_b = *pos_; 553 int8_t signed_b = *pos_;
632 // Signed right shift is arithmetic shift. Tested in test-utils.cc. 554 // Signed right shift is arithmetic shift. Tested in test-utils.cc.
633 last_position_ += signed_b >> kLocatableTypeTagBits; 555 last_position_ += signed_b >> kShortDataTypeTagBits;
634 rinfo_.data_ = last_position_; 556 rinfo_.data_ = last_position_;
635 } 557 }
636 558
637 559
638 inline void RelocIterator::ReadTaggedData() { 560 inline void RelocIterator::ReadShortTaggedData() {
639 uint8_t unsigned_b = *pos_; 561 uint8_t unsigned_b = *pos_;
640 rinfo_.data_ = unsigned_b >> kTagBits; 562 rinfo_.data_ = unsigned_b >> kTagBits;
641 } 563 }
642 564
643 565
644 static inline RelocInfo::Mode GetPositionModeFromTag(int tag) { 566 static inline RelocInfo::Mode GetPositionModeFromTag(int tag) {
645 DCHECK(tag == kNonstatementPositionTag || 567 DCHECK(tag == kNonstatementPositionTag ||
646 tag == kStatementPositionTag); 568 tag == kStatementPositionTag);
647 return (tag == kNonstatementPositionTag) ? 569 return (tag == kNonstatementPositionTag) ?
648 RelocInfo::POSITION : 570 RelocInfo::POSITION :
649 RelocInfo::STATEMENT_POSITION; 571 RelocInfo::STATEMENT_POSITION;
650 } 572 }
651 573
652 574
653 void RelocIterator::next() { 575 void RelocIterator::next() {
654 DCHECK(!done()); 576 DCHECK(!done());
655 // Basically, do the opposite of RelocInfoWriter::Write. 577 // Basically, do the opposite of RelocInfoWriter::Write.
656 // Reading of data is as far as possible avoided for unwanted modes, 578 // Reading of data is as far as possible avoided for unwanted modes,
657 // but we must always update the pc. 579 // but we must always update the pc.
658 // 580 //
659 // We exit this loop by returning when we find a mode we want. 581 // We exit this loop by returning when we find a mode we want.
660 while (pos_ > end_) { 582 while (pos_ > end_) {
661 int tag = AdvanceGetTag(); 583 int tag = AdvanceGetTag();
662 if (tag == kEmbeddedObjectTag) { 584 if (tag == kEmbeddedObjectTag) {
663 ReadTaggedPC(); 585 ReadShortTaggedPC();
664 if (SetMode(RelocInfo::EMBEDDED_OBJECT)) return; 586 if (SetMode(RelocInfo::EMBEDDED_OBJECT)) return;
665 } else if (tag == kCodeTargetTag) { 587 } else if (tag == kCodeTargetTag) {
666 ReadTaggedPC(); 588 ReadShortTaggedPC();
667 if (SetMode(RelocInfo::CODE_TARGET)) return; 589 if (SetMode(RelocInfo::CODE_TARGET)) return;
668 } else if (tag == kLocatableTag) { 590 } else if (tag == kLocatableTag) {
669 ReadTaggedPC(); 591 ReadShortTaggedPC();
670 Advance(); 592 Advance();
671 int locatable_tag = GetLocatableTypeTag(); 593 int data_type_tag = GetShortDataTypeTag();
672 if (locatable_tag == kCodeWithIdTag) { 594 if (data_type_tag == kCodeWithIdTag) {
673 if (SetMode(RelocInfo::CODE_TARGET_WITH_ID)) { 595 if (SetMode(RelocInfo::CODE_TARGET_WITH_ID)) {
674 ReadTaggedId(); 596 ReadShortTaggedId();
675 return; 597 return;
676 } 598 }
677 } else if (locatable_tag == kDeoptReasonTag) { 599 } else if (data_type_tag == kDeoptReasonTag) {
678 ReadTaggedData(); 600 if (SetMode(RelocInfo::DEOPT_REASON)) {
679 if (SetMode(RelocInfo::DEOPT_REASON)) return; 601 ReadShortTaggedData();
602 return;
603 }
680 } else { 604 } else {
681 DCHECK(locatable_tag == kNonstatementPositionTag || 605 DCHECK(data_type_tag == kNonstatementPositionTag ||
682 locatable_tag == kStatementPositionTag); 606 data_type_tag == kStatementPositionTag);
683 if (mode_mask_ & RelocInfo::kPositionMask) { 607 if (mode_mask_ & RelocInfo::kPositionMask) {
684 ReadTaggedPosition(); 608 // Always update the position if we are interested in either
685 if (SetMode(GetPositionModeFromTag(locatable_tag))) return; 609 // statement positions or non-statement positions.
610 ReadShortTaggedPosition();
611 if (SetMode(GetPositionModeFromTag(data_type_tag))) return;
686 } 612 }
687 } 613 }
688 } else { 614 } else {
689 DCHECK(tag == kDefaultTag); 615 DCHECK(tag == kDefaultTag);
690 int extra_tag = GetExtraTag(); 616 RelocInfo::Mode rmode = GetMode();
691 if (extra_tag == kPCJumpExtraTag) { 617 if (rmode == RelocInfo::PC_JUMP) {
692 if (GetTopTag() == kVariableLengthPCJumpTopTag) { 618 AdvanceReadLongPCJump();
693 AdvanceReadVariableLengthPCJump(); 619 } else {
694 } else { 620 AdvanceReadPC();
695 AdvanceReadPC(); 621 if (rmode == RelocInfo::CODE_TARGET_WITH_ID) {
696 } 622 if (SetMode(rmode)) {
697 } else if (extra_tag == kDataJumpExtraTag) {
698 int locatable_tag = GetTopTag();
699 if (locatable_tag == kCodeWithIdTag) {
700 if (SetMode(RelocInfo::CODE_TARGET_WITH_ID)) {
701 AdvanceReadId(); 623 AdvanceReadId();
702 return; 624 return;
703 } 625 }
704 Advance(kIntSize); 626 Advance(kIntSize);
705 } else if (locatable_tag != kCommentTag) { 627 } else if (RelocInfo::IsComment(rmode)) {
706 DCHECK(locatable_tag == kNonstatementPositionTag || 628 if (SetMode(rmode)) {
707 locatable_tag == kStatementPositionTag);
708 if (mode_mask_ & RelocInfo::kPositionMask) {
709 AdvanceReadPosition();
710 if (SetMode(GetPositionModeFromTag(locatable_tag))) return;
711 } else {
712 Advance(kIntSize);
713 }
714 } else {
715 DCHECK(locatable_tag == kCommentTag);
716 if (SetMode(RelocInfo::COMMENT)) {
717 AdvanceReadData(); 629 AdvanceReadData();
718 return; 630 return;
719 } 631 }
720 Advance(kIntptrSize); 632 Advance(kIntptrSize);
721 } 633 } else if (RelocInfo::IsPosition(rmode)) {
722 } else if (extra_tag == kPoolExtraTag) { 634 if (mode_mask_ & RelocInfo::kPositionMask) {
723 int pool_type = GetTopTag(); 635 // Always update the position if we are interested in either
724 DCHECK(pool_type == kConstPoolTag || pool_type == kVeneerPoolTag); 636 // statement positions or non-statement positions.
725 RelocInfo::Mode rmode = (pool_type == kConstPoolTag) ? 637 AdvanceReadPosition();
726 RelocInfo::CONST_POOL : RelocInfo::VENEER_POOL; 638 if (SetMode(rmode)) return;
727 if (SetMode(rmode)) { 639 } else {
728 AdvanceReadPoolData(); 640 Advance(kIntSize);
729 return; 641 }
730 } 642 } else if (RelocInfo::IsConstPool(rmode) ||
731 Advance(kIntSize); 643 RelocInfo::IsVeneerPool(rmode) ||
732 } else { 644 RelocInfo::IsDebugBreakSlot(rmode)) {
733 AdvanceReadPC();
734 RelocInfo::Mode rmode = static_cast<RelocInfo::Mode>(
735 extra_tag + RelocInfo::LAST_COMPACT_ENUM + 1);
736 if (RelocInfo::IsDebugBreakSlot(rmode)) {
737 if (SetMode(rmode)) { 645 if (SetMode(rmode)) {
738 AdvanceReadDebugBreakSlotData(); 646 AdvanceReadInt();
739 return; 647 return;
740 } 648 }
741 Advance(kIntSize); 649 Advance(kIntSize);
742 } else if (SetMode(rmode)) { 650 } else if (SetMode(static_cast<RelocInfo::Mode>(rmode))) {
743 return; 651 return;
744 } 652 }
745 } 653 }
746 } 654 }
747 } 655 }
748 if (code_age_sequence_ != NULL) { 656 if (code_age_sequence_ != NULL) {
749 byte* old_code_age_sequence = code_age_sequence_; 657 byte* old_code_age_sequence = code_age_sequence_;
750 code_age_sequence_ = NULL; 658 code_age_sequence_ = NULL;
751 if (SetMode(RelocInfo::CODE_AGE_SEQUENCE)) { 659 if (SetMode(RelocInfo::CODE_AGE_SEQUENCE)) {
752 rinfo_.data_ = 0; 660 rinfo_.data_ = 0;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
814 RelocInfo::kApplyMask; 722 RelocInfo::kApplyMask;
815 RelocIterator it(desc, mode_mask); 723 RelocIterator it(desc, mode_mask);
816 return !it.done(); 724 return !it.done();
817 } 725 }
818 #endif 726 #endif
819 727
820 728
821 #ifdef ENABLE_DISASSEMBLER 729 #ifdef ENABLE_DISASSEMBLER
822 const char* RelocInfo::RelocModeName(RelocInfo::Mode rmode) { 730 const char* RelocInfo::RelocModeName(RelocInfo::Mode rmode) {
823 switch (rmode) { 731 switch (rmode) {
824 case RelocInfo::NONE32: 732 case NONE32:
825 return "no reloc 32"; 733 return "no reloc 32";
826 case RelocInfo::NONE64: 734 case NONE64:
827 return "no reloc 64"; 735 return "no reloc 64";
828 case RelocInfo::EMBEDDED_OBJECT: 736 case EMBEDDED_OBJECT:
829 return "embedded object"; 737 return "embedded object";
830 case RelocInfo::CONSTRUCT_CALL: 738 case CONSTRUCT_CALL:
831 return "code target (js construct call)"; 739 return "code target (js construct call)";
832 case RelocInfo::DEBUG_BREAK: 740 case DEBUG_BREAK:
833 return "debug break"; 741 return "debug break";
834 case RelocInfo::CODE_TARGET: 742 case CODE_TARGET:
835 return "code target"; 743 return "code target";
836 case RelocInfo::CODE_TARGET_WITH_ID: 744 case CODE_TARGET_WITH_ID:
837 return "code target with id"; 745 return "code target with id";
838 case RelocInfo::CELL: 746 case CELL:
839 return "property cell"; 747 return "property cell";
840 case RelocInfo::RUNTIME_ENTRY: 748 case RUNTIME_ENTRY:
841 return "runtime entry"; 749 return "runtime entry";
842 case RelocInfo::JS_RETURN: 750 case JS_RETURN:
843 return "js return"; 751 return "js return";
844 case RelocInfo::COMMENT: 752 case COMMENT:
845 return "comment"; 753 return "comment";
846 case RelocInfo::POSITION: 754 case POSITION:
847 return "position"; 755 return "position";
848 case RelocInfo::STATEMENT_POSITION: 756 case STATEMENT_POSITION:
849 return "statement position"; 757 return "statement position";
850 case RelocInfo::EXTERNAL_REFERENCE: 758 case EXTERNAL_REFERENCE:
851 return "external reference"; 759 return "external reference";
852 case RelocInfo::INTERNAL_REFERENCE: 760 case INTERNAL_REFERENCE:
853 return "internal reference"; 761 return "internal reference";
854 case RelocInfo::INTERNAL_REFERENCE_ENCODED: 762 case INTERNAL_REFERENCE_ENCODED:
855 return "encoded internal reference"; 763 return "encoded internal reference";
856 case RelocInfo::DEOPT_REASON: 764 case DEOPT_REASON:
857 return "deopt reason"; 765 return "deopt reason";
858 case RelocInfo::CONST_POOL: 766 case CONST_POOL:
859 return "constant pool"; 767 return "constant pool";
860 case RelocInfo::VENEER_POOL: 768 case VENEER_POOL:
861 return "veneer pool"; 769 return "veneer pool";
862 case RelocInfo::DEBUG_BREAK_SLOT: 770 case DEBUG_BREAK_SLOT:
863 return "debug break slot"; 771 return "debug break slot";
864 case RelocInfo::CODE_AGE_SEQUENCE: 772 case CODE_AGE_SEQUENCE:
865 return "code_age_sequence"; 773 return "code_age_sequence";
866 case RelocInfo::NUMBER_OF_MODES: 774 case NUMBER_OF_MODES:
775 case PC_JUMP:
867 UNREACHABLE(); 776 UNREACHABLE();
868 return "number_of_modes"; 777 return "number_of_modes";
869 } 778 }
870 return "unknown relocation type"; 779 return "unknown relocation type";
871 } 780 }
872 781
873 782
874 void RelocInfo::Print(Isolate* isolate, std::ostream& os) { // NOLINT 783 void RelocInfo::Print(Isolate* isolate, std::ostream& os) { // NOLINT
875 os << static_cast<const void*>(pc_) << " " << RelocModeName(rmode_); 784 os << static_cast<const void*>(pc_) << " " << RelocModeName(rmode_);
876 if (IsComment(rmode_)) { 785 if (IsComment(rmode_)) {
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
959 case STATEMENT_POSITION: 868 case STATEMENT_POSITION:
960 case EXTERNAL_REFERENCE: 869 case EXTERNAL_REFERENCE:
961 case DEOPT_REASON: 870 case DEOPT_REASON:
962 case CONST_POOL: 871 case CONST_POOL:
963 case VENEER_POOL: 872 case VENEER_POOL:
964 case DEBUG_BREAK_SLOT: 873 case DEBUG_BREAK_SLOT:
965 case NONE32: 874 case NONE32:
966 case NONE64: 875 case NONE64:
967 break; 876 break;
968 case NUMBER_OF_MODES: 877 case NUMBER_OF_MODES:
878 case PC_JUMP:
969 UNREACHABLE(); 879 UNREACHABLE();
970 break; 880 break;
971 case CODE_AGE_SEQUENCE: 881 case CODE_AGE_SEQUENCE:
972 DCHECK(Code::IsYoungSequence(isolate, pc_) || code_age_stub()->IsCode()); 882 DCHECK(Code::IsYoungSequence(isolate, pc_) || code_age_stub()->IsCode());
973 break; 883 break;
974 } 884 }
975 } 885 }
976 #endif // VERIFY_HEAP 886 #endif // VERIFY_HEAP
977 887
978 888
(...skipping 955 matching lines...) Expand 10 before | Expand all | Expand 10 after
1934 1844
1935 1845
1936 void Assembler::DataAlign(int m) { 1846 void Assembler::DataAlign(int m) {
1937 DCHECK(m >= 2 && base::bits::IsPowerOfTwo32(m)); 1847 DCHECK(m >= 2 && base::bits::IsPowerOfTwo32(m));
1938 while ((pc_offset() & (m - 1)) != 0) { 1848 while ((pc_offset() & (m - 1)) != 0) {
1939 db(0); 1849 db(0);
1940 } 1850 }
1941 } 1851 }
1942 } // namespace internal 1852 } // namespace internal
1943 } // namespace v8 1853 } // namespace v8
OLDNEW
« no previous file with comments | « src/assembler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698