205 NOT_PRODUCT(trace_type_profile(jvms->method(), jvms->depth(), jvms->bci(), next_receiver_method, profile.receiver(1), site_count, profile.receiver_count(1)));
206 // We don't need to record dependency on a receiver here and below.
207 // Whenever we inline, the dependency is added by Parse::Parse().
208 miss_cg = CallGenerator::for_predicted_call(profile.receiver(1), miss_cg, next_hit_cg, PROB_MAX);
209 }
210 if (miss_cg != NULL) {
211 NOT_PRODUCT(trace_type_profile(jvms->method(), jvms->depth(), jvms->bci(), receiver_method, profile.receiver(0), site_count, receiver_count));
212 cg = CallGenerator::for_predicted_call(profile.receiver(0), miss_cg, hit_cg, profile.receiver_prob(0));
213 if (cg != NULL) return cg;
214 }
215 }
216 }
217 }
218 }
219 }
220
221 // There was no special inlining tactic, or it bailed out.
222 // Use a more generic tactic, like a simple call.
223 if (call_is_virtual) {
224 return CallGenerator::for_virtual_call(call_method, vtable_index);
225 } else {
226 // Class Hierarchy Analysis or Type Profile reveals a unique target,
227 // or it is a static or special call.
228 return CallGenerator::for_direct_call(call_method);
229 }
230 }
231
232
233 // uncommon-trap call-sites where callee is unloaded, uninitialized or will not link
234 bool Parse::can_not_compile_call_site(ciMethod *dest_method, ciInstanceKlass* klass) {
235 // Additional inputs to consider...
236 // bc = bc()
237 // caller = method()
238 // iter().get_method_holder_index()
239 assert( dest_method->is_loaded(), "ciTypeFlow should not let us get here" );
240 // Interface classes can be loaded & linked and never get around to
241 // being initialized. Uncommon-trap for not-initialized static or
242 // v-calls. Let interface calls happen.
243 ciInstanceKlass* holder_klass = dest_method->holder();
244 if (!holder_klass->is_initialized() &&
245 !holder_klass->is_interface()) {
246 uncommon_trap(Deoptimization::Reason_uninitialized,
247 Deoptimization::Action_reinterpret,
248 holder_klass);
249 return true;
250 }
251 if (dest_method->is_method_handle_invoke()
252 && holder_klass->name() == ciSymbol::java_dyn_InvokeDynamic()) {
253 // FIXME: NYI
254 uncommon_trap(Deoptimization::Reason_unhandled,
255 Deoptimization::Action_none,
256 holder_klass);
257 return true;
258 }
259
260 assert(dest_method->will_link(method()->holder(), klass, bc()), "dest_method: typeflow responsibility");
261 return false;
262 }
263
264
265 //------------------------------do_call----------------------------------------
266 // Handle your basic call. Inline if we can & want to, else just setup call.
267 void Parse::do_call() {
268 // It's likely we are going to add debug info soon.
269 // Also, if we inline a guy who eventually needs debug info for this JVMS,
270 // our contribution to it is cleaned up right here.
271 kill_dead_locals();
272
273 // Set frequently used booleans
274 bool is_virtual = bc() == Bytecodes::_invokevirtual;
275 bool is_virtual_or_interface = is_virtual || bc() == Bytecodes::_invokeinterface;
276 bool has_receiver = is_virtual_or_interface || bc() == Bytecodes::_invokespecial;
277
278 // Find target being called
279 bool will_link;
280 ciMethod* dest_method = iter().get_method(will_link);
281 ciInstanceKlass* holder_klass = dest_method->holder();
282 ciKlass* holder = iter().get_declared_method_holder();
283 ciInstanceKlass* klass = ciEnv::get_instance_klass_for_declared_method_holder(holder);
284
285 int nargs = dest_method->arg_size();
286
287 // uncommon-trap when callee is unloaded, uninitialized or will not link
288 // bailout when too many arguments for register representation
289 if (!will_link || can_not_compile_call_site(dest_method, klass)) {
290 #ifndef PRODUCT
291 if (PrintOpto && (Verbose || WizardMode)) {
292 method()->print_name(); tty->print_cr(" can not compile call at bci %d to:", bci());
293 dest_method->print_name(); tty->cr();
294 }
295 #endif
296 return;
297 }
298 assert(holder_klass->is_loaded(), "");
299 assert(dest_method->is_static() == !has_receiver, "must match bc");
300 // Note: this takes into account invokeinterface of methods declared in java/lang/Object,
301 // which should be invokevirtuals but according to the VM spec may be invokeinterfaces
302 assert(holder_klass->is_interface() || holder_klass->super() == NULL || (bc() != Bytecodes::_invokeinterface), "must match bc");
303 // Note: In the absence of miranda methods, an abstract class K can perform
304 // an invokevirtual directly on an interface method I.m if K implements I.
305
306 // ---------------------
307 // Does Class Hierarchy Analysis reveal only a single target of a v-call?
308 // Then we may inline or make a static call, but become dependent on there being only 1 target.
309 // Does the call-site type profile reveal only one receiver?
310 // Then we may introduce a run-time check and inline on the path where it succeeds.
311 // The other path may uncommon_trap, check for another receiver, or do a v-call.
312
313 // Choose call strategy.
314 bool call_is_virtual = is_virtual_or_interface;
315 int vtable_index = methodOopDesc::invalid_vtable_index;
316 ciMethod* call_method = dest_method;
317
318 // Try to get the most accurate receiver type
319 if (is_virtual_or_interface) {
|
205 NOT_PRODUCT(trace_type_profile(jvms->method(), jvms->depth(), jvms->bci(), next_receiver_method, profile.receiver(1), site_count, profile.receiver_count(1)));
206 // We don't need to record dependency on a receiver here and below.
207 // Whenever we inline, the dependency is added by Parse::Parse().
208 miss_cg = CallGenerator::for_predicted_call(profile.receiver(1), miss_cg, next_hit_cg, PROB_MAX);
209 }
210 if (miss_cg != NULL) {
211 NOT_PRODUCT(trace_type_profile(jvms->method(), jvms->depth(), jvms->bci(), receiver_method, profile.receiver(0), site_count, receiver_count));
212 cg = CallGenerator::for_predicted_call(profile.receiver(0), miss_cg, hit_cg, profile.receiver_prob(0));
213 if (cg != NULL) return cg;
214 }
215 }
216 }
217 }
218 }
219 }
220
221 // There was no special inlining tactic, or it bailed out.
222 // Use a more generic tactic, like a simple call.
223 if (call_is_virtual) {
224 return CallGenerator::for_virtual_call(call_method, vtable_index);
225 } else if (call_method->is_method_handle_invoke()) {
226 if (jvms->method()->java_code_at_bci(jvms->bci()) == Bytecodes::_invokedynamic)
227 return CallGenerator::for_dynamic_call(call_method);
228 else
229 // %%% if the target MH is a compile-time constant, we should try to inline it
230 return CallGenerator::for_direct_call(call_method);
231 } else {
232 // Class Hierarchy Analysis or Type Profile reveals a unique target,
233 // or it is a static or special call.
234 return CallGenerator::for_direct_call(call_method);
235 }
236 }
237
238
239 // uncommon-trap call-sites where callee is unloaded, uninitialized or will not link
240 bool Parse::can_not_compile_call_site(ciMethod *dest_method, ciInstanceKlass* klass) {
241 // Additional inputs to consider...
242 // bc = bc()
243 // caller = method()
244 // iter().get_method_holder_index()
245 assert( dest_method->is_loaded(), "ciTypeFlow should not let us get here" );
246 // Interface classes can be loaded & linked and never get around to
247 // being initialized. Uncommon-trap for not-initialized static or
248 // v-calls. Let interface calls happen.
249 ciInstanceKlass* holder_klass = dest_method->holder();
250 if (!holder_klass->is_initialized() &&
251 !holder_klass->is_interface()) {
252 uncommon_trap(Deoptimization::Reason_uninitialized,
253 Deoptimization::Action_reinterpret,
254 holder_klass);
255 return true;
256 }
257
258 assert(dest_method->will_link(method()->holder(), klass, bc()), "dest_method: typeflow responsibility");
259 return false;
260 }
261
262
263 //------------------------------do_call----------------------------------------
264 // Handle your basic call. Inline if we can & want to, else just setup call.
265 void Parse::do_call() {
266 // It's likely we are going to add debug info soon.
267 // Also, if we inline a guy who eventually needs debug info for this JVMS,
268 // our contribution to it is cleaned up right here.
269 kill_dead_locals();
270
271 // Set frequently used booleans
272 bool is_virtual = bc() == Bytecodes::_invokevirtual;
273 bool is_virtual_or_interface = is_virtual || bc() == Bytecodes::_invokeinterface;
274 bool has_receiver = is_virtual_or_interface || bc() == Bytecodes::_invokespecial;
275 bool is_invokedynamic = bc() == Bytecodes::_invokedynamic;
276
277 // Find target being called
278 bool will_link;
279 ciMethod* dest_method = iter().get_method(will_link);
280 ciInstanceKlass* holder_klass = dest_method->holder();
281 ciKlass* holder = iter().get_declared_method_holder();
282 ciInstanceKlass* klass = ciEnv::get_instance_klass_for_declared_method_holder(holder);
283
284 int nargs = dest_method->arg_size();
285 if (is_invokedynamic) nargs -= 1;
286
287 // uncommon-trap when callee is unloaded, uninitialized or will not link
288 // bailout when too many arguments for register representation
289 if (!will_link || can_not_compile_call_site(dest_method, klass)) {
290 #ifndef PRODUCT
291 if (PrintOpto && (Verbose || WizardMode)) {
292 method()->print_name(); tty->print_cr(" can not compile call at bci %d to:", bci());
293 dest_method->print_name(); tty->cr();
294 }
295 #endif
296 return;
297 }
298 assert(holder_klass->is_loaded(), "");
299 assert((dest_method->is_static() || is_invokedynamic) == !has_receiver , "must match bc");
300 // Note: this takes into account invokeinterface of methods declared in java/lang/Object,
301 // which should be invokevirtuals but according to the VM spec may be invokeinterfaces
302 assert(holder_klass->is_interface() || holder_klass->super() == NULL || (bc() != Bytecodes::_invokeinterface), "must match bc");
303 // Note: In the absence of miranda methods, an abstract class K can perform
304 // an invokevirtual directly on an interface method I.m if K implements I.
305
306 // ---------------------
307 // Does Class Hierarchy Analysis reveal only a single target of a v-call?
308 // Then we may inline or make a static call, but become dependent on there being only 1 target.
309 // Does the call-site type profile reveal only one receiver?
310 // Then we may introduce a run-time check and inline on the path where it succeeds.
311 // The other path may uncommon_trap, check for another receiver, or do a v-call.
312
313 // Choose call strategy.
314 bool call_is_virtual = is_virtual_or_interface;
315 int vtable_index = methodOopDesc::invalid_vtable_index;
316 ciMethod* call_method = dest_method;
317
318 // Try to get the most accurate receiver type
319 if (is_virtual_or_interface) {
|