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