< prev index next >

src/hotspot/cpu/x86/sharedRuntime_x86_64.cpp

Print this page

 659   // Allocate argument register save area
 660   if (frame::arg_reg_save_area_bytes != 0) {
 661     __ subptr(rsp, frame::arg_reg_save_area_bytes);
 662   }
 663   __ mov(c_rarg0, rbx);
 664   __ mov(c_rarg1, rax);
 665   __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, SharedRuntime::fixup_callers_callsite)));
 666 
 667   // De-allocate argument register save area
 668   if (frame::arg_reg_save_area_bytes != 0) {
 669     __ addptr(rsp, frame::arg_reg_save_area_bytes);
 670   }
 671 
 672   __ vzeroupper();
 673   __ pop_CPU_state();
 674   // restore sp
 675   __ mov(rsp, r13);
 676   __ bind(L);
 677 }
 678 
 679 
 680 static void gen_c2i_adapter(MacroAssembler *masm,
 681                             int total_args_passed,
 682                             int comp_args_on_stack,
 683                             const BasicType *sig_bt,
 684                             const VMRegPair *regs,
 685                             Label& skip_fixup) {
 686   // Before we get into the guts of the C2I adapter, see if we should be here
 687   // at all.  We've come from compiled code and are attempting to jump to the
 688   // interpreter, which means the caller made a static call to get here
 689   // (vcalls always get a compiled target if there is one).  Check for a
 690   // compiled target.  If there is one, we need to patch the caller's call.
 691   patch_callers_callsite(masm);
 692 
 693   __ bind(skip_fixup);
 694 
 695   // Since all args are passed on the stack, total_args_passed *
 696   // Interpreter::stackElementSize is the space we need.
 697 
 698   assert(total_args_passed >= 0, "total_args_passed is %d", total_args_passed);
 699 

 810       assert(r_1->is_XMMRegister(), "");
 811       if (!r_2->is_valid()) {
 812         // only a float use just part of the slot
 813         __ movflt(Address(rsp, st_off), r_1->as_XMMRegister());
 814       } else {
 815 #ifdef ASSERT
 816         // Overwrite the unused slot with known junk
 817         __ mov64(rax, CONST64(0xdeadffffdeadaaac));
 818         __ movptr(Address(rsp, st_off), rax);
 819 #endif /* ASSERT */
 820         __ movdbl(Address(rsp, next_off), r_1->as_XMMRegister());
 821       }
 822     }
 823   }
 824 
 825   // Schedule the branch target address early.
 826   __ movptr(rcx, Address(rbx, in_bytes(Method::interpreter_entry_offset())));
 827   __ jmp(rcx);
 828 }
 829 
 830 static void range_check(MacroAssembler* masm, Register pc_reg, Register temp_reg,
 831                         address code_start, address code_end,
 832                         Label& L_ok) {
 833   Label L_fail;
 834   __ lea(temp_reg, AddressLiteral(code_start, relocInfo::none));
 835   __ cmpptr(pc_reg, temp_reg);
 836   __ jcc(Assembler::belowEqual, L_fail);
 837   __ lea(temp_reg, AddressLiteral(code_end, relocInfo::none));
 838   __ cmpptr(pc_reg, temp_reg);
 839   __ jcc(Assembler::below, L_ok);
 840   __ bind(L_fail);
 841 }
 842 
 843 void SharedRuntime::gen_i2c_adapter(MacroAssembler *masm,
 844                                     int total_args_passed,
 845                                     int comp_args_on_stack,
 846                                     const BasicType *sig_bt,
 847                                     const VMRegPair *regs) {
 848 
 849   // Note: r13 contains the senderSP on entry. We must preserve it since
 850   // we may do a i2c -> c2i transition if we lose a race where compiled
 851   // code goes non-entrant while we get args ready.
 852   // In addition we use r13 to locate all the interpreter args as
 853   // we must align the stack to 16 bytes on an i2c entry else we
 854   // lose alignment we expect in all compiled code and register
 855   // save code can segv when fxsave instructions find improperly
 856   // aligned stack pointer.
 857 
 858   // Adapters can be frameless because they do not require the caller
 859   // to perform additional cleanup work, such as correcting the stack pointer.
 860   // An i2c adapter is frameless because the *caller* frame, which is interpreted,
 861   // routinely repairs its own stack pointer (from interpreter_frame_last_sp),
 862   // even if a callee has modified the stack pointer.
 863   // A c2i adapter is frameless because the *callee* frame, which is interpreted,
 864   // routinely repairs its caller's stack pointer (from sender_sp, which is set
 865   // up via the senderSP register).
 866   // In other words, if *either* the caller or callee is interpreted, we can
 867   // get the stack pointer repaired after a call.
 868   // This is why c2i and i2c adapters cannot be indefinitely composed.
 869   // In particular, if a c2i adapter were to somehow call an i2c adapter,
 870   // both caller and callee would be compiled methods, and neither would
 871   // clean up the stack pointer changes performed by the two adapters.
 872   // If this happens, control eventually transfers back to the compiled
 873   // caller, but with an uncorrected stack, causing delayed havoc.
 874 
 875   if (VerifyAdapterCalls &&
 876       (Interpreter::code() != nullptr || StubRoutines::final_stubs_code() != nullptr)) {
 877     // So, let's test for cascading c2i/i2c adapters right now.
 878     //  assert(Interpreter::contains($return_addr) ||
 879     //         StubRoutines::contains($return_addr),
 880     //         "i2c adapter must return to an interpreter frame");
 881     __ block_comment("verify_i2c { ");
 882     // Pick up the return address
 883     __ movptr(rax, Address(rsp, 0));
 884     Label L_ok;
 885     if (Interpreter::code() != nullptr) {
 886       range_check(masm, rax, r11,
 887                   Interpreter::code()->code_start(),
 888                   Interpreter::code()->code_end(),
 889                   L_ok);
 890     }
 891     if (StubRoutines::initial_stubs_code() != nullptr) {
 892       range_check(masm, rax, r11,
 893                   StubRoutines::initial_stubs_code()->code_begin(),
 894                   StubRoutines::initial_stubs_code()->code_end(),
 895                   L_ok);
 896     }
 897     if (StubRoutines::final_stubs_code() != nullptr) {
 898       range_check(masm, rax, r11,
 899                   StubRoutines::final_stubs_code()->code_begin(),
 900                   StubRoutines::final_stubs_code()->code_end(),
 901                   L_ok);
 902     }
 903     const char* msg = "i2c adapter must return to an interpreter frame";
 904     __ block_comment(msg);
 905     __ stop(msg);
 906     __ bind(L_ok);
 907     __ block_comment("} verify_i2ce ");
 908   }
 909 
 910   // Must preserve original SP for loading incoming arguments because
 911   // we need to align the outgoing SP for compiled code.
 912   __ movptr(r11, rsp);
 913 
 914   // Pick up the return address
 915   __ pop(rax);
 916 
 917   // Convert 4-byte c2 stack slots to words.
 918   int comp_words_on_stack = align_up(comp_args_on_stack*VMRegImpl::stack_slot_size, wordSize)>>LogBytesPerWord;
 919 
 920   if (comp_args_on_stack) {
 921     __ subptr(rsp, comp_words_on_stack * wordSize);
 922   }
 923 
 924   // Ensure compiled code always sees stack at proper alignment
 925   __ andptr(rsp, -16);
 926 
 927   // push the return address and misalign the stack that youngest frame always sees
 928   // as far as the placement of the call instruction
 929   __ push(rax);

1034   // 6243940 We might end up in handle_wrong_method if
1035   // the callee is deoptimized as we race thru here. If that
1036   // happens we don't want to take a safepoint because the
1037   // caller frame will look interpreted and arguments are now
1038   // "compiled" so it is much better to make this transition
1039   // invisible to the stack walking code. Unfortunately if
1040   // we try and find the callee by normal means a safepoint
1041   // is possible. So we stash the desired callee in the thread
1042   // and the vm will find there should this case occur.
1043 
1044   __ movptr(Address(r15_thread, JavaThread::callee_target_offset()), rbx);
1045 
1046   // put Method* where a c2i would expect should we end up there
1047   // only needed because eof c2 resolve stubs return Method* as a result in
1048   // rax
1049   __ mov(rax, rbx);
1050   __ jmp(r11);
1051 }
1052 
1053 // ---------------------------------------------------------------
1054 AdapterHandlerEntry* SharedRuntime::generate_i2c2i_adapters(MacroAssembler *masm,
1055                                                             int total_args_passed,
1056                                                             int comp_args_on_stack,
1057                                                             const BasicType *sig_bt,
1058                                                             const VMRegPair *regs,
1059                                                             AdapterFingerPrint* fingerprint) {
1060   address i2c_entry = __ pc();
1061 
1062   gen_i2c_adapter(masm, total_args_passed, comp_args_on_stack, sig_bt, regs);
1063 
1064   // -------------------------------------------------------------------------
1065   // Generate a C2I adapter.  On entry we know rbx holds the Method* during calls
1066   // to the interpreter.  The args start out packed in the compiled layout.  They
1067   // need to be unpacked into the interpreter layout.  This will almost always
1068   // require some stack space.  We grow the current (compiled) stack, then repack
1069   // the args.  We  finally end in a jump to the generic interpreter entry point.
1070   // On exit from the interpreter, the interpreter will restore our SP (lest the
1071   // compiled code, which relies solely on SP and not RBP, get sick).
1072 
1073   address c2i_unverified_entry = __ pc();
1074   Label skip_fixup;
1075 
1076   Register data = rax;
1077   Register receiver = j_rarg0;
1078   Register temp = rbx;
1079 

1101       __ load_unsigned_short(flags, Address(method, Method::access_flags_offset()));
1102       __ testl(flags, JVM_ACC_STATIC);
1103       __ jcc(Assembler::zero, L_skip_barrier); // non-static
1104     }
1105 
1106     Register klass = rscratch1;
1107     __ load_method_holder(klass, method);
1108     __ clinit_barrier(klass, r15_thread, &L_skip_barrier /*L_fast_path*/);
1109 
1110     __ jump(RuntimeAddress(SharedRuntime::get_handle_wrong_method_stub())); // slow path
1111 
1112     __ bind(L_skip_barrier);
1113     c2i_no_clinit_check_entry = __ pc();
1114   }
1115 
1116   BarrierSetAssembler* bs = BarrierSet::barrier_set()->barrier_set_assembler();
1117   bs->c2i_entry_barrier(masm);
1118 
1119   gen_c2i_adapter(masm, total_args_passed, comp_args_on_stack, sig_bt, regs, skip_fixup);
1120 
1121   return AdapterHandlerLibrary::new_entry(fingerprint, i2c_entry, c2i_entry, c2i_unverified_entry, c2i_no_clinit_check_entry);

1122 }
1123 
1124 int SharedRuntime::c_calling_convention(const BasicType *sig_bt,
1125                                          VMRegPair *regs,
1126                                          int total_args_passed) {
1127 
1128 // We return the amount of VMRegImpl stack slots we need to reserve for all
1129 // the arguments NOT counting out_preserve_stack_slots.
1130 
1131 // NOTE: These arrays will have to change when c1 is ported
1132 #ifdef _WIN64
1133     static const Register INT_ArgReg[Argument::n_int_register_parameters_c] = {
1134       c_rarg0, c_rarg1, c_rarg2, c_rarg3
1135     };
1136     static const XMMRegister FP_ArgReg[Argument::n_float_register_parameters_c] = {
1137       c_farg0, c_farg1, c_farg2, c_farg3
1138     };
1139 #else
1140     static const Register INT_ArgReg[Argument::n_int_register_parameters_c] = {
1141       c_rarg0, c_rarg1, c_rarg2, c_rarg3, c_rarg4, c_rarg5

 659   // Allocate argument register save area
 660   if (frame::arg_reg_save_area_bytes != 0) {
 661     __ subptr(rsp, frame::arg_reg_save_area_bytes);
 662   }
 663   __ mov(c_rarg0, rbx);
 664   __ mov(c_rarg1, rax);
 665   __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, SharedRuntime::fixup_callers_callsite)));
 666 
 667   // De-allocate argument register save area
 668   if (frame::arg_reg_save_area_bytes != 0) {
 669     __ addptr(rsp, frame::arg_reg_save_area_bytes);
 670   }
 671 
 672   __ vzeroupper();
 673   __ pop_CPU_state();
 674   // restore sp
 675   __ mov(rsp, r13);
 676   __ bind(L);
 677 }
 678 

 679 static void gen_c2i_adapter(MacroAssembler *masm,
 680                             int total_args_passed,
 681                             int comp_args_on_stack,
 682                             const BasicType *sig_bt,
 683                             const VMRegPair *regs,
 684                             Label& skip_fixup) {
 685   // Before we get into the guts of the C2I adapter, see if we should be here
 686   // at all.  We've come from compiled code and are attempting to jump to the
 687   // interpreter, which means the caller made a static call to get here
 688   // (vcalls always get a compiled target if there is one).  Check for a
 689   // compiled target.  If there is one, we need to patch the caller's call.
 690   patch_callers_callsite(masm);
 691 
 692   __ bind(skip_fixup);
 693 
 694   // Since all args are passed on the stack, total_args_passed *
 695   // Interpreter::stackElementSize is the space we need.
 696 
 697   assert(total_args_passed >= 0, "total_args_passed is %d", total_args_passed);
 698 

 809       assert(r_1->is_XMMRegister(), "");
 810       if (!r_2->is_valid()) {
 811         // only a float use just part of the slot
 812         __ movflt(Address(rsp, st_off), r_1->as_XMMRegister());
 813       } else {
 814 #ifdef ASSERT
 815         // Overwrite the unused slot with known junk
 816         __ mov64(rax, CONST64(0xdeadffffdeadaaac));
 817         __ movptr(Address(rsp, st_off), rax);
 818 #endif /* ASSERT */
 819         __ movdbl(Address(rsp, next_off), r_1->as_XMMRegister());
 820       }
 821     }
 822   }
 823 
 824   // Schedule the branch target address early.
 825   __ movptr(rcx, Address(rbx, in_bytes(Method::interpreter_entry_offset())));
 826   __ jmp(rcx);
 827 }
 828 













 829 void SharedRuntime::gen_i2c_adapter(MacroAssembler *masm,
 830                                     int total_args_passed,
 831                                     int comp_args_on_stack,
 832                                     const BasicType *sig_bt,
 833                                     const VMRegPair *regs) {
 834 
 835   // Note: r13 contains the senderSP on entry. We must preserve it since
 836   // we may do a i2c -> c2i transition if we lose a race where compiled
 837   // code goes non-entrant while we get args ready.
 838   // In addition we use r13 to locate all the interpreter args as
 839   // we must align the stack to 16 bytes on an i2c entry else we
 840   // lose alignment we expect in all compiled code and register
 841   // save code can segv when fxsave instructions find improperly
 842   // aligned stack pointer.
 843 
 844   // Adapters can be frameless because they do not require the caller
 845   // to perform additional cleanup work, such as correcting the stack pointer.
 846   // An i2c adapter is frameless because the *caller* frame, which is interpreted,
 847   // routinely repairs its own stack pointer (from interpreter_frame_last_sp),
 848   // even if a callee has modified the stack pointer.
 849   // A c2i adapter is frameless because the *callee* frame, which is interpreted,
 850   // routinely repairs its caller's stack pointer (from sender_sp, which is set
 851   // up via the senderSP register).
 852   // In other words, if *either* the caller or callee is interpreted, we can
 853   // get the stack pointer repaired after a call.
 854   // This is why c2i and i2c adapters cannot be indefinitely composed.
 855   // In particular, if a c2i adapter were to somehow call an i2c adapter,
 856   // both caller and callee would be compiled methods, and neither would
 857   // clean up the stack pointer changes performed by the two adapters.
 858   // If this happens, control eventually transfers back to the compiled
 859   // caller, but with an uncorrected stack, causing delayed havoc.
 860 



































 861   // Must preserve original SP for loading incoming arguments because
 862   // we need to align the outgoing SP for compiled code.
 863   __ movptr(r11, rsp);
 864 
 865   // Pick up the return address
 866   __ pop(rax);
 867 
 868   // Convert 4-byte c2 stack slots to words.
 869   int comp_words_on_stack = align_up(comp_args_on_stack*VMRegImpl::stack_slot_size, wordSize)>>LogBytesPerWord;
 870 
 871   if (comp_args_on_stack) {
 872     __ subptr(rsp, comp_words_on_stack * wordSize);
 873   }
 874 
 875   // Ensure compiled code always sees stack at proper alignment
 876   __ andptr(rsp, -16);
 877 
 878   // push the return address and misalign the stack that youngest frame always sees
 879   // as far as the placement of the call instruction
 880   __ push(rax);

 985   // 6243940 We might end up in handle_wrong_method if
 986   // the callee is deoptimized as we race thru here. If that
 987   // happens we don't want to take a safepoint because the
 988   // caller frame will look interpreted and arguments are now
 989   // "compiled" so it is much better to make this transition
 990   // invisible to the stack walking code. Unfortunately if
 991   // we try and find the callee by normal means a safepoint
 992   // is possible. So we stash the desired callee in the thread
 993   // and the vm will find there should this case occur.
 994 
 995   __ movptr(Address(r15_thread, JavaThread::callee_target_offset()), rbx);
 996 
 997   // put Method* where a c2i would expect should we end up there
 998   // only needed because eof c2 resolve stubs return Method* as a result in
 999   // rax
1000   __ mov(rax, rbx);
1001   __ jmp(r11);
1002 }
1003 
1004 // ---------------------------------------------------------------
1005 void SharedRuntime::generate_i2c2i_adapters(MacroAssembler *masm,
1006                                             int total_args_passed,
1007                                             int comp_args_on_stack,
1008                                             const BasicType *sig_bt,
1009                                             const VMRegPair *regs,
1010                                             AdapterHandlerEntry* handler) {
1011   address i2c_entry = __ pc();
1012 
1013   gen_i2c_adapter(masm, total_args_passed, comp_args_on_stack, sig_bt, regs);
1014 
1015   // -------------------------------------------------------------------------
1016   // Generate a C2I adapter.  On entry we know rbx holds the Method* during calls
1017   // to the interpreter.  The args start out packed in the compiled layout.  They
1018   // need to be unpacked into the interpreter layout.  This will almost always
1019   // require some stack space.  We grow the current (compiled) stack, then repack
1020   // the args.  We  finally end in a jump to the generic interpreter entry point.
1021   // On exit from the interpreter, the interpreter will restore our SP (lest the
1022   // compiled code, which relies solely on SP and not RBP, get sick).
1023 
1024   address c2i_unverified_entry = __ pc();
1025   Label skip_fixup;
1026 
1027   Register data = rax;
1028   Register receiver = j_rarg0;
1029   Register temp = rbx;
1030 

1052       __ load_unsigned_short(flags, Address(method, Method::access_flags_offset()));
1053       __ testl(flags, JVM_ACC_STATIC);
1054       __ jcc(Assembler::zero, L_skip_barrier); // non-static
1055     }
1056 
1057     Register klass = rscratch1;
1058     __ load_method_holder(klass, method);
1059     __ clinit_barrier(klass, r15_thread, &L_skip_barrier /*L_fast_path*/);
1060 
1061     __ jump(RuntimeAddress(SharedRuntime::get_handle_wrong_method_stub())); // slow path
1062 
1063     __ bind(L_skip_barrier);
1064     c2i_no_clinit_check_entry = __ pc();
1065   }
1066 
1067   BarrierSetAssembler* bs = BarrierSet::barrier_set()->barrier_set_assembler();
1068   bs->c2i_entry_barrier(masm);
1069 
1070   gen_c2i_adapter(masm, total_args_passed, comp_args_on_stack, sig_bt, regs, skip_fixup);
1071 
1072   handler->set_entry_points(i2c_entry, c2i_entry, c2i_unverified_entry, c2i_no_clinit_check_entry);
1073   return;
1074 }
1075 
1076 int SharedRuntime::c_calling_convention(const BasicType *sig_bt,
1077                                          VMRegPair *regs,
1078                                          int total_args_passed) {
1079 
1080 // We return the amount of VMRegImpl stack slots we need to reserve for all
1081 // the arguments NOT counting out_preserve_stack_slots.
1082 
1083 // NOTE: These arrays will have to change when c1 is ported
1084 #ifdef _WIN64
1085     static const Register INT_ArgReg[Argument::n_int_register_parameters_c] = {
1086       c_rarg0, c_rarg1, c_rarg2, c_rarg3
1087     };
1088     static const XMMRegister FP_ArgReg[Argument::n_float_register_parameters_c] = {
1089       c_farg0, c_farg1, c_farg2, c_farg3
1090     };
1091 #else
1092     static const Register INT_ArgReg[Argument::n_int_register_parameters_c] = {
1093       c_rarg0, c_rarg1, c_rarg2, c_rarg3, c_rarg4, c_rarg5
< prev index next >