OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 __ ldrh(result, MemOperand(string, index, LSL, 1)); | 445 __ ldrh(result, MemOperand(string, index, LSL, 1)); |
446 __ jmp(&done); | 446 __ jmp(&done); |
447 __ bind(&ascii); | 447 __ bind(&ascii); |
448 // Ascii string. | 448 // Ascii string. |
449 __ ldrb(result, MemOperand(string, index)); | 449 __ ldrb(result, MemOperand(string, index)); |
450 __ bind(&done); | 450 __ bind(&done); |
451 } | 451 } |
452 | 452 |
453 #undef __ | 453 #undef __ |
454 | 454 |
| 455 // add(r0, pc, Operand(-8)) |
| 456 static const uint32_t kCodeAgePatchFirstInstruction = 0xe24f0008; |
| 457 |
| 458 static byte* GetNoCodeAgeSequence(uint32_t* length) { |
| 459 // The sequence of instructions that is patched out for aging code is the |
| 460 // following boilerplate stack-building prologue that is found in FUNCTIONS |
| 461 static bool initialized = false; |
| 462 static uint32_t sequence[kNoCodeAgeSequenceLength]; |
| 463 byte* byte_sequence = reinterpret_cast<byte*>(sequence); |
| 464 *length = kNoCodeAgeSequenceLength * Assembler::kInstrSize; |
| 465 if (!initialized) { |
| 466 CodePatcher patcher(byte_sequence, kNoCodeAgeSequenceLength); |
| 467 patcher.masm()->stm(db_w, sp, r1.bit() | cp.bit() | fp.bit() | lr.bit()); |
| 468 patcher.masm()->LoadRoot(ip, Heap::kUndefinedValueRootIndex); |
| 469 patcher.masm()->add(fp, sp, Operand(2 * kPointerSize)); |
| 470 initialized = true; |
| 471 } |
| 472 return byte_sequence; |
| 473 } |
| 474 |
| 475 |
| 476 byte* Code::FindPlatformCodeAgeSequence() { |
| 477 byte* start = instruction_start(); |
| 478 uint32_t young_length; |
| 479 byte* young_sequence = GetNoCodeAgeSequence(&young_length); |
| 480 if (!memcmp(start, young_sequence, young_length) || |
| 481 Memory::uint32_at(start) == kCodeAgePatchFirstInstruction) { |
| 482 return start; |
| 483 } else { |
| 484 byte* start_after_strict = NULL; |
| 485 if (kind() == FUNCTION) { |
| 486 start_after_strict = start + kSizeOfFullCodegenStrictModePrologue; |
| 487 } else { |
| 488 ASSERT(kind() == OPTIMIZED_FUNCTION); |
| 489 start_after_strict = start + kSizeOfOptimizedStrictModePrologue; |
| 490 } |
| 491 ASSERT(!memcmp(start_after_strict, young_sequence, young_length) || |
| 492 Memory::uint32_at(start_after_strict) == |
| 493 kCodeAgePatchFirstInstruction); |
| 494 return start_after_strict; |
| 495 } |
| 496 } |
| 497 |
| 498 |
| 499 bool Code::IsYoungSequence(byte* sequence) { |
| 500 uint32_t young_length; |
| 501 byte* young_sequence = GetNoCodeAgeSequence(&young_length); |
| 502 bool result = !memcmp(sequence, young_sequence, young_length); |
| 503 ASSERT(result || |
| 504 Memory::uint32_at(sequence) == kCodeAgePatchFirstInstruction); |
| 505 return result; |
| 506 } |
| 507 |
| 508 |
| 509 void Code::GetCodeAgeAndParity(byte* sequence, Age* age, |
| 510 MarkingParity* parity) { |
| 511 if (IsYoungSequence(sequence)) { |
| 512 *age = kNoAge; |
| 513 *parity = NO_MARKING_PARITY; |
| 514 } else { |
| 515 Address target_address = Memory::Address_at( |
| 516 sequence + Assembler::kInstrSize * (kNoCodeAgeSequenceLength - 1)); |
| 517 Code* stub = GetCodeFromTargetAddress(target_address); |
| 518 GetCodeAgeAndParity(stub, age, parity); |
| 519 } |
| 520 } |
| 521 |
| 522 |
| 523 void Code::PatchPlatformCodeAge(byte* sequence, |
| 524 Code::Age age, |
| 525 MarkingParity parity) { |
| 526 uint32_t young_length; |
| 527 byte* young_sequence = GetNoCodeAgeSequence(&young_length); |
| 528 if (age == kNoAge) { |
| 529 memcpy(sequence, young_sequence, young_length); |
| 530 CPU::FlushICache(sequence, young_length); |
| 531 } else { |
| 532 Code* stub = GetCodeAgeStub(age, parity); |
| 533 CodePatcher patcher(sequence, young_length / Assembler::kInstrSize); |
| 534 patcher.masm()->add(r0, pc, Operand(-8)); |
| 535 patcher.masm()->ldr(pc, MemOperand(pc, -4)); |
| 536 patcher.masm()->dd(reinterpret_cast<uint32_t>(stub->instruction_start())); |
| 537 } |
| 538 } |
| 539 |
| 540 |
455 } } // namespace v8::internal | 541 } } // namespace v8::internal |
456 | 542 |
457 #endif // V8_TARGET_ARCH_ARM | 543 #endif // V8_TARGET_ARCH_ARM |
OLD | NEW |