Changeset 43839 in webkit for trunk/JavaScriptCore/assembler/AbstractMacroAssembler.h
- Timestamp:
- May 18, 2009, 1:22:52 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/assembler/AbstractMacroAssembler.h
r43837 r43839 27 27 #define AbstractMacroAssembler_h 28 28 29 #include <wtf/Noncopyable.h>30 29 #include <wtf/Platform.h> 31 #include <wtf/UnusedParam.h>32 30 33 31 #if ENABLE(ASSEMBLER) … … 46 44 class CodeLocationDataLabel32; 47 45 class CodeLocationDataLabelPtr; 48 class ProcessorReturnAddress;49 50 struct CodeRef;51 46 52 47 typedef typename AssemblerType::RegisterID RegisterID; … … 200 195 // it may be used as a destination for a jump. 201 196 class Label { 202 template<class TemplateAssemblerType> 197 friend class Jump; 198 template<class AssemblerType_T> 203 199 friend class AbstractMacroAssembler; 204 friend class Jump; 205 friend class PatchBuffer; 206 207 friend struct CodeRef; 208 200 friend class PatchBuffer; 209 201 public: 210 202 Label() … … 228 220 // patched after the code has been generated. 229 221 class DataLabelPtr { 230 template<class TemplateAssemblerType>222 template<class AssemblerType_T> 231 223 friend class AbstractMacroAssembler; 232 224 friend class PatchBuffer; … … 250 242 // patched after the code has been generated. 251 243 class DataLabel32 { 252 template<class TemplateAssemblerType>244 template<class AssemblerType_T> 253 245 friend class AbstractMacroAssembler; 254 246 friend class PatchBuffer; … … 274 266 // destination. 275 267 class Call { 276 template<class TemplateAssemblerType> 268 friend class PatchBuffer; 269 template<class AssemblerType_T> 277 270 friend class AbstractMacroAssembler; 278 friend class PatchBuffer;279 271 public: 280 272 enum Flags { … … 318 310 // destination. 319 311 class Jump { 320 template<class TemplateAssemblerType> 312 friend class PatchBuffer; 313 template<class AssemblerType_T> 321 314 friend class AbstractMacroAssembler; 322 315 friend class Call; 323 friend class PatchBuffer;324 316 public: 325 317 Jump() … … 464 456 friend class CodeLocationJump; 465 457 friend class PatchBuffer; 466 friend class ProcessorReturnAddress;467 468 458 public: 469 459 CodeLocationLabel() … … 625 615 } 626 616 627 void relinkCallerToTrampoline(CodeLocationLabel label)628 {629 AssemblerType::patchMacroAssemblerCall(reinterpret_cast<intptr_t>(this->m_location), label.getJumpDestination());630 }631 632 617 template<typename FunctionSig> 633 618 void relinkCallerToFunction(FunctionSig* newCalleeFunction) … … 652 637 653 638 654 // Section 4: CodeRef & PatchBuffer - utility to finalize code generation. 655 656 // CodeRef: 657 // 658 // A reference to a section of JIT generated code. A CodeRef consists of a 659 // pointer to the code, and a ref pointer to the pool from within which it 660 // was allocated. 661 class CodeRef { 662 public: 663 CodeRef() 664 : m_code(0) 665 #ifndef NDEBUG 666 , m_size(0) 667 #endif 668 { 669 } 670 671 CodeRef(AbstractMacroAssembler<AssemblerType>* masm, PassRefPtr<ExecutablePool> executablePool) 672 : m_executablePool(executablePool) 673 #ifndef NDEBUG 674 , m_size(masm->m_assembler.size()) 675 #endif 676 { 677 m_code = masm->m_assembler.executableCopy(m_executablePool.get()); 678 } 679 680 CodeRef(void* code, PassRefPtr<ExecutablePool> executablePool, size_t size) 681 : m_code(code) 682 , m_executablePool(executablePool) 683 { 684 #ifndef NDEBUG 685 m_size = size; 686 #else 687 UNUSED_PARAM(size); 688 #endif 689 } 690 691 void* trampolineAt(Label label) 692 { 693 return AssemblerType::getRelocatedAddress(m_code, label.m_label); 694 } 695 696 void* m_code; 697 RefPtr<ExecutablePool> m_executablePool; 698 #ifndef NDEBUG 699 size_t m_size; 700 #endif 701 }; 639 // Section 4: The patch buffer - utility to finalize code generation. 640 702 641 703 642 // PatchBuffer: … … 718 657 // address of calls, as opposed to a point that can be used to later relink a Jump - 719 658 // possibly wrap the later up in an object that can do just that). 720 class PatchBuffer : public Noncopyable{721 public: 722 PatchBuffer( AbstractMacroAssembler<AssemblerType>* masm, PassRefPtr<ExecutablePool> executablePool)723 : m_ ref(masm, executablePool)724 #ifndef NDEBUG 725 , m_completed(false)726 #endif 727 {728 }729 730 #ifndef NDEBUG 731 ~PatchBuffer() 732 {733 ASSERT(m_completed);734 }735 #endif 736 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 737 676 // These methods are used to link or set values at code generation time. 738 677 … … 742 681 ASSERT(call.isFlagSet(Call::Linkable)); 743 682 #if PLATFORM(X86_64) 744 if (call.isFlagSet(Call::Near)) 745 AssemblerType::linkCall( code(), call.m_jmp, reinterpret_cast<void*>(function));746 else {747 intptr_t callLocation = reinterpret_cast<intptr_t>(AssemblerType::getRelocatedAddress( code(), call.m_jmp));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)); 748 687 AssemblerType::patchMacroAssemblerCall(callLocation, reinterpret_cast<void*>(function)); 749 688 } 750 689 #else 751 AssemblerType::linkCall( code(), call.m_jmp, reinterpret_cast<void*>(function));690 AssemblerType::linkCall(m_code, call.m_jmp, reinterpret_cast<void*>(function)); 752 691 #endif 753 692 } … … 756 695 void linkTailRecursive(Jump jump, FunctionSig* function) 757 696 { 758 AssemblerType::linkJump( code(), jump.m_jmp, reinterpret_cast<void*>(function));697 AssemblerType::linkJump(m_code, jump.m_jmp, reinterpret_cast<void*>(function)); 759 698 } 760 699 … … 762 701 void linkTailRecursive(JumpList list, FunctionSig* function) 763 702 { 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 } 706 } 707 708 void link(Jump jump, CodeLocationLabel label) 709 { 710 AssemblerType::linkJump(m_code, jump.m_jmp, label.m_location); 711 } 712 713 void link(JumpList list, CodeLocationLabel label) 714 { 764 715 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); 716 AssemblerType::linkJump(m_code, list.m_jumps[i].m_jmp, label.m_location); 777 717 } 778 718 779 719 void patch(DataLabelPtr label, void* value) 780 720 { 781 AssemblerType::patchAddress(code(), label.m_label, value); 782 } 783 784 void patch(DataLabelPtr label, CodeLocationLabel value) 785 { 786 AssemblerType::patchAddress(code(), label.m_label, value.getJumpDestination()); 721 AssemblerType::patchAddress(m_code, label.m_label, value); 787 722 } 788 723 … … 793 728 ASSERT(call.isFlagSet(Call::Linkable)); 794 729 ASSERT(!call.isFlagSet(Call::Near)); 795 return CodeLocationCall(AssemblerType::getRelocatedAddress( code(), call.m_jmp));730 return CodeLocationCall(AssemblerType::getRelocatedAddress(m_code, call.m_jmp)); 796 731 } 797 732 … … 800 735 ASSERT(call.isFlagSet(Call::Linkable)); 801 736 ASSERT(call.isFlagSet(Call::Near)); 802 return CodeLocationNearCall(AssemblerType::getRelocatedAddress( code(), call.m_jmp));737 return CodeLocationNearCall(AssemblerType::getRelocatedAddress(m_code, call.m_jmp)); 803 738 } 804 739 805 740 CodeLocationLabel locationOf(Label label) 806 741 { 807 return CodeLocationLabel(AssemblerType::getRelocatedAddress( code(), label.m_label));742 return CodeLocationLabel(AssemblerType::getRelocatedAddress(m_code, label.m_label)); 808 743 } 809 744 810 745 CodeLocationDataLabelPtr locationOf(DataLabelPtr label) 811 746 { 812 return CodeLocationDataLabelPtr(AssemblerType::getRelocatedAddress( code(), label.m_label));747 return CodeLocationDataLabelPtr(AssemblerType::getRelocatedAddress(m_code, label.m_label)); 813 748 } 814 749 815 750 CodeLocationDataLabel32 locationOf(DataLabel32 label) 816 751 { 817 return CodeLocationDataLabel32(AssemblerType::getRelocatedAddress( code(), label.m_label));752 return CodeLocationDataLabel32(AssemblerType::getRelocatedAddress(m_code, label.m_label)); 818 753 } 819 754 … … 825 760 } 826 761 827 // Upon completion of all patching either 'finalizeCode()' or 'finalizeCodeAddendum()' should be called 828 // once to complete generation of the code. 'finalizeCode()' is suited to situations 829 // where the executable pool must also be retained, the lighter-weight 'finalizeCodeAddendum()' is 830 // suited to adding to an existing allocation. 831 CodeRef finalizeCode() 832 { 833 performFinalization(); 834 835 return m_ref; 836 } 837 CodeLocationLabel finalizeCodeAddendum() 838 { 839 performFinalization(); 840 841 return CodeLocationLabel(code()); 842 } 843 844 private: 845 // Keep this private! - the underlying code should only be obtained externally via 846 // finalizeCode() or finalizeCodeAddendum(). 847 void* code() 848 { 849 return m_ref.m_code; 850 } 851 852 void performFinalization() 853 { 854 #ifndef NDEBUG 855 ASSERT(!m_completed); 856 m_completed = true; 857 #endif 858 } 859 860 CodeRef m_ref; 861 #ifndef NDEBUG 862 bool m_completed; 863 #endif 762 private: 763 void* m_code; 864 764 }; 865 765 … … 870 770 { 871 771 return m_assembler.size(); 772 } 773 774 void* copyCode(ExecutablePool* allocator) 775 { 776 return m_assembler.executableCopy(allocator); 872 777 } 873 778
Note:
See TracChangeset
for help on using the changeset viewer.