Changeset 44455 in webkit for trunk/JavaScriptCore/assembler
- Timestamp:
- Jun 5, 2009, 12:55:38 AM (16 years ago)
- Location:
- trunk/JavaScriptCore/assembler
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/assembler/AbstractMacroAssembler.h
r44443 r44455 45 45 class AbstractMacroAssembler { 46 46 public: 47 typedef MacroAssemblerCodePtr CodePtr; 47 48 typedef MacroAssemblerCodeRef CodeRef; 48 49 … … 415 416 public: 416 417 CodeLocationCommon() 417 : m_location(0)418 418 { 419 419 } … … 432 432 CodeLocationDataLabel32 dataLabel32AtOffset(int offset); 433 433 434 operator bool() { return m_location; }435 void reset() { m_location = 0; }436 437 434 protected: 438 explicit CodeLocationCommon( void*location)435 explicit CodeLocationCommon(CodePtr location) 439 436 : m_location(location) 440 437 { 441 438 } 442 439 443 void* m_location; 440 void* dataLocation() { return m_location.dataLocation(); } 441 void* executableAddress() { return m_location.executableAddress(); } 442 443 void reset() 444 { 445 m_location = CodePtr(); 446 } 447 448 private: 449 CodePtr m_location; 444 450 }; 445 451 … … 456 462 void repatchLoadToLEA() 457 463 { 458 AssemblerType::repatchLoadToLEA(this-> m_location);464 AssemblerType::repatchLoadToLEA(this->dataLocation()); 459 465 } 460 466 461 467 private: 462 468 explicit CodeLocationInstruction(void* location) 463 : CodeLocationCommon( location)469 : CodeLocationCommon(CodePtr(location)) 464 470 { 465 471 } … … 482 488 } 483 489 484 void* addressForSwitch() { return this->m_location; } 485 void* addressForExceptionHandler() { return this->m_location; } 486 void* addressForJSR() { return this->m_location; } 487 488 template<typename FunctionSig> 489 static CodeLocationLabel fromFunctionPointer(FunctionSig* function) 490 { 491 return CodeLocationLabel(reinterpret_cast<void*>(function)); 492 } 493 494 private: 490 void* addressForSwitch() { return this->executableAddress(); } 491 void* addressForExceptionHandler() { return this->executableAddress(); } 492 void* addressForJSR() { return this->executableAddress(); } 493 494 bool operator!() 495 { 496 return !this->executableAddress(); 497 } 498 499 void reset() 500 { 501 CodeLocationCommon::reset(); 502 } 503 504 private: 505 explicit CodeLocationLabel(CodePtr location) 506 : CodeLocationCommon(location) 507 { 508 } 509 495 510 explicit CodeLocationLabel(void* location) 496 : CodeLocationCommon( location)497 { 498 } 499 500 void* getJumpDestination() { return this-> m_location; }511 : CodeLocationCommon(CodePtr(location)) 512 { 513 } 514 515 void* getJumpDestination() { return this->executableAddress(); } 501 516 }; 502 517 … … 514 529 void relink(CodeLocationLabel destination) 515 530 { 516 AssemblerType::relinkJump(this-> m_location, destination.m_location);531 AssemblerType::relinkJump(this->dataLocation(), destination.executableAddress()); 517 532 } 518 533 519 534 private: 520 535 explicit CodeLocationJump(void* location) 521 : CodeLocationCommon( location)536 : CodeLocationCommon(CodePtr(location)) 522 537 { 523 538 } … … 530 545 friend class CodeLocationCommon; 531 546 friend class PatchBuffer; 547 friend class ProcessorReturnAddress; 532 548 public: 533 549 CodeLocationCall() … … 535 551 } 536 552 537 CodeLocationCall(ProcessorReturnAddress*);538 539 553 void relink(CodeLocationLabel destination) 540 554 { 541 555 #if PLATFORM(X86_64) 542 CodeLocationCommon::dataLabelPtrAtOffset(-REPTACH_OFFSET_CALL_R11).repatch(destination. m_location);556 CodeLocationCommon::dataLabelPtrAtOffset(-REPTACH_OFFSET_CALL_R11).repatch(destination.executableAddress()); 543 557 #else 544 AssemblerType::relinkCall(this-> m_location, destination.m_location);558 AssemblerType::relinkCall(this->dataLocation(), destination.executableAddress()); 545 559 #endif 546 560 } 547 561 548 template<typename FunctionSig> 549 void relink(FunctionSig* function) 550 { 551 relink(CodeLocationLabel::fromFunctionPointer(function)); 562 void relink(FunctionPtr destination) 563 { 564 #if PLATFORM(X86_64) 565 CodeLocationCommon::dataLabelPtrAtOffset(-REPTACH_OFFSET_CALL_R11).repatch(destination.executableAddress()); 566 #else 567 AssemblerType::relinkCall(this->dataLocation(), destination.executableAddress()); 568 #endif 552 569 } 553 570 … … 556 573 void* calleeReturnAddressValue() 557 574 { 558 return this->m_location; 559 } 560 561 private: 575 return this->executableAddress(); 576 } 577 578 private: 579 explicit CodeLocationCall(CodePtr location) 580 : CodeLocationCommon(location) 581 { 582 } 583 562 584 explicit CodeLocationCall(void* location) 563 : CodeLocationCommon( location)585 : CodeLocationCommon(CodePtr(location)) 564 586 { 565 587 } … … 572 594 friend class CodeLocationCommon; 573 595 friend class PatchBuffer; 596 friend class ProcessorReturnAddress; 574 597 public: 575 598 CodeLocationNearCall() … … 577 600 } 578 601 579 CodeLocationNearCall(ProcessorReturnAddress*); 602 void relink(CodePtr destination) 603 { 604 AssemblerType::relinkCall(this->dataLocation(), destination.executableAddress()); 605 } 580 606 581 607 void relink(CodeLocationLabel destination) 582 608 { 583 AssemblerType::relinkCall(this->m_location, destination.m_location); 584 } 585 586 template<typename FunctionSig> 587 void relink(FunctionSig* function) 588 { 589 relink(CodeLocationLabel::fromFunctionPointer(function)); 609 AssemblerType::relinkCall(this->dataLocation(), destination.executableAddress()); 610 } 611 612 void relink(FunctionPtr destination) 613 { 614 AssemblerType::relinkCall(this->dataLocation(), destination.executableAddress()); 590 615 } 591 616 … … 594 619 void* calleeReturnAddressValue() 595 620 { 596 return this->m_location; 597 } 598 599 private: 621 return this->executableAddress(); 622 } 623 624 private: 625 explicit CodeLocationNearCall(CodePtr location) 626 : CodeLocationCommon(location) 627 { 628 } 629 600 630 explicit CodeLocationNearCall(void* location) 601 : CodeLocationCommon( location)631 : CodeLocationCommon(CodePtr(location)) 602 632 { 603 633 } … … 617 647 void repatch(int32_t value) 618 648 { 619 AssemblerType::repatchInt32(this-> m_location, value);649 AssemblerType::repatchInt32(this->dataLocation(), value); 620 650 } 621 651 622 652 private: 623 653 explicit CodeLocationDataLabel32(void* location) 624 : CodeLocationCommon( location)654 : CodeLocationCommon(CodePtr(location)) 625 655 { 626 656 } … … 640 670 void repatch(void* value) 641 671 { 642 AssemblerType::repatchPointer(this-> m_location, value);672 AssemblerType::repatchPointer(this->dataLocation(), value); 643 673 } 644 674 645 675 private: 646 676 explicit CodeLocationDataLabelPtr(void* location) 647 : CodeLocationCommon( location)677 : CodeLocationCommon(CodePtr(location)) 648 678 { 649 679 } … … 664 694 void relinkCallerToTrampoline(CodeLocationLabel label) 665 695 { 666 CodeLocationCall(this).relink(label); 667 } 668 669 template<typename FunctionSig> 670 void relinkCallerToFunction(FunctionSig* newCalleeFunction) 671 { 672 relinkCallerToTrampoline(CodeLocationLabel::fromFunctionPointer(newCalleeFunction)); 696 CodeLocationCall(CodePtr(m_location)).relink(label); 697 } 698 699 void relinkCallerToTrampoline(CodePtr newCalleeFunction) 700 { 701 relinkCallerToTrampoline(CodeLocationLabel(newCalleeFunction)); 702 } 703 704 void relinkCallerToFunction(FunctionPtr function) 705 { 706 CodeLocationCall(CodePtr(m_location)).relink(function); 673 707 } 674 708 675 709 void relinkNearCallerToTrampoline(CodeLocationLabel label) 676 710 { 677 CodeLocationNearCall(this).relink(label); 678 } 679 680 template<typename FunctionSig> 681 void relinkNearCallerToFunction(FunctionSig* newCalleeFunction) 682 { 683 relinkNearCallerToTrampoline(CodeLocationLabel::fromFunctionPointer(newCalleeFunction)); 684 } 685 686 operator void*() 687 { 688 return m_location; 689 } 690 691 private: 692 void* m_location; 711 CodeLocationNearCall(CodePtr(m_location)).relink(label); 712 } 713 714 void relinkNearCallerToTrampoline(CodePtr newCalleeFunction) 715 { 716 relinkNearCallerToTrampoline(CodeLocationLabel(newCalleeFunction)); 717 } 718 719 void* addressForLookup() 720 { 721 return m_location.value(); 722 } 723 724 private: 725 ReturnAddressPtr m_location; 693 726 }; 694 727 … … 696 729 // Section 4: PatchBuffer - utility to finalize code generation. 697 730 698 static void*trampolineAt(CodeRef ref, Label label)699 { 700 return AssemblerType::getRelocatedAddress(ref.m_code, label.m_label);731 static CodePtr trampolineAt(CodeRef ref, Label label) 732 { 733 return CodePtr(AssemblerType::getRelocatedAddress(ref.m_code.dataLocation(), label.m_label)); 701 734 } 702 735 … … 740 773 // These methods are used to link or set values at code generation time. 741 774 742 template<typename FunctionSig> 743 void link(Call call, FunctionSig* function) 775 void link(Call call, FunctionPtr function) 744 776 { 745 777 ASSERT(call.isFlagSet(Call::Linkable)); 746 778 #if PLATFORM(X86_64) 747 779 if (!call.isFlagSet(Call::Near)) { 748 intptr_t callLocation = reinterpret_cast<intptr_t>(AssemblerType::getRelocatedAddress(code(), call.m_jmp)) - REPTACH_OFFSET_CALL_R11;749 AssemblerType::patchPointer (reinterpret_cast<void*>(callLocation), reinterpret_cast<void*>(function));780 char* callLocation = reinterpret_cast<char*>(AssemblerType::getRelocatedAddress(code(), call.m_jmp)) - REPTACH_OFFSET_CALL_R11; 781 AssemblerType::patchPointerForCall(callLocation, function.value()); 750 782 } else 751 783 #endif 752 AssemblerType::linkCall(code(), call.m_jmp, reinterpret_cast<void*>(function)); 753 } 754 755 template<typename FunctionSig> 756 void linkTailRecursive(Jump jump, FunctionSig* function) 757 { 758 AssemblerType::linkJump(code(), jump.m_jmp, reinterpret_cast<void*>(function)); 759 } 760 761 template<typename FunctionSig> 762 void linkTailRecursive(JumpList list, FunctionSig* function) 784 AssemblerType::linkCall(code(), call.m_jmp, function.value()); 785 } 786 787 void link(Jump jump, CodeLocationLabel label) 788 { 789 AssemblerType::linkJump(code(), jump.m_jmp, label.executableAddress()); 790 } 791 792 void link(JumpList list, CodeLocationLabel label) 763 793 { 764 794 for (unsigned i = 0; i < list.m_jumps.size(); ++i) 765 AssemblerType::linkJump(code(), list.m_jumps[i].m_jmp, reinterpret_cast<void*>(function)); 766 } 767 768 void link(Jump jump, CodeLocationLabel label) 769 { 770 AssemblerType::linkJump(code(), jump.m_jmp, label.m_location); 771 } 772 773 void link(JumpList list, CodeLocationLabel label) 774 { 775 for (unsigned i = 0; i < list.m_jumps.size(); ++i) 776 AssemblerType::linkJump(code(), list.m_jumps[i].m_jmp, label.m_location); 795 AssemblerType::linkJump(code(), list.m_jumps[i].m_jmp, label.executableAddress()); 777 796 } 778 797 … … 857 876 #endif 858 877 859 ExecutableAllocator::makeExecutable( m_code, m_size);878 ExecutableAllocator::makeExecutable(code(), m_size); 860 879 } 861 880 … … 935 954 typename AbstractMacroAssembler<AssemblerType>::CodeLocationInstruction AbstractMacroAssembler<AssemblerType>::CodeLocationCommon::instructionAtOffset(int offset) 936 955 { 937 return typename AbstractMacroAssembler::CodeLocationInstruction(reinterpret_cast<char*>( m_location) + offset);956 return typename AbstractMacroAssembler::CodeLocationInstruction(reinterpret_cast<char*>(dataLocation()) + offset); 938 957 } 939 958 … … 941 960 typename AbstractMacroAssembler<AssemblerType>::CodeLocationLabel AbstractMacroAssembler<AssemblerType>::CodeLocationCommon::labelAtOffset(int offset) 942 961 { 943 return typename AbstractMacroAssembler::CodeLocationLabel(reinterpret_cast<char*>( m_location) + offset);962 return typename AbstractMacroAssembler::CodeLocationLabel(reinterpret_cast<char*>(dataLocation()) + offset); 944 963 } 945 964 … … 947 966 typename AbstractMacroAssembler<AssemblerType>::CodeLocationJump AbstractMacroAssembler<AssemblerType>::CodeLocationCommon::jumpAtOffset(int offset) 948 967 { 949 return typename AbstractMacroAssembler::CodeLocationJump(reinterpret_cast<char*>( m_location) + offset);968 return typename AbstractMacroAssembler::CodeLocationJump(reinterpret_cast<char*>(dataLocation()) + offset); 950 969 } 951 970 … … 953 972 typename AbstractMacroAssembler<AssemblerType>::CodeLocationCall AbstractMacroAssembler<AssemblerType>::CodeLocationCommon::callAtOffset(int offset) 954 973 { 955 return typename AbstractMacroAssembler::CodeLocationCall(reinterpret_cast<char*>( m_location) + offset);974 return typename AbstractMacroAssembler::CodeLocationCall(reinterpret_cast<char*>(dataLocation()) + offset); 956 975 } 957 976 … … 959 978 typename AbstractMacroAssembler<AssemblerType>::CodeLocationNearCall AbstractMacroAssembler<AssemblerType>::CodeLocationCommon::nearCallAtOffset(int offset) 960 979 { 961 return typename AbstractMacroAssembler::CodeLocationNearCall(reinterpret_cast<char*>( m_location) + offset);980 return typename AbstractMacroAssembler::CodeLocationNearCall(reinterpret_cast<char*>(dataLocation()) + offset); 962 981 } 963 982 … … 965 984 typename AbstractMacroAssembler<AssemblerType>::CodeLocationDataLabelPtr AbstractMacroAssembler<AssemblerType>::CodeLocationCommon::dataLabelPtrAtOffset(int offset) 966 985 { 967 return typename AbstractMacroAssembler::CodeLocationDataLabelPtr(reinterpret_cast<char*>( m_location) + offset);986 return typename AbstractMacroAssembler::CodeLocationDataLabelPtr(reinterpret_cast<char*>(dataLocation()) + offset); 968 987 } 969 988 … … 971 990 typename AbstractMacroAssembler<AssemblerType>::CodeLocationDataLabel32 AbstractMacroAssembler<AssemblerType>::CodeLocationCommon::dataLabel32AtOffset(int offset) 972 991 { 973 return typename AbstractMacroAssembler::CodeLocationDataLabel32(reinterpret_cast<char*>( m_location) + offset);992 return typename AbstractMacroAssembler::CodeLocationDataLabel32(reinterpret_cast<char*>(dataLocation()) + offset); 974 993 } 975 994 976 template <class AssemblerType>977 AbstractMacroAssembler<AssemblerType>::CodeLocationCall::CodeLocationCall(typename AbstractMacroAssembler<AssemblerType>::ProcessorReturnAddress* ra)978 : CodeLocationCommon(ra->m_location)979 {980 }981 982 template <class AssemblerType>983 AbstractMacroAssembler<AssemblerType>::CodeLocationNearCall::CodeLocationNearCall(typename AbstractMacroAssembler<AssemblerType>::ProcessorReturnAddress* ra)984 : CodeLocationCommon(ra->m_location)985 {986 }987 988 995 } // namespace JSC 989 996 -
trunk/JavaScriptCore/assembler/MacroAssemblerCodeRef.h
r44030 r44455 38 38 namespace JSC { 39 39 40 // FunctionPtr: 41 // 42 // FunctionPtr should be used to wrap pointers to C/C++ functions in JSC 43 // (particularly, the stub functions). 44 class FunctionPtr { 45 public: 46 FunctionPtr() 47 : m_value(0) 48 { 49 } 50 51 template<typename FunctionType> 52 explicit FunctionPtr(FunctionType* value) 53 : m_value(reinterpret_cast<void*>(value)) 54 { 55 ASSERT(m_value); 56 } 57 58 void* value() const { return m_value; } 59 void* executableAddress() const { return m_value; } 60 61 62 private: 63 void* m_value; 64 }; 65 66 // ReturnAddressPtr: 67 // 68 // ReturnAddressPtr should be used to wrap return addresses generated by processor 69 // 'call' instructions exectued in JIT code. We use return addresses to look up 70 // exception and optimization information, and to repatch the call instruction 71 // that is the source of the return address. 72 class ReturnAddressPtr { 73 public: 74 ReturnAddressPtr() 75 : m_value(0) 76 { 77 } 78 79 explicit ReturnAddressPtr(void* value) 80 : m_value(value) 81 { 82 ASSERT(m_value); 83 } 84 85 void* value() const { return m_value; } 86 87 private: 88 void* m_value; 89 }; 90 91 // MacroAssemblerCodePtr: 92 // 93 // MacroAssemblerCodePtr should be used to wrap pointers to JIT generated code. 94 class MacroAssemblerCodePtr { 95 public: 96 MacroAssemblerCodePtr() 97 : m_value(0) 98 { 99 } 100 101 explicit MacroAssemblerCodePtr(void* value) 102 : m_value(value) 103 { 104 ASSERT(m_value); 105 } 106 107 explicit MacroAssemblerCodePtr(ReturnAddressPtr ra) 108 : m_value(ra.value()) 109 { 110 ASSERT(m_value); 111 } 112 113 void* executableAddress() const { return m_value; } 114 void* dataLocation() const { ASSERT(m_value); return m_value; } 115 116 private: 117 void* m_value; 118 }; 119 40 120 // MacroAssemblerCodeRef: 41 121 // … … 46 126 public: 47 127 MacroAssemblerCodeRef() 48 : m_code(0)49 128 #ifndef NDEBUG 50 ,m_size(0)129 : m_size(0) 51 130 #endif 52 131 { … … 64 143 } 65 144 66 void*m_code;145 MacroAssemblerCodePtr m_code; 67 146 RefPtr<ExecutablePool> m_executablePool; 68 147 #ifndef NDEBUG -
trunk/JavaScriptCore/assembler/X86Assembler.h
r44341 r44455 1370 1370 } 1371 1371 1372 void linkCall(JmpSrc from, JmpDstto)1372 static void linkJump(void* code, JmpSrc from, void* to) 1373 1373 { 1374 1374 ASSERT(from.m_offset != -1); 1375 ASSERT(to.m_offset != -1); 1376 1377 char* code = reinterpret_cast<char*>(m_formatter.data()); 1378 patchRel32(code + from.m_offset, code + to.m_offset); 1379 } 1380 1381 static void linkJump(void* code, JmpSrc from, void* to) 1375 1376 patchRel32(reinterpret_cast<char*>(code) + from.m_offset, to); 1377 } 1378 1379 static void linkCall(void* code, JmpSrc from, void* to) 1382 1380 { 1383 1381 ASSERT(from.m_offset != -1); … … 1386 1384 } 1387 1385 1388 static void linkCall(void* code, JmpSrc from, void* to)1389 {1390 ASSERT(from.m_offset != -1);1391 1392 patchRel32(reinterpret_cast<char*>(code) + from.m_offset, to);1393 }1394 1395 1386 static void patchPointer(void* where, void* value) 1396 1387 { 1397 1388 reinterpret_cast<void**>(where)[-1] = value; 1398 1389 } 1390 1391 #if PLATFORM(X86_64) 1392 static void patchPointerForCall(void* where, void* value) 1393 { 1394 reinterpret_cast<void**>(where)[-1] = value; 1395 } 1396 #endif 1399 1397 1400 1398 static void patchPointer(void* code, JmpDst where, void* value)
Note:
See TracChangeset
for help on using the changeset viewer.