540
541 // An i2c adapter is frameless because the *caller* frame, which is
542 // interpreted, routinely repairs its own esp (from
543 // interpreter_frame_last_sp), even if a callee has modified the
544 // stack pointer. It also recalculates and aligns sp.
545
546 // A c2i adapter is frameless because the *callee* frame, which is
547 // interpreted, routinely repairs its caller's sp (from sender_sp,
548 // which is set up via the senderSP register).
549
550 // In other words, if *either* the caller or callee is interpreted, we can
551 // get the stack pointer repaired after a call.
552
553 // This is why c2i and i2c adapters cannot be indefinitely composed.
554 // In particular, if a c2i adapter were to somehow call an i2c adapter,
555 // both caller and callee would be compiled methods, and neither would
556 // clean up the stack pointer changes performed by the two adapters.
557 // If this happens, control eventually transfers back to the compiled
558 // caller, but with an uncorrected stack, causing delayed havoc.
559
560 if (VerifyAdapterCalls &&
561 (Interpreter::code() != nullptr || StubRoutines::final_stubs_code() != nullptr)) {
562 #if 0
563 // So, let's test for cascading c2i/i2c adapters right now.
564 // assert(Interpreter::contains($return_addr) ||
565 // StubRoutines::contains($return_addr),
566 // "i2c adapter must return to an interpreter frame");
567 __ block_comment("verify_i2c { ");
568 Label L_ok;
569 if (Interpreter::code() != nullptr) {
570 range_check(masm, rax, r11,
571 Interpreter::code()->code_start(), Interpreter::code()->code_end(),
572 L_ok);
573 }
574 if (StubRoutines::initial_stubs_code() != nullptr) {
575 range_check(masm, rax, r11,
576 StubRoutines::initial_stubs_code()->code_begin(),
577 StubRoutines::initial_stubs_code()->code_end(),
578 L_ok);
579 }
580 if (StubRoutines::final_stubs_code() != nullptr) {
581 range_check(masm, rax, r11,
582 StubRoutines::final_stubs_code()->code_begin(),
583 StubRoutines::final_stubs_code()->code_end(),
584 L_ok);
585 }
586 const char* msg = "i2c adapter must return to an interpreter frame";
587 __ block_comment(msg);
588 __ stop(msg);
589 __ bind(L_ok);
590 __ block_comment("} verify_i2ce ");
591 #endif
592 }
593
594 // Cut-out for having no stack args.
595 int comp_words_on_stack = align_up(comp_args_on_stack*VMRegImpl::stack_slot_size, wordSize)>>LogBytesPerWord;
596 if (comp_args_on_stack) {
597 __ sub(rscratch1, sp, comp_words_on_stack * wordSize);
598 __ andr(sp, rscratch1, -16);
599 }
600
601 // Will jump to the compiled code just as if compiled code was doing it.
602 // Pre-load the register-jump target early, to schedule it better.
603 __ ldr(rscratch1, Address(rmethod, in_bytes(Method::from_compiled_offset())));
604
605 #if INCLUDE_JVMCI
606 if (EnableJVMCI) {
607 // check if this call should be routed towards a specific entry point
608 __ ldr(rscratch2, Address(rthread, in_bytes(JavaThread::jvmci_alternate_call_target_offset())));
609 Label no_alternative_target;
610 __ cbz(rscratch2, no_alternative_target);
611 __ mov(rscratch1, rscratch2);
612 __ str(zr, Address(rthread, in_bytes(JavaThread::jvmci_alternate_call_target_offset())));
613 __ bind(no_alternative_target);
694 __ mov(rscratch2, rscratch1);
695 __ push_cont_fastpath(rthread); // Set JavaThread::_cont_fastpath to the sp of the oldest interpreted frame we know about; kills rscratch1
696 __ mov(rscratch1, rscratch2);
697
698 // 6243940 We might end up in handle_wrong_method if
699 // the callee is deoptimized as we race thru here. If that
700 // happens we don't want to take a safepoint because the
701 // caller frame will look interpreted and arguments are now
702 // "compiled" so it is much better to make this transition
703 // invisible to the stack walking code. Unfortunately if
704 // we try and find the callee by normal means a safepoint
705 // is possible. So we stash the desired callee in the thread
706 // and the vm will find there should this case occur.
707
708 __ str(rmethod, Address(rthread, JavaThread::callee_target_offset()));
709
710 __ br(rscratch1);
711 }
712
713 // ---------------------------------------------------------------
714 AdapterHandlerEntry* SharedRuntime::generate_i2c2i_adapters(MacroAssembler *masm,
715 int total_args_passed,
716 int comp_args_on_stack,
717 const BasicType *sig_bt,
718 const VMRegPair *regs,
719 AdapterFingerPrint* fingerprint) {
720 address i2c_entry = __ pc();
721
722 gen_i2c_adapter(masm, total_args_passed, comp_args_on_stack, sig_bt, regs);
723
724 address c2i_unverified_entry = __ pc();
725 Label skip_fixup;
726
727 Register data = rscratch2;
728 Register receiver = j_rarg0;
729 Register tmp = r10; // A call-clobbered register not used for arg passing
730
731 // -------------------------------------------------------------------------
732 // Generate a C2I adapter. On entry we know rmethod holds the Method* during calls
733 // to the interpreter. The args start out packed in the compiled layout. They
734 // need to be unpacked into the interpreter layout. This will almost always
735 // require some stack space. We grow the current (compiled) stack, then repack
736 // the args. We finally end in a jump to the generic interpreter entry point.
737 // On exit from the interpreter, the interpreter will restore our SP (lest the
738 // compiled code, which relies solely on SP and not FP, get sick).
739
760
761 { // Bypass the barrier for non-static methods
762 __ ldrh(rscratch1, Address(rmethod, Method::access_flags_offset()));
763 __ andsw(zr, rscratch1, JVM_ACC_STATIC);
764 __ br(Assembler::EQ, L_skip_barrier); // non-static
765 }
766
767 __ load_method_holder(rscratch2, rmethod);
768 __ clinit_barrier(rscratch2, rscratch1, &L_skip_barrier);
769 __ far_jump(RuntimeAddress(SharedRuntime::get_handle_wrong_method_stub()));
770
771 __ bind(L_skip_barrier);
772 c2i_no_clinit_check_entry = __ pc();
773 }
774
775 BarrierSetAssembler* bs = BarrierSet::barrier_set()->barrier_set_assembler();
776 bs->c2i_entry_barrier(masm);
777
778 gen_c2i_adapter(masm, total_args_passed, comp_args_on_stack, sig_bt, regs, skip_fixup);
779
780 return AdapterHandlerLibrary::new_entry(fingerprint, i2c_entry, c2i_entry, c2i_unverified_entry, c2i_no_clinit_check_entry);
781 }
782
783 static int c_calling_convention_priv(const BasicType *sig_bt,
784 VMRegPair *regs,
785 int total_args_passed) {
786
787 // We return the amount of VMRegImpl stack slots we need to reserve for all
788 // the arguments NOT counting out_preserve_stack_slots.
789
790 static const Register INT_ArgReg[Argument::n_int_register_parameters_c] = {
791 c_rarg0, c_rarg1, c_rarg2, c_rarg3, c_rarg4, c_rarg5, c_rarg6, c_rarg7
792 };
793 static const FloatRegister FP_ArgReg[Argument::n_float_register_parameters_c] = {
794 c_farg0, c_farg1, c_farg2, c_farg3,
795 c_farg4, c_farg5, c_farg6, c_farg7
796 };
797
798 uint int_args = 0;
799 uint fp_args = 0;
800 uint stk_args = 0; // inc by 2 each time
|
540
541 // An i2c adapter is frameless because the *caller* frame, which is
542 // interpreted, routinely repairs its own esp (from
543 // interpreter_frame_last_sp), even if a callee has modified the
544 // stack pointer. It also recalculates and aligns sp.
545
546 // A c2i adapter is frameless because the *callee* frame, which is
547 // interpreted, routinely repairs its caller's sp (from sender_sp,
548 // which is set up via the senderSP register).
549
550 // In other words, if *either* the caller or callee is interpreted, we can
551 // get the stack pointer repaired after a call.
552
553 // This is why c2i and i2c adapters cannot be indefinitely composed.
554 // In particular, if a c2i adapter were to somehow call an i2c adapter,
555 // both caller and callee would be compiled methods, and neither would
556 // clean up the stack pointer changes performed by the two adapters.
557 // If this happens, control eventually transfers back to the compiled
558 // caller, but with an uncorrected stack, causing delayed havoc.
559
560 // Cut-out for having no stack args.
561 int comp_words_on_stack = align_up(comp_args_on_stack*VMRegImpl::stack_slot_size, wordSize)>>LogBytesPerWord;
562 if (comp_args_on_stack) {
563 __ sub(rscratch1, sp, comp_words_on_stack * wordSize);
564 __ andr(sp, rscratch1, -16);
565 }
566
567 // Will jump to the compiled code just as if compiled code was doing it.
568 // Pre-load the register-jump target early, to schedule it better.
569 __ ldr(rscratch1, Address(rmethod, in_bytes(Method::from_compiled_offset())));
570
571 #if INCLUDE_JVMCI
572 if (EnableJVMCI) {
573 // check if this call should be routed towards a specific entry point
574 __ ldr(rscratch2, Address(rthread, in_bytes(JavaThread::jvmci_alternate_call_target_offset())));
575 Label no_alternative_target;
576 __ cbz(rscratch2, no_alternative_target);
577 __ mov(rscratch1, rscratch2);
578 __ str(zr, Address(rthread, in_bytes(JavaThread::jvmci_alternate_call_target_offset())));
579 __ bind(no_alternative_target);
660 __ mov(rscratch2, rscratch1);
661 __ push_cont_fastpath(rthread); // Set JavaThread::_cont_fastpath to the sp of the oldest interpreted frame we know about; kills rscratch1
662 __ mov(rscratch1, rscratch2);
663
664 // 6243940 We might end up in handle_wrong_method if
665 // the callee is deoptimized as we race thru here. If that
666 // happens we don't want to take a safepoint because the
667 // caller frame will look interpreted and arguments are now
668 // "compiled" so it is much better to make this transition
669 // invisible to the stack walking code. Unfortunately if
670 // we try and find the callee by normal means a safepoint
671 // is possible. So we stash the desired callee in the thread
672 // and the vm will find there should this case occur.
673
674 __ str(rmethod, Address(rthread, JavaThread::callee_target_offset()));
675
676 __ br(rscratch1);
677 }
678
679 // ---------------------------------------------------------------
680 void SharedRuntime::generate_i2c2i_adapters(MacroAssembler *masm,
681 int total_args_passed,
682 int comp_args_on_stack,
683 const BasicType *sig_bt,
684 const VMRegPair *regs,
685 AdapterHandlerEntry* handler) {
686 address i2c_entry = __ pc();
687
688 gen_i2c_adapter(masm, total_args_passed, comp_args_on_stack, sig_bt, regs);
689
690 address c2i_unverified_entry = __ pc();
691 Label skip_fixup;
692
693 Register data = rscratch2;
694 Register receiver = j_rarg0;
695 Register tmp = r10; // A call-clobbered register not used for arg passing
696
697 // -------------------------------------------------------------------------
698 // Generate a C2I adapter. On entry we know rmethod holds the Method* during calls
699 // to the interpreter. The args start out packed in the compiled layout. They
700 // need to be unpacked into the interpreter layout. This will almost always
701 // require some stack space. We grow the current (compiled) stack, then repack
702 // the args. We finally end in a jump to the generic interpreter entry point.
703 // On exit from the interpreter, the interpreter will restore our SP (lest the
704 // compiled code, which relies solely on SP and not FP, get sick).
705
726
727 { // Bypass the barrier for non-static methods
728 __ ldrh(rscratch1, Address(rmethod, Method::access_flags_offset()));
729 __ andsw(zr, rscratch1, JVM_ACC_STATIC);
730 __ br(Assembler::EQ, L_skip_barrier); // non-static
731 }
732
733 __ load_method_holder(rscratch2, rmethod);
734 __ clinit_barrier(rscratch2, rscratch1, &L_skip_barrier);
735 __ far_jump(RuntimeAddress(SharedRuntime::get_handle_wrong_method_stub()));
736
737 __ bind(L_skip_barrier);
738 c2i_no_clinit_check_entry = __ pc();
739 }
740
741 BarrierSetAssembler* bs = BarrierSet::barrier_set()->barrier_set_assembler();
742 bs->c2i_entry_barrier(masm);
743
744 gen_c2i_adapter(masm, total_args_passed, comp_args_on_stack, sig_bt, regs, skip_fixup);
745
746 handler->set_entry_points(i2c_entry, c2i_entry, c2i_unverified_entry, c2i_no_clinit_check_entry);
747 return;
748 }
749
750 static int c_calling_convention_priv(const BasicType *sig_bt,
751 VMRegPair *regs,
752 int total_args_passed) {
753
754 // We return the amount of VMRegImpl stack slots we need to reserve for all
755 // the arguments NOT counting out_preserve_stack_slots.
756
757 static const Register INT_ArgReg[Argument::n_int_register_parameters_c] = {
758 c_rarg0, c_rarg1, c_rarg2, c_rarg3, c_rarg4, c_rarg5, c_rarg6, c_rarg7
759 };
760 static const FloatRegister FP_ArgReg[Argument::n_float_register_parameters_c] = {
761 c_farg0, c_farg1, c_farg2, c_farg3,
762 c_farg4, c_farg5, c_farg6, c_farg7
763 };
764
765 uint int_args = 0;
766 uint fp_args = 0;
767 uint stk_args = 0; // inc by 2 each time
|