Changeset 44030 in webkit for trunk/JavaScriptCore/assembler/AbstractMacroAssembler.h
- Timestamp:
- May 21, 2009, 7:34:41 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/assembler/AbstractMacroAssembler.h
r43839 r44030 29 29 #include <wtf/Platform.h> 30 30 31 #include <MacroAssemblerCodeRef.h> 32 #include <wtf/Noncopyable.h> 33 #include <wtf/UnusedParam.h> 34 31 35 #if ENABLE(ASSEMBLER) 32 36 … … 36 40 class AbstractMacroAssembler { 37 41 public: 42 typedef MacroAssemblerCodeRef CodeRef; 43 38 44 class Jump; 39 45 class PatchBuffer; … … 44 50 class CodeLocationDataLabel32; 45 51 class CodeLocationDataLabelPtr; 52 class ProcessorReturnAddress; 46 53 47 54 typedef typename AssemblerType::RegisterID RegisterID; … … 195 202 // it may be used as a destination for a jump. 196 203 class Label { 204 template<class TemplateAssemblerType> 205 friend class AbstractMacroAssembler; 197 206 friend class Jump; 198 template<class AssemblerType_T>199 friend class AbstractMacroAssembler;200 friend class PatchBuffer; 207 friend class MacroAssemblerCodeRef; 208 friend class PatchBuffer; 209 201 210 public: 202 211 Label() … … 220 229 // patched after the code has been generated. 221 230 class DataLabelPtr { 222 template<class AssemblerType_T>231 template<class TemplateAssemblerType> 223 232 friend class AbstractMacroAssembler; 224 233 friend class PatchBuffer; … … 242 251 // patched after the code has been generated. 243 252 class DataLabel32 { 244 template<class AssemblerType_T>253 template<class TemplateAssemblerType> 245 254 friend class AbstractMacroAssembler; 246 255 friend class PatchBuffer; … … 266 275 // destination. 267 276 class Call { 268 friend class PatchBuffer; 269 template<class AssemblerType_T> 277 template<class TemplateAssemblerType> 270 278 friend class AbstractMacroAssembler; 279 friend class PatchBuffer; 271 280 public: 272 281 enum Flags { … … 310 319 // destination. 311 320 class Jump { 312 friend class PatchBuffer; 313 template<class AssemblerType_T> 321 template<class TemplateAssemblerType> 314 322 friend class AbstractMacroAssembler; 315 323 friend class Call; 324 friend class PatchBuffer; 316 325 public: 317 326 Jump() … … 456 465 friend class CodeLocationJump; 457 466 friend class PatchBuffer; 467 friend class ProcessorReturnAddress; 468 458 469 public: 459 470 CodeLocationLabel() … … 615 626 } 616 627 628 void relinkCallerToTrampoline(CodeLocationLabel label) 629 { 630 AssemblerType::patchMacroAssemblerCall(reinterpret_cast<intptr_t>(this->m_location), label.getJumpDestination()); 631 } 632 617 633 template<typename FunctionSig> 618 634 void relinkCallerToFunction(FunctionSig* newCalleeFunction) … … 637 653 638 654 639 // Section 4: The patch buffer - utility to finalize code generation. 640 655 // Section 4: PatchBuffer - utility to finalize code generation. 656 657 static void* trampolineAt(CodeRef ref, Label label) 658 { 659 return AssemblerType::getRelocatedAddress(ref.m_code, label.m_label); 660 } 641 661 642 662 // PatchBuffer: … … 657 677 // address of calls, as opposed to a point that can be used to later relink a Jump - 658 678 // possibly wrap the later up in an object that can do just that). 659 class PatchBuffer { 660 public: 661 PatchBuffer(void* code) 662 : m_code(code) 663 { 664 } 665 666 CodeLocationLabel entry() 667 { 668 return CodeLocationLabel(m_code); 669 } 670 671 void* trampolineAt(Label label) 672 { 673 return AssemblerType::getRelocatedAddress(m_code, label.m_label); 674 } 675 679 class PatchBuffer : public Noncopyable { 680 public: 681 PatchBuffer(AbstractMacroAssembler<AssemblerType>* masm, PassRefPtr<ExecutablePool> executablePool) 682 : m_ref(0, executablePool, masm->m_assembler.size()) 683 #ifndef NDEBUG 684 , m_completed(false) 685 #endif 686 { 687 m_ref.m_code = masm->m_assembler.executableCopy(m_ref.m_executablePool.get()); 688 } 689 690 #ifndef NDEBUG 691 ~PatchBuffer() 692 { 693 ASSERT(m_completed); 694 } 695 #endif 696 676 697 // These methods are used to link or set values at code generation time. 677 698 … … 681 702 ASSERT(call.isFlagSet(Call::Linkable)); 682 703 #if PLATFORM(X86_64) 683 if (call.isFlagSet(Call::Near)) {684 AssemblerType::linkCall( m_code, call.m_jmp, reinterpret_cast<void*>(function));685 }else {686 intptr_t callLocation = reinterpret_cast<intptr_t>(AssemblerType::getRelocatedAddress( m_code, call.m_jmp));704 if (call.isFlagSet(Call::Near)) 705 AssemblerType::linkCall(code(), call.m_jmp, reinterpret_cast<void*>(function)); 706 else { 707 intptr_t callLocation = reinterpret_cast<intptr_t>(AssemblerType::getRelocatedAddress(code(), call.m_jmp)); 687 708 AssemblerType::patchMacroAssemblerCall(callLocation, reinterpret_cast<void*>(function)); 688 709 } 689 710 #else 690 AssemblerType::linkCall( m_code, call.m_jmp, reinterpret_cast<void*>(function));711 AssemblerType::linkCall(code(), call.m_jmp, reinterpret_cast<void*>(function)); 691 712 #endif 692 713 } … … 695 716 void linkTailRecursive(Jump jump, FunctionSig* function) 696 717 { 697 AssemblerType::linkJump( m_code, jump.m_jmp, reinterpret_cast<void*>(function));718 AssemblerType::linkJump(code(), jump.m_jmp, reinterpret_cast<void*>(function)); 698 719 } 699 720 … … 701 722 void linkTailRecursive(JumpList list, FunctionSig* function) 702 723 { 703 for (unsigned i = 0; i < list.m_jumps.size(); ++i) { 704 AssemblerType::linkJump(m_code, list.m_jumps[i].m_jmp, reinterpret_cast<void*>(function)); 705 } 724 for (unsigned i = 0; i < list.m_jumps.size(); ++i) 725 AssemblerType::linkJump(code(), list.m_jumps[i].m_jmp, reinterpret_cast<void*>(function)); 706 726 } 707 727 708 728 void link(Jump jump, CodeLocationLabel label) 709 729 { 710 AssemblerType::linkJump( m_code, jump.m_jmp, label.m_location);730 AssemblerType::linkJump(code(), jump.m_jmp, label.m_location); 711 731 } 712 732 … … 714 734 { 715 735 for (unsigned i = 0; i < list.m_jumps.size(); ++i) 716 AssemblerType::linkJump( m_code, list.m_jumps[i].m_jmp, label.m_location);736 AssemblerType::linkJump(code(), list.m_jumps[i].m_jmp, label.m_location); 717 737 } 718 738 719 739 void patch(DataLabelPtr label, void* value) 720 740 { 721 AssemblerType::patchAddress(m_code, label.m_label, value); 741 AssemblerType::patchAddress(code(), label.m_label, value); 742 } 743 744 void patch(DataLabelPtr label, CodeLocationLabel value) 745 { 746 AssemblerType::patchAddress(code(), label.m_label, value.getJumpDestination()); 722 747 } 723 748 … … 728 753 ASSERT(call.isFlagSet(Call::Linkable)); 729 754 ASSERT(!call.isFlagSet(Call::Near)); 730 return CodeLocationCall(AssemblerType::getRelocatedAddress( m_code, call.m_jmp));755 return CodeLocationCall(AssemblerType::getRelocatedAddress(code(), call.m_jmp)); 731 756 } 732 757 … … 735 760 ASSERT(call.isFlagSet(Call::Linkable)); 736 761 ASSERT(call.isFlagSet(Call::Near)); 737 return CodeLocationNearCall(AssemblerType::getRelocatedAddress( m_code, call.m_jmp));762 return CodeLocationNearCall(AssemblerType::getRelocatedAddress(code(), call.m_jmp)); 738 763 } 739 764 740 765 CodeLocationLabel locationOf(Label label) 741 766 { 742 return CodeLocationLabel(AssemblerType::getRelocatedAddress( m_code, label.m_label));767 return CodeLocationLabel(AssemblerType::getRelocatedAddress(code(), label.m_label)); 743 768 } 744 769 745 770 CodeLocationDataLabelPtr locationOf(DataLabelPtr label) 746 771 { 747 return CodeLocationDataLabelPtr(AssemblerType::getRelocatedAddress( m_code, label.m_label));772 return CodeLocationDataLabelPtr(AssemblerType::getRelocatedAddress(code(), label.m_label)); 748 773 } 749 774 750 775 CodeLocationDataLabel32 locationOf(DataLabel32 label) 751 776 { 752 return CodeLocationDataLabel32(AssemblerType::getRelocatedAddress( m_code, label.m_label));777 return CodeLocationDataLabel32(AssemblerType::getRelocatedAddress(code(), label.m_label)); 753 778 } 754 779 … … 760 785 } 761 786 762 private: 763 void* m_code; 787 // Upon completion of all patching either 'finalizeCode()' or 'finalizeCodeAddendum()' should be called 788 // once to complete generation of the code. 'finalizeCode()' is suited to situations 789 // where the executable pool must also be retained, the lighter-weight 'finalizeCodeAddendum()' is 790 // suited to adding to an existing allocation. 791 CodeRef finalizeCode() 792 { 793 performFinalization(); 794 795 return m_ref; 796 } 797 CodeLocationLabel finalizeCodeAddendum() 798 { 799 performFinalization(); 800 801 return CodeLocationLabel(code()); 802 } 803 804 private: 805 // Keep this private! - the underlying code should only be obtained externally via 806 // finalizeCode() or finalizeCodeAddendum(). 807 void* code() 808 { 809 return m_ref.m_code; 810 } 811 812 void performFinalization() 813 { 814 #ifndef NDEBUG 815 ASSERT(!m_completed); 816 m_completed = true; 817 #endif 818 } 819 820 CodeRef m_ref; 821 #ifndef NDEBUG 822 bool m_completed; 823 #endif 764 824 }; 765 825 … … 770 830 { 771 831 return m_assembler.size(); 772 }773 774 void* copyCode(ExecutablePool* allocator)775 {776 return m_assembler.executableCopy(allocator);777 832 } 778 833
Note:
See TracChangeset
for help on using the changeset viewer.