Changeset 43837 in webkit for trunk/JavaScriptCore/assembler/AbstractMacroAssembler.h
- Timestamp:
- May 18, 2009, 12:46:37 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/assembler/AbstractMacroAssembler.h
r43781 r43837 27 27 #define AbstractMacroAssembler_h 28 28 29 #include <wtf/Noncopyable.h> 29 30 #include <wtf/Platform.h> 31 #include <wtf/UnusedParam.h> 30 32 31 33 #if ENABLE(ASSEMBLER) … … 44 46 class CodeLocationDataLabel32; 45 47 class CodeLocationDataLabelPtr; 48 class ProcessorReturnAddress; 49 50 struct CodeRef; 46 51 47 52 typedef typename AssemblerType::RegisterID RegisterID; … … 195 200 // it may be used as a destination for a jump. 196 201 class Label { 202 template<class TemplateAssemblerType> 203 friend class AbstractMacroAssembler; 197 204 friend class Jump; 198 template<class AssemblerType_T> 199 friend class AbstractMacroAssembler; 200 friend class PatchBuffer; 205 friend class PatchBuffer; 206 207 friend struct CodeRef; 208 201 209 public: 202 210 Label() … … 220 228 // patched after the code has been generated. 221 229 class DataLabelPtr { 222 template<class AssemblerType_T>230 template<class TemplateAssemblerType> 223 231 friend class AbstractMacroAssembler; 224 232 friend class PatchBuffer; … … 242 250 // patched after the code has been generated. 243 251 class DataLabel32 { 244 template<class AssemblerType_T>252 template<class TemplateAssemblerType> 245 253 friend class AbstractMacroAssembler; 246 254 friend class PatchBuffer; … … 266 274 // destination. 267 275 class Call { 268 friend class PatchBuffer; 269 template<class AssemblerType_T> 276 template<class TemplateAssemblerType> 270 277 friend class AbstractMacroAssembler; 278 friend class PatchBuffer; 271 279 public: 272 280 enum Flags { … … 310 318 // destination. 311 319 class Jump { 312 friend class PatchBuffer; 313 template<class AssemblerType_T> 320 template<class TemplateAssemblerType> 314 321 friend class AbstractMacroAssembler; 315 322 friend class Call; 323 friend class PatchBuffer; 316 324 public: 317 325 Jump() … … 456 464 friend class CodeLocationJump; 457 465 friend class PatchBuffer; 466 friend class ProcessorReturnAddress; 467 458 468 public: 459 469 CodeLocationLabel() … … 615 625 } 616 626 627 void relinkCallerToTrampoline(CodeLocationLabel label) 628 { 629 AssemblerType::patchMacroAssemblerCall(reinterpret_cast<intptr_t>(this->m_location), label.getJumpDestination()); 630 } 631 617 632 template<typename FunctionSig> 618 633 void relinkCallerToFunction(FunctionSig* newCalleeFunction) … … 637 652 638 653 639 // Section 4: The patch buffer - utility to finalize code generation. 640 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 }; 641 702 642 703 // PatchBuffer: … … 657 718 // address of calls, as opposed to a point that can be used to later relink a Jump - 658 719 // 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 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 676 737 // These methods are used to link or set values at code generation time. 677 738 … … 681 742 ASSERT(call.isFlagSet(Call::Linkable)); 682 743 #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));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)); 687 748 AssemblerType::patchMacroAssemblerCall(callLocation, reinterpret_cast<void*>(function)); 688 749 } 689 750 #else 690 AssemblerType::linkCall( m_code, call.m_jmp, reinterpret_cast<void*>(function));751 AssemblerType::linkCall(code(), call.m_jmp, reinterpret_cast<void*>(function)); 691 752 #endif 692 753 } … … 695 756 void linkTailRecursive(Jump jump, FunctionSig* function) 696 757 { 697 AssemblerType::linkJump( m_code, jump.m_jmp, reinterpret_cast<void*>(function));758 AssemblerType::linkJump(code(), jump.m_jmp, reinterpret_cast<void*>(function)); 698 759 } 699 760 … … 701 762 void linkTailRecursive(JumpList list, FunctionSig* function) 702 763 { 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 } 764 for (unsigned i = 0; i < list.m_jumps.size(); ++i) 765 AssemblerType::linkJump(code(), list.m_jumps[i].m_jmp, reinterpret_cast<void*>(function)); 706 766 } 707 767 708 768 void link(Jump jump, CodeLocationLabel label) 709 769 { 710 AssemblerType::linkJump( m_code, jump.m_jmp, label.m_location);770 AssemblerType::linkJump(code(), jump.m_jmp, label.m_location); 711 771 } 712 772 … … 714 774 { 715 775 for (unsigned i = 0; i < list.m_jumps.size(); ++i) 716 AssemblerType::linkJump( m_code, list.m_jumps[i].m_jmp, label.m_location);776 AssemblerType::linkJump(code(), list.m_jumps[i].m_jmp, label.m_location); 717 777 } 718 778 719 779 void patch(DataLabelPtr label, void* value) 720 780 { 721 AssemblerType::patchAddress(m_code, label.m_label, value); 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()); 722 787 } 723 788 … … 728 793 ASSERT(call.isFlagSet(Call::Linkable)); 729 794 ASSERT(!call.isFlagSet(Call::Near)); 730 return CodeLocationCall(AssemblerType::getRelocatedAddress( m_code, call.m_jmp));795 return CodeLocationCall(AssemblerType::getRelocatedAddress(code(), call.m_jmp)); 731 796 } 732 797 … … 735 800 ASSERT(call.isFlagSet(Call::Linkable)); 736 801 ASSERT(call.isFlagSet(Call::Near)); 737 return CodeLocationNearCall(AssemblerType::getRelocatedAddress( m_code, call.m_jmp));802 return CodeLocationNearCall(AssemblerType::getRelocatedAddress(code(), call.m_jmp)); 738 803 } 739 804 740 805 CodeLocationLabel locationOf(Label label) 741 806 { 742 return CodeLocationLabel(AssemblerType::getRelocatedAddress( m_code, label.m_label));807 return CodeLocationLabel(AssemblerType::getRelocatedAddress(code(), label.m_label)); 743 808 } 744 809 745 810 CodeLocationDataLabelPtr locationOf(DataLabelPtr label) 746 811 { 747 return CodeLocationDataLabelPtr(AssemblerType::getRelocatedAddress( m_code, label.m_label));812 return CodeLocationDataLabelPtr(AssemblerType::getRelocatedAddress(code(), label.m_label)); 748 813 } 749 814 750 815 CodeLocationDataLabel32 locationOf(DataLabel32 label) 751 816 { 752 return CodeLocationDataLabel32(AssemblerType::getRelocatedAddress( m_code, label.m_label));817 return CodeLocationDataLabel32(AssemblerType::getRelocatedAddress(code(), label.m_label)); 753 818 } 754 819 … … 760 825 } 761 826 762 private: 763 void* m_code; 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 764 864 }; 765 865 … … 770 870 { 771 871 return m_assembler.size(); 772 }773 774 void* copyCode(ExecutablePool* allocator)775 {776 return m_assembler.executableCopy(allocator);777 872 } 778 873
Note:
See TracChangeset
for help on using the changeset viewer.