Mercurial > hg > graal-jvmci-8
comparison src/share/vm/opto/doCall.cpp @ 14422:2b8e28fdf503
Merge
author | kvn |
---|---|
date | Tue, 05 Nov 2013 17:38:04 -0800 |
parents | b2ee5dc63353 |
children | de6a9e811145 |
comparison
equal
deleted
inserted
replaced
14421:3068270ba476 | 14422:2b8e28fdf503 |
---|---|
39 #include "opto/subnode.hpp" | 39 #include "opto/subnode.hpp" |
40 #include "prims/nativeLookup.hpp" | 40 #include "prims/nativeLookup.hpp" |
41 #include "runtime/sharedRuntime.hpp" | 41 #include "runtime/sharedRuntime.hpp" |
42 | 42 |
43 void trace_type_profile(Compile* C, ciMethod *method, int depth, int bci, ciMethod *prof_method, ciKlass *prof_klass, int site_count, int receiver_count) { | 43 void trace_type_profile(Compile* C, ciMethod *method, int depth, int bci, ciMethod *prof_method, ciKlass *prof_klass, int site_count, int receiver_count) { |
44 if (TraceTypeProfile || PrintInlining NOT_PRODUCT(|| PrintOptoInlining)) { | 44 if (TraceTypeProfile || C->print_inlining()) { |
45 outputStream* out = tty; | 45 outputStream* out = tty; |
46 if (!PrintInlining) { | 46 if (!C->print_inlining()) { |
47 if (NOT_PRODUCT(!PrintOpto &&) !PrintCompilation) { | 47 if (NOT_PRODUCT(!PrintOpto &&) !PrintCompilation) { |
48 method->print_short_name(); | 48 method->print_short_name(); |
49 tty->cr(); | 49 tty->cr(); |
50 } | 50 } |
51 CompileTask::print_inlining(prof_method, depth, bci); | 51 CompileTask::print_inlining(prof_method, depth, bci); |
61 } | 61 } |
62 } | 62 } |
63 | 63 |
64 CallGenerator* Compile::call_generator(ciMethod* callee, int vtable_index, bool call_does_dispatch, | 64 CallGenerator* Compile::call_generator(ciMethod* callee, int vtable_index, bool call_does_dispatch, |
65 JVMState* jvms, bool allow_inline, | 65 JVMState* jvms, bool allow_inline, |
66 float prof_factor, bool allow_intrinsics, bool delayed_forbidden) { | 66 float prof_factor, ciKlass* speculative_receiver_type, |
67 bool allow_intrinsics, bool delayed_forbidden) { | |
67 ciMethod* caller = jvms->method(); | 68 ciMethod* caller = jvms->method(); |
68 int bci = jvms->bci(); | 69 int bci = jvms->bci(); |
69 Bytecodes::Code bytecode = caller->java_code_at_bci(bci); | 70 Bytecodes::Code bytecode = caller->java_code_at_bci(bci); |
70 guarantee(callee != NULL, "failed method resolution"); | 71 guarantee(callee != NULL, "failed method resolution"); |
71 | 72 |
108 // Special case the handling of certain common, profitable library | 109 // Special case the handling of certain common, profitable library |
109 // methods. If these methods are replaced with specialized code, | 110 // methods. If these methods are replaced with specialized code, |
110 // then we return it as the inlined version of the call. | 111 // then we return it as the inlined version of the call. |
111 // We do this before the strict f.p. check below because the | 112 // We do this before the strict f.p. check below because the |
112 // intrinsics handle strict f.p. correctly. | 113 // intrinsics handle strict f.p. correctly. |
114 CallGenerator* cg_intrinsic = NULL; | |
113 if (allow_inline && allow_intrinsics) { | 115 if (allow_inline && allow_intrinsics) { |
114 CallGenerator* cg = find_intrinsic(callee, call_does_dispatch); | 116 CallGenerator* cg = find_intrinsic(callee, call_does_dispatch); |
115 if (cg != NULL) { | 117 if (cg != NULL) { |
116 if (cg->is_predicted()) { | 118 if (cg->is_predicted()) { |
117 // Code without intrinsic but, hopefully, inlined. | 119 // Code without intrinsic but, hopefully, inlined. |
118 CallGenerator* inline_cg = this->call_generator(callee, | 120 CallGenerator* inline_cg = this->call_generator(callee, |
119 vtable_index, call_does_dispatch, jvms, allow_inline, prof_factor, false); | 121 vtable_index, call_does_dispatch, jvms, allow_inline, prof_factor, speculative_receiver_type, false); |
120 if (inline_cg != NULL) { | 122 if (inline_cg != NULL) { |
121 cg = CallGenerator::for_predicted_intrinsic(cg, inline_cg); | 123 cg = CallGenerator::for_predicted_intrinsic(cg, inline_cg); |
122 } | 124 } |
123 } | 125 } |
124 return cg; | 126 |
127 // If intrinsic does the virtual dispatch, we try to use the type profile | |
128 // first, and hopefully inline it as the regular virtual call below. | |
129 // We will retry the intrinsic if nothing had claimed it afterwards. | |
130 if (cg->does_virtual_dispatch()) { | |
131 cg_intrinsic = cg; | |
132 cg = NULL; | |
133 } else { | |
134 return cg; | |
135 } | |
125 } | 136 } |
126 } | 137 } |
127 | 138 |
128 // Do method handle calls. | 139 // Do method handle calls. |
129 // NOTE: This must happen before normal inlining logic below since | 140 // NOTE: This must happen before normal inlining logic below since |
200 // Try using the type profile. | 211 // Try using the type profile. |
201 if (call_does_dispatch && site_count > 0 && receiver_count > 0) { | 212 if (call_does_dispatch && site_count > 0 && receiver_count > 0) { |
202 // The major receiver's count >= TypeProfileMajorReceiverPercent of site_count. | 213 // The major receiver's count >= TypeProfileMajorReceiverPercent of site_count. |
203 bool have_major_receiver = (100.*profile.receiver_prob(0) >= (float)TypeProfileMajorReceiverPercent); | 214 bool have_major_receiver = (100.*profile.receiver_prob(0) >= (float)TypeProfileMajorReceiverPercent); |
204 ciMethod* receiver_method = NULL; | 215 ciMethod* receiver_method = NULL; |
205 if (have_major_receiver || profile.morphism() == 1 || | 216 |
206 (profile.morphism() == 2 && UseBimorphicInlining)) { | 217 int morphism = profile.morphism(); |
218 if (speculative_receiver_type != NULL) { | |
219 // We have a speculative type, we should be able to resolve | |
220 // the call. We do that before looking at the profiling at | |
221 // this invoke because it may lead to bimorphic inlining which | |
222 // a speculative type should help us avoid. | |
223 receiver_method = callee->resolve_invoke(jvms->method()->holder(), | |
224 speculative_receiver_type); | |
225 if (receiver_method == NULL) { | |
226 speculative_receiver_type = NULL; | |
227 } else { | |
228 morphism = 1; | |
229 } | |
230 } | |
231 if (receiver_method == NULL && | |
232 (have_major_receiver || morphism == 1 || | |
233 (morphism == 2 && UseBimorphicInlining))) { | |
207 // receiver_method = profile.method(); | 234 // receiver_method = profile.method(); |
208 // Profiles do not suggest methods now. Look it up in the major receiver. | 235 // Profiles do not suggest methods now. Look it up in the major receiver. |
209 receiver_method = callee->resolve_invoke(jvms->method()->holder(), | 236 receiver_method = callee->resolve_invoke(jvms->method()->holder(), |
210 profile.receiver(0)); | 237 profile.receiver(0)); |
211 } | 238 } |
215 vtable_index, !call_does_dispatch, jvms, allow_inline, prof_factor); | 242 vtable_index, !call_does_dispatch, jvms, allow_inline, prof_factor); |
216 if (hit_cg != NULL) { | 243 if (hit_cg != NULL) { |
217 // Look up second receiver. | 244 // Look up second receiver. |
218 CallGenerator* next_hit_cg = NULL; | 245 CallGenerator* next_hit_cg = NULL; |
219 ciMethod* next_receiver_method = NULL; | 246 ciMethod* next_receiver_method = NULL; |
220 if (profile.morphism() == 2 && UseBimorphicInlining) { | 247 if (morphism == 2 && UseBimorphicInlining) { |
221 next_receiver_method = callee->resolve_invoke(jvms->method()->holder(), | 248 next_receiver_method = callee->resolve_invoke(jvms->method()->holder(), |
222 profile.receiver(1)); | 249 profile.receiver(1)); |
223 if (next_receiver_method != NULL) { | 250 if (next_receiver_method != NULL) { |
224 next_hit_cg = this->call_generator(next_receiver_method, | 251 next_hit_cg = this->call_generator(next_receiver_method, |
225 vtable_index, !call_does_dispatch, jvms, | 252 vtable_index, !call_does_dispatch, jvms, |
230 next_hit_cg = NULL; | 257 next_hit_cg = NULL; |
231 } | 258 } |
232 } | 259 } |
233 } | 260 } |
234 CallGenerator* miss_cg; | 261 CallGenerator* miss_cg; |
235 Deoptimization::DeoptReason reason = (profile.morphism() == 2) ? | 262 Deoptimization::DeoptReason reason = morphism == 2 ? |
236 Deoptimization::Reason_bimorphic : | 263 Deoptimization::Reason_bimorphic : |
237 Deoptimization::Reason_class_check; | 264 Deoptimization::Reason_class_check; |
238 if (( profile.morphism() == 1 || | 265 if ((morphism == 1 || (morphism == 2 && next_hit_cg != NULL)) && |
239 (profile.morphism() == 2 && next_hit_cg != NULL) ) && | |
240 !too_many_traps(jvms->method(), jvms->bci(), reason) | 266 !too_many_traps(jvms->method(), jvms->bci(), reason) |
241 ) { | 267 ) { |
242 // Generate uncommon trap for class check failure path | 268 // Generate uncommon trap for class check failure path |
243 // in case of monomorphic or bimorphic virtual call site. | 269 // in case of monomorphic or bimorphic virtual call site. |
244 miss_cg = CallGenerator::for_uncommon_trap(callee, reason, | 270 miss_cg = CallGenerator::for_uncommon_trap(callee, reason, |
248 // in case of polymorphic virtual call site. | 274 // in case of polymorphic virtual call site. |
249 miss_cg = CallGenerator::for_virtual_call(callee, vtable_index); | 275 miss_cg = CallGenerator::for_virtual_call(callee, vtable_index); |
250 } | 276 } |
251 if (miss_cg != NULL) { | 277 if (miss_cg != NULL) { |
252 if (next_hit_cg != NULL) { | 278 if (next_hit_cg != NULL) { |
279 assert(speculative_receiver_type == NULL, "shouldn't end up here if we used speculation"); | |
253 trace_type_profile(C, jvms->method(), jvms->depth() - 1, jvms->bci(), next_receiver_method, profile.receiver(1), site_count, profile.receiver_count(1)); | 280 trace_type_profile(C, jvms->method(), jvms->depth() - 1, jvms->bci(), next_receiver_method, profile.receiver(1), site_count, profile.receiver_count(1)); |
254 // We don't need to record dependency on a receiver here and below. | 281 // We don't need to record dependency on a receiver here and below. |
255 // Whenever we inline, the dependency is added by Parse::Parse(). | 282 // Whenever we inline, the dependency is added by Parse::Parse(). |
256 miss_cg = CallGenerator::for_predicted_call(profile.receiver(1), miss_cg, next_hit_cg, PROB_MAX); | 283 miss_cg = CallGenerator::for_predicted_call(profile.receiver(1), miss_cg, next_hit_cg, PROB_MAX); |
257 } | 284 } |
258 if (miss_cg != NULL) { | 285 if (miss_cg != NULL) { |
259 trace_type_profile(C, jvms->method(), jvms->depth() - 1, jvms->bci(), receiver_method, profile.receiver(0), site_count, receiver_count); | 286 trace_type_profile(C, jvms->method(), jvms->depth() - 1, jvms->bci(), receiver_method, profile.receiver(0), site_count, receiver_count); |
260 CallGenerator* cg = CallGenerator::for_predicted_call(profile.receiver(0), miss_cg, hit_cg, profile.receiver_prob(0)); | 287 ciKlass* k = speculative_receiver_type != NULL ? speculative_receiver_type : profile.receiver(0); |
288 float hit_prob = speculative_receiver_type != NULL ? 1.0 : profile.receiver_prob(0); | |
289 CallGenerator* cg = CallGenerator::for_predicted_call(k, miss_cg, hit_cg, hit_prob); | |
261 if (cg != NULL) return cg; | 290 if (cg != NULL) return cg; |
262 } | 291 } |
263 } | 292 } |
264 } | 293 } |
265 } | 294 } |
266 } | 295 } |
296 } | |
297 | |
298 // Nothing claimed the intrinsic, we go with straight-forward inlining | |
299 // for already discovered intrinsic. | |
300 if (allow_inline && allow_intrinsics && cg_intrinsic != NULL) { | |
301 assert(cg_intrinsic->does_virtual_dispatch(), "sanity"); | |
302 return cg_intrinsic; | |
267 } | 303 } |
268 | 304 |
269 // There was no special inlining tactic, or it bailed out. | 305 // There was no special inlining tactic, or it bailed out. |
270 // Use a more generic tactic, like a simple call. | 306 // Use a more generic tactic, like a simple call. |
271 if (call_does_dispatch) { | 307 if (call_does_dispatch) { |
427 // Try to get the most accurate receiver type | 463 // Try to get the most accurate receiver type |
428 ciMethod* callee = orig_callee; | 464 ciMethod* callee = orig_callee; |
429 int vtable_index = Method::invalid_vtable_index; | 465 int vtable_index = Method::invalid_vtable_index; |
430 bool call_does_dispatch = false; | 466 bool call_does_dispatch = false; |
431 | 467 |
468 // Speculative type of the receiver if any | |
469 ciKlass* speculative_receiver_type = NULL; | |
432 if (is_virtual_or_interface) { | 470 if (is_virtual_or_interface) { |
433 Node* receiver_node = stack(sp() - nargs); | 471 Node* receiver_node = stack(sp() - nargs); |
434 const TypeOopPtr* receiver_type = _gvn.type(receiver_node)->isa_oopptr(); | 472 const TypeOopPtr* receiver_type = _gvn.type(receiver_node)->isa_oopptr(); |
435 // call_does_dispatch and vtable_index are out-parameters. They might be changed. | 473 // call_does_dispatch and vtable_index are out-parameters. They might be changed. |
436 callee = C->optimize_virtual_call(method(), bci(), klass, orig_callee, receiver_type, | 474 callee = C->optimize_virtual_call(method(), bci(), klass, orig_callee, receiver_type, |
437 is_virtual, | 475 is_virtual, |
438 call_does_dispatch, vtable_index); // out-parameters | 476 call_does_dispatch, vtable_index); // out-parameters |
477 speculative_receiver_type = receiver_type != NULL ? receiver_type->speculative_type() : NULL; | |
439 } | 478 } |
440 | 479 |
441 // Note: It's OK to try to inline a virtual call. | 480 // Note: It's OK to try to inline a virtual call. |
442 // The call generator will not attempt to inline a polymorphic call | 481 // The call generator will not attempt to inline a polymorphic call |
443 // unless it knows how to optimize the receiver dispatch. | 482 // unless it knows how to optimize the receiver dispatch. |
449 | 488 |
450 // --------------------- | 489 // --------------------- |
451 // Decide call tactic. | 490 // Decide call tactic. |
452 // This call checks with CHA, the interpreter profile, intrinsics table, etc. | 491 // This call checks with CHA, the interpreter profile, intrinsics table, etc. |
453 // It decides whether inlining is desirable or not. | 492 // It decides whether inlining is desirable or not. |
454 CallGenerator* cg = C->call_generator(callee, vtable_index, call_does_dispatch, jvms, try_inline, prof_factor()); | 493 CallGenerator* cg = C->call_generator(callee, vtable_index, call_does_dispatch, jvms, try_inline, prof_factor(), speculative_receiver_type); |
455 | 494 |
456 // NOTE: Don't use orig_callee and callee after this point! Use cg->method() instead. | 495 // NOTE: Don't use orig_callee and callee after this point! Use cg->method() instead. |
457 orig_callee = callee = NULL; | 496 orig_callee = callee = NULL; |
458 | 497 |
459 // --------------------- | 498 // --------------------- |
460 // Round double arguments before call | 499 // Round double arguments before call |
461 round_double_arguments(cg->method()); | 500 round_double_arguments(cg->method()); |
462 | 501 |
502 // Feed profiling data for arguments to the type system so it can | |
503 // propagate it as speculative types | |
504 record_profiled_arguments_for_speculation(cg->method(), bc()); | |
505 | |
463 #ifndef PRODUCT | 506 #ifndef PRODUCT |
464 // bump global counters for calls | 507 // bump global counters for calls |
465 count_compiled_calls(/*at_method_entry*/ false, cg->is_inline()); | 508 count_compiled_calls(/*at_method_entry*/ false, cg->is_inline()); |
466 | 509 |
467 // Record first part of parsing work for this call | 510 // Record first part of parsing work for this call |
472 assert(jvms_in_sync(), "jvms must carry full info into CG"); | 515 assert(jvms_in_sync(), "jvms must carry full info into CG"); |
473 | 516 |
474 // save across call, for a subsequent cast_not_null. | 517 // save across call, for a subsequent cast_not_null. |
475 Node* receiver = has_receiver ? argument(0) : NULL; | 518 Node* receiver = has_receiver ? argument(0) : NULL; |
476 | 519 |
520 // The extra CheckCastPP for speculative types mess with PhaseStringOpts | |
521 if (receiver != NULL && !call_does_dispatch && !cg->is_string_late_inline()) { | |
522 // Feed profiling data for a single receiver to the type system so | |
523 // it can propagate it as a speculative type | |
524 receiver = record_profiled_receiver_for_speculation(receiver); | |
525 } | |
526 | |
477 // Bump method data counters (We profile *before* the call is made | 527 // Bump method data counters (We profile *before* the call is made |
478 // because exceptions don't return to the call site.) | 528 // because exceptions don't return to the call site.) |
479 profile_call(receiver); | 529 profile_call(receiver); |
480 | 530 |
481 JVMState* new_jvms = cg->generate(jvms); | 531 JVMState* new_jvms = cg->generate(jvms, this); |
482 if (new_jvms == NULL) { | 532 if (new_jvms == NULL) { |
483 // When inlining attempt fails (e.g., too many arguments), | 533 // When inlining attempt fails (e.g., too many arguments), |
484 // it may contaminate the current compile state, making it | 534 // it may contaminate the current compile state, making it |
485 // impossible to pull back and try again. Once we call | 535 // impossible to pull back and try again. Once we call |
486 // cg->generate(), we are committed. If it fails, the whole | 536 // cg->generate(), we are committed. If it fails, the whole |
489 | 539 |
490 // This can happen if a library intrinsic is available, but refuses | 540 // This can happen if a library intrinsic is available, but refuses |
491 // the call site, perhaps because it did not match a pattern the | 541 // the call site, perhaps because it did not match a pattern the |
492 // intrinsic was expecting to optimize. Should always be possible to | 542 // intrinsic was expecting to optimize. Should always be possible to |
493 // get a normal java call that may inline in that case | 543 // get a normal java call that may inline in that case |
494 cg = C->call_generator(cg->method(), vtable_index, call_does_dispatch, jvms, try_inline, prof_factor(), /* allow_intrinsics= */ false); | 544 cg = C->call_generator(cg->method(), vtable_index, call_does_dispatch, jvms, try_inline, prof_factor(), speculative_receiver_type, /* allow_intrinsics= */ false); |
495 if ((new_jvms = cg->generate(jvms)) == NULL) { | 545 if ((new_jvms = cg->generate(jvms, this)) == NULL) { |
496 guarantee(failing(), "call failed to generate: calls should work"); | 546 guarantee(failing(), "call failed to generate: calls should work"); |
497 return; | 547 return; |
498 } | 548 } |
499 } | 549 } |
500 | 550 |
588 // If there is going to be a trap, put it at the next bytecode: | 638 // If there is going to be a trap, put it at the next bytecode: |
589 set_bci(iter().next_bci()); | 639 set_bci(iter().next_bci()); |
590 null_assert(peek()); | 640 null_assert(peek()); |
591 set_bci(iter().cur_bci()); // put it back | 641 set_bci(iter().cur_bci()); // put it back |
592 } | 642 } |
643 BasicType ct = ctype->basic_type(); | |
644 if (ct == T_OBJECT || ct == T_ARRAY) { | |
645 ciKlass* better_type = method()->return_profiled_type(bci()); | |
646 if (UseTypeSpeculation && better_type != NULL) { | |
647 // If profiling reports a single type for the return value, | |
648 // feed it to the type system so it can propagate it as a | |
649 // speculative type | |
650 record_profile_for_speculation(stack(sp()-1), better_type); | |
651 } | |
652 } | |
593 } | 653 } |
594 | 654 |
595 // Restart record of parsing work after possible inlining of call | 655 // Restart record of parsing work after possible inlining of call |
596 #ifndef PRODUCT | 656 #ifndef PRODUCT |
597 parse_histogram()->set_initial_state(bc()); | 657 parse_histogram()->set_initial_state(bc()); |