1154 1155 // 6243940 We might end up in handle_wrong_method if 1156 // the callee is deoptimized as we race thru here. If that 1157 // happens we don't want to take a safepoint because the 1158 // caller frame will look interpreted and arguments are now 1159 // "compiled" so it is much better to make this transition 1160 // invisible to the stack walking code. Unfortunately if 1161 // we try and find the callee by normal means a safepoint 1162 // is possible. So we stash the desired callee in the thread 1163 // and the vm will find there should this case occur. 1164 1165 __ movptr(Address(r15_thread, JavaThread::callee_target_offset()), rbx); 1166 1167 // put Method* where a c2i would expect should we end up there 1168 // only needed because of c2 resolve stubs return Method* as a result in 1169 // rax 1170 __ mov(rax, rbx); 1171 __ jmp(r11); 1172 } 1173 1174 // --------------------------------------------------------------- 1175 AdapterHandlerEntry* SharedRuntime::generate_i2c2i_adapters(MacroAssembler *masm, 1176 int comp_args_on_stack, 1177 const GrowableArray<SigEntry>* sig, 1178 const VMRegPair* regs, 1179 const GrowableArray<SigEntry>* sig_cc, 1180 const VMRegPair* regs_cc, 1181 const GrowableArray<SigEntry>* sig_cc_ro, 1182 const VMRegPair* regs_cc_ro, 1183 AdapterFingerPrint* fingerprint, 1184 AdapterBlob*& new_adapter) { 1185 address i2c_entry = __ pc(); 1186 gen_i2c_adapter(masm, comp_args_on_stack, sig, regs); 1187 1188 // ------------------------------------------------------------------------- 1189 // Generate a C2I adapter. On entry we know rbx holds the Method* during calls 1190 // to the interpreter. The args start out packed in the compiled layout. They 1191 // need to be unpacked into the interpreter layout. This will almost always 1192 // require some stack space. We grow the current (compiled) stack, then repack 1193 // the args. We finally end in a jump to the generic interpreter entry point. 1194 // On exit from the interpreter, the interpreter will restore our SP (lest the 1195 // compiled code, which relys solely on SP and not RBP, get sick). 1196 1197 address c2i_unverified_entry = __ pc(); 1198 Label skip_fixup; 1199 Label ok; 1200 1201 Register holder = rax; 1202 Register receiver = j_rarg0; 1203 Register temp = rbx; 1204 1205 { 1206 __ load_klass(temp, receiver); 1207 __ cmpptr(temp, Address(holder, CompiledICHolder::holder_klass_offset())); 1208 __ movptr(rbx, Address(holder, CompiledICHolder::holder_metadata_offset())); 1209 __ jcc(Assembler::equal, ok); 1210 __ jump(RuntimeAddress(SharedRuntime::get_ic_miss_stub())); 1211 1212 __ bind(ok); 1213 // Method might have been compiled since the call site was patched to 1214 // interpreted if that is the case treat it as a miss so we can get 1215 // the call site corrected. 1216 __ cmpptr(Address(rbx, in_bytes(Method::code_offset())), (int32_t)NULL_WORD); 1217 __ jcc(Assembler::equal, skip_fixup); 1218 __ jump(RuntimeAddress(SharedRuntime::get_ic_miss_stub())); 1219 } 1220 1221 OopMapSet* oop_maps = new OopMapSet(); 1222 int frame_complete = CodeOffsets::frame_never_safe; 1223 int frame_size_in_words = 0; 1224 1225 // Scalarized c2i adapter with non-scalarized receiver (i.e., don't pack receiver) 1226 address c2i_value_ro_entry = __ pc(); 1227 if (regs_cc != regs_cc_ro) { 1228 Label unused; 1229 gen_c2i_adapter(masm, sig_cc_ro, regs_cc_ro, skip_fixup, i2c_entry, oop_maps, frame_complete, frame_size_in_words, false); 1230 skip_fixup = unused; 1231 } 1232 1233 // Scalarized c2i adapter 1234 address c2i_entry = __ pc(); 1235 gen_c2i_adapter(masm, sig_cc, regs_cc, skip_fixup, i2c_entry, oop_maps, frame_complete, frame_size_in_words, true); 1236 1237 // Non-scalarized c2i adapter 1238 address c2i_value_entry = c2i_entry; 1239 if (regs != regs_cc) { 1240 c2i_value_entry = __ pc(); 1241 Label unused; 1242 gen_c2i_adapter(masm, sig, regs, unused, i2c_entry, oop_maps, frame_complete, frame_size_in_words, false); 1243 } 1244 1245 __ flush(); 1246 1247 // The c2i adapters might safepoint and trigger a GC. The caller must make sure that 1248 // the GC knows about the location of oop argument locations passed to the c2i adapter. 1249 bool caller_must_gc_arguments = (regs != regs_cc); 1250 new_adapter = AdapterBlob::create(masm->code(), frame_complete, frame_size_in_words, oop_maps, caller_must_gc_arguments); 1251 1252 return AdapterHandlerLibrary::new_entry(fingerprint, i2c_entry, c2i_entry, c2i_value_entry, c2i_value_ro_entry, c2i_unverified_entry); 1253 } 1254 1255 int SharedRuntime::c_calling_convention(const BasicType *sig_bt, 1256 VMRegPair *regs, 1257 VMRegPair *regs2, 1258 int total_args_passed) { 1259 assert(regs2 == NULL, "not needed on x86"); 1260 // We return the amount of VMRegImpl stack slots we need to reserve for all 1261 // the arguments NOT counting out_preserve_stack_slots. 1262 1263 // NOTE: These arrays will have to change when c1 is ported 1264 #ifdef _WIN64 1265 static const Register INT_ArgReg[Argument::n_int_register_parameters_c] = { 1266 c_rarg0, c_rarg1, c_rarg2, c_rarg3 1267 }; 1268 static const XMMRegister FP_ArgReg[Argument::n_float_register_parameters_c] = { 1269 c_farg0, c_farg1, c_farg2, c_farg3 1270 }; 1271 #else 1272 static const Register INT_ArgReg[Argument::n_int_register_parameters_c] = { | 1154 1155 // 6243940 We might end up in handle_wrong_method if 1156 // the callee is deoptimized as we race thru here. If that 1157 // happens we don't want to take a safepoint because the 1158 // caller frame will look interpreted and arguments are now 1159 // "compiled" so it is much better to make this transition 1160 // invisible to the stack walking code. Unfortunately if 1161 // we try and find the callee by normal means a safepoint 1162 // is possible. So we stash the desired callee in the thread 1163 // and the vm will find there should this case occur. 1164 1165 __ movptr(Address(r15_thread, JavaThread::callee_target_offset()), rbx); 1166 1167 // put Method* where a c2i would expect should we end up there 1168 // only needed because of c2 resolve stubs return Method* as a result in 1169 // rax 1170 __ mov(rax, rbx); 1171 __ jmp(r11); 1172 } 1173 1174 static void gen_inline_cache_check(MacroAssembler *masm, Label& skip_fixup) { 1175 Label ok; 1176 1177 Register holder = rax; 1178 Register receiver = j_rarg0; 1179 Register temp = rbx; 1180 1181 __ load_klass(temp, receiver); 1182 __ cmpptr(temp, Address(holder, CompiledICHolder::holder_klass_offset())); 1183 __ movptr(rbx, Address(holder, CompiledICHolder::holder_metadata_offset())); 1184 __ jcc(Assembler::equal, ok); 1185 __ jump(RuntimeAddress(SharedRuntime::get_ic_miss_stub())); 1186 1187 __ bind(ok); 1188 // Method might have been compiled since the call site was patched to 1189 // interpreted if that is the case treat it as a miss so we can get 1190 // the call site corrected. 1191 __ cmpptr(Address(rbx, in_bytes(Method::code_offset())), (int32_t)NULL_WORD); 1192 __ jcc(Assembler::equal, skip_fixup); 1193 __ jump(RuntimeAddress(SharedRuntime::get_ic_miss_stub())); 1194 } 1195 1196 // --------------------------------------------------------------- 1197 AdapterHandlerEntry* SharedRuntime::generate_i2c2i_adapters(MacroAssembler *masm, 1198 int comp_args_on_stack, 1199 const GrowableArray<SigEntry>* sig, 1200 const VMRegPair* regs, 1201 const GrowableArray<SigEntry>* sig_cc, 1202 const VMRegPair* regs_cc, 1203 const GrowableArray<SigEntry>* sig_cc_ro, 1204 const VMRegPair* regs_cc_ro, 1205 AdapterFingerPrint* fingerprint, 1206 AdapterBlob*& new_adapter) { 1207 address i2c_entry = __ pc(); 1208 gen_i2c_adapter(masm, comp_args_on_stack, sig, regs); 1209 1210 // ------------------------------------------------------------------------- 1211 // Generate a C2I adapter. On entry we know rbx holds the Method* during calls 1212 // to the interpreter. The args start out packed in the compiled layout. They 1213 // need to be unpacked into the interpreter layout. This will almost always 1214 // require some stack space. We grow the current (compiled) stack, then repack 1215 // the args. We finally end in a jump to the generic interpreter entry point. 1216 // On exit from the interpreter, the interpreter will restore our SP (lest the 1217 // compiled code, which relys solely on SP and not RBP, get sick). 1218 1219 address c2i_unverified_entry = __ pc(); 1220 Label skip_fixup; 1221 1222 gen_inline_cache_check(masm, skip_fixup); 1223 1224 OopMapSet* oop_maps = new OopMapSet(); 1225 int frame_complete = CodeOffsets::frame_never_safe; 1226 int frame_size_in_words = 0; 1227 1228 // Scalarized c2i adapter with non-scalarized receiver (i.e., don't pack receiver) 1229 address c2i_value_ro_entry = __ pc(); 1230 if (regs_cc != regs_cc_ro) { 1231 Label unused; 1232 gen_c2i_adapter(masm, sig_cc_ro, regs_cc_ro, skip_fixup, i2c_entry, oop_maps, frame_complete, frame_size_in_words, false); 1233 skip_fixup = unused; 1234 } 1235 1236 // Scalarized c2i adapter 1237 address c2i_entry = __ pc(); 1238 gen_c2i_adapter(masm, sig_cc, regs_cc, skip_fixup, i2c_entry, oop_maps, frame_complete, frame_size_in_words, true); 1239 1240 address c2i_unverified_value_entry = c2i_unverified_entry; 1241 1242 // Non-scalarized c2i adapter 1243 address c2i_value_entry = c2i_entry; 1244 if (regs != regs_cc) { 1245 Label value_entry_skip_fixup; 1246 c2i_unverified_value_entry = __ pc(); 1247 gen_inline_cache_check(masm, value_entry_skip_fixup); 1248 1249 c2i_value_entry = __ pc(); 1250 Label unused; 1251 gen_c2i_adapter(masm, sig, regs, value_entry_skip_fixup, i2c_entry, oop_maps, frame_complete, frame_size_in_words, false); 1252 } 1253 1254 __ flush(); 1255 1256 // The c2i adapters might safepoint and trigger a GC. The caller must make sure that 1257 // the GC knows about the location of oop argument locations passed to the c2i adapter. 1258 bool caller_must_gc_arguments = (regs != regs_cc); 1259 new_adapter = AdapterBlob::create(masm->code(), frame_complete, frame_size_in_words, oop_maps, caller_must_gc_arguments); 1260 1261 return AdapterHandlerLibrary::new_entry(fingerprint, i2c_entry, c2i_entry, c2i_value_entry, c2i_value_ro_entry, c2i_unverified_entry, c2i_unverified_value_entry); 1262 } 1263 1264 int SharedRuntime::c_calling_convention(const BasicType *sig_bt, 1265 VMRegPair *regs, 1266 VMRegPair *regs2, 1267 int total_args_passed) { 1268 assert(regs2 == NULL, "not needed on x86"); 1269 // We return the amount of VMRegImpl stack slots we need to reserve for all 1270 // the arguments NOT counting out_preserve_stack_slots. 1271 1272 // NOTE: These arrays will have to change when c1 is ported 1273 #ifdef _WIN64 1274 static const Register INT_ArgReg[Argument::n_int_register_parameters_c] = { 1275 c_rarg0, c_rarg1, c_rarg2, c_rarg3 1276 }; 1277 static const XMMRegister FP_ArgReg[Argument::n_float_register_parameters_c] = { 1278 c_farg0, c_farg1, c_farg2, c_farg3 1279 }; 1280 #else 1281 static const Register INT_ArgReg[Argument::n_int_register_parameters_c] = { |