757 }
758
759 static void pass_arg1(MacroAssembler* masm, Register arg) {
760 if (c_rarg1 != arg ) {
761 masm->mov(c_rarg1, arg);
762 }
763 }
764
765 static void pass_arg2(MacroAssembler* masm, Register arg) {
766 if (c_rarg2 != arg ) {
767 masm->mov(c_rarg2, arg);
768 }
769 }
770
771 static void pass_arg3(MacroAssembler* masm, Register arg) {
772 if (c_rarg3 != arg ) {
773 masm->mov(c_rarg3, arg);
774 }
775 }
776
777 static bool is_preemptable(address entry_point) {
778 return entry_point == CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter);
779 }
780
781 void MacroAssembler::call_VM_base(Register oop_result,
782 Register java_thread,
783 Register last_java_sp,
784 address entry_point,
785 int number_of_arguments,
786 bool check_exceptions) {
787 // determine java_thread register
788 if (!java_thread->is_valid()) {
789 java_thread = rthread;
790 }
791
792 // determine last_java_sp register
793 if (!last_java_sp->is_valid()) {
794 last_java_sp = esp;
795 }
796
797 // debugging support
798 assert(number_of_arguments >= 0 , "cannot have negative number of arguments");
799 assert(java_thread == rthread, "unexpected register");
800 #ifdef ASSERT
801 // TraceBytecodes does not use r12 but saves it over the call, so don't verify
802 // if ((UseCompressedOops || UseCompressedClassPointers) && !TraceBytecodes) verify_heapbase("call_VM_base: heap base corrupted?");
803 #endif // ASSERT
804
805 assert(java_thread != oop_result , "cannot use the same register for java_thread & oop_result");
806 assert(java_thread != last_java_sp, "cannot use the same register for java_thread & last_java_sp");
807
808 // push java thread (becomes first argument of C function)
809
810 mov(c_rarg0, java_thread);
811
812 // set last Java frame before call
813 assert(last_java_sp != rfp, "can't use rfp");
814
815 Label l;
816 if (is_preemptable(entry_point)) {
817 // skip setting last_pc since we already set it to desired value.
818 set_last_Java_frame(last_java_sp, rfp, noreg, rscratch1);
819 } else {
820 set_last_Java_frame(last_java_sp, rfp, l, rscratch1);
821 }
822
823 // do the call, remove parameters
824 MacroAssembler::call_VM_leaf_base(entry_point, number_of_arguments, &l);
825
826 // lr could be poisoned with PAC signature during throw_pending_exception
827 // if it was tail-call optimized by compiler, since lr is not callee-saved
828 // reload it with proper value
829 adr(lr, l);
830
831 // reset last Java frame
832 // Only interpreter should have to clear fp
833 reset_last_Java_frame(true);
834
835 // C++ interp handles this in the interpreter
836 check_and_handle_popframe(java_thread);
837 check_and_handle_earlyret(java_thread);
838
839 if (check_exceptions) {
840 // check for pending exceptions (java_thread is set upon return)
841 ldr(rscratch1, Address(java_thread, in_bytes(Thread::pending_exception_offset())));
842 Label ok;
843 cbz(rscratch1, ok);
844 lea(rscratch1, RuntimeAddress(StubRoutines::forward_exception_entry()));
845 br(rscratch1);
846 bind(ok);
847 }
848
849 // get oop result if there is one and reset the value in the thread
850 if (oop_result->is_valid()) {
851 get_vm_result_oop(oop_result, java_thread);
852 }
853 }
854
855 void MacroAssembler::call_VM_helper(Register oop_result, address entry_point, int number_of_arguments, bool check_exceptions) {
856 call_VM_base(oop_result, noreg, noreg, entry_point, number_of_arguments, check_exceptions);
857 }
858
859 // Check the entry target is always reachable from any branch.
860 static bool is_always_within_branch_range(Address entry) {
861 if (AOTCodeCache::is_on_for_dump()) {
862 return false;
863 }
864 const address target = entry.target();
865
866 if (!CodeCache::contains(target)) {
867 // We always use trampolines for callees outside CodeCache.
868 assert(entry.rspec().type() == relocInfo::runtime_call_type, "non-runtime call of an external target");
869 return false;
870 }
871
872 if (!MacroAssembler::far_branches()) {
873 return true;
874 }
875
876 if (entry.rspec().type() == relocInfo::runtime_call_type) {
1094 address entry_point,
1095 Register arg_1,
1096 Register arg_2,
1097 Register arg_3,
1098 bool check_exceptions) {
1099 assert_different_registers(arg_1, c_rarg2, c_rarg3);
1100 assert_different_registers(arg_2, c_rarg3);
1101 pass_arg3(this, arg_3);
1102
1103 pass_arg2(this, arg_2);
1104
1105 pass_arg1(this, arg_1);
1106 call_VM_helper(oop_result, entry_point, 3, check_exceptions);
1107 }
1108
1109 void MacroAssembler::call_VM(Register oop_result,
1110 Register last_java_sp,
1111 address entry_point,
1112 int number_of_arguments,
1113 bool check_exceptions) {
1114 call_VM_base(oop_result, rthread, last_java_sp, entry_point, number_of_arguments, check_exceptions);
1115 }
1116
1117 void MacroAssembler::call_VM(Register oop_result,
1118 Register last_java_sp,
1119 address entry_point,
1120 Register arg_1,
1121 bool check_exceptions) {
1122 pass_arg1(this, arg_1);
1123 call_VM(oop_result, last_java_sp, entry_point, 1, check_exceptions);
1124 }
1125
1126 void MacroAssembler::call_VM(Register oop_result,
1127 Register last_java_sp,
1128 address entry_point,
1129 Register arg_1,
1130 Register arg_2,
1131 bool check_exceptions) {
1132
1133 assert_different_registers(arg_1, c_rarg2);
1134 pass_arg2(this, arg_2);
|
757 }
758
759 static void pass_arg1(MacroAssembler* masm, Register arg) {
760 if (c_rarg1 != arg ) {
761 masm->mov(c_rarg1, arg);
762 }
763 }
764
765 static void pass_arg2(MacroAssembler* masm, Register arg) {
766 if (c_rarg2 != arg ) {
767 masm->mov(c_rarg2, arg);
768 }
769 }
770
771 static void pass_arg3(MacroAssembler* masm, Register arg) {
772 if (c_rarg3 != arg ) {
773 masm->mov(c_rarg3, arg);
774 }
775 }
776
777 void MacroAssembler::call_VM_base(Register oop_result,
778 Register java_thread,
779 Register last_java_sp,
780 Label* return_pc,
781 address entry_point,
782 int number_of_arguments,
783 bool check_exceptions) {
784 // determine java_thread register
785 if (!java_thread->is_valid()) {
786 java_thread = rthread;
787 }
788
789 // determine last_java_sp register
790 if (!last_java_sp->is_valid()) {
791 last_java_sp = esp;
792 }
793
794 // debugging support
795 assert(number_of_arguments >= 0 , "cannot have negative number of arguments");
796 assert(java_thread == rthread, "unexpected register");
797 #ifdef ASSERT
798 // TraceBytecodes does not use r12 but saves it over the call, so don't verify
799 // if ((UseCompressedOops || UseCompressedClassPointers) && !TraceBytecodes) verify_heapbase("call_VM_base: heap base corrupted?");
800 #endif // ASSERT
801
802 assert(java_thread != oop_result , "cannot use the same register for java_thread & oop_result");
803 assert(java_thread != last_java_sp, "cannot use the same register for java_thread & last_java_sp");
804
805 // push java thread (becomes first argument of C function)
806
807 mov(c_rarg0, java_thread);
808
809 // set last Java frame before call
810 assert(last_java_sp != rfp, "can't use rfp");
811
812 Label l;
813 set_last_Java_frame(last_java_sp, rfp, return_pc != nullptr ? *return_pc : l, rscratch1);
814
815 // do the call, remove parameters
816 MacroAssembler::call_VM_leaf_base(entry_point, number_of_arguments, &l);
817
818 // lr could be poisoned with PAC signature during throw_pending_exception
819 // if it was tail-call optimized by compiler, since lr is not callee-saved
820 // reload it with proper value
821 adr(lr, l);
822
823 // reset last Java frame
824 // Only interpreter should have to clear fp
825 reset_last_Java_frame(true);
826
827 // C++ interp handles this in the interpreter
828 check_and_handle_popframe(java_thread);
829 check_and_handle_earlyret(java_thread);
830
831 if (check_exceptions) {
832 // check for pending exceptions (java_thread is set upon return)
833 ldr(rscratch1, Address(java_thread, in_bytes(Thread::pending_exception_offset())));
834 Label ok;
835 cbz(rscratch1, ok);
836 lea(rscratch1, RuntimeAddress(StubRoutines::forward_exception_entry()));
837 br(rscratch1);
838 bind(ok);
839 }
840
841 // get oop result if there is one and reset the value in the thread
842 if (oop_result->is_valid()) {
843 get_vm_result_oop(oop_result, java_thread);
844 }
845 }
846
847 void MacroAssembler::call_VM_helper(Register oop_result, address entry_point, int number_of_arguments, bool check_exceptions) {
848 call_VM_base(oop_result, noreg, noreg, nullptr, entry_point, number_of_arguments, check_exceptions);
849 }
850
851 // Check the entry target is always reachable from any branch.
852 static bool is_always_within_branch_range(Address entry) {
853 if (AOTCodeCache::is_on_for_dump()) {
854 return false;
855 }
856 const address target = entry.target();
857
858 if (!CodeCache::contains(target)) {
859 // We always use trampolines for callees outside CodeCache.
860 assert(entry.rspec().type() == relocInfo::runtime_call_type, "non-runtime call of an external target");
861 return false;
862 }
863
864 if (!MacroAssembler::far_branches()) {
865 return true;
866 }
867
868 if (entry.rspec().type() == relocInfo::runtime_call_type) {
1086 address entry_point,
1087 Register arg_1,
1088 Register arg_2,
1089 Register arg_3,
1090 bool check_exceptions) {
1091 assert_different_registers(arg_1, c_rarg2, c_rarg3);
1092 assert_different_registers(arg_2, c_rarg3);
1093 pass_arg3(this, arg_3);
1094
1095 pass_arg2(this, arg_2);
1096
1097 pass_arg1(this, arg_1);
1098 call_VM_helper(oop_result, entry_point, 3, check_exceptions);
1099 }
1100
1101 void MacroAssembler::call_VM(Register oop_result,
1102 Register last_java_sp,
1103 address entry_point,
1104 int number_of_arguments,
1105 bool check_exceptions) {
1106 call_VM_base(oop_result, rthread, last_java_sp, nullptr, entry_point, number_of_arguments, check_exceptions);
1107 }
1108
1109 void MacroAssembler::call_VM(Register oop_result,
1110 Register last_java_sp,
1111 address entry_point,
1112 Register arg_1,
1113 bool check_exceptions) {
1114 pass_arg1(this, arg_1);
1115 call_VM(oop_result, last_java_sp, entry_point, 1, check_exceptions);
1116 }
1117
1118 void MacroAssembler::call_VM(Register oop_result,
1119 Register last_java_sp,
1120 address entry_point,
1121 Register arg_1,
1122 Register arg_2,
1123 bool check_exceptions) {
1124
1125 assert_different_registers(arg_1, c_rarg2);
1126 pass_arg2(this, arg_2);
|