277 float hit_prob = speculative_receiver_type != NULL ? 1.0 : profile.receiver_prob(0);
278 CallGenerator* cg = CallGenerator::for_predicted_call(k, miss_cg, hit_cg, hit_prob);
279 if (cg != NULL) return cg;
280 }
281 }
282 }
283 }
284 }
285 }
286
287 // Nothing claimed the intrinsic, we go with straight-forward inlining
288 // for already discovered intrinsic.
289 if (allow_inline && allow_intrinsics && cg_intrinsic != NULL) {
290 assert(cg_intrinsic->does_virtual_dispatch(), "sanity");
291 return cg_intrinsic;
292 }
293
294 // There was no special inlining tactic, or it bailed out.
295 // Use a more generic tactic, like a simple call.
296 if (call_does_dispatch) {
297 return CallGenerator::for_virtual_call(callee, vtable_index);
298 } else {
299 // Class Hierarchy Analysis or Type Profile reveals a unique target,
300 // or it is a static or special call.
301 return CallGenerator::for_direct_call(callee, should_delay_inlining(callee, jvms));
302 }
303 }
304
305 // Return true for methods that shouldn't be inlined early so that
306 // they are easier to analyze and optimize as intrinsics.
307 bool Compile::should_delay_string_inlining(ciMethod* call_method, JVMState* jvms) {
308 if (has_stringbuilder()) {
309
310 if ((call_method->holder() == C->env()->StringBuilder_klass() ||
311 call_method->holder() == C->env()->StringBuffer_klass()) &&
312 (jvms->method()->holder() == C->env()->StringBuilder_klass() ||
313 jvms->method()->holder() == C->env()->StringBuffer_klass())) {
314 // Delay SB calls only when called from non-SB code
315 return false;
316 }
379 !holder_klass->is_interface()) {
380 uncommon_trap(Deoptimization::Reason_uninitialized,
381 Deoptimization::Action_reinterpret,
382 holder_klass);
383 return true;
384 }
385
386 assert(dest_method->is_loaded(), "dest_method: typeflow responsibility");
387 return false;
388 }
389
390
391 //------------------------------do_call----------------------------------------
392 // Handle your basic call. Inline if we can & want to, else just setup call.
393 void Parse::do_call() {
394 // It's likely we are going to add debug info soon.
395 // Also, if we inline a guy who eventually needs debug info for this JVMS,
396 // our contribution to it is cleaned up right here.
397 kill_dead_locals();
398
399 // Set frequently used booleans
400 const bool is_virtual = bc() == Bytecodes::_invokevirtual;
401 const bool is_virtual_or_interface = is_virtual || bc() == Bytecodes::_invokeinterface;
402 const bool has_receiver = Bytecodes::has_receiver(bc());
403
404 // Find target being called
405 bool will_link;
406 ciSignature* declared_signature = NULL;
407 ciMethod* orig_callee = iter().get_method(will_link, &declared_signature); // callee in the bytecode
408 ciInstanceKlass* holder_klass = orig_callee->holder();
409 ciKlass* holder = iter().get_declared_method_holder();
410 ciInstanceKlass* klass = ciEnv::get_instance_klass_for_declared_method_holder(holder);
411 assert(declared_signature != NULL, "cannot be null");
412
413 // uncommon-trap when callee is unloaded, uninitialized or will not link
414 // bailout when too many arguments for register representation
415 if (!will_link || can_not_compile_call_site(orig_callee, klass)) {
416 #ifndef PRODUCT
417 if (PrintOpto && (Verbose || WizardMode)) {
418 method()->print_name(); tty->print_cr(" can not compile call at bci %d to:", bci());
514 }
515
516 // Bump method data counters (We profile *before* the call is made
517 // because exceptions don't return to the call site.)
518 profile_call(receiver);
519
520 JVMState* new_jvms = cg->generate(jvms, this);
521 if (new_jvms == NULL) {
522 // When inlining attempt fails (e.g., too many arguments),
523 // it may contaminate the current compile state, making it
524 // impossible to pull back and try again. Once we call
525 // cg->generate(), we are committed. If it fails, the whole
526 // compilation task is compromised.
527 if (failing()) return;
528
529 // This can happen if a library intrinsic is available, but refuses
530 // the call site, perhaps because it did not match a pattern the
531 // intrinsic was expecting to optimize. Should always be possible to
532 // get a normal java call that may inline in that case
533 cg = C->call_generator(cg->method(), vtable_index, call_does_dispatch, jvms, try_inline, prof_factor(), speculative_receiver_type, /* allow_intrinsics= */ false);
534 if ((new_jvms = cg->generate(jvms, this)) == NULL) {
535 guarantee(failing(), "call failed to generate: calls should work");
536 return;
537 }
538 }
539
540 if (cg->is_inline()) {
541 // Accumulate has_loops estimate
542 C->set_has_loops(C->has_loops() || cg->method()->has_loops());
543 C->env()->notice_inlined_method(cg->method());
544 }
545
546 // Reset parser state from [new_]jvms, which now carries results of the call.
547 // Return value (if any) is already pushed on the stack by the cg.
548 add_exception_states_from(new_jvms);
549 if (new_jvms->map()->control() == top()) {
550 stop_and_kill_map();
551 } else {
552 assert(new_jvms->same_calls_as(jvms), "method/bci left unchanged");
553 set_jvms(new_jvms);
554 }
|
277 float hit_prob = speculative_receiver_type != NULL ? 1.0 : profile.receiver_prob(0);
278 CallGenerator* cg = CallGenerator::for_predicted_call(k, miss_cg, hit_cg, hit_prob);
279 if (cg != NULL) return cg;
280 }
281 }
282 }
283 }
284 }
285 }
286
287 // Nothing claimed the intrinsic, we go with straight-forward inlining
288 // for already discovered intrinsic.
289 if (allow_inline && allow_intrinsics && cg_intrinsic != NULL) {
290 assert(cg_intrinsic->does_virtual_dispatch(), "sanity");
291 return cg_intrinsic;
292 }
293
294 // There was no special inlining tactic, or it bailed out.
295 // Use a more generic tactic, like a simple call.
296 if (call_does_dispatch) {
297 const char* msg = "virtual call";
298 if (PrintInlining) print_inlining(callee, jvms->depth() - 1, jvms->bci(), msg);
299 return CallGenerator::for_virtual_call(callee, vtable_index);
300 } else {
301 // Class Hierarchy Analysis or Type Profile reveals a unique target,
302 // or it is a static or special call.
303 return CallGenerator::for_direct_call(callee, should_delay_inlining(callee, jvms));
304 }
305 }
306
307 // Return true for methods that shouldn't be inlined early so that
308 // they are easier to analyze and optimize as intrinsics.
309 bool Compile::should_delay_string_inlining(ciMethod* call_method, JVMState* jvms) {
310 if (has_stringbuilder()) {
311
312 if ((call_method->holder() == C->env()->StringBuilder_klass() ||
313 call_method->holder() == C->env()->StringBuffer_klass()) &&
314 (jvms->method()->holder() == C->env()->StringBuilder_klass() ||
315 jvms->method()->holder() == C->env()->StringBuffer_klass())) {
316 // Delay SB calls only when called from non-SB code
317 return false;
318 }
381 !holder_klass->is_interface()) {
382 uncommon_trap(Deoptimization::Reason_uninitialized,
383 Deoptimization::Action_reinterpret,
384 holder_klass);
385 return true;
386 }
387
388 assert(dest_method->is_loaded(), "dest_method: typeflow responsibility");
389 return false;
390 }
391
392
393 //------------------------------do_call----------------------------------------
394 // Handle your basic call. Inline if we can & want to, else just setup call.
395 void Parse::do_call() {
396 // It's likely we are going to add debug info soon.
397 // Also, if we inline a guy who eventually needs debug info for this JVMS,
398 // our contribution to it is cleaned up right here.
399 kill_dead_locals();
400
401 C->print_inlining_assert_ready();
402
403 // Set frequently used booleans
404 const bool is_virtual = bc() == Bytecodes::_invokevirtual;
405 const bool is_virtual_or_interface = is_virtual || bc() == Bytecodes::_invokeinterface;
406 const bool has_receiver = Bytecodes::has_receiver(bc());
407
408 // Find target being called
409 bool will_link;
410 ciSignature* declared_signature = NULL;
411 ciMethod* orig_callee = iter().get_method(will_link, &declared_signature); // callee in the bytecode
412 ciInstanceKlass* holder_klass = orig_callee->holder();
413 ciKlass* holder = iter().get_declared_method_holder();
414 ciInstanceKlass* klass = ciEnv::get_instance_klass_for_declared_method_holder(holder);
415 assert(declared_signature != NULL, "cannot be null");
416
417 // uncommon-trap when callee is unloaded, uninitialized or will not link
418 // bailout when too many arguments for register representation
419 if (!will_link || can_not_compile_call_site(orig_callee, klass)) {
420 #ifndef PRODUCT
421 if (PrintOpto && (Verbose || WizardMode)) {
422 method()->print_name(); tty->print_cr(" can not compile call at bci %d to:", bci());
518 }
519
520 // Bump method data counters (We profile *before* the call is made
521 // because exceptions don't return to the call site.)
522 profile_call(receiver);
523
524 JVMState* new_jvms = cg->generate(jvms, this);
525 if (new_jvms == NULL) {
526 // When inlining attempt fails (e.g., too many arguments),
527 // it may contaminate the current compile state, making it
528 // impossible to pull back and try again. Once we call
529 // cg->generate(), we are committed. If it fails, the whole
530 // compilation task is compromised.
531 if (failing()) return;
532
533 // This can happen if a library intrinsic is available, but refuses
534 // the call site, perhaps because it did not match a pattern the
535 // intrinsic was expecting to optimize. Should always be possible to
536 // get a normal java call that may inline in that case
537 cg = C->call_generator(cg->method(), vtable_index, call_does_dispatch, jvms, try_inline, prof_factor(), speculative_receiver_type, /* allow_intrinsics= */ false);
538 new_jvms = cg->generate(jvms, this);
539 if (new_jvms == NULL) {
540 guarantee(failing(), "call failed to generate: calls should work");
541 return;
542 }
543 }
544
545 if (cg->is_inline()) {
546 // Accumulate has_loops estimate
547 C->set_has_loops(C->has_loops() || cg->method()->has_loops());
548 C->env()->notice_inlined_method(cg->method());
549 }
550
551 // Reset parser state from [new_]jvms, which now carries results of the call.
552 // Return value (if any) is already pushed on the stack by the cg.
553 add_exception_states_from(new_jvms);
554 if (new_jvms->map()->control() == top()) {
555 stop_and_kill_map();
556 } else {
557 assert(new_jvms->same_calls_as(jvms), "method/bci left unchanged");
558 set_jvms(new_jvms);
559 }
|