comparison src/cpu/ppc/vm/sharedRuntime_ppc.cpp @ 14684:e5e8aa897002

8035647: PPC64: Support for elf v2 abi. Summary: ELFv2 ABI used by the little endian PowerPC64 on Linux. Reviewed-by: kvn Contributed-by: asmundak@google.com
author goetz
date Thu, 06 Mar 2014 10:55:28 -0800
parents 67fa91961822
children 58cf34613a72
comparison
equal deleted inserted replaced
14682:84eafecdb9a9 14684:e5e8aa897002
65 return_pc_is_lr, 65 return_pc_is_lr,
66 return_pc_is_r4, 66 return_pc_is_r4,
67 return_pc_is_thread_saved_exception_pc 67 return_pc_is_thread_saved_exception_pc
68 }; 68 };
69 69
70 static OopMap* push_frame_abi112_and_save_live_registers(MacroAssembler* masm, 70 static OopMap* push_frame_reg_args_and_save_live_registers(MacroAssembler* masm,
71 int* out_frame_size_in_bytes, 71 int* out_frame_size_in_bytes,
72 bool generate_oop_map, 72 bool generate_oop_map,
73 int return_pc_adjustment, 73 int return_pc_adjustment,
74 ReturnPCLocation return_pc_location); 74 ReturnPCLocation return_pc_location);
75 static void restore_live_registers_and_pop_frame(MacroAssembler* masm, 75 static void restore_live_registers_and_pop_frame(MacroAssembler* masm,
198 RegisterSaver_LiveIntReg( R29 ), 198 RegisterSaver_LiveIntReg( R29 ),
199 RegisterSaver_LiveIntReg( R31 ), 199 RegisterSaver_LiveIntReg( R31 ),
200 RegisterSaver_LiveIntReg( R30 ), // r30 must be the last register 200 RegisterSaver_LiveIntReg( R30 ), // r30 must be the last register
201 }; 201 };
202 202
203 OopMap* RegisterSaver::push_frame_abi112_and_save_live_registers(MacroAssembler* masm, 203 OopMap* RegisterSaver::push_frame_reg_args_and_save_live_registers(MacroAssembler* masm,
204 int* out_frame_size_in_bytes, 204 int* out_frame_size_in_bytes,
205 bool generate_oop_map, 205 bool generate_oop_map,
206 int return_pc_adjustment, 206 int return_pc_adjustment,
207 ReturnPCLocation return_pc_location) { 207 ReturnPCLocation return_pc_location) {
208 // Push an abi112-frame and store all registers which may be live. 208 // Push an abi_reg_args-frame and store all registers which may be live.
209 // If requested, create an OopMap: Record volatile registers as 209 // If requested, create an OopMap: Record volatile registers as
210 // callee-save values in an OopMap so their save locations will be 210 // callee-save values in an OopMap so their save locations will be
211 // propagated to the RegisterMap of the caller frame during 211 // propagated to the RegisterMap of the caller frame during
212 // StackFrameStream construction (needed for deoptimization; see 212 // StackFrameStream construction (needed for deoptimization; see
213 // compiledVFrame::create_stack_value). 213 // compiledVFrame::create_stack_value).
219 // calcualte frame size 219 // calcualte frame size
220 const int regstosave_num = sizeof(RegisterSaver_LiveRegs) / 220 const int regstosave_num = sizeof(RegisterSaver_LiveRegs) /
221 sizeof(RegisterSaver::LiveRegType); 221 sizeof(RegisterSaver::LiveRegType);
222 const int register_save_size = regstosave_num * reg_size; 222 const int register_save_size = regstosave_num * reg_size;
223 const int frame_size_in_bytes = round_to(register_save_size, frame::alignment_in_bytes) 223 const int frame_size_in_bytes = round_to(register_save_size, frame::alignment_in_bytes)
224 + frame::abi_112_size; 224 + frame::abi_reg_args_size;
225 *out_frame_size_in_bytes = frame_size_in_bytes; 225 *out_frame_size_in_bytes = frame_size_in_bytes;
226 const int frame_size_in_slots = frame_size_in_bytes / sizeof(jint); 226 const int frame_size_in_slots = frame_size_in_bytes / sizeof(jint);
227 const int register_save_offset = frame_size_in_bytes - register_save_size; 227 const int register_save_offset = frame_size_in_bytes - register_save_size;
228 228
229 // OopMap frame size is in c2 stack slots (sizeof(jint)) not bytes or words. 229 // OopMap frame size is in c2 stack slots (sizeof(jint)) not bytes or words.
230 OopMap* map = generate_oop_map ? new OopMap(frame_size_in_slots, 0) : NULL; 230 OopMap* map = generate_oop_map ? new OopMap(frame_size_in_slots, 0) : NULL;
231 231
232 BLOCK_COMMENT("push_frame_abi112_and_save_live_registers {"); 232 BLOCK_COMMENT("push_frame_reg_args_and_save_live_registers {");
233 233
234 // Save r30 in the last slot of the not yet pushed frame so that we 234 // Save r30 in the last slot of the not yet pushed frame so that we
235 // can use it as scratch reg. 235 // can use it as scratch reg.
236 __ std(R30, -reg_size, R1_SP); 236 __ std(R30, -reg_size, R1_SP);
237 assert(-reg_size == register_save_offset - frame_size_in_bytes + ((regstosave_num-1)*reg_size), 237 assert(-reg_size == register_save_offset - frame_size_in_bytes + ((regstosave_num-1)*reg_size),
292 RegisterSaver_LiveRegs[i].vmreg->next()); 292 RegisterSaver_LiveRegs[i].vmreg->next());
293 } 293 }
294 offset += reg_size; 294 offset += reg_size;
295 } 295 }
296 296
297 BLOCK_COMMENT("} push_frame_abi112_and_save_live_registers"); 297 BLOCK_COMMENT("} push_frame_reg_args_and_save_live_registers");
298 298
299 // And we're done. 299 // And we're done.
300 return map; 300 return map;
301 } 301 }
302 302
697 const int inc_stk_for_intfloat = 2; // 2 slots for ints and floats 697 const int inc_stk_for_intfloat = 2; // 2 slots for ints and floats
698 const int inc_stk_for_longdouble = 2; // 2 slots for longs and doubles 698 const int inc_stk_for_longdouble = 2; // 2 slots for longs and doubles
699 699
700 int i; 700 int i;
701 VMReg reg; 701 VMReg reg;
702 // Leave room for C-compatible ABI_112. 702 // Leave room for C-compatible ABI_REG_ARGS.
703 int stk = (frame::abi_112_size - frame::jit_out_preserve_size) / VMRegImpl::stack_slot_size; 703 int stk = (frame::abi_reg_args_size - frame::jit_out_preserve_size) / VMRegImpl::stack_slot_size;
704 int arg = 0; 704 int arg = 0;
705 int freg = 0; 705 int freg = 0;
706 706
707 // Avoid passing C arguments in the wrong stack slots. 707 // Avoid passing C arguments in the wrong stack slots.
708 #if defined(ABI_ELFv2)
709 assert((SharedRuntime::out_preserve_stack_slots() + stk) * VMRegImpl::stack_slot_size == 96,
710 "passing C arguments in wrong stack slots");
711 #else
708 assert((SharedRuntime::out_preserve_stack_slots() + stk) * VMRegImpl::stack_slot_size == 112, 712 assert((SharedRuntime::out_preserve_stack_slots() + stk) * VMRegImpl::stack_slot_size == 112,
709 "passing C arguments in wrong stack slots"); 713 "passing C arguments in wrong stack slots");
710 714 #endif
711 // We fill-out regs AND regs2 if an argument must be passed in a 715 // We fill-out regs AND regs2 if an argument must be passed in a
712 // register AND in a stack slot. If regs2 is NULL in such a 716 // register AND in a stack slot. If regs2 is NULL in such a
713 // situation, we bail-out with a fatal error. 717 // situation, we bail-out with a fatal error.
714 for (int i = 0; i < total_args_passed; ++i, ++arg) { 718 for (int i = 0; i < total_args_passed; ++i, ++arg) {
715 // Initialize regs2 to BAD. 719 // Initialize regs2 to BAD.
1502 __ mr(R3_ARG1, R16_thread); 1506 __ mr(R3_ARG1, R16_thread);
1503 __ set_last_Java_frame(R1_SP, noreg); 1507 __ set_last_Java_frame(R1_SP, noreg);
1504 1508
1505 __ block_comment("block_for_jni_critical"); 1509 __ block_comment("block_for_jni_critical");
1506 address entry_point = CAST_FROM_FN_PTR(address, SharedRuntime::block_for_jni_critical); 1510 address entry_point = CAST_FROM_FN_PTR(address, SharedRuntime::block_for_jni_critical);
1511 #if defined(ABI_ELFv2)
1512 __ call_c(entry_point, relocInfo::runtime_call_type);
1513 #else
1507 __ call_c(CAST_FROM_FN_PTR(FunctionDescriptor*, entry_point), relocInfo::runtime_call_type); 1514 __ call_c(CAST_FROM_FN_PTR(FunctionDescriptor*, entry_point), relocInfo::runtime_call_type);
1515 #endif
1508 address start = __ pc() - __ offset(), 1516 address start = __ pc() - __ offset(),
1509 calls_return_pc = __ last_calls_return_pc(); 1517 calls_return_pc = __ last_calls_return_pc();
1510 oop_maps->add_gc_map(calls_return_pc - start, map); 1518 oop_maps->add_gc_map(calls_return_pc - start, map);
1511 1519
1512 __ reset_last_Java_frame(); 1520 __ reset_last_Java_frame();
1875 // 7) alignment 1883 // 7) alignment
1876 // 1884 //
1877 // Layout of the native wrapper frame: 1885 // Layout of the native wrapper frame:
1878 // (stack grows upwards, memory grows downwards) 1886 // (stack grows upwards, memory grows downwards)
1879 // 1887 //
1880 // NW [ABI_112] <-- 1) R1_SP 1888 // NW [ABI_REG_ARGS] <-- 1) R1_SP
1881 // [outgoing arguments] <-- 2) R1_SP + out_arg_slot_offset 1889 // [outgoing arguments] <-- 2) R1_SP + out_arg_slot_offset
1882 // [oopHandle area] <-- 3) R1_SP + oop_handle_offset (save area for critical natives) 1890 // [oopHandle area] <-- 3) R1_SP + oop_handle_offset (save area for critical natives)
1883 // klass <-- 4) R1_SP + klass_offset 1891 // klass <-- 4) R1_SP + klass_offset
1884 // lock <-- 5) R1_SP + lock_offset 1892 // lock <-- 5) R1_SP + lock_offset
1885 // [workspace] <-- 6) R1_SP + workspace_offset 1893 // [workspace] <-- 6) R1_SP + workspace_offset
2209 2217
2210 // None of the above fast optimizations worked so we have to get into the 2218 // None of the above fast optimizations worked so we have to get into the
2211 // slow case of monitor enter. Inline a special case of call_VM that 2219 // slow case of monitor enter. Inline a special case of call_VM that
2212 // disallows any pending_exception. 2220 // disallows any pending_exception.
2213 2221
2214 // Save argument registers and leave room for C-compatible ABI_112. 2222 // Save argument registers and leave room for C-compatible ABI_REG_ARGS.
2215 int frame_size = frame::abi_112_size + 2223 int frame_size = frame::abi_reg_args_size +
2216 round_to(total_c_args * wordSize, frame::alignment_in_bytes); 2224 round_to(total_c_args * wordSize, frame::alignment_in_bytes);
2217 __ mr(R11_scratch1, R1_SP); 2225 __ mr(R11_scratch1, R1_SP);
2218 RegisterSaver::push_frame_and_save_argument_registers(masm, R12_scratch2, frame_size, total_c_args, out_regs, out_regs2); 2226 RegisterSaver::push_frame_and_save_argument_registers(masm, R12_scratch2, frame_size, total_c_args, out_regs, out_regs2);
2219 2227
2220 // Do the call. 2228 // Do the call.
2248 } 2256 }
2249 2257
2250 2258
2251 // The JNI call 2259 // The JNI call
2252 // -------------------------------------------------------------------------- 2260 // --------------------------------------------------------------------------
2253 2261 #if defined(ABI_ELFv2)
2262 __ call_c(native_func, relocInfo::runtime_call_type);
2263 #else
2254 FunctionDescriptor* fd_native_method = (FunctionDescriptor*) native_func; 2264 FunctionDescriptor* fd_native_method = (FunctionDescriptor*) native_func;
2255 __ call_c(fd_native_method, relocInfo::runtime_call_type); 2265 __ call_c(fd_native_method, relocInfo::runtime_call_type);
2266 #endif
2256 2267
2257 2268
2258 // Now, we are back from the native code. 2269 // Now, we are back from the native code.
2259 2270
2260 2271
2722 int frame_size_in_words; 2733 int frame_size_in_words;
2723 OopMap* map = NULL; 2734 OopMap* map = NULL;
2724 OopMapSet *oop_maps = new OopMapSet(); 2735 OopMapSet *oop_maps = new OopMapSet();
2725 2736
2726 // size of ABI112 plus spill slots for R3_RET and F1_RET. 2737 // size of ABI112 plus spill slots for R3_RET and F1_RET.
2727 const int frame_size_in_bytes = frame::abi_112_spill_size; 2738 const int frame_size_in_bytes = frame::abi_reg_args_spill_size;
2728 const int frame_size_in_slots = frame_size_in_bytes / sizeof(jint); 2739 const int frame_size_in_slots = frame_size_in_bytes / sizeof(jint);
2729 int first_frame_size_in_bytes = 0; // frame size of "unpack frame" for call to fetch_unroll_info. 2740 int first_frame_size_in_bytes = 0; // frame size of "unpack frame" for call to fetch_unroll_info.
2730 2741
2731 const Register exec_mode_reg = R21_tmp1; 2742 const Register exec_mode_reg = R21_tmp1;
2732 2743
2755 // of the return pc. 2766 // of the return pc.
2756 const int return_pc_adjustment_no_exception = -size_deopt_handler(); 2767 const int return_pc_adjustment_no_exception = -size_deopt_handler();
2757 2768
2758 // Push the "unpack frame" 2769 // Push the "unpack frame"
2759 // Save everything in sight. 2770 // Save everything in sight.
2760 map = RegisterSaver::push_frame_abi112_and_save_live_registers(masm, 2771 map = RegisterSaver::push_frame_reg_args_and_save_live_registers(masm,
2761 &first_frame_size_in_bytes, 2772 &first_frame_size_in_bytes,
2762 /*generate_oop_map=*/ true, 2773 /*generate_oop_map=*/ true,
2763 return_pc_adjustment_no_exception, 2774 return_pc_adjustment_no_exception,
2764 RegisterSaver::return_pc_is_lr); 2775 RegisterSaver::return_pc_is_lr);
2765 assert(map != NULL, "OopMap must have been created"); 2776 assert(map != NULL, "OopMap must have been created");
2766 2777
2767 __ li(exec_mode_reg, Deoptimization::Unpack_deopt); 2778 __ li(exec_mode_reg, Deoptimization::Unpack_deopt);
2768 // Save exec mode for unpack_frames. 2779 // Save exec mode for unpack_frames.
2769 __ b(exec_mode_initialized); 2780 __ b(exec_mode_initialized);
2785 const int return_pc_adjustment_exception = 0; 2796 const int return_pc_adjustment_exception = 0;
2786 2797
2787 // Push the "unpack frame". 2798 // Push the "unpack frame".
2788 // Save everything in sight. 2799 // Save everything in sight.
2789 assert(R4 == R4_ARG2, "exception pc must be in r4"); 2800 assert(R4 == R4_ARG2, "exception pc must be in r4");
2790 RegisterSaver::push_frame_abi112_and_save_live_registers(masm, 2801 RegisterSaver::push_frame_reg_args_and_save_live_registers(masm,
2791 &first_frame_size_in_bytes, 2802 &first_frame_size_in_bytes,
2792 /*generate_oop_map=*/ false, 2803 /*generate_oop_map=*/ false,
2793 return_pc_adjustment_exception, 2804 return_pc_adjustment_exception,
2794 RegisterSaver::return_pc_is_r4); 2805 RegisterSaver::return_pc_is_r4);
2795 2806
2796 // Deopt during an exception. Save exec mode for unpack_frames. 2807 // Deopt during an exception. Save exec mode for unpack_frames.
2797 __ li(exec_mode_reg, Deoptimization::Unpack_exception); 2808 __ li(exec_mode_reg, Deoptimization::Unpack_exception);
2798 2809
2799 // Store exception oop and pc in thread (location known to GC). 2810 // Store exception oop and pc in thread (location known to GC).
2874 // stack: (unpack frame, skeletal interpreter frame, ..., optional 2885 // stack: (unpack frame, skeletal interpreter frame, ..., optional
2875 // skeletal interpreter frame, optional c2i, caller of deoptee, 2886 // skeletal interpreter frame, optional c2i, caller of deoptee,
2876 // ...). 2887 // ...).
2877 2888
2878 // Spill live volatile registers since we'll do a call. 2889 // Spill live volatile registers since we'll do a call.
2879 __ std( R3_RET, _abi_112_spill(spill_ret), R1_SP); 2890 __ std( R3_RET, _abi_reg_args_spill(spill_ret), R1_SP);
2880 __ stfd(F1_RET, _abi_112_spill(spill_fret), R1_SP); 2891 __ stfd(F1_RET, _abi_reg_args_spill(spill_fret), R1_SP);
2881 2892
2882 // Let the unpacker layout information in the skeletal frames just 2893 // Let the unpacker layout information in the skeletal frames just
2883 // allocated. 2894 // allocated.
2884 __ get_PC_trash_LR(R3_RET); 2895 __ get_PC_trash_LR(R3_RET);
2885 __ set_last_Java_frame(/*sp*/R1_SP, /*pc*/R3_RET); 2896 __ set_last_Java_frame(/*sp*/R1_SP, /*pc*/R3_RET);
2887 __ call_VM_leaf(CAST_FROM_FN_PTR(address, Deoptimization::unpack_frames), 2898 __ call_VM_leaf(CAST_FROM_FN_PTR(address, Deoptimization::unpack_frames),
2888 R16_thread/*thread*/, exec_mode_reg/*exec_mode*/); 2899 R16_thread/*thread*/, exec_mode_reg/*exec_mode*/);
2889 __ reset_last_Java_frame(); 2900 __ reset_last_Java_frame();
2890 2901
2891 // Restore the volatiles saved above. 2902 // Restore the volatiles saved above.
2892 __ ld( R3_RET, _abi_112_spill(spill_ret), R1_SP); 2903 __ ld( R3_RET, _abi_reg_args_spill(spill_ret), R1_SP);
2893 __ lfd(F1_RET, _abi_112_spill(spill_fret), R1_SP); 2904 __ lfd(F1_RET, _abi_reg_args_spill(spill_fret), R1_SP);
2894 2905
2895 // Pop the unpack frame. 2906 // Pop the unpack frame.
2896 __ pop_frame(); 2907 __ pop_frame();
2897 __ restore_LR_CR(R0); 2908 __ restore_LR_CR(R0);
2898 2909
2928 Register unroll_block_reg = R21_tmp1; 2939 Register unroll_block_reg = R21_tmp1;
2929 Register klass_index_reg = R22_tmp2; 2940 Register klass_index_reg = R22_tmp2;
2930 Register unc_trap_reg = R23_tmp3; 2941 Register unc_trap_reg = R23_tmp3;
2931 2942
2932 OopMapSet* oop_maps = new OopMapSet(); 2943 OopMapSet* oop_maps = new OopMapSet();
2933 int frame_size_in_bytes = frame::abi_112_size; 2944 int frame_size_in_bytes = frame::abi_reg_args_size;
2934 OopMap* map = new OopMap(frame_size_in_bytes / sizeof(jint), 0); 2945 OopMap* map = new OopMap(frame_size_in_bytes / sizeof(jint), 0);
2935 2946
2936 // stack: (deoptee, optional i2c, caller_of_deoptee, ...). 2947 // stack: (deoptee, optional i2c, caller_of_deoptee, ...).
2937 2948
2938 // Push a dummy `unpack_frame' and call 2949 // Push a dummy `unpack_frame' and call
2941 2952
2942 // Save LR to compiled frame. 2953 // Save LR to compiled frame.
2943 __ save_LR_CR(R11_scratch1); 2954 __ save_LR_CR(R11_scratch1);
2944 2955
2945 // Push an "uncommon_trap" frame. 2956 // Push an "uncommon_trap" frame.
2946 __ push_frame_abi112(0, R11_scratch1); 2957 __ push_frame_reg_args(0, R11_scratch1);
2947 2958
2948 // stack: (unpack frame, deoptee, optional i2c, caller_of_deoptee, ...). 2959 // stack: (unpack frame, deoptee, optional i2c, caller_of_deoptee, ...).
2949 2960
2950 // Set the `unpack_frame' as last_Java_frame. 2961 // Set the `unpack_frame' as last_Java_frame.
2951 // `Deoptimization::uncommon_trap' expects it and considers its 2962 // `Deoptimization::uncommon_trap' expects it and considers its
2994 // Push a dummy `unpack_frame' taking care of float return values. 3005 // Push a dummy `unpack_frame' taking care of float return values.
2995 // Call `Deoptimization::unpack_frames' to layout information in the 3006 // Call `Deoptimization::unpack_frames' to layout information in the
2996 // interpreter frames just created. 3007 // interpreter frames just created.
2997 3008
2998 // Push a simple "unpack frame" here. 3009 // Push a simple "unpack frame" here.
2999 __ push_frame_abi112(0, R11_scratch1); 3010 __ push_frame_reg_args(0, R11_scratch1);
3000 3011
3001 // stack: (unpack frame, skeletal interpreter frame, ..., optional 3012 // stack: (unpack frame, skeletal interpreter frame, ..., optional
3002 // skeletal interpreter frame, optional c2i, caller of deoptee, 3013 // skeletal interpreter frame, optional c2i, caller of deoptee,
3003 // ...). 3014 // ...).
3004 3015
3062 // Use thread()->saved_exception_pc() as return pc. 3073 // Use thread()->saved_exception_pc() as return pc.
3063 return_pc_location = RegisterSaver::return_pc_is_thread_saved_exception_pc; 3074 return_pc_location = RegisterSaver::return_pc_is_thread_saved_exception_pc;
3064 } 3075 }
3065 3076
3066 // Save registers, fpu state, and flags. 3077 // Save registers, fpu state, and flags.
3067 map = RegisterSaver::push_frame_abi112_and_save_live_registers(masm, 3078 map = RegisterSaver::push_frame_reg_args_and_save_live_registers(masm,
3068 &frame_size_in_bytes, 3079 &frame_size_in_bytes,
3069 /*generate_oop_map=*/ true, 3080 /*generate_oop_map=*/ true,
3070 /*return_pc_adjustment=*/0, 3081 /*return_pc_adjustment=*/0,
3071 return_pc_location); 3082 return_pc_location);
3072 3083
3073 // The following is basically a call_VM. However, we need the precise 3084 // The following is basically a call_VM. However, we need the precise
3074 // address of the call in order to generate an oopmap. Hence, we do all the 3085 // address of the call in order to generate an oopmap. Hence, we do all the
3075 // work outselves. 3086 // work outselves.
3076 __ set_last_Java_frame(/*sp=*/R1_SP, /*pc=*/noreg); 3087 __ set_last_Java_frame(/*sp=*/R1_SP, /*pc=*/noreg);
3149 OopMapSet *oop_maps = new OopMapSet(); 3160 OopMapSet *oop_maps = new OopMapSet();
3150 OopMap* map = NULL; 3161 OopMap* map = NULL;
3151 3162
3152 address start = __ pc(); 3163 address start = __ pc();
3153 3164
3154 map = RegisterSaver::push_frame_abi112_and_save_live_registers(masm, 3165 map = RegisterSaver::push_frame_reg_args_and_save_live_registers(masm,
3155 &frame_size_in_bytes, 3166 &frame_size_in_bytes,
3156 /*generate_oop_map*/ true, 3167 /*generate_oop_map*/ true,
3157 /*return_pc_adjustment*/ 0, 3168 /*return_pc_adjustment*/ 0,
3158 RegisterSaver::return_pc_is_lr); 3169 RegisterSaver::return_pc_is_lr);
3159 3170
3160 // Use noreg as last_Java_pc, the return pc will be reconstructed 3171 // Use noreg as last_Java_pc, the return pc will be reconstructed
3161 // from the physical frame. 3172 // from the physical frame.
3162 __ set_last_Java_frame(/*sp*/R1_SP, noreg); 3173 __ set_last_Java_frame(/*sp*/R1_SP, noreg);
3163 3174