src/cpu/x86/vm/sharedRuntime_x86_32.cpp

Print this page
rev 5188 : 8024344: PPC64 (part 112): C argument in register AND stack slot.
Summary: On PPC, the first 13 floating point arguments to C calls are passed in floating point registers. Also, all but the first 8 arguments are passed on the stack. So there can be floating point arguments that are passed on the stack and in a register. We duplicate the regs datastructure in c_calling_convention() to represent this.


 960     // Method might have been compiled since the call site was patched to
 961     // interpreted if that is the case treat it as a miss so we can get
 962     // the call site corrected.
 963     __ cmpptr(Address(rbx, in_bytes(Method::code_offset())), (int32_t)NULL_WORD);
 964     __ jcc(Assembler::equal, skip_fixup);
 965 
 966     __ bind(missed);
 967     __ jump(RuntimeAddress(SharedRuntime::get_ic_miss_stub()));
 968   }
 969 
 970   address c2i_entry = __ pc();
 971 
 972   gen_c2i_adapter(masm, total_args_passed, comp_args_on_stack, sig_bt, regs, skip_fixup);
 973 
 974   __ flush();
 975   return AdapterHandlerLibrary::new_entry(fingerprint, i2c_entry, c2i_entry, c2i_unverified_entry);
 976 }
 977 
 978 int SharedRuntime::c_calling_convention(const BasicType *sig_bt,
 979                                          VMRegPair *regs,

 980                                          int total_args_passed) {

 981 // We return the amount of VMRegImpl stack slots we need to reserve for all
 982 // the arguments NOT counting out_preserve_stack_slots.
 983 
 984   uint    stack = 0;        // All arguments on stack
 985 
 986   for( int i = 0; i < total_args_passed; i++) {
 987     // From the type and the argument number (count) compute the location
 988     switch( sig_bt[i] ) {
 989     case T_BOOLEAN:
 990     case T_CHAR:
 991     case T_FLOAT:
 992     case T_BYTE:
 993     case T_SHORT:
 994     case T_INT:
 995     case T_OBJECT:
 996     case T_ARRAY:
 997     case T_ADDRESS:
 998     case T_METADATA:
 999       regs[i].set1(VMRegImpl::stack2reg(stack++));
1000       break;


1607             case 'J': in_elem_bt[i]  = T_LONG; break;
1608             case 'S': in_elem_bt[i]  = T_SHORT; break;
1609             case 'Z': in_elem_bt[i]  = T_BOOLEAN; break;
1610             default: ShouldNotReachHere();
1611           }
1612         }
1613       } else {
1614         out_sig_bt[argc++] = in_sig_bt[i];
1615         in_elem_bt[i] = T_VOID;
1616       }
1617       if (in_sig_bt[i] != T_VOID) {
1618         assert(in_sig_bt[i] == ss.type(), "must match");
1619         ss.next();
1620       }
1621     }
1622   }
1623 
1624   // Now figure out where the args must be stored and how much stack space
1625   // they require.
1626   int out_arg_slots;
1627   out_arg_slots = c_calling_convention(out_sig_bt, out_regs, total_c_args);
1628 
1629   // Compute framesize for the wrapper.  We need to handlize all oops in
1630   // registers a max of 2 on x86.
1631 
1632   // Calculate the total number of stack slots we will need.
1633 
1634   // First count the abi requirement plus all of the outgoing args
1635   int stack_slots = SharedRuntime::out_preserve_stack_slots() + out_arg_slots;
1636 
1637   // Now the space for the inbound oop handle area
1638   int total_save_slots = 2 * VMRegImpl::slots_per_word; // 2 arguments passed in registers
1639   if (is_critical_native) {
1640     // Critical natives may have to call out so they need a save area
1641     // for register arguments.
1642     int double_slots = 0;
1643     int single_slots = 0;
1644     for ( int i = 0; i < total_in_args; i++) {
1645       if (in_regs[i].first()->is_Register()) {
1646         const Register reg = in_regs[i].first()->as_Register();
1647         switch (in_sig_bt[i]) {


2478         out_sig_bt[total_c_args-1] = T_LONG;
2479         out_sig_bt[total_c_args++] = T_VOID;
2480       }
2481     } else if ( bt == T_LONG || bt == T_DOUBLE ) {
2482       in_sig_bt[i++] = T_VOID;   // Longs & doubles take 2 Java slots
2483       out_sig_bt[total_c_args++] = T_VOID;
2484     }
2485   }
2486 
2487   assert(i==total_args_passed, "validly parsed signature");
2488 
2489   // Now get the compiled-Java layout as input arguments
2490   int comp_args_on_stack;
2491   comp_args_on_stack = SharedRuntime::java_calling_convention(
2492       in_sig_bt, in_regs, total_args_passed, false);
2493 
2494   // Now figure out where the args must be stored and how much stack space
2495   // they require (neglecting out_preserve_stack_slots).
2496 
2497   int out_arg_slots;
2498   out_arg_slots = c_calling_convention(out_sig_bt, out_regs, total_c_args);
2499 
2500   // Calculate the total number of stack slots we will need.
2501 
2502   // First count the abi requirement plus all of the outgoing args
2503   int stack_slots = SharedRuntime::out_preserve_stack_slots() + out_arg_slots;
2504 
2505   // Now space for the string(s) we must convert
2506 
2507   int* string_locs   = NEW_RESOURCE_ARRAY(int, total_strings + 1);
2508   for (i = 0; i < total_strings ; i++) {
2509     string_locs[i] = stack_slots;
2510     stack_slots += max_dtrace_string_size / VMRegImpl::stack_slot_size;
2511   }
2512 
2513   // + 2 for return address (which we own) and saved rbp,
2514 
2515   stack_slots += 2;
2516 
2517   // Ok The space we have allocated will look like:
2518   //




 960     // Method might have been compiled since the call site was patched to
 961     // interpreted if that is the case treat it as a miss so we can get
 962     // the call site corrected.
 963     __ cmpptr(Address(rbx, in_bytes(Method::code_offset())), (int32_t)NULL_WORD);
 964     __ jcc(Assembler::equal, skip_fixup);
 965 
 966     __ bind(missed);
 967     __ jump(RuntimeAddress(SharedRuntime::get_ic_miss_stub()));
 968   }
 969 
 970   address c2i_entry = __ pc();
 971 
 972   gen_c2i_adapter(masm, total_args_passed, comp_args_on_stack, sig_bt, regs, skip_fixup);
 973 
 974   __ flush();
 975   return AdapterHandlerLibrary::new_entry(fingerprint, i2c_entry, c2i_entry, c2i_unverified_entry);
 976 }
 977 
 978 int SharedRuntime::c_calling_convention(const BasicType *sig_bt,
 979                                          VMRegPair *regs,
 980                                          VMRegPair *regs2,
 981                                          int total_args_passed) {
 982   assert(regs2 == NULL, "not needed on x86");
 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:
 996     case T_INT:
 997     case T_OBJECT:
 998     case T_ARRAY:
 999     case T_ADDRESS:
1000     case T_METADATA:
1001       regs[i].set1(VMRegImpl::stack2reg(stack++));
1002       break;


1609             case 'J': in_elem_bt[i]  = T_LONG; break;
1610             case 'S': in_elem_bt[i]  = T_SHORT; break;
1611             case 'Z': in_elem_bt[i]  = T_BOOLEAN; break;
1612             default: ShouldNotReachHere();
1613           }
1614         }
1615       } else {
1616         out_sig_bt[argc++] = in_sig_bt[i];
1617         in_elem_bt[i] = T_VOID;
1618       }
1619       if (in_sig_bt[i] != T_VOID) {
1620         assert(in_sig_bt[i] == ss.type(), "must match");
1621         ss.next();
1622       }
1623     }
1624   }
1625 
1626   // Now figure out where the args must be stored and how much stack space
1627   // they require.
1628   int out_arg_slots;
1629   out_arg_slots = c_calling_convention(out_sig_bt, out_regs, NULL, total_c_args);
1630 
1631   // Compute framesize for the wrapper.  We need to handlize all oops in
1632   // registers a max of 2 on x86.
1633 
1634   // Calculate the total number of stack slots we will need.
1635 
1636   // First count the abi requirement plus all of the outgoing args
1637   int stack_slots = SharedRuntime::out_preserve_stack_slots() + out_arg_slots;
1638 
1639   // Now the space for the inbound oop handle area
1640   int total_save_slots = 2 * VMRegImpl::slots_per_word; // 2 arguments passed in registers
1641   if (is_critical_native) {
1642     // Critical natives may have to call out so they need a save area
1643     // for register arguments.
1644     int double_slots = 0;
1645     int single_slots = 0;
1646     for ( int i = 0; i < total_in_args; i++) {
1647       if (in_regs[i].first()->is_Register()) {
1648         const Register reg = in_regs[i].first()->as_Register();
1649         switch (in_sig_bt[i]) {


2480         out_sig_bt[total_c_args-1] = T_LONG;
2481         out_sig_bt[total_c_args++] = T_VOID;
2482       }
2483     } else if ( bt == T_LONG || bt == T_DOUBLE ) {
2484       in_sig_bt[i++] = T_VOID;   // Longs & doubles take 2 Java slots
2485       out_sig_bt[total_c_args++] = T_VOID;
2486     }
2487   }
2488 
2489   assert(i==total_args_passed, "validly parsed signature");
2490 
2491   // Now get the compiled-Java layout as input arguments
2492   int comp_args_on_stack;
2493   comp_args_on_stack = SharedRuntime::java_calling_convention(
2494       in_sig_bt, in_regs, total_args_passed, false);
2495 
2496   // Now figure out where the args must be stored and how much stack space
2497   // they require (neglecting out_preserve_stack_slots).
2498 
2499   int out_arg_slots;
2500   out_arg_slots = c_calling_convention(out_sig_bt, out_regs, NULL, total_c_args);
2501 
2502   // Calculate the total number of stack slots we will need.
2503 
2504   // First count the abi requirement plus all of the outgoing args
2505   int stack_slots = SharedRuntime::out_preserve_stack_slots() + out_arg_slots;
2506 
2507   // Now space for the string(s) we must convert
2508 
2509   int* string_locs   = NEW_RESOURCE_ARRAY(int, total_strings + 1);
2510   for (i = 0; i < total_strings ; i++) {
2511     string_locs[i] = stack_slots;
2512     stack_slots += max_dtrace_string_size / VMRegImpl::stack_slot_size;
2513   }
2514 
2515   // + 2 for return address (which we own) and saved rbp,
2516 
2517   stack_slots += 2;
2518 
2519   // Ok The space we have allocated will look like:
2520   //