< prev index next >

src/cpu/x86/vm/sharedRuntime_x86_64.cpp

Print this page




  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #ifndef _WINDOWS
  27 #include "alloca.h"
  28 #endif
  29 #include "asm/macroAssembler.hpp"
  30 #include "asm/macroAssembler.inline.hpp"

  31 #include "code/debugInfoRec.hpp"
  32 #include "code/icBuffer.hpp"
  33 #include "code/vtableStubs.hpp"
  34 #include "interpreter/interpreter.hpp"
  35 #include "logging/log.hpp"
  36 #include "memory/resourceArea.hpp"
  37 #include "oops/compiledICHolder.hpp"
  38 #include "runtime/sharedRuntime.hpp"
  39 #include "runtime/vframeArray.hpp"
  40 #include "vmreg_x86.inline.hpp"
  41 #ifdef COMPILER1
  42 #include "c1/c1_Runtime1.hpp"
  43 #endif
  44 #ifdef COMPILER2
  45 #include "opto/runtime.hpp"
  46 #endif
  47 #if INCLUDE_JVMCI
  48 #include "jvmci/jvmciJavaClasses.hpp"
  49 #endif
  50 


 587             vt--;
 588           }
 589         } while (vt != 0);
 590       } else {
 591         total_args_passed++;
 592       }
 593     }
 594   } else {
 595     total_args_passed = sig_extended.length();
 596   }
 597   return total_args_passed;
 598 }
 599 
 600 
 601 static void gen_c2i_adapter_helper(MacroAssembler* masm,
 602                                    BasicType bt,
 603                                    BasicType prev_bt,
 604                                    size_t size_in_bytes,
 605                                    const VMRegPair& reg_pair,
 606                                    const Address& to,
 607                                    int extraspace) {

 608   assert(bt != T_VALUETYPE || !ValueTypePassFieldsAsArgs, "no value type here");
 609   if (bt == T_VOID) {
 610     assert(prev_bt == T_LONG || prev_bt == T_DOUBLE, "missing half");
 611     return;
 612   }
 613 
 614   // Say 4 args:
 615   // i   st_off
 616   // 0   32 T_LONG
 617   // 1   24 T_VOID
 618   // 2   16 T_OBJECT
 619   // 3    8 T_BOOL
 620   // -    0 return address
 621   //
 622   // However to make thing extra confusing. Because we can fit a long/double in
 623   // a single slot on a 64 bt vm and it would be silly to break them up, the interpreter
 624   // leaves one slot empty and only stores to a single slot. In this case the
 625   // slot that is occupied is the T_VOID slot. See I said it was confusing.
 626 
 627   bool wide = (size_in_bytes == wordSize);
 628   VMReg r_1 = reg_pair.first();
 629   VMReg r_2 = reg_pair.second();
 630   assert(r_2->is_valid() == wide, "invalid size");
 631   if (!r_1->is_valid()) {
 632     assert(!r_2->is_valid(), "must be invalid");
 633     return;
 634   }
 635   if (r_1->is_stack()) {




 636     int ld_off = r_1->reg2stack() * VMRegImpl::stack_slot_size + extraspace;
 637     __ load_sized_value(rax, Address(rsp, ld_off), size_in_bytes, /* is_signed */ false);
 638     __ store_sized_value(to, rax, size_in_bytes);
 639   } else if (r_1->is_Register()) {
 640     __ store_sized_value(to, r_1->as_Register(), size_in_bytes);





 641   } else {
 642     if (wide) {
 643       __ movdbl(to, r_1->as_XMMRegister());
 644     } else {
 645       __ movflt(to, r_1->as_XMMRegister());
 646     }
 647   }
 648 }
 649 
 650 static void gen_c2i_adapter(MacroAssembler *masm,
 651                             const GrowableArray<SigEntry>& sig_extended,
 652                             const VMRegPair *regs,
 653                             Label& skip_fixup,
 654                             address start,
 655                             OopMapSet*& oop_maps,
 656                             int& frame_complete,
 657                             int& frame_size_in_words) {
 658   // Before we get into the guts of the C2I adapter, see if we should be here
 659   // at all.  We've come from compiled code and are attempting to jump to the
 660   // interpreter, which means the caller made a static call to get here
 661   // (vcalls always get a compiled target if there is one).  Check for a
 662   // compiled target.  If there is one, we need to patch the caller's call.
 663   patch_callers_callsite(masm);
 664 
 665   __ bind(skip_fixup);
 666 

 667   if (ValueTypePassFieldsAsArgs) {
 668     // Is there a value type arguments?
 669     int i = 0;
 670     for (; i < sig_extended.length() && sig_extended.at(i)._bt != T_VALUETYPE; i++);
 671 
 672     if (i < sig_extended.length()) {
 673       // There is at least a value type argument: we're coming from
 674       // compiled code so we have no buffers to back the value
 675       // types. Allocate the buffers here with a runtime call.
 676       oop_maps = new OopMapSet();
 677       OopMap* map = NULL;
 678 
 679       map = RegisterSaver::save_live_registers(masm, 0, &frame_size_in_words);
 680 
 681       frame_complete = __ offset();
 682 
 683       __ set_last_Java_frame(noreg, noreg, NULL);
 684 
 685       __ mov(c_rarg0, r15_thread);
 686       __ mov(c_rarg1, rbx);
 687 
 688       __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, SharedRuntime::allocate_value_types)));
 689 
 690       oop_maps->add_gc_map((int)(__ pc() - start), map);
 691       __ reset_last_Java_frame(false);
 692 
 693       RegisterSaver::restore_live_registers(masm);
 694 
 695       Label no_exception;
 696       __ cmpptr(Address(r15_thread, Thread::pending_exception_offset()), (int32_t)NULL_WORD);
 697       __ jcc(Assembler::equal, no_exception);
 698 
 699       __ movptr(Address(r15_thread, JavaThread::vm_result_offset()), (int)NULL_WORD);
 700       __ movptr(rax, Address(r15_thread, Thread::pending_exception_offset()));
 701       __ jump(RuntimeAddress(StubRoutines::forward_exception_entry()));
 702 
 703       __ bind(no_exception);
 704 
 705       // We get an array of objects from the runtime call
 706       int offset_in_bytes = arrayOopDesc::base_offset_in_bytes(T_OBJECT);
 707       __ get_vm_result(r13, r15_thread);
 708       __ get_vm_result_2(rbx, r15_thread); // TODO: required to keep the callee Method live?
 709       __ addptr(r13, offset_in_bytes);
 710       __ mov(r10, r13);
 711     }
 712   }
 713 
 714 
 715   // Since all args are passed on the stack, total_args_passed *
 716   // Interpreter::stackElementSize is the space we need. Plus 1 because
 717   // we also account for the return address location since
 718   // we store it first rather than hold it in rax across all the shuffling
 719   int total_args_passed = compute_total_args_passed_int(sig_extended);
 720   int extraspace = (total_args_passed * Interpreter::stackElementSize) + wordSize;
 721 
 722   // stack is aligned, keep it that way
 723   extraspace = round_to(extraspace, 2*wordSize);
 724 
 725   // Get return address
 726   __ pop(rax);
 727 
 728   // set senderSP value
 729   __ mov(r13, rsp);
 730 
 731   __ subptr(rsp, extraspace);
 732 
 733   // Store the return address in the expected location
 734   __ movptr(Address(rsp, 0), rax);
 735 
 736   // Now write the args into the outgoing interpreter space
 737 
 738   // next_arg_comp is the next argument from the compiler point of
 739   // view (value type fields are passed in registers/on the stack). In
 740   // sig_extended, a value type argument starts with: T_VALUETYPE,
 741   // followed by the types of the fields of the value type and T_VOID
 742   // to mark the end of the value type. ignored counts the number of
 743   // T_VALUETYPE/T_VOID. next_vt_arg is the next value type argument:
 744   // used to get the buffer for that argument from the pool of buffers
 745   // we allocated above and want to pass to the
 746   // interpreter. next_arg_int is the next argument from the
 747   // interpreter point of view (value types are passed by reference).

 748   for (int next_arg_comp = 0, ignored = 0, next_vt_arg = 0, next_arg_int = 0;
 749        next_arg_comp < sig_extended.length(); next_arg_comp++) {
 750     assert(ignored <= next_arg_comp, "shouldn't skip over more slot than there are arguments");
 751     assert(next_arg_int < total_args_passed, "more arguments for the interpreter than expected?");
 752     BasicType bt = sig_extended.at(next_arg_comp)._bt;
 753     int st_off = (total_args_passed - next_arg_int) * Interpreter::stackElementSize;
 754     if (!ValueTypePassFieldsAsArgs || bt != T_VALUETYPE) {
 755       int next_off = st_off - Interpreter::stackElementSize;
 756       const int offset = (bt == T_LONG || bt == T_DOUBLE) ? next_off : st_off;
 757       const VMRegPair reg_pair = regs[next_arg_comp-ignored];
 758       size_t size_in_bytes = reg_pair.second()->is_valid() ? 8 : 4;
 759       gen_c2i_adapter_helper(masm, bt, next_arg_comp > 0 ? sig_extended.at(next_arg_comp-1)._bt : T_ILLEGAL,
 760                              size_in_bytes, reg_pair, Address(rsp, offset), extraspace);
 761       next_arg_int++;
 762 #ifdef ASSERT
 763       if (bt == T_LONG || bt == T_DOUBLE) {
 764         // Overwrite the unused slot with known junk
 765         __ mov64(rax, CONST64(0xdeadffffdeadaaaa));
 766         __ movptr(Address(rsp, st_off), rax);
 767       }
 768 #endif /* ASSERT */
 769     } else {
 770       ignored++;
 771       // get the buffer from the just allocated pool of buffers
 772       __ load_heap_oop(r11, Address(r10, next_vt_arg * type2aelembytes(T_VALUETYPE)));

 773       next_vt_arg++; next_arg_int++;
 774       int vt = 1;
 775       // write fields we get from compiled code in registers/stack
 776       // slots to the buffer: we know we are done with that value type
 777       // argument when we hit the T_VOID that acts as an end of value
 778       // type delimiter for this value type. Value types are flattened
 779       // so we might encounter embedded value types. Each entry in
 780       // sig_extended contains a field offset in the buffer.
 781       do {
 782         next_arg_comp++;
 783         BasicType bt = sig_extended.at(next_arg_comp)._bt;
 784         BasicType prev_bt = sig_extended.at(next_arg_comp-1)._bt;
 785         if (bt == T_VALUETYPE) {
 786           vt++;
 787           ignored++;
 788         } else if (bt == T_VOID &&
 789                    prev_bt != T_LONG &&
 790                    prev_bt != T_DOUBLE) {
 791           vt--;
 792           ignored++;
 793         } else {
 794           int off = sig_extended.at(next_arg_comp)._offset;
 795           assert(off > 0, "offset in object should be positive");
 796           size_t size_in_bytes = is_java_primitive(bt) ? type2aelembytes(bt) : wordSize;


 797           gen_c2i_adapter_helper(masm, bt, next_arg_comp > 0 ? sig_extended.at(next_arg_comp-1)._bt : T_ILLEGAL,
 798                                  size_in_bytes, regs[next_arg_comp-ignored], Address(r11, off), extraspace);
 799         }
 800       } while (vt != 0);
 801       // pass the buffer to the interpreter
 802       __ movptr(Address(rsp, st_off), r11);
 803     }
 804   }
 805 

















 806   // Schedule the branch target address early.
 807   __ movptr(rcx, Address(rbx, in_bytes(Method::interpreter_entry_offset())));
 808   __ jmp(rcx);
 809 }
 810 
 811 static void range_check(MacroAssembler* masm, Register pc_reg, Register temp_reg,
 812                         address code_start, address code_end,
 813                         Label& L_ok) {
 814   Label L_fail;
 815   __ lea(temp_reg, ExternalAddress(code_start));
 816   __ cmpptr(pc_reg, temp_reg);
 817   __ jcc(Assembler::belowEqual, L_fail);
 818   __ lea(temp_reg, ExternalAddress(code_end));
 819   __ cmpptr(pc_reg, temp_reg);
 820   __ jcc(Assembler::below, L_ok);
 821   __ bind(L_fail);
 822 }
 823 
 824 static void gen_i2c_adapter_helper(MacroAssembler* masm,
 825                                    BasicType bt,
 826                                    BasicType prev_bt,
 827                                    size_t size_in_bytes,
 828                                    const VMRegPair& reg_pair,
 829                                    const Address& from) {

 830   assert(bt != T_VALUETYPE || !ValueTypePassFieldsAsArgs, "no value type here");
 831   if (bt == T_VOID) {
 832     // Longs and doubles are passed in native word order, but misaligned
 833     // in the 32-bit build.
 834     assert(prev_bt == T_LONG || prev_bt == T_DOUBLE, "missing half");
 835     return;
 836   }
 837   assert(!reg_pair.second()->is_valid() || reg_pair.first()->next() == reg_pair.second(),
 838          "scrambled load targets?");
 839 
 840   bool wide = (size_in_bytes == wordSize);
 841   VMReg r_1 = reg_pair.first();
 842   VMReg r_2 = reg_pair.second();
 843   assert(r_2->is_valid() == wide, "invalid size");
 844   if (!r_1->is_valid()) {
 845     assert(!r_2->is_valid(), "must be invalid");
 846     return;
 847   }
 848 
 849   bool is_signed = (bt != T_CHAR) && (bt != T_BOOLEAN);
 850   if (r_1->is_stack()) {
 851     // Convert stack slot to an SP offset (+ wordSize to account for return address)
 852     int st_off = reg_pair.first()->reg2stack() * VMRegImpl::stack_slot_size + wordSize;
 853     // We can use r13 as a temp here because compiled code doesn't need r13 as an input
 854     // and if we end up going thru a c2i because of a miss a reasonable value of r13
 855     // will be generated.
 856     __ load_sized_value(r13, from, size_in_bytes, is_signed);
 857     __ movq(Address(rsp, st_off), r13);
 858   } else if (r_1->is_Register()) {
 859     Register r = r_1->as_Register();
 860     assert(r != rax, "must be different");
 861     __ load_sized_value(r, from, size_in_bytes, is_signed);





 862   } else {
 863     if (wide) {
 864       __ movdbl(r_1->as_XMMRegister(), from);
 865     } else {
 866       __ movflt(r_1->as_XMMRegister(), from);
 867     }
 868   }
 869 }
 870 
 871 void SharedRuntime::gen_i2c_adapter(MacroAssembler *masm,
 872                                     int comp_args_on_stack,
 873                                     const GrowableArray<SigEntry>& sig_extended,
 874                                     const VMRegPair *regs) {
 875 
 876   // Note: r13 contains the senderSP on entry. We must preserve it since
 877   // we may do a i2c -> c2i transition if we lose a race where compiled
 878   // code goes non-entrant while we get args ready.
 879   // In addition we use r13 to locate all the interpreter args as
 880   // we must align the stack to 16 bytes on an i2c entry else we
 881   // lose alignment we expect in all compiled code and register


 983   // next_arg_comp is the next argument from the compiler point of
 984   // view (value type fields are passed in registers/on the stack). In
 985   // sig_extended, a value type argument starts with: T_VALUETYPE,
 986   // followed by the types of the fields of the value type and T_VOID
 987   // to mark the end of the value type. ignored counts the number of
 988   // T_VALUETYPE/T_VOID. next_arg_int is the next argument from the
 989   // interpreter point of view (value types are passed by reference).
 990   for (int next_arg_comp = 0, ignored = 0, next_arg_int = 0; next_arg_comp < sig_extended.length(); next_arg_comp++) {
 991     assert(ignored <= next_arg_comp, "shouldn't skip over more slot than there are arguments");
 992     assert(next_arg_int < total_args_passed, "more arguments from the interpreter than expected?");
 993     BasicType bt = sig_extended.at(next_arg_comp)._bt;
 994     int ld_off = (total_args_passed - next_arg_int)*Interpreter::stackElementSize;
 995     if (!ValueTypePassFieldsAsArgs || bt != T_VALUETYPE) {
 996       // Load in argument order going down.
 997       // Point to interpreter value (vs. tag)
 998       int next_off = ld_off - Interpreter::stackElementSize;
 999       int offset = (bt == T_LONG || bt == T_DOUBLE) ? next_off : ld_off;
1000       const VMRegPair reg_pair = regs[next_arg_comp-ignored];
1001       size_t size_in_bytes = reg_pair.second()->is_valid() ? 8 : 4;
1002       gen_i2c_adapter_helper(masm, bt, next_arg_comp > 0 ? sig_extended.at(next_arg_comp-1)._bt : T_ILLEGAL,
1003                              size_in_bytes, reg_pair, Address(saved_sp, offset));
1004       next_arg_int++;
1005     } else {
1006       next_arg_int++;
1007       ignored++;
1008       // get the buffer for that value type
1009       __ movptr(r10, Address(saved_sp, ld_off));
1010       int vt = 1;
1011       // load fields to registers/stack slots from the buffer: we know
1012       // we are done with that value type argument when we hit the
1013       // T_VOID that acts as an end of value type delimiter for this
1014       // value type. Value types are flattened so we might encounter
1015       // embedded value types. Each entry in sig_extended contains a
1016       // field offset in the buffer.
1017       do {
1018         next_arg_comp++;
1019         BasicType bt = sig_extended.at(next_arg_comp)._bt;
1020         BasicType prev_bt = sig_extended.at(next_arg_comp-1)._bt;
1021         if (bt == T_VALUETYPE) {
1022           vt++;
1023           ignored++;
1024         } else if (bt == T_VOID &&
1025                    prev_bt != T_LONG &&
1026                    prev_bt != T_DOUBLE) {
1027           vt--;
1028           ignored++;
1029         } else {
1030           int off = sig_extended.at(next_arg_comp)._offset;
1031           assert(off > 0, "offset in object should be positive");
1032           size_t size_in_bytes = is_java_primitive(bt) ? type2aelembytes(bt) : wordSize;
1033           gen_i2c_adapter_helper(masm, bt, prev_bt, size_in_bytes, regs[next_arg_comp - ignored], Address(r10, off));

1034         }
1035       } while (vt != 0);
1036     }
1037   }
1038 
1039   // 6243940 We might end up in handle_wrong_method if
1040   // the callee is deoptimized as we race thru here. If that
1041   // happens we don't want to take a safepoint because the
1042   // caller frame will look interpreted and arguments are now
1043   // "compiled" so it is much better to make this transition
1044   // invisible to the stack walking code. Unfortunately if
1045   // we try and find the callee by normal means a safepoint
1046   // is possible. So we stash the desired callee in the thread
1047   // and the vm will find there should this case occur.
1048 
1049   __ movptr(Address(r15_thread, JavaThread::callee_target_offset()), rbx);
1050 
1051   // put Method* where a c2i would expect should we end up there
1052   // only needed because of c2 resolve stubs return Method* as a result in
1053   // rax


1091     __ jump(RuntimeAddress(SharedRuntime::get_ic_miss_stub()));
1092 
1093     __ bind(ok);
1094     // Method might have been compiled since the call site was patched to
1095     // interpreted if that is the case treat it as a miss so we can get
1096     // the call site corrected.
1097     __ cmpptr(Address(rbx, in_bytes(Method::code_offset())), (int32_t)NULL_WORD);
1098     __ jcc(Assembler::equal, skip_fixup);
1099     __ jump(RuntimeAddress(SharedRuntime::get_ic_miss_stub()));
1100   }
1101 
1102   address c2i_entry = __ pc();
1103 
1104   OopMapSet* oop_maps = NULL;
1105   int frame_complete = CodeOffsets::frame_never_safe;
1106   int frame_size_in_words = 0;
1107   gen_c2i_adapter(masm, sig_extended, regs, skip_fixup, i2c_entry, oop_maps, frame_complete, frame_size_in_words);
1108 
1109   __ flush();
1110   new_adapter = AdapterBlob::create(masm->code(), frame_complete, frame_size_in_words, oop_maps);
1111   return AdapterHandlerLibrary::new_entry(fingerprint, i2c_entry, c2i_entry, c2i_unverified_entry);


































1112 }
1113 
1114 int SharedRuntime::c_calling_convention(const BasicType *sig_bt,
1115                                          VMRegPair *regs,
1116                                          VMRegPair *regs2,
1117                                          int total_args_passed) {
1118   assert(regs2 == NULL, "not needed on x86");
1119 // We return the amount of VMRegImpl stack slots we need to reserve for all
1120 // the arguments NOT counting out_preserve_stack_slots.
1121 
1122 // NOTE: These arrays will have to change when c1 is ported
1123 #ifdef _WIN64
1124     static const Register INT_ArgReg[Argument::n_int_register_parameters_c] = {
1125       c_rarg0, c_rarg1, c_rarg2, c_rarg3
1126     };
1127     static const XMMRegister FP_ArgReg[Argument::n_float_register_parameters_c] = {
1128       c_farg0, c_farg1, c_farg2, c_farg3
1129     };
1130 #else
1131     static const Register INT_ArgReg[Argument::n_int_register_parameters_c] = {




  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #ifndef _WINDOWS
  27 #include "alloca.h"
  28 #endif
  29 #include "asm/macroAssembler.hpp"
  30 #include "asm/macroAssembler.inline.hpp"
  31 #include "classfile/symbolTable.hpp"
  32 #include "code/debugInfoRec.hpp"
  33 #include "code/icBuffer.hpp"
  34 #include "code/vtableStubs.hpp"
  35 #include "interpreter/interpreter.hpp"
  36 #include "logging/log.hpp"
  37 #include "memory/resourceArea.hpp"
  38 #include "oops/compiledICHolder.hpp"
  39 #include "runtime/sharedRuntime.hpp"
  40 #include "runtime/vframeArray.hpp"
  41 #include "vmreg_x86.inline.hpp"
  42 #ifdef COMPILER1
  43 #include "c1/c1_Runtime1.hpp"
  44 #endif
  45 #ifdef COMPILER2
  46 #include "opto/runtime.hpp"
  47 #endif
  48 #if INCLUDE_JVMCI
  49 #include "jvmci/jvmciJavaClasses.hpp"
  50 #endif
  51 


 588             vt--;
 589           }
 590         } while (vt != 0);
 591       } else {
 592         total_args_passed++;
 593       }
 594     }
 595   } else {
 596     total_args_passed = sig_extended.length();
 597   }
 598   return total_args_passed;
 599 }
 600 
 601 
 602 static void gen_c2i_adapter_helper(MacroAssembler* masm,
 603                                    BasicType bt,
 604                                    BasicType prev_bt,
 605                                    size_t size_in_bytes,
 606                                    const VMRegPair& reg_pair,
 607                                    const Address& to,
 608                                    int extraspace,
 609                                    bool is_oop) {
 610   assert(bt != T_VALUETYPE || !ValueTypePassFieldsAsArgs, "no value type here");
 611   if (bt == T_VOID) {
 612     assert(prev_bt == T_LONG || prev_bt == T_DOUBLE, "missing half");
 613     return;
 614   }
 615 
 616   // Say 4 args:
 617   // i   st_off
 618   // 0   32 T_LONG
 619   // 1   24 T_VOID
 620   // 2   16 T_OBJECT
 621   // 3    8 T_BOOL
 622   // -    0 return address
 623   //
 624   // However to make thing extra confusing. Because we can fit a long/double in
 625   // a single slot on a 64 bt vm and it would be silly to break them up, the interpreter
 626   // leaves one slot empty and only stores to a single slot. In this case the
 627   // slot that is occupied is the T_VOID slot. See I said it was confusing.
 628 
 629   bool wide = (size_in_bytes == wordSize);
 630   VMReg r_1 = reg_pair.first();
 631   VMReg r_2 = reg_pair.second();
 632   assert(r_2->is_valid() == wide, "invalid size");
 633   if (!r_1->is_valid()) {
 634     assert(!r_2->is_valid(), "must be invalid");
 635     return;
 636   }
 637 
 638   if (!r_1->is_XMMRegister()) {
 639     Register val = rax;
 640     assert_different_registers(to.base(), val);
 641     if(r_1->is_stack()) {
 642       int ld_off = r_1->reg2stack() * VMRegImpl::stack_slot_size + extraspace;
 643       __ load_sized_value(val, Address(rsp, ld_off), size_in_bytes, /* is_signed */ false);
 644     } else {
 645       val = r_1->as_Register();
 646     }
 647     if (is_oop) {
 648       __ store_heap_oop(to, val);
 649     } else {
 650       __ store_sized_value(to, val, size_in_bytes);
 651     }
 652   } else {
 653     if (wide) {
 654       __ movdbl(to, r_1->as_XMMRegister());
 655     } else {
 656       __ movflt(to, r_1->as_XMMRegister());
 657     }
 658   }
 659 }
 660 
 661 static void gen_c2i_adapter(MacroAssembler *masm,
 662                             const GrowableArray<SigEntry>& sig_extended,
 663                             const VMRegPair *regs,
 664                             Label& skip_fixup,
 665                             address start,
 666                             OopMapSet*& oop_maps,
 667                             int& frame_complete,
 668                             int& frame_size_in_words) {
 669   // Before we get into the guts of the C2I adapter, see if we should be here
 670   // at all.  We've come from compiled code and are attempting to jump to the
 671   // interpreter, which means the caller made a static call to get here
 672   // (vcalls always get a compiled target if there is one).  Check for a
 673   // compiled target.  If there is one, we need to patch the caller's call.
 674   patch_callers_callsite(masm);
 675 
 676   __ bind(skip_fixup);
 677 
 678   bool has_value_argument = false;
 679   if (ValueTypePassFieldsAsArgs) {
 680     // Is there a value type argument?
 681     for (int i = 0; i < sig_extended.length() && !has_value_argument; i++) {
 682       has_value_argument = (sig_extended.at(i)._bt == T_VALUETYPE);
 683     }
 684     if (has_value_argument) {
 685       // There is at least a value type argument: we're coming from
 686       // compiled code so we have no buffers to back the value
 687       // types. Allocate the buffers here with a runtime call.
 688       oop_maps = new OopMapSet();
 689       OopMap* map = NULL;
 690 
 691       map = RegisterSaver::save_live_registers(masm, 0, &frame_size_in_words);
 692 
 693       frame_complete = __ offset();
 694 
 695       __ set_last_Java_frame(noreg, noreg, NULL);
 696 
 697       __ mov(c_rarg0, r15_thread);
 698       __ mov(c_rarg1, rbx);
 699 
 700       __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, SharedRuntime::allocate_value_types)));
 701 
 702       oop_maps->add_gc_map((int)(__ pc() - start), map);
 703       __ reset_last_Java_frame(false);
 704 
 705       RegisterSaver::restore_live_registers(masm);
 706 
 707       Label no_exception;
 708       __ cmpptr(Address(r15_thread, Thread::pending_exception_offset()), (int32_t)NULL_WORD);
 709       __ jcc(Assembler::equal, no_exception);
 710 
 711       __ movptr(Address(r15_thread, JavaThread::vm_result_offset()), (int)NULL_WORD);
 712       __ movptr(rax, Address(r15_thread, Thread::pending_exception_offset()));
 713       __ jump(RuntimeAddress(StubRoutines::forward_exception_entry()));
 714 
 715       __ bind(no_exception);
 716 
 717       // We get an array of objects from the runtime call
 718       __ get_vm_result(r13, r15_thread); // Use r13 as temporary because r10 is trashed by movptr()

 719       __ get_vm_result_2(rbx, r15_thread); // TODO: required to keep the callee Method live?

 720       __ mov(r10, r13);
 721     }
 722   }
 723 

 724   // Since all args are passed on the stack, total_args_passed *
 725   // Interpreter::stackElementSize is the space we need. Plus 1 because
 726   // we also account for the return address location since
 727   // we store it first rather than hold it in rax across all the shuffling
 728   int total_args_passed = compute_total_args_passed_int(sig_extended);
 729   int extraspace = (total_args_passed * Interpreter::stackElementSize) + wordSize;
 730 
 731   // stack is aligned, keep it that way
 732   extraspace = round_to(extraspace, 2*wordSize);
 733 
 734   // Get return address
 735   __ pop(rax);
 736 
 737   // set senderSP value
 738   __ mov(r13, rsp);
 739 
 740   __ subptr(rsp, extraspace);
 741 
 742   // Store the return address in the expected location
 743   __ movptr(Address(rsp, 0), rax);
 744 
 745   // Now write the args into the outgoing interpreter space
 746 
 747   // next_arg_comp is the next argument from the compiler point of
 748   // view (value type fields are passed in registers/on the stack). In
 749   // sig_extended, a value type argument starts with: T_VALUETYPE,
 750   // followed by the types of the fields of the value type and T_VOID
 751   // to mark the end of the value type. ignored counts the number of
 752   // T_VALUETYPE/T_VOID. next_vt_arg is the next value type argument:
 753   // used to get the buffer for that argument from the pool of buffers
 754   // we allocated above and want to pass to the
 755   // interpreter. next_arg_int is the next argument from the
 756   // interpreter point of view (value types are passed by reference).
 757   bool has_oop_field = false;
 758   for (int next_arg_comp = 0, ignored = 0, next_vt_arg = 0, next_arg_int = 0;
 759        next_arg_comp < sig_extended.length(); next_arg_comp++) {
 760     assert(ignored <= next_arg_comp, "shouldn't skip over more slot than there are arguments");
 761     assert(next_arg_int < total_args_passed, "more arguments for the interpreter than expected?");
 762     BasicType bt = sig_extended.at(next_arg_comp)._bt;
 763     int st_off = (total_args_passed - next_arg_int) * Interpreter::stackElementSize;
 764     if (!ValueTypePassFieldsAsArgs || bt != T_VALUETYPE) {
 765       int next_off = st_off - Interpreter::stackElementSize;
 766       const int offset = (bt == T_LONG || bt == T_DOUBLE) ? next_off : st_off;
 767       const VMRegPair reg_pair = regs[next_arg_comp-ignored];
 768       size_t size_in_bytes = reg_pair.second()->is_valid() ? 8 : 4;
 769       gen_c2i_adapter_helper(masm, bt, next_arg_comp > 0 ? sig_extended.at(next_arg_comp-1)._bt : T_ILLEGAL,
 770                              size_in_bytes, reg_pair, Address(rsp, offset), extraspace, false);
 771       next_arg_int++;
 772 #ifdef ASSERT
 773       if (bt == T_LONG || bt == T_DOUBLE) {
 774         // Overwrite the unused slot with known junk
 775         __ mov64(rax, CONST64(0xdeadffffdeadaaaa));
 776         __ movptr(Address(rsp, st_off), rax);
 777       }
 778 #endif /* ASSERT */
 779     } else {
 780       ignored++;
 781       // get the buffer from the just allocated pool of buffers
 782       int index = arrayOopDesc::base_offset_in_bytes(T_OBJECT) + next_vt_arg * type2aelembytes(T_VALUETYPE);
 783       __ load_heap_oop(r11, Address(r10, index));
 784       next_vt_arg++; next_arg_int++;
 785       int vt = 1;
 786       // write fields we get from compiled code in registers/stack
 787       // slots to the buffer: we know we are done with that value type
 788       // argument when we hit the T_VOID that acts as an end of value
 789       // type delimiter for this value type. Value types are flattened
 790       // so we might encounter embedded value types. Each entry in
 791       // sig_extended contains a field offset in the buffer.
 792       do {
 793         next_arg_comp++;
 794         BasicType bt = sig_extended.at(next_arg_comp)._bt;
 795         BasicType prev_bt = sig_extended.at(next_arg_comp-1)._bt;
 796         if (bt == T_VALUETYPE) {
 797           vt++;
 798           ignored++;
 799         } else if (bt == T_VOID &&
 800                    prev_bt != T_LONG &&
 801                    prev_bt != T_DOUBLE) {
 802           vt--;
 803           ignored++;
 804         } else {
 805           int off = sig_extended.at(next_arg_comp)._offset;
 806           assert(off > 0, "offset in object should be positive");
 807           size_t size_in_bytes = is_java_primitive(bt) ? type2aelembytes(bt) : wordSize;
 808           bool is_oop = (bt == T_OBJECT || bt == T_ARRAY);
 809           has_oop_field = has_oop_field || is_oop;
 810           gen_c2i_adapter_helper(masm, bt, next_arg_comp > 0 ? sig_extended.at(next_arg_comp-1)._bt : T_ILLEGAL,
 811                                  size_in_bytes, regs[next_arg_comp-ignored], Address(r11, off), extraspace, is_oop);
 812         }
 813       } while (vt != 0);
 814       // pass the buffer to the interpreter
 815       __ movptr(Address(rsp, st_off), r11);
 816     }
 817   }
 818 
 819   // If a value type was allocated and initialized, apply post barrier to all oop fields
 820   if (has_value_argument && has_oop_field) {
 821     __ push(r13); // save senderSP
 822     __ push(rbx); // save callee
 823     // Allocate argument register save area
 824     if (frame::arg_reg_save_area_bytes != 0) {
 825       __ subptr(rsp, frame::arg_reg_save_area_bytes);
 826     }
 827     __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::apply_post_barriers), r15_thread, r10);
 828     // De-allocate argument register save area
 829     if (frame::arg_reg_save_area_bytes != 0) {
 830       __ addptr(rsp, frame::arg_reg_save_area_bytes);
 831     }
 832     __ pop(rbx); // restore callee
 833     __ pop(r13); // restore sender SP
 834   }
 835 
 836   // Schedule the branch target address early.
 837   __ movptr(rcx, Address(rbx, in_bytes(Method::interpreter_entry_offset())));
 838   __ jmp(rcx);
 839 }
 840 
 841 static void range_check(MacroAssembler* masm, Register pc_reg, Register temp_reg,
 842                         address code_start, address code_end,
 843                         Label& L_ok) {
 844   Label L_fail;
 845   __ lea(temp_reg, ExternalAddress(code_start));
 846   __ cmpptr(pc_reg, temp_reg);
 847   __ jcc(Assembler::belowEqual, L_fail);
 848   __ lea(temp_reg, ExternalAddress(code_end));
 849   __ cmpptr(pc_reg, temp_reg);
 850   __ jcc(Assembler::below, L_ok);
 851   __ bind(L_fail);
 852 }
 853 
 854 static void gen_i2c_adapter_helper(MacroAssembler* masm,
 855                                    BasicType bt,
 856                                    BasicType prev_bt,
 857                                    size_t size_in_bytes,
 858                                    const VMRegPair& reg_pair,
 859                                    const Address& from,
 860                                    bool is_oop) {
 861   assert(bt != T_VALUETYPE || !ValueTypePassFieldsAsArgs, "no value type here");
 862   if (bt == T_VOID) {
 863     // Longs and doubles are passed in native word order, but misaligned
 864     // in the 32-bit build.
 865     assert(prev_bt == T_LONG || prev_bt == T_DOUBLE, "missing half");
 866     return;
 867   }
 868   assert(!reg_pair.second()->is_valid() || reg_pair.first()->next() == reg_pair.second(),
 869          "scrambled load targets?");
 870 
 871   bool wide = (size_in_bytes == wordSize);
 872   VMReg r_1 = reg_pair.first();
 873   VMReg r_2 = reg_pair.second();
 874   assert(r_2->is_valid() == wide, "invalid size");
 875   if (!r_1->is_valid()) {
 876     assert(!r_2->is_valid(), "must be invalid");
 877     return;
 878   }
 879 
 880   bool is_signed = (bt != T_CHAR) && (bt != T_BOOLEAN);
 881   if (!r_1->is_XMMRegister()) {


 882     // We can use r13 as a temp here because compiled code doesn't need r13 as an input
 883     // and if we end up going thru a c2i because of a miss a reasonable value of r13
 884     // will be generated.
 885     Register dst = r_1->is_stack() ? r13 : r_1->as_Register();
 886     if (is_oop) {
 887       __ load_heap_oop(dst, from);
 888     } else {
 889       __ load_sized_value(dst, from, size_in_bytes, is_signed);
 890     }
 891     if (r_1->is_stack()) {
 892       // Convert stack slot to an SP offset (+ wordSize to account for return address)
 893       int st_off = reg_pair.first()->reg2stack() * VMRegImpl::stack_slot_size + wordSize;
 894       __ movq(Address(rsp, st_off), dst);
 895     }
 896   } else {
 897     if (wide) {
 898       __ movdbl(r_1->as_XMMRegister(), from);
 899     } else {
 900       __ movflt(r_1->as_XMMRegister(), from);
 901     }
 902   }
 903 }
 904 
 905 void SharedRuntime::gen_i2c_adapter(MacroAssembler *masm,
 906                                     int comp_args_on_stack,
 907                                     const GrowableArray<SigEntry>& sig_extended,
 908                                     const VMRegPair *regs) {
 909 
 910   // Note: r13 contains the senderSP on entry. We must preserve it since
 911   // we may do a i2c -> c2i transition if we lose a race where compiled
 912   // code goes non-entrant while we get args ready.
 913   // In addition we use r13 to locate all the interpreter args as
 914   // we must align the stack to 16 bytes on an i2c entry else we
 915   // lose alignment we expect in all compiled code and register


1017   // next_arg_comp is the next argument from the compiler point of
1018   // view (value type fields are passed in registers/on the stack). In
1019   // sig_extended, a value type argument starts with: T_VALUETYPE,
1020   // followed by the types of the fields of the value type and T_VOID
1021   // to mark the end of the value type. ignored counts the number of
1022   // T_VALUETYPE/T_VOID. next_arg_int is the next argument from the
1023   // interpreter point of view (value types are passed by reference).
1024   for (int next_arg_comp = 0, ignored = 0, next_arg_int = 0; next_arg_comp < sig_extended.length(); next_arg_comp++) {
1025     assert(ignored <= next_arg_comp, "shouldn't skip over more slot than there are arguments");
1026     assert(next_arg_int < total_args_passed, "more arguments from the interpreter than expected?");
1027     BasicType bt = sig_extended.at(next_arg_comp)._bt;
1028     int ld_off = (total_args_passed - next_arg_int)*Interpreter::stackElementSize;
1029     if (!ValueTypePassFieldsAsArgs || bt != T_VALUETYPE) {
1030       // Load in argument order going down.
1031       // Point to interpreter value (vs. tag)
1032       int next_off = ld_off - Interpreter::stackElementSize;
1033       int offset = (bt == T_LONG || bt == T_DOUBLE) ? next_off : ld_off;
1034       const VMRegPair reg_pair = regs[next_arg_comp-ignored];
1035       size_t size_in_bytes = reg_pair.second()->is_valid() ? 8 : 4;
1036       gen_i2c_adapter_helper(masm, bt, next_arg_comp > 0 ? sig_extended.at(next_arg_comp-1)._bt : T_ILLEGAL,
1037                              size_in_bytes, reg_pair, Address(saved_sp, offset), false);
1038       next_arg_int++;
1039     } else {
1040       next_arg_int++;
1041       ignored++;
1042       // get the buffer for that value type
1043       __ movptr(r10, Address(saved_sp, ld_off));
1044       int vt = 1;
1045       // load fields to registers/stack slots from the buffer: we know
1046       // we are done with that value type argument when we hit the
1047       // T_VOID that acts as an end of value type delimiter for this
1048       // value type. Value types are flattened so we might encounter
1049       // embedded value types. Each entry in sig_extended contains a
1050       // field offset in the buffer.
1051       do {
1052         next_arg_comp++;
1053         BasicType bt = sig_extended.at(next_arg_comp)._bt;
1054         BasicType prev_bt = sig_extended.at(next_arg_comp-1)._bt;
1055         if (bt == T_VALUETYPE) {
1056           vt++;
1057           ignored++;
1058         } else if (bt == T_VOID &&
1059                    prev_bt != T_LONG &&
1060                    prev_bt != T_DOUBLE) {
1061           vt--;
1062           ignored++;
1063         } else {
1064           int off = sig_extended.at(next_arg_comp)._offset;
1065           assert(off > 0, "offset in object should be positive");
1066           size_t size_in_bytes = is_java_primitive(bt) ? type2aelembytes(bt) : wordSize;
1067           bool is_oop = (bt == T_OBJECT || bt == T_ARRAY);
1068           gen_i2c_adapter_helper(masm, bt, prev_bt, size_in_bytes, regs[next_arg_comp - ignored], Address(r10, off), is_oop);
1069         }
1070       } while (vt != 0);
1071     }
1072   }
1073 
1074   // 6243940 We might end up in handle_wrong_method if
1075   // the callee is deoptimized as we race thru here. If that
1076   // happens we don't want to take a safepoint because the
1077   // caller frame will look interpreted and arguments are now
1078   // "compiled" so it is much better to make this transition
1079   // invisible to the stack walking code. Unfortunately if
1080   // we try and find the callee by normal means a safepoint
1081   // is possible. So we stash the desired callee in the thread
1082   // and the vm will find there should this case occur.
1083 
1084   __ movptr(Address(r15_thread, JavaThread::callee_target_offset()), rbx);
1085 
1086   // put Method* where a c2i would expect should we end up there
1087   // only needed because of c2 resolve stubs return Method* as a result in
1088   // rax


1126     __ jump(RuntimeAddress(SharedRuntime::get_ic_miss_stub()));
1127 
1128     __ bind(ok);
1129     // Method might have been compiled since the call site was patched to
1130     // interpreted if that is the case treat it as a miss so we can get
1131     // the call site corrected.
1132     __ cmpptr(Address(rbx, in_bytes(Method::code_offset())), (int32_t)NULL_WORD);
1133     __ jcc(Assembler::equal, skip_fixup);
1134     __ jump(RuntimeAddress(SharedRuntime::get_ic_miss_stub()));
1135   }
1136 
1137   address c2i_entry = __ pc();
1138 
1139   OopMapSet* oop_maps = NULL;
1140   int frame_complete = CodeOffsets::frame_never_safe;
1141   int frame_size_in_words = 0;
1142   gen_c2i_adapter(masm, sig_extended, regs, skip_fixup, i2c_entry, oop_maps, frame_complete, frame_size_in_words);
1143 
1144   __ flush();
1145   new_adapter = AdapterBlob::create(masm->code(), frame_complete, frame_size_in_words, oop_maps);
1146 
1147   // If value types are passed as fields, save the extended signature as symbol in
1148   // the AdapterHandlerEntry to be used by nmethod::preserve_callee_argument_oops().
1149   Symbol* extended_signature = NULL;
1150   if (ValueTypePassFieldsAsArgs) {
1151     bool has_value_argument = false;
1152     Thread* THREAD = Thread::current();
1153     ResourceMark rm(THREAD);
1154     int length = sig_extended.length();
1155     char* sig_str = NEW_RESOURCE_ARRAY(char, 2*length + 3);
1156     int idx = 0;
1157     sig_str[idx++] = '(';
1158     for (int index = 0; index < length; index++) {
1159       BasicType bt = sig_extended.at(index)._bt;
1160       if (bt == T_VALUETYPE || bt == T_VOID) {
1161         has_value_argument = true;
1162         continue; // Ignore wrapper types
1163       }
1164       sig_str[idx++] = type2char(bt);
1165       if (bt == T_OBJECT) {
1166         sig_str[idx++] = ';';
1167       } else if (bt == T_ARRAY) {
1168         // We don't know the array element type, put void as placeholder
1169         sig_str[idx++] = 'V';
1170       }
1171     }
1172     sig_str[idx++] = ')';
1173     sig_str[idx++] = '\0';
1174     if (has_value_argument) {
1175       // Extended signature is only required if a value type argument is passed
1176       extended_signature = SymbolTable::new_permanent_symbol(sig_str, THREAD);
1177     }
1178   }
1179 
1180   return AdapterHandlerLibrary::new_entry(fingerprint, i2c_entry, c2i_entry, c2i_unverified_entry, extended_signature);
1181 }
1182 
1183 int SharedRuntime::c_calling_convention(const BasicType *sig_bt,
1184                                          VMRegPair *regs,
1185                                          VMRegPair *regs2,
1186                                          int total_args_passed) {
1187   assert(regs2 == NULL, "not needed on x86");
1188 // We return the amount of VMRegImpl stack slots we need to reserve for all
1189 // the arguments NOT counting out_preserve_stack_slots.
1190 
1191 // NOTE: These arrays will have to change when c1 is ported
1192 #ifdef _WIN64
1193     static const Register INT_ArgReg[Argument::n_int_register_parameters_c] = {
1194       c_rarg0, c_rarg1, c_rarg2, c_rarg3
1195     };
1196     static const XMMRegister FP_ArgReg[Argument::n_float_register_parameters_c] = {
1197       c_farg0, c_farg1, c_farg2, c_farg3
1198     };
1199 #else
1200     static const Register INT_ArgReg[Argument::n_int_register_parameters_c] = {


< prev index next >