689 } else {
690 assert(sig_bt[i] == T_DOUBLE || sig_bt[i] == T_LONG, "wrong type");
691 move_c2i_double(masm, r_1->as_XMMRegister(), st_off);
692 }
693 }
694 }
695
696 // Schedule the branch target address early.
697 __ movptr(rcx, Address(rbx, in_bytes(Method::interpreter_entry_offset())));
698 // And repush original return address
699 __ push(rax);
700 __ jmp(rcx);
701 }
702
703
704 static void move_i2c_double(MacroAssembler *masm, XMMRegister r, Register saved_sp, int ld_off) {
705 int next_val_off = ld_off - Interpreter::stackElementSize;
706 __ movdbl(r, Address(saved_sp, next_val_off));
707 }
708
709 static void range_check(MacroAssembler* masm, Register pc_reg, Register temp_reg,
710 address code_start, address code_end,
711 Label& L_ok) {
712 Label L_fail;
713 __ lea(temp_reg, AddressLiteral(code_start, relocInfo::none));
714 __ cmpptr(pc_reg, temp_reg);
715 __ jcc(Assembler::belowEqual, L_fail);
716 __ lea(temp_reg, AddressLiteral(code_end, relocInfo::none));
717 __ cmpptr(pc_reg, temp_reg);
718 __ jcc(Assembler::below, L_ok);
719 __ bind(L_fail);
720 }
721
722 void SharedRuntime::gen_i2c_adapter(MacroAssembler *masm,
723 int total_args_passed,
724 int comp_args_on_stack,
725 const BasicType *sig_bt,
726 const VMRegPair *regs) {
727 // Note: rsi contains the senderSP on entry. We must preserve it since
728 // we may do a i2c -> c2i transition if we lose a race where compiled
729 // code goes non-entrant while we get args ready.
730
731 // Adapters can be frameless because they do not require the caller
732 // to perform additional cleanup work, such as correcting the stack pointer.
733 // An i2c adapter is frameless because the *caller* frame, which is interpreted,
734 // routinely repairs its own stack pointer (from interpreter_frame_last_sp),
735 // even if a callee has modified the stack pointer.
736 // A c2i adapter is frameless because the *callee* frame, which is interpreted,
737 // routinely repairs its caller's stack pointer (from sender_sp, which is set
738 // up via the senderSP register).
739 // In other words, if *either* the caller or callee is interpreted, we can
740 // get the stack pointer repaired after a call.
741 // This is why c2i and i2c adapters cannot be indefinitely composed.
742 // In particular, if a c2i adapter were to somehow call an i2c adapter,
743 // both caller and callee would be compiled methods, and neither would
744 // clean up the stack pointer changes performed by the two adapters.
745 // If this happens, control eventually transfers back to the compiled
746 // caller, but with an uncorrected stack, causing delayed havoc.
747
748 // Pick up the return address
749 __ movptr(rax, Address(rsp, 0));
750
751 if (VerifyAdapterCalls &&
752 (Interpreter::code() != nullptr || StubRoutines::final_stubs_code() != nullptr)) {
753 // So, let's test for cascading c2i/i2c adapters right now.
754 // assert(Interpreter::contains($return_addr) ||
755 // StubRoutines::contains($return_addr),
756 // "i2c adapter must return to an interpreter frame");
757 __ block_comment("verify_i2c { ");
758 Label L_ok;
759 if (Interpreter::code() != nullptr) {
760 range_check(masm, rax, rdi,
761 Interpreter::code()->code_start(), Interpreter::code()->code_end(),
762 L_ok);
763 }
764 if (StubRoutines::initial_stubs_code() != nullptr) {
765 range_check(masm, rax, rdi,
766 StubRoutines::initial_stubs_code()->code_begin(),
767 StubRoutines::initial_stubs_code()->code_end(),
768 L_ok);
769 }
770 if (StubRoutines::final_stubs_code() != nullptr) {
771 range_check(masm, rax, rdi,
772 StubRoutines::final_stubs_code()->code_begin(),
773 StubRoutines::final_stubs_code()->code_end(),
774 L_ok);
775 }
776 const char* msg = "i2c adapter must return to an interpreter frame";
777 __ block_comment(msg);
778 __ stop(msg);
779 __ bind(L_ok);
780 __ block_comment("} verify_i2ce ");
781 }
782
783 // Must preserve original SP for loading incoming arguments because
784 // we need to align the outgoing SP for compiled code.
785 __ movptr(rdi, rsp);
786
787 // Cut-out for having no stack args. Since up to 2 int/oop args are passed
788 // in registers, we will occasionally have no stack args.
789 int comp_words_on_stack = 0;
790 if (comp_args_on_stack) {
791 // Sig words on the stack are greater-than VMRegImpl::stack0. Those in
792 // registers are below. By subtracting stack0, we either get a negative
793 // number (all values in registers) or the maximum stack slot accessed.
794 // int comp_args_on_stack = VMRegImpl::reg2stack(max_arg);
795 // Convert 4-byte stack slots to words.
796 comp_words_on_stack = align_up(comp_args_on_stack*4, wordSize)>>LogBytesPerWord;
797 // Round up to miminum stack alignment, in wordSize
798 comp_words_on_stack = align_up(comp_words_on_stack, 2);
799 __ subptr(rsp, comp_words_on_stack * wordSize);
800 }
801
802 // Align the outgoing SP
910 // caller frame will look interpreted and arguments are now
911 // "compiled" so it is much better to make this transition
912 // invisible to the stack walking code. Unfortunately if
913 // we try and find the callee by normal means a safepoint
914 // is possible. So we stash the desired callee in the thread
915 // and the vm will find there should this case occur.
916
917 __ get_thread(rax);
918 __ movptr(Address(rax, JavaThread::callee_target_offset()), rbx);
919
920 // move Method* to rax, in case we end up in an c2i adapter.
921 // the c2i adapters expect Method* in rax, (c2) because c2's
922 // resolve stubs return the result (the method) in rax,.
923 // I'd love to fix this.
924 __ mov(rax, rbx);
925
926 __ jmp(rdi);
927 }
928
929 // ---------------------------------------------------------------
930 AdapterHandlerEntry* SharedRuntime::generate_i2c2i_adapters(MacroAssembler *masm,
931 int total_args_passed,
932 int comp_args_on_stack,
933 const BasicType *sig_bt,
934 const VMRegPair *regs,
935 AdapterFingerPrint* fingerprint) {
936 address i2c_entry = __ pc();
937
938 gen_i2c_adapter(masm, total_args_passed, comp_args_on_stack, sig_bt, regs);
939
940 // -------------------------------------------------------------------------
941 // Generate a C2I adapter. On entry we know rbx, holds the Method* during calls
942 // to the interpreter. The args start out packed in the compiled layout. They
943 // need to be unpacked into the interpreter layout. This will almost always
944 // require some stack space. We grow the current (compiled) stack, then repack
945 // the args. We finally end in a jump to the generic interpreter entry point.
946 // On exit from the interpreter, the interpreter will restore our SP (lest the
947 // compiled code, which relies solely on SP and not EBP, get sick).
948
949 address c2i_unverified_entry = __ pc();
950 Label skip_fixup;
951
952 Register data = rax;
953 Register receiver = rcx;
954 Register temp = rbx;
955
956 {
957 __ ic_check(1 /* end_alignment */);
958 __ movptr(rbx, Address(data, CompiledICData::speculated_method_offset()));
959 // Method might have been compiled since the call site was patched to
960 // interpreted if that is the case treat it as a miss so we can get
961 // the call site corrected.
962 __ cmpptr(Address(rbx, in_bytes(Method::code_offset())), NULL_WORD);
963 __ jcc(Assembler::equal, skip_fixup);
964 }
965
966 address c2i_entry = __ pc();
967
968 BarrierSetAssembler* bs = BarrierSet::barrier_set()->barrier_set_assembler();
969 bs->c2i_entry_barrier(masm);
970
971 gen_c2i_adapter(masm, total_args_passed, comp_args_on_stack, sig_bt, regs, skip_fixup);
972
973 return AdapterHandlerLibrary::new_entry(fingerprint, i2c_entry, c2i_entry, c2i_unverified_entry);
974 }
975
976 int SharedRuntime::c_calling_convention(const BasicType *sig_bt,
977 VMRegPair *regs,
978 int total_args_passed) {
979
980 // We return the amount of VMRegImpl stack slots we need to reserve for all
981 // the arguments NOT counting out_preserve_stack_slots.
982
983 uint stack = 0; // All arguments on stack
984
985 for( int i = 0; i < total_args_passed; i++) {
986 // From the type and the argument number (count) compute the location
987 switch( sig_bt[i] ) {
988 case T_BOOLEAN:
989 case T_CHAR:
990 case T_FLOAT:
991 case T_BYTE:
992 case T_SHORT:
993 case T_INT:
|
689 } else {
690 assert(sig_bt[i] == T_DOUBLE || sig_bt[i] == T_LONG, "wrong type");
691 move_c2i_double(masm, r_1->as_XMMRegister(), st_off);
692 }
693 }
694 }
695
696 // Schedule the branch target address early.
697 __ movptr(rcx, Address(rbx, in_bytes(Method::interpreter_entry_offset())));
698 // And repush original return address
699 __ push(rax);
700 __ jmp(rcx);
701 }
702
703
704 static void move_i2c_double(MacroAssembler *masm, XMMRegister r, Register saved_sp, int ld_off) {
705 int next_val_off = ld_off - Interpreter::stackElementSize;
706 __ movdbl(r, Address(saved_sp, next_val_off));
707 }
708
709 void SharedRuntime::gen_i2c_adapter(MacroAssembler *masm,
710 int total_args_passed,
711 int comp_args_on_stack,
712 const BasicType *sig_bt,
713 const VMRegPair *regs) {
714 // Note: rsi contains the senderSP on entry. We must preserve it since
715 // we may do a i2c -> c2i transition if we lose a race where compiled
716 // code goes non-entrant while we get args ready.
717
718 // Adapters can be frameless because they do not require the caller
719 // to perform additional cleanup work, such as correcting the stack pointer.
720 // An i2c adapter is frameless because the *caller* frame, which is interpreted,
721 // routinely repairs its own stack pointer (from interpreter_frame_last_sp),
722 // even if a callee has modified the stack pointer.
723 // A c2i adapter is frameless because the *callee* frame, which is interpreted,
724 // routinely repairs its caller's stack pointer (from sender_sp, which is set
725 // up via the senderSP register).
726 // In other words, if *either* the caller or callee is interpreted, we can
727 // get the stack pointer repaired after a call.
728 // This is why c2i and i2c adapters cannot be indefinitely composed.
729 // In particular, if a c2i adapter were to somehow call an i2c adapter,
730 // both caller and callee would be compiled methods, and neither would
731 // clean up the stack pointer changes performed by the two adapters.
732 // If this happens, control eventually transfers back to the compiled
733 // caller, but with an uncorrected stack, causing delayed havoc.
734
735 // Pick up the return address
736 __ movptr(rax, Address(rsp, 0));
737
738 // Must preserve original SP for loading incoming arguments because
739 // we need to align the outgoing SP for compiled code.
740 __ movptr(rdi, rsp);
741
742 // Cut-out for having no stack args. Since up to 2 int/oop args are passed
743 // in registers, we will occasionally have no stack args.
744 int comp_words_on_stack = 0;
745 if (comp_args_on_stack) {
746 // Sig words on the stack are greater-than VMRegImpl::stack0. Those in
747 // registers are below. By subtracting stack0, we either get a negative
748 // number (all values in registers) or the maximum stack slot accessed.
749 // int comp_args_on_stack = VMRegImpl::reg2stack(max_arg);
750 // Convert 4-byte stack slots to words.
751 comp_words_on_stack = align_up(comp_args_on_stack*4, wordSize)>>LogBytesPerWord;
752 // Round up to miminum stack alignment, in wordSize
753 comp_words_on_stack = align_up(comp_words_on_stack, 2);
754 __ subptr(rsp, comp_words_on_stack * wordSize);
755 }
756
757 // Align the outgoing SP
865 // caller frame will look interpreted and arguments are now
866 // "compiled" so it is much better to make this transition
867 // invisible to the stack walking code. Unfortunately if
868 // we try and find the callee by normal means a safepoint
869 // is possible. So we stash the desired callee in the thread
870 // and the vm will find there should this case occur.
871
872 __ get_thread(rax);
873 __ movptr(Address(rax, JavaThread::callee_target_offset()), rbx);
874
875 // move Method* to rax, in case we end up in an c2i adapter.
876 // the c2i adapters expect Method* in rax, (c2) because c2's
877 // resolve stubs return the result (the method) in rax,.
878 // I'd love to fix this.
879 __ mov(rax, rbx);
880
881 __ jmp(rdi);
882 }
883
884 // ---------------------------------------------------------------
885 void SharedRuntime::generate_i2c2i_adapters(MacroAssembler *masm,
886 int total_args_passed,
887 int comp_args_on_stack,
888 const BasicType *sig_bt,
889 const VMRegPair *regs,
890 AdapterHandlerEntry* handler) {
891 address i2c_entry = __ pc();
892
893 gen_i2c_adapter(masm, total_args_passed, comp_args_on_stack, sig_bt, regs);
894
895 // -------------------------------------------------------------------------
896 // Generate a C2I adapter. On entry we know rbx, holds the Method* during calls
897 // to the interpreter. The args start out packed in the compiled layout. They
898 // need to be unpacked into the interpreter layout. This will almost always
899 // require some stack space. We grow the current (compiled) stack, then repack
900 // the args. We finally end in a jump to the generic interpreter entry point.
901 // On exit from the interpreter, the interpreter will restore our SP (lest the
902 // compiled code, which relies solely on SP and not EBP, get sick).
903
904 address c2i_unverified_entry = __ pc();
905 Label skip_fixup;
906
907 Register data = rax;
908 Register receiver = rcx;
909 Register temp = rbx;
910
911 {
912 __ ic_check(1 /* end_alignment */);
913 __ movptr(rbx, Address(data, CompiledICData::speculated_method_offset()));
914 // Method might have been compiled since the call site was patched to
915 // interpreted if that is the case treat it as a miss so we can get
916 // the call site corrected.
917 __ cmpptr(Address(rbx, in_bytes(Method::code_offset())), NULL_WORD);
918 __ jcc(Assembler::equal, skip_fixup);
919 }
920
921 address c2i_entry = __ pc();
922
923 BarrierSetAssembler* bs = BarrierSet::barrier_set()->barrier_set_assembler();
924 bs->c2i_entry_barrier(masm);
925
926 gen_c2i_adapter(masm, total_args_passed, comp_args_on_stack, sig_bt, regs, skip_fixup);
927
928 handler->set_entry_points(i2c_entry, c2i_entry, c2i_unverified_entry, nullptr);
929 return;
930 }
931
932 int SharedRuntime::c_calling_convention(const BasicType *sig_bt,
933 VMRegPair *regs,
934 int total_args_passed) {
935
936 // We return the amount of VMRegImpl stack slots we need to reserve for all
937 // the arguments NOT counting out_preserve_stack_slots.
938
939 uint stack = 0; // All arguments on stack
940
941 for( int i = 0; i < total_args_passed; i++) {
942 // From the type and the argument number (count) compute the location
943 switch( sig_bt[i] ) {
944 case T_BOOLEAN:
945 case T_CHAR:
946 case T_FLOAT:
947 case T_BYTE:
948 case T_SHORT:
949 case T_INT:
|