515 regs[i].set2(xmm0->as_VMReg());
516 } else if( freg_arg1 == (uint)i ) {
517 regs[i].set2(xmm1->as_VMReg());
518 } else {
519 regs[i].set2(VMRegImpl::stack2reg(dstack));
520 dstack += 2;
521 }
522 break;
523 case T_VOID: regs[i].set_bad(); break;
524 break;
525 default:
526 ShouldNotReachHere();
527 break;
528 }
529 }
530
531 // return value can be odd number of VMRegImpl stack slots make multiple of 2
532 return align_up(stack, 2);
533 }
534
535 // Patch the callers callsite with entry to compiled code if it exists.
536 static void patch_callers_callsite(MacroAssembler *masm) {
537 Label L;
538 __ cmpptr(Address(rbx, in_bytes(Method::code_offset())), NULL_WORD);
539 __ jcc(Assembler::equal, L);
540 // Schedule the branch target address early.
541 // Call into the VM to patch the caller, then jump to compiled callee
542 // rax, isn't live so capture return address while we easily can
543 __ movptr(rax, Address(rsp, 0));
544 __ pusha();
545 __ pushf();
546
547 if (UseSSE == 1) {
548 __ subptr(rsp, 2*wordSize);
549 __ movflt(Address(rsp, 0), xmm0);
550 __ movflt(Address(rsp, wordSize), xmm1);
551 }
552 if (UseSSE >= 2) {
553 __ subptr(rsp, 4*wordSize);
554 __ movdbl(Address(rsp, 0), xmm0);
576 __ addptr(rsp, 2*wordSize);
577 }
578 if (UseSSE >= 2) {
579 __ movdbl(xmm0, Address(rsp, 0));
580 __ movdbl(xmm1, Address(rsp, 2*wordSize));
581 __ addptr(rsp, 4*wordSize);
582 }
583
584 __ popf();
585 __ popa();
586 __ bind(L);
587 }
588
589
590 static void move_c2i_double(MacroAssembler *masm, XMMRegister r, int st_off) {
591 int next_off = st_off - Interpreter::stackElementSize;
592 __ movdbl(Address(rsp, next_off), r);
593 }
594
595 static void gen_c2i_adapter(MacroAssembler *masm,
596 int total_args_passed,
597 int comp_args_on_stack,
598 const BasicType *sig_bt,
599 const VMRegPair *regs,
600 Label& skip_fixup) {
601 // Before we get into the guts of the C2I adapter, see if we should be here
602 // at all. We've come from compiled code and are attempting to jump to the
603 // interpreter, which means the caller made a static call to get here
604 // (vcalls always get a compiled target if there is one). Check for a
605 // compiled target. If there is one, we need to patch the caller's call.
606 patch_callers_callsite(masm);
607
608 __ bind(skip_fixup);
609
610 #ifdef COMPILER2
611 // C2 may leave the stack dirty if not in SSE2+ mode
612 if (UseSSE >= 2) {
613 __ verify_FPU(0, "c2i transition should have clean FPU stack");
614 } else {
615 __ empty_FPU_stack();
616 }
617 #endif /* COMPILER2 */
618
619 // Since all args are passed on the stack, total_args_passed * interpreter_
620 // stack_element_size is the
621 // space we need.
622 int extraspace = total_args_passed * Interpreter::stackElementSize;
623
624 // Get return address
625 __ pop(rax);
626
627 // set senderSP value
628 __ movptr(rsi, rsp);
629
630 __ subptr(rsp, extraspace);
631
632 // Now write the args into the outgoing interpreter space
633 for (int i = 0; i < total_args_passed; i++) {
634 if (sig_bt[i] == T_VOID) {
635 assert(i > 0 && (sig_bt[i-1] == T_LONG || sig_bt[i-1] == T_DOUBLE), "missing half");
636 continue;
637 }
638
639 // st_off points to lowest address on stack.
640 int st_off = ((total_args_passed - 1) - i) * Interpreter::stackElementSize;
641 int next_off = st_off - Interpreter::stackElementSize;
642
643 // Say 4 args:
644 // i st_off
645 // 0 12 T_LONG
646 // 1 8 T_VOID
647 // 2 4 T_OBJECT
648 // 3 0 T_BOOL
649 VMReg r_1 = regs[i].first();
650 VMReg r_2 = regs[i].second();
651 if (!r_1->is_valid()) {
652 assert(!r_2->is_valid(), "");
653 continue;
654 }
655
656 if (r_1->is_stack()) {
657 // memory to memory use fpu stack top
658 int ld_off = r_1->reg2stack() * VMRegImpl::stack_slot_size + extraspace;
659
660 if (!r_2->is_valid()) {
666 // st_off == MSW, st_off-wordSize == LSW
667
668 __ movptr(rdi, Address(rsp, ld_off));
669 __ movptr(Address(rsp, next_off), rdi);
670 __ movptr(rdi, Address(rsp, ld_off + wordSize));
671 __ movptr(Address(rsp, st_off), rdi);
672 }
673 } else if (r_1->is_Register()) {
674 Register r = r_1->as_Register();
675 if (!r_2->is_valid()) {
676 __ movl(Address(rsp, st_off), r);
677 } else {
678 // long/double in gpr
679 ShouldNotReachHere();
680 }
681 } else {
682 assert(r_1->is_XMMRegister(), "");
683 if (!r_2->is_valid()) {
684 __ movflt(Address(rsp, st_off), r_1->as_XMMRegister());
685 } else {
686 assert(sig_bt[i] == T_DOUBLE || sig_bt[i] == T_LONG, "wrong type");
687 move_c2i_double(masm, r_1->as_XMMRegister(), st_off);
688 }
689 }
690 }
691
692 // Schedule the branch target address early.
693 __ movptr(rcx, Address(rbx, in_bytes(Method::interpreter_entry_offset())));
694 // And repush original return address
695 __ push(rax);
696 __ jmp(rcx);
697 }
698
699
700 static void move_i2c_double(MacroAssembler *masm, XMMRegister r, Register saved_sp, int ld_off) {
701 int next_val_off = ld_off - Interpreter::stackElementSize;
702 __ movdbl(r, Address(saved_sp, next_val_off));
703 }
704
705 static void range_check(MacroAssembler* masm, Register pc_reg, Register temp_reg,
706 address code_start, address code_end,
707 Label& L_ok) {
708 Label L_fail;
709 __ lea(temp_reg, ExternalAddress(code_start));
710 __ cmpptr(pc_reg, temp_reg);
711 __ jcc(Assembler::belowEqual, L_fail);
712 __ lea(temp_reg, ExternalAddress(code_end));
713 __ cmpptr(pc_reg, temp_reg);
714 __ jcc(Assembler::below, L_ok);
715 __ bind(L_fail);
716 }
717
718 void SharedRuntime::gen_i2c_adapter(MacroAssembler *masm,
719 int total_args_passed,
720 int comp_args_on_stack,
721 const BasicType *sig_bt,
722 const VMRegPair *regs) {
723 // Note: rsi contains the senderSP on entry. We must preserve it since
724 // we may do a i2c -> c2i transition if we lose a race where compiled
725 // code goes non-entrant while we get args ready.
726
727 // Adapters can be frameless because they do not require the caller
728 // to perform additional cleanup work, such as correcting the stack pointer.
729 // An i2c adapter is frameless because the *caller* frame, which is interpreted,
730 // routinely repairs its own stack pointer (from interpreter_frame_last_sp),
731 // even if a callee has modified the stack pointer.
732 // A c2i adapter is frameless because the *callee* frame, which is interpreted,
733 // routinely repairs its caller's stack pointer (from sender_sp, which is set
734 // up via the senderSP register).
735 // In other words, if *either* the caller or callee is interpreted, we can
736 // get the stack pointer repaired after a call.
737 // This is why c2i and i2c adapters cannot be indefinitely composed.
738 // In particular, if a c2i adapter were to somehow call an i2c adapter,
739 // both caller and callee would be compiled methods, and neither would
740 // clean up the stack pointer changes performed by the two adapters.
741 // If this happens, control eventually transfers back to the compiled
742 // caller, but with an uncorrected stack, causing delayed havoc.
796 }
797
798 // Align the outgoing SP
799 __ andptr(rsp, -(StackAlignmentInBytes));
800
801 // push the return address on the stack (note that pushing, rather
802 // than storing it, yields the correct frame alignment for the callee)
803 __ push(rax);
804
805 // Put saved SP in another register
806 const Register saved_sp = rax;
807 __ movptr(saved_sp, rdi);
808
809
810 // Will jump to the compiled code just as if compiled code was doing it.
811 // Pre-load the register-jump target early, to schedule it better.
812 __ movptr(rdi, Address(rbx, in_bytes(Method::from_compiled_offset())));
813
814 // Now generate the shuffle code. Pick up all register args and move the
815 // rest through the floating point stack top.
816 for (int i = 0; i < total_args_passed; i++) {
817 if (sig_bt[i] == T_VOID) {
818 // Longs and doubles are passed in native word order, but misaligned
819 // in the 32-bit build.
820 assert(i > 0 && (sig_bt[i-1] == T_LONG || sig_bt[i-1] == T_DOUBLE), "missing half");
821 continue;
822 }
823
824 // Pick up 0, 1 or 2 words from SP+offset.
825
826 assert(!regs[i].second()->is_valid() || regs[i].first()->next() == regs[i].second(),
827 "scrambled load targets?");
828 // Load in argument order going down.
829 int ld_off = (total_args_passed - i) * Interpreter::stackElementSize;
830 // Point to interpreter value (vs. tag)
831 int next_off = ld_off - Interpreter::stackElementSize;
832 //
833 //
834 //
835 VMReg r_1 = regs[i].first();
836 VMReg r_2 = regs[i].second();
837 if (!r_1->is_valid()) {
838 assert(!r_2->is_valid(), "");
839 continue;
840 }
841 if (r_1->is_stack()) {
842 // Convert stack slot to an SP offset (+ wordSize to account for return address )
843 int st_off = regs[i].first()->reg2stack()*VMRegImpl::stack_slot_size + wordSize;
844
845 // We can use rsi as a temp here because compiled code doesn't need rsi as an input
846 // and if we end up going thru a c2i because of a miss a reasonable value of rsi
847 // we be generated.
848 if (!r_2->is_valid()) {
849 // __ fld_s(Address(saved_sp, ld_off));
907 // "compiled" so it is much better to make this transition
908 // invisible to the stack walking code. Unfortunately if
909 // we try and find the callee by normal means a safepoint
910 // is possible. So we stash the desired callee in the thread
911 // and the vm will find there should this case occur.
912
913 __ get_thread(rax);
914 __ movptr(Address(rax, JavaThread::callee_target_offset()), rbx);
915
916 // move Method* to rax, in case we end up in an c2i adapter.
917 // the c2i adapters expect Method* in rax, (c2) because c2's
918 // resolve stubs return the result (the method) in rax,.
919 // I'd love to fix this.
920 __ mov(rax, rbx);
921
922 __ jmp(rdi);
923 }
924
925 // ---------------------------------------------------------------
926 AdapterHandlerEntry* SharedRuntime::generate_i2c2i_adapters(MacroAssembler *masm,
927 int total_args_passed,
928 int comp_args_on_stack,
929 const BasicType *sig_bt,
930 const VMRegPair *regs,
931 AdapterFingerPrint* fingerprint) {
932 address i2c_entry = __ pc();
933
934 gen_i2c_adapter(masm, total_args_passed, comp_args_on_stack, sig_bt, regs);
935
936 // -------------------------------------------------------------------------
937 // Generate a C2I adapter. On entry we know rbx, holds the Method* during calls
938 // to the interpreter. The args start out packed in the compiled layout. They
939 // need to be unpacked into the interpreter layout. This will almost always
940 // require some stack space. We grow the current (compiled) stack, then repack
941 // the args. We finally end in a jump to the generic interpreter entry point.
942 // On exit from the interpreter, the interpreter will restore our SP (lest the
943 // compiled code, which relies solely on SP and not EBP, get sick).
944
945 address c2i_unverified_entry = __ pc();
946 Label skip_fixup;
947
948 Register holder = rax;
949 Register receiver = rcx;
950 Register temp = rbx;
951
952 {
953
954 Label missed;
955 __ movptr(temp, Address(receiver, oopDesc::klass_offset_in_bytes()));
956 __ cmpptr(temp, Address(holder, CompiledICHolder::holder_klass_offset()));
957 __ movptr(rbx, Address(holder, CompiledICHolder::holder_metadata_offset()));
958 __ jcc(Assembler::notEqual, missed);
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 __ bind(missed);
966 __ jump(RuntimeAddress(SharedRuntime::get_ic_miss_stub()));
967 }
968
969 address c2i_entry = __ pc();
970
971 BarrierSetAssembler* bs = BarrierSet::barrier_set()->barrier_set_assembler();
972 bs->c2i_entry_barrier(masm);
973
974 gen_c2i_adapter(masm, total_args_passed, comp_args_on_stack, sig_bt, regs, skip_fixup);
975
976 return AdapterHandlerLibrary::new_entry(fingerprint, i2c_entry, c2i_entry, c2i_unverified_entry);
977 }
978
979 int SharedRuntime::c_calling_convention(const BasicType *sig_bt,
980 VMRegPair *regs,
981 int total_args_passed) {
982
983 // We return the amount of VMRegImpl stack slots we need to reserve for all
984 // the arguments NOT counting out_preserve_stack_slots.
985
986 uint stack = 0; // All arguments on stack
987
988 for( int i = 0; i < total_args_passed; i++) {
989 // From the type and the argument number (count) compute the location
990 switch( sig_bt[i] ) {
991 case T_BOOLEAN:
992 case T_CHAR:
993 case T_FLOAT:
994 case T_BYTE:
995 case T_SHORT:
2835
2836 __ bind(pending);
2837
2838 RegisterSaver::restore_live_registers(masm);
2839
2840 // exception pending => remove activation and forward to exception handler
2841
2842 __ get_thread(thread);
2843 __ movptr(Address(thread, JavaThread::vm_result_offset()), NULL_WORD);
2844 __ movptr(rax, Address(thread, Thread::pending_exception_offset()));
2845 __ jump(RuntimeAddress(StubRoutines::forward_exception_entry()));
2846
2847 // -------------
2848 // make sure all code is generated
2849 masm->flush();
2850
2851 // return the blob
2852 // frame_size_words or bytes??
2853 return RuntimeStub::new_runtime_stub(name, &buffer, frame_complete, frame_size_words, oop_maps, true);
2854 }
|
515 regs[i].set2(xmm0->as_VMReg());
516 } else if( freg_arg1 == (uint)i ) {
517 regs[i].set2(xmm1->as_VMReg());
518 } else {
519 regs[i].set2(VMRegImpl::stack2reg(dstack));
520 dstack += 2;
521 }
522 break;
523 case T_VOID: regs[i].set_bad(); break;
524 break;
525 default:
526 ShouldNotReachHere();
527 break;
528 }
529 }
530
531 // return value can be odd number of VMRegImpl stack slots make multiple of 2
532 return align_up(stack, 2);
533 }
534
535 const uint SharedRuntime::java_return_convention_max_int = 1;
536 const uint SharedRuntime::java_return_convention_max_float = 1;
537 int SharedRuntime::java_return_convention(const BasicType *sig_bt,
538 VMRegPair *regs,
539 int total_args_passed) {
540 Unimplemented();
541 return 0;
542 }
543
544 // Patch the callers callsite with entry to compiled code if it exists.
545 static void patch_callers_callsite(MacroAssembler *masm) {
546 Label L;
547 __ cmpptr(Address(rbx, in_bytes(Method::code_offset())), NULL_WORD);
548 __ jcc(Assembler::equal, L);
549 // Schedule the branch target address early.
550 // Call into the VM to patch the caller, then jump to compiled callee
551 // rax, isn't live so capture return address while we easily can
552 __ movptr(rax, Address(rsp, 0));
553 __ pusha();
554 __ pushf();
555
556 if (UseSSE == 1) {
557 __ subptr(rsp, 2*wordSize);
558 __ movflt(Address(rsp, 0), xmm0);
559 __ movflt(Address(rsp, wordSize), xmm1);
560 }
561 if (UseSSE >= 2) {
562 __ subptr(rsp, 4*wordSize);
563 __ movdbl(Address(rsp, 0), xmm0);
585 __ addptr(rsp, 2*wordSize);
586 }
587 if (UseSSE >= 2) {
588 __ movdbl(xmm0, Address(rsp, 0));
589 __ movdbl(xmm1, Address(rsp, 2*wordSize));
590 __ addptr(rsp, 4*wordSize);
591 }
592
593 __ popf();
594 __ popa();
595 __ bind(L);
596 }
597
598
599 static void move_c2i_double(MacroAssembler *masm, XMMRegister r, int st_off) {
600 int next_off = st_off - Interpreter::stackElementSize;
601 __ movdbl(Address(rsp, next_off), r);
602 }
603
604 static void gen_c2i_adapter(MacroAssembler *masm,
605 const GrowableArray<SigEntry>& sig_extended,
606 const VMRegPair *regs,
607 Label& skip_fixup,
608 address start,
609 OopMapSet*& oop_maps,
610 int& frame_complete,
611 int& frame_size_in_words) {
612 // Before we get into the guts of the C2I adapter, see if we should be here
613 // at all. We've come from compiled code and are attempting to jump to the
614 // interpreter, which means the caller made a static call to get here
615 // (vcalls always get a compiled target if there is one). Check for a
616 // compiled target. If there is one, we need to patch the caller's call.
617 patch_callers_callsite(masm);
618
619 __ bind(skip_fixup);
620
621 #ifdef COMPILER2
622 // C2 may leave the stack dirty if not in SSE2+ mode
623 if (UseSSE >= 2) {
624 __ verify_FPU(0, "c2i transition should have clean FPU stack");
625 } else {
626 __ empty_FPU_stack();
627 }
628 #endif /* COMPILER2 */
629
630 // Since all args are passed on the stack, total_args_passed * interpreter_
631 // stack_element_size is the
632 // space we need.
633 int extraspace = sig_extended.length() * Interpreter::stackElementSize;
634
635 // Get return address
636 __ pop(rax);
637
638 // set senderSP value
639 __ movptr(rsi, rsp);
640
641 __ subptr(rsp, extraspace);
642
643 // Now write the args into the outgoing interpreter space
644 for (int i = 0; i < sig_extended.length(); i++) {
645 if (sig_extended.at(i)._bt == T_VOID) {
646 assert(i > 0 && (sig_extended.at(i-1)._bt == T_LONG || sig_extended.at(i-1)._bt == T_DOUBLE), "missing half");
647 continue;
648 }
649
650 // st_off points to lowest address on stack.
651 int st_off = ((sig_extended.length() - 1) - i) * Interpreter::stackElementSize;
652 int next_off = st_off - Interpreter::stackElementSize;
653
654 // Say 4 args:
655 // i st_off
656 // 0 12 T_LONG
657 // 1 8 T_VOID
658 // 2 4 T_OBJECT
659 // 3 0 T_BOOL
660 VMReg r_1 = regs[i].first();
661 VMReg r_2 = regs[i].second();
662 if (!r_1->is_valid()) {
663 assert(!r_2->is_valid(), "");
664 continue;
665 }
666
667 if (r_1->is_stack()) {
668 // memory to memory use fpu stack top
669 int ld_off = r_1->reg2stack() * VMRegImpl::stack_slot_size + extraspace;
670
671 if (!r_2->is_valid()) {
677 // st_off == MSW, st_off-wordSize == LSW
678
679 __ movptr(rdi, Address(rsp, ld_off));
680 __ movptr(Address(rsp, next_off), rdi);
681 __ movptr(rdi, Address(rsp, ld_off + wordSize));
682 __ movptr(Address(rsp, st_off), rdi);
683 }
684 } else if (r_1->is_Register()) {
685 Register r = r_1->as_Register();
686 if (!r_2->is_valid()) {
687 __ movl(Address(rsp, st_off), r);
688 } else {
689 // long/double in gpr
690 ShouldNotReachHere();
691 }
692 } else {
693 assert(r_1->is_XMMRegister(), "");
694 if (!r_2->is_valid()) {
695 __ movflt(Address(rsp, st_off), r_1->as_XMMRegister());
696 } else {
697 assert(sig_extended.at(i)._bt == T_DOUBLE || sig_extended.at(i)._bt == T_LONG, "wrong type");
698 move_c2i_double(masm, r_1->as_XMMRegister(), st_off);
699 }
700 }
701 }
702
703 // Schedule the branch target address early.
704 __ movptr(rcx, Address(rbx, in_bytes(Method::interpreter_entry_offset())));
705 // And repush original return address
706 __ push(rax);
707 __ jmp(rcx);
708 }
709
710
711 static void move_i2c_double(MacroAssembler *masm, XMMRegister r, Register saved_sp, int ld_off) {
712 int next_val_off = ld_off - Interpreter::stackElementSize;
713 __ movdbl(r, Address(saved_sp, next_val_off));
714 }
715
716 static void range_check(MacroAssembler* masm, Register pc_reg, Register temp_reg,
717 address code_start, address code_end,
718 Label& L_ok) {
719 Label L_fail;
720 __ lea(temp_reg, ExternalAddress(code_start));
721 __ cmpptr(pc_reg, temp_reg);
722 __ jcc(Assembler::belowEqual, L_fail);
723 __ lea(temp_reg, ExternalAddress(code_end));
724 __ cmpptr(pc_reg, temp_reg);
725 __ jcc(Assembler::below, L_ok);
726 __ bind(L_fail);
727 }
728
729 void SharedRuntime::gen_i2c_adapter(MacroAssembler *masm,
730 int comp_args_on_stack,
731 const GrowableArray<SigEntry>& sig_extended,
732 const VMRegPair *regs) {
733
734 // Note: rsi contains the senderSP on entry. We must preserve it since
735 // we may do a i2c -> c2i transition if we lose a race where compiled
736 // code goes non-entrant while we get args ready.
737
738 // Adapters can be frameless because they do not require the caller
739 // to perform additional cleanup work, such as correcting the stack pointer.
740 // An i2c adapter is frameless because the *caller* frame, which is interpreted,
741 // routinely repairs its own stack pointer (from interpreter_frame_last_sp),
742 // even if a callee has modified the stack pointer.
743 // A c2i adapter is frameless because the *callee* frame, which is interpreted,
744 // routinely repairs its caller's stack pointer (from sender_sp, which is set
745 // up via the senderSP register).
746 // In other words, if *either* the caller or callee is interpreted, we can
747 // get the stack pointer repaired after a call.
748 // This is why c2i and i2c adapters cannot be indefinitely composed.
749 // In particular, if a c2i adapter were to somehow call an i2c adapter,
750 // both caller and callee would be compiled methods, and neither would
751 // clean up the stack pointer changes performed by the two adapters.
752 // If this happens, control eventually transfers back to the compiled
753 // caller, but with an uncorrected stack, causing delayed havoc.
807 }
808
809 // Align the outgoing SP
810 __ andptr(rsp, -(StackAlignmentInBytes));
811
812 // push the return address on the stack (note that pushing, rather
813 // than storing it, yields the correct frame alignment for the callee)
814 __ push(rax);
815
816 // Put saved SP in another register
817 const Register saved_sp = rax;
818 __ movptr(saved_sp, rdi);
819
820
821 // Will jump to the compiled code just as if compiled code was doing it.
822 // Pre-load the register-jump target early, to schedule it better.
823 __ movptr(rdi, Address(rbx, in_bytes(Method::from_compiled_offset())));
824
825 // Now generate the shuffle code. Pick up all register args and move the
826 // rest through the floating point stack top.
827 for (int i = 0; i < sig_extended.length(); i++) {
828 if (sig_extended.at(i)._bt == T_VOID) {
829 // Longs and doubles are passed in native word order, but misaligned
830 // in the 32-bit build.
831 assert(i > 0 && (sig_extended.at(i-1)._bt == T_LONG || sig_extended.at(i-1)._bt == T_DOUBLE), "missing half");
832 continue;
833 }
834
835 // Pick up 0, 1 or 2 words from SP+offset.
836
837 assert(!regs[i].second()->is_valid() || regs[i].first()->next() == regs[i].second(),
838 "scrambled load targets?");
839 // Load in argument order going down.
840 int ld_off = (sig_extended.length() - i) * Interpreter::stackElementSize;
841 // Point to interpreter value (vs. tag)
842 int next_off = ld_off - Interpreter::stackElementSize;
843 //
844 //
845 //
846 VMReg r_1 = regs[i].first();
847 VMReg r_2 = regs[i].second();
848 if (!r_1->is_valid()) {
849 assert(!r_2->is_valid(), "");
850 continue;
851 }
852 if (r_1->is_stack()) {
853 // Convert stack slot to an SP offset (+ wordSize to account for return address )
854 int st_off = regs[i].first()->reg2stack()*VMRegImpl::stack_slot_size + wordSize;
855
856 // We can use rsi as a temp here because compiled code doesn't need rsi as an input
857 // and if we end up going thru a c2i because of a miss a reasonable value of rsi
858 // we be generated.
859 if (!r_2->is_valid()) {
860 // __ fld_s(Address(saved_sp, ld_off));
918 // "compiled" so it is much better to make this transition
919 // invisible to the stack walking code. Unfortunately if
920 // we try and find the callee by normal means a safepoint
921 // is possible. So we stash the desired callee in the thread
922 // and the vm will find there should this case occur.
923
924 __ get_thread(rax);
925 __ movptr(Address(rax, JavaThread::callee_target_offset()), rbx);
926
927 // move Method* to rax, in case we end up in an c2i adapter.
928 // the c2i adapters expect Method* in rax, (c2) because c2's
929 // resolve stubs return the result (the method) in rax,.
930 // I'd love to fix this.
931 __ mov(rax, rbx);
932
933 __ jmp(rdi);
934 }
935
936 // ---------------------------------------------------------------
937 AdapterHandlerEntry* SharedRuntime::generate_i2c2i_adapters(MacroAssembler *masm,
938 int comp_args_on_stack,
939 const GrowableArray<SigEntry>& sig_extended,
940 const VMRegPair *regs,
941 AdapterFingerPrint* fingerprint,
942 AdapterBlob*& new_adapter) {
943 address i2c_entry = __ pc();
944
945 gen_i2c_adapter(masm, comp_args_on_stack, sig_extended, regs);
946
947 // -------------------------------------------------------------------------
948 // Generate a C2I adapter. On entry we know rbx, holds the Method* during calls
949 // to the interpreter. The args start out packed in the compiled layout. They
950 // need to be unpacked into the interpreter layout. This will almost always
951 // require some stack space. We grow the current (compiled) stack, then repack
952 // the args. We finally end in a jump to the generic interpreter entry point.
953 // On exit from the interpreter, the interpreter will restore our SP (lest the
954 // compiled code, which relies solely on SP and not EBP, get sick).
955
956 address c2i_unverified_entry = __ pc();
957 Label skip_fixup;
958
959 Register holder = rax;
960 Register receiver = rcx;
961 Register temp = rbx;
962
963 {
964
965 Label missed;
966 __ movptr(temp, Address(receiver, oopDesc::klass_offset_in_bytes()));
967 __ cmpptr(temp, Address(holder, CompiledICHolder::holder_klass_offset()));
968 __ movptr(rbx, Address(holder, CompiledICHolder::holder_metadata_offset()));
969 __ jcc(Assembler::notEqual, missed);
970 // Method might have been compiled since the call site was patched to
971 // interpreted if that is the case treat it as a miss so we can get
972 // the call site corrected.
973 __ cmpptr(Address(rbx, in_bytes(Method::code_offset())), NULL_WORD);
974 __ jcc(Assembler::equal, skip_fixup);
975
976 __ bind(missed);
977 __ jump(RuntimeAddress(SharedRuntime::get_ic_miss_stub()));
978 }
979
980 address c2i_entry = __ pc();
981
982 BarrierSetAssembler* bs = BarrierSet::barrier_set()->barrier_set_assembler();
983 bs->c2i_entry_barrier(masm);
984
985 OopMapSet* oop_maps = nullptr;
986 int frame_complete = CodeOffsets::frame_never_safe;
987 int frame_size_in_words = 0;
988 gen_c2i_adapter(masm, sig_extended, regs, skip_fixup, i2c_entry, oop_maps, frame_complete, frame_size_in_words);
989
990 new_adapter = AdapterBlob::create(masm->code(), frame_complete, frame_size_in_words, oop_maps);
991 return AdapterHandlerLibrary::new_entry(fingerprint, i2c_entry, c2i_entry, c2i_unverified_entry);
992 }
993
994 int SharedRuntime::c_calling_convention(const BasicType *sig_bt,
995 VMRegPair *regs,
996 int total_args_passed) {
997
998 // We return the amount of VMRegImpl stack slots we need to reserve for all
999 // the arguments NOT counting out_preserve_stack_slots.
1000
1001 uint stack = 0; // All arguments on stack
1002
1003 for( int i = 0; i < total_args_passed; i++) {
1004 // From the type and the argument number (count) compute the location
1005 switch( sig_bt[i] ) {
1006 case T_BOOLEAN:
1007 case T_CHAR:
1008 case T_FLOAT:
1009 case T_BYTE:
1010 case T_SHORT:
2850
2851 __ bind(pending);
2852
2853 RegisterSaver::restore_live_registers(masm);
2854
2855 // exception pending => remove activation and forward to exception handler
2856
2857 __ get_thread(thread);
2858 __ movptr(Address(thread, JavaThread::vm_result_offset()), NULL_WORD);
2859 __ movptr(rax, Address(thread, Thread::pending_exception_offset()));
2860 __ jump(RuntimeAddress(StubRoutines::forward_exception_entry()));
2861
2862 // -------------
2863 // make sure all code is generated
2864 masm->flush();
2865
2866 // return the blob
2867 // frame_size_words or bytes??
2868 return RuntimeStub::new_runtime_stub(name, &buffer, frame_complete, frame_size_words, oop_maps, true);
2869 }
2870
2871 BufferedInlineTypeBlob* SharedRuntime::generate_buffered_inline_type_adapter(const InlineKlass* vk) {
2872 Unimplemented();
2873 return nullptr;
2874 }
|