comparison src/share/vm/opto/doCall.cpp @ 7482:989155e2d07a

Merge with hs25-b15.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Wed, 16 Jan 2013 01:34:24 +0100
parents 5698813d45eb
children f1de9dbc914e
comparison
equal deleted inserted replaced
7381:6761a8f854a4 7482:989155e2d07a
38 #include "opto/runtime.hpp" 38 #include "opto/runtime.hpp"
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(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 || PrintInlining NOT_PRODUCT(|| PrintOptoInlining)) {
45 outputStream* out = tty;
45 if (!PrintInlining) { 46 if (!PrintInlining) {
46 if (NOT_PRODUCT(!PrintOpto &&) !PrintCompilation) { 47 if (NOT_PRODUCT(!PrintOpto &&) !PrintCompilation) {
47 method->print_short_name(); 48 method->print_short_name();
48 tty->cr(); 49 tty->cr();
49 } 50 }
50 CompileTask::print_inlining(prof_method, depth, bci); 51 CompileTask::print_inlining(prof_method, depth, bci);
51 } 52 } else {
52 CompileTask::print_inline_indent(depth); 53 out = C->print_inlining_stream();
53 tty->print(" \\-> TypeProfile (%d/%d counts) = ", receiver_count, site_count); 54 }
54 prof_klass->name()->print_symbol(); 55 CompileTask::print_inline_indent(depth, out);
55 tty->cr(); 56 out->print(" \\-> TypeProfile (%d/%d counts) = ", receiver_count, site_count);
57 stringStream ss;
58 prof_klass->name()->print_symbol_on(&ss);
59 out->print(ss.as_string());
60 out->cr();
56 } 61 }
57 } 62 }
58 63
59 CallGenerator* Compile::call_generator(ciMethod* callee, int vtable_index, bool call_is_virtual, 64 CallGenerator* Compile::call_generator(ciMethod* callee, int vtable_index, bool call_does_dispatch,
60 JVMState* jvms, bool allow_inline, 65 JVMState* jvms, bool allow_inline,
61 float prof_factor, bool allow_intrinsics) { 66 float prof_factor, bool allow_intrinsics, bool delayed_forbidden) {
62 ciMethod* caller = jvms->method(); 67 ciMethod* caller = jvms->method();
63 int bci = jvms->bci(); 68 int bci = jvms->bci();
64 Bytecodes::Code bytecode = caller->java_code_at_bci(bci); 69 Bytecodes::Code bytecode = caller->java_code_at_bci(bci);
65 guarantee(callee != NULL, "failed method resolution"); 70 guarantee(callee != NULL, "failed method resolution");
66 71
75 ciCallProfile profile = caller->call_profile_at_bci(bci); 80 ciCallProfile profile = caller->call_profile_at_bci(bci);
76 81
77 // See how many times this site has been invoked. 82 // See how many times this site has been invoked.
78 int site_count = profile.count(); 83 int site_count = profile.count();
79 int receiver_count = -1; 84 int receiver_count = -1;
80 if (call_is_virtual && UseTypeProfile && profile.has_receiver(0)) { 85 if (call_does_dispatch && UseTypeProfile && profile.has_receiver(0)) {
81 // Receivers in the profile structure are ordered by call counts 86 // Receivers in the profile structure are ordered by call counts
82 // so that the most called (major) receiver is profile.receiver(0). 87 // so that the most called (major) receiver is profile.receiver(0).
83 receiver_count = profile.receiver_count(0); 88 receiver_count = profile.receiver_count(0);
84 } 89 }
85 90
87 if (log != NULL) { 92 if (log != NULL) {
88 int rid = (receiver_count >= 0)? log->identify(profile.receiver(0)): -1; 93 int rid = (receiver_count >= 0)? log->identify(profile.receiver(0)): -1;
89 int r2id = (rid != -1 && profile.has_receiver(1))? log->identify(profile.receiver(1)):-1; 94 int r2id = (rid != -1 && profile.has_receiver(1))? log->identify(profile.receiver(1)):-1;
90 log->begin_elem("call method='%d' count='%d' prof_factor='%g'", 95 log->begin_elem("call method='%d' count='%d' prof_factor='%g'",
91 log->identify(callee), site_count, prof_factor); 96 log->identify(callee), site_count, prof_factor);
92 if (call_is_virtual) log->print(" virtual='1'"); 97 if (call_does_dispatch) log->print(" virtual='1'");
93 if (allow_inline) log->print(" inline='1'"); 98 if (allow_inline) log->print(" inline='1'");
94 if (receiver_count >= 0) { 99 if (receiver_count >= 0) {
95 log->print(" receiver='%d' receiver_count='%d'", rid, receiver_count); 100 log->print(" receiver='%d' receiver_count='%d'", rid, receiver_count);
96 if (profile.has_receiver(1)) { 101 if (profile.has_receiver(1)) {
97 log->print(" receiver2='%d' receiver2_count='%d'", r2id, profile.receiver_count(1)); 102 log->print(" receiver2='%d' receiver2_count='%d'", r2id, profile.receiver_count(1));
104 // methods. If these methods are replaced with specialized code, 109 // methods. If these methods are replaced with specialized code,
105 // then we return it as the inlined version of the call. 110 // then we return it as the inlined version of the call.
106 // We do this before the strict f.p. check below because the 111 // We do this before the strict f.p. check below because the
107 // intrinsics handle strict f.p. correctly. 112 // intrinsics handle strict f.p. correctly.
108 if (allow_inline && allow_intrinsics) { 113 if (allow_inline && allow_intrinsics) {
109 CallGenerator* cg = find_intrinsic(callee, call_is_virtual); 114 CallGenerator* cg = find_intrinsic(callee, call_does_dispatch);
110 if (cg != NULL) { 115 if (cg != NULL) {
111 if (cg->is_predicted()) { 116 if (cg->is_predicted()) {
112 // Code without intrinsic but, hopefully, inlined. 117 // Code without intrinsic but, hopefully, inlined.
113 CallGenerator* inline_cg = this->call_generator(callee, 118 CallGenerator* inline_cg = this->call_generator(callee,
114 vtable_index, call_is_virtual, jvms, allow_inline, prof_factor, false); 119 vtable_index, call_does_dispatch, jvms, allow_inline, prof_factor, false);
115 if (inline_cg != NULL) { 120 if (inline_cg != NULL) {
116 cg = CallGenerator::for_predicted_intrinsic(cg, inline_cg); 121 cg = CallGenerator::for_predicted_intrinsic(cg, inline_cg);
117 } 122 }
118 } 123 }
119 return cg; 124 return cg;
123 // Do method handle calls. 128 // Do method handle calls.
124 // NOTE: This must happen before normal inlining logic below since 129 // NOTE: This must happen before normal inlining logic below since
125 // MethodHandle.invoke* are native methods which obviously don't 130 // MethodHandle.invoke* are native methods which obviously don't
126 // have bytecodes and so normal inlining fails. 131 // have bytecodes and so normal inlining fails.
127 if (callee->is_method_handle_intrinsic()) { 132 if (callee->is_method_handle_intrinsic()) {
128 return CallGenerator::for_method_handle_call(jvms, caller, callee); 133 CallGenerator* cg = CallGenerator::for_method_handle_call(jvms, caller, callee, delayed_forbidden);
134 assert(cg == NULL || !delayed_forbidden || !cg->is_late_inline() || cg->is_mh_late_inline(), "unexpected CallGenerator");
135 return cg;
129 } 136 }
130 137
131 // Do not inline strict fp into non-strict code, or the reverse 138 // Do not inline strict fp into non-strict code, or the reverse
132 if (caller->is_strict() ^ callee->is_strict()) { 139 if (caller->is_strict() ^ callee->is_strict()) {
133 allow_inline = false; 140 allow_inline = false;
140 float past_uses = jvms->method()->scale_count(site_count, prof_factor); 147 float past_uses = jvms->method()->scale_count(site_count, prof_factor);
141 // This is the number of times we expect the call code to be used. 148 // This is the number of times we expect the call code to be used.
142 float expected_uses = past_uses; 149 float expected_uses = past_uses;
143 150
144 // Try inlining a bytecoded method: 151 // Try inlining a bytecoded method:
145 if (!call_is_virtual) { 152 if (!call_does_dispatch) {
146 InlineTree* ilt; 153 InlineTree* ilt;
147 if (UseOldInlining) { 154 if (UseOldInlining) {
148 ilt = InlineTree::find_subtree_from_root(this->ilt(), jvms->caller(), jvms->method()); 155 ilt = InlineTree::find_subtree_from_root(this->ilt(), jvms->caller(), jvms->method());
149 } else { 156 } else {
150 // Make a disembodied, stateless ILT. 157 // Make a disembodied, stateless ILT.
154 ilt = new InlineTree(this, jvms->method(), jvms->caller(), site_invoke_ratio, MaxInlineLevel); 161 ilt = new InlineTree(this, jvms->method(), jvms->caller(), site_invoke_ratio, MaxInlineLevel);
155 } 162 }
156 WarmCallInfo scratch_ci; 163 WarmCallInfo scratch_ci;
157 if (!UseOldInlining) 164 if (!UseOldInlining)
158 scratch_ci.init(jvms, callee, profile, prof_factor); 165 scratch_ci.init(jvms, callee, profile, prof_factor);
159 WarmCallInfo* ci = ilt->ok_to_inline(callee, jvms, profile, &scratch_ci); 166 bool should_delay = false;
167 WarmCallInfo* ci = ilt->ok_to_inline(callee, jvms, profile, &scratch_ci, should_delay);
160 assert(ci != &scratch_ci, "do not let this pointer escape"); 168 assert(ci != &scratch_ci, "do not let this pointer escape");
161 bool allow_inline = (ci != NULL && !ci->is_cold()); 169 bool allow_inline = (ci != NULL && !ci->is_cold());
162 bool require_inline = (allow_inline && ci->is_hot()); 170 bool require_inline = (allow_inline && ci->is_hot());
163 171
164 if (allow_inline) { 172 if (allow_inline) {
165 CallGenerator* cg = CallGenerator::for_inline(callee, expected_uses); 173 CallGenerator* cg = CallGenerator::for_inline(callee, expected_uses);
166 if (require_inline && cg != NULL && should_delay_inlining(callee, jvms)) { 174
175 if (require_inline && cg != NULL) {
167 // Delay the inlining of this method to give us the 176 // Delay the inlining of this method to give us the
168 // opportunity to perform some high level optimizations 177 // opportunity to perform some high level optimizations
169 // first. 178 // first.
170 return CallGenerator::for_late_inline(callee, cg); 179 if (should_delay_inlining(callee, jvms)) {
180 assert(!delayed_forbidden, "strange");
181 return CallGenerator::for_string_late_inline(callee, cg);
182 } else if ((should_delay || AlwaysIncrementalInline) && !delayed_forbidden) {
183 return CallGenerator::for_late_inline(callee, cg);
184 }
171 } 185 }
172 if (cg == NULL) { 186 if (cg == NULL || should_delay) {
173 // Fall through. 187 // Fall through.
174 } else if (require_inline || !InlineWarmCalls) { 188 } else if (require_inline || !InlineWarmCalls) {
175 return cg; 189 return cg;
176 } else { 190 } else {
177 CallGenerator* cold_cg = call_generator(callee, vtable_index, call_is_virtual, jvms, false, prof_factor); 191 CallGenerator* cold_cg = call_generator(callee, vtable_index, call_does_dispatch, jvms, false, prof_factor);
178 return CallGenerator::for_warm_call(ci, cold_cg, cg); 192 return CallGenerator::for_warm_call(ci, cold_cg, cg);
179 } 193 }
180 } 194 }
181 } 195 }
182 196
183 // Try using the type profile. 197 // Try using the type profile.
184 if (call_is_virtual && site_count > 0 && receiver_count > 0) { 198 if (call_does_dispatch && site_count > 0 && receiver_count > 0) {
185 // The major receiver's count >= TypeProfileMajorReceiverPercent of site_count. 199 // The major receiver's count >= TypeProfileMajorReceiverPercent of site_count.
186 bool have_major_receiver = (100.*profile.receiver_prob(0) >= (float)TypeProfileMajorReceiverPercent); 200 bool have_major_receiver = (100.*profile.receiver_prob(0) >= (float)TypeProfileMajorReceiverPercent);
187 ciMethod* receiver_method = NULL; 201 ciMethod* receiver_method = NULL;
188 if (have_major_receiver || profile.morphism() == 1 || 202 if (have_major_receiver || profile.morphism() == 1 ||
189 (profile.morphism() == 2 && UseBimorphicInlining)) { 203 (profile.morphism() == 2 && UseBimorphicInlining)) {
193 profile.receiver(0)); 207 profile.receiver(0));
194 } 208 }
195 if (receiver_method != NULL) { 209 if (receiver_method != NULL) {
196 // The single majority receiver sufficiently outweighs the minority. 210 // The single majority receiver sufficiently outweighs the minority.
197 CallGenerator* hit_cg = this->call_generator(receiver_method, 211 CallGenerator* hit_cg = this->call_generator(receiver_method,
198 vtable_index, !call_is_virtual, jvms, allow_inline, prof_factor); 212 vtable_index, !call_does_dispatch, jvms, allow_inline, prof_factor);
199 if (hit_cg != NULL) { 213 if (hit_cg != NULL) {
200 // Look up second receiver. 214 // Look up second receiver.
201 CallGenerator* next_hit_cg = NULL; 215 CallGenerator* next_hit_cg = NULL;
202 ciMethod* next_receiver_method = NULL; 216 ciMethod* next_receiver_method = NULL;
203 if (profile.morphism() == 2 && UseBimorphicInlining) { 217 if (profile.morphism() == 2 && UseBimorphicInlining) {
204 next_receiver_method = callee->resolve_invoke(jvms->method()->holder(), 218 next_receiver_method = callee->resolve_invoke(jvms->method()->holder(),
205 profile.receiver(1)); 219 profile.receiver(1));
206 if (next_receiver_method != NULL) { 220 if (next_receiver_method != NULL) {
207 next_hit_cg = this->call_generator(next_receiver_method, 221 next_hit_cg = this->call_generator(next_receiver_method,
208 vtable_index, !call_is_virtual, jvms, 222 vtable_index, !call_does_dispatch, jvms,
209 allow_inline, prof_factor); 223 allow_inline, prof_factor);
210 if (next_hit_cg != NULL && !next_hit_cg->is_inline() && 224 if (next_hit_cg != NULL && !next_hit_cg->is_inline() &&
211 have_major_receiver && UseOnlyInlinedBimorphic) { 225 have_major_receiver && UseOnlyInlinedBimorphic) {
212 // Skip if we can't inline second receiver's method 226 // Skip if we can't inline second receiver's method
213 next_hit_cg = NULL; 227 next_hit_cg = NULL;
231 // in case of polymorphic virtual call site. 245 // in case of polymorphic virtual call site.
232 miss_cg = CallGenerator::for_virtual_call(callee, vtable_index); 246 miss_cg = CallGenerator::for_virtual_call(callee, vtable_index);
233 } 247 }
234 if (miss_cg != NULL) { 248 if (miss_cg != NULL) {
235 if (next_hit_cg != NULL) { 249 if (next_hit_cg != NULL) {
236 trace_type_profile(jvms->method(), jvms->depth() - 1, jvms->bci(), next_receiver_method, profile.receiver(1), site_count, profile.receiver_count(1)); 250 trace_type_profile(C, jvms->method(), jvms->depth() - 1, jvms->bci(), next_receiver_method, profile.receiver(1), site_count, profile.receiver_count(1));
237 // We don't need to record dependency on a receiver here and below. 251 // We don't need to record dependency on a receiver here and below.
238 // Whenever we inline, the dependency is added by Parse::Parse(). 252 // Whenever we inline, the dependency is added by Parse::Parse().
239 miss_cg = CallGenerator::for_predicted_call(profile.receiver(1), miss_cg, next_hit_cg, PROB_MAX); 253 miss_cg = CallGenerator::for_predicted_call(profile.receiver(1), miss_cg, next_hit_cg, PROB_MAX);
240 } 254 }
241 if (miss_cg != NULL) { 255 if (miss_cg != NULL) {
242 trace_type_profile(jvms->method(), jvms->depth() - 1, jvms->bci(), receiver_method, profile.receiver(0), site_count, receiver_count); 256 trace_type_profile(C, jvms->method(), jvms->depth() - 1, jvms->bci(), receiver_method, profile.receiver(0), site_count, receiver_count);
243 CallGenerator* cg = CallGenerator::for_predicted_call(profile.receiver(0), miss_cg, hit_cg, profile.receiver_prob(0)); 257 CallGenerator* cg = CallGenerator::for_predicted_call(profile.receiver(0), miss_cg, hit_cg, profile.receiver_prob(0));
244 if (cg != NULL) return cg; 258 if (cg != NULL) return cg;
245 } 259 }
246 } 260 }
247 } 261 }
249 } 263 }
250 } 264 }
251 265
252 // There was no special inlining tactic, or it bailed out. 266 // There was no special inlining tactic, or it bailed out.
253 // Use a more generic tactic, like a simple call. 267 // Use a more generic tactic, like a simple call.
254 if (call_is_virtual) { 268 if (call_does_dispatch) {
255 return CallGenerator::for_virtual_call(callee, vtable_index); 269 return CallGenerator::for_virtual_call(callee, vtable_index);
256 } else { 270 } else {
257 // Class Hierarchy Analysis or Type Profile reveals a unique target, 271 // Class Hierarchy Analysis or Type Profile reveals a unique target,
258 // or it is a static or special call. 272 // or it is a static or special call.
259 return CallGenerator::for_direct_call(callee, should_delay_inlining(callee, jvms)); 273 return CallGenerator::for_direct_call(callee, should_delay_inlining(callee, jvms));
381 // an invokevirtual directly on an interface method I.m if K implements I. 395 // an invokevirtual directly on an interface method I.m if K implements I.
382 396
383 // orig_callee is the resolved callee which's signature includes the 397 // orig_callee is the resolved callee which's signature includes the
384 // appendix argument. 398 // appendix argument.
385 const int nargs = orig_callee->arg_size(); 399 const int nargs = orig_callee->arg_size();
400 const bool is_signature_polymorphic = MethodHandles::is_signature_polymorphic(orig_callee->intrinsic_id());
386 401
387 // Push appendix argument (MethodType, CallSite, etc.), if one. 402 // Push appendix argument (MethodType, CallSite, etc.), if one.
388 if (iter().has_appendix()) { 403 if (iter().has_appendix()) {
389 ciObject* appendix_arg = iter().get_appendix(); 404 ciObject* appendix_arg = iter().get_appendix();
390 const TypeOopPtr* appendix_arg_type = TypeOopPtr::make_from_constant(appendix_arg); 405 const TypeOopPtr* appendix_arg_type = TypeOopPtr::make_from_constant(appendix_arg);
397 // Then we may inline or make a static call, but become dependent on there being only 1 target. 412 // Then we may inline or make a static call, but become dependent on there being only 1 target.
398 // Does the call-site type profile reveal only one receiver? 413 // Does the call-site type profile reveal only one receiver?
399 // Then we may introduce a run-time check and inline on the path where it succeeds. 414 // Then we may introduce a run-time check and inline on the path where it succeeds.
400 // The other path may uncommon_trap, check for another receiver, or do a v-call. 415 // The other path may uncommon_trap, check for another receiver, or do a v-call.
401 416
402 // Choose call strategy.
403 bool call_is_virtual = is_virtual_or_interface;
404 int vtable_index = Method::invalid_vtable_index;
405 ciMethod* callee = orig_callee;
406
407 // Try to get the most accurate receiver type 417 // Try to get the most accurate receiver type
418 ciMethod* callee = orig_callee;
419 int vtable_index = Method::invalid_vtable_index;
420 bool call_does_dispatch = false;
421
408 if (is_virtual_or_interface) { 422 if (is_virtual_or_interface) {
409 Node* receiver_node = stack(sp() - nargs); 423 Node* receiver_node = stack(sp() - nargs);
410 const TypeOopPtr* receiver_type = _gvn.type(receiver_node)->isa_oopptr(); 424 const TypeOopPtr* receiver_type = _gvn.type(receiver_node)->isa_oopptr();
411 ciMethod* optimized_virtual_method = optimize_inlining(method(), bci(), klass, orig_callee, receiver_type); 425 // call_does_dispatch and vtable_index are out-parameters. They might be changed.
412 426 callee = C->optimize_virtual_call(method(), bci(), klass, orig_callee, receiver_type,
413 // Have the call been sufficiently improved such that it is no longer a virtual? 427 is_virtual,
414 if (optimized_virtual_method != NULL) { 428 call_does_dispatch, vtable_index); // out-parameters
415 callee = optimized_virtual_method;
416 call_is_virtual = false;
417 } else if (!UseInlineCaches && is_virtual && callee->is_loaded()) {
418 // We can make a vtable call at this site
419 vtable_index = callee->resolve_vtable_index(method()->holder(), klass);
420 }
421 } 429 }
422 430
423 // Note: It's OK to try to inline a virtual call. 431 // Note: It's OK to try to inline a virtual call.
424 // The call generator will not attempt to inline a polymorphic call 432 // The call generator will not attempt to inline a polymorphic call
425 // unless it knows how to optimize the receiver dispatch. 433 // unless it knows how to optimize the receiver dispatch.
431 439
432 // --------------------- 440 // ---------------------
433 // Decide call tactic. 441 // Decide call tactic.
434 // This call checks with CHA, the interpreter profile, intrinsics table, etc. 442 // This call checks with CHA, the interpreter profile, intrinsics table, etc.
435 // It decides whether inlining is desirable or not. 443 // It decides whether inlining is desirable or not.
436 CallGenerator* cg = C->call_generator(callee, vtable_index, call_is_virtual, jvms, try_inline, prof_factor()); 444 CallGenerator* cg = C->call_generator(callee, vtable_index, call_does_dispatch, jvms, try_inline, prof_factor());
437 445
438 // NOTE: Don't use orig_callee and callee after this point! Use cg->method() instead. 446 // NOTE: Don't use orig_callee and callee after this point! Use cg->method() instead.
439 orig_callee = callee = NULL; 447 orig_callee = callee = NULL;
440 448
441 // --------------------- 449 // ---------------------
471 479
472 // This can happen if a library intrinsic is available, but refuses 480 // This can happen if a library intrinsic is available, but refuses
473 // the call site, perhaps because it did not match a pattern the 481 // the call site, perhaps because it did not match a pattern the
474 // intrinsic was expecting to optimize. Should always be possible to 482 // intrinsic was expecting to optimize. Should always be possible to
475 // get a normal java call that may inline in that case 483 // get a normal java call that may inline in that case
476 cg = C->call_generator(cg->method(), vtable_index, call_is_virtual, jvms, try_inline, prof_factor(), /* allow_intrinsics= */ false); 484 cg = C->call_generator(cg->method(), vtable_index, call_does_dispatch, jvms, try_inline, prof_factor(), /* allow_intrinsics= */ false);
477 if ((new_jvms = cg->generate(jvms)) == NULL) { 485 if ((new_jvms = cg->generate(jvms)) == NULL) {
478 guarantee(failing(), "call failed to generate: calls should work"); 486 guarantee(failing(), "call failed to generate: calls should work");
479 return; 487 return;
480 } 488 }
481 } 489 }
506 514
507 // Round double result after a call from strict to non-strict code 515 // Round double result after a call from strict to non-strict code
508 round_double_result(cg->method()); 516 round_double_result(cg->method());
509 517
510 ciType* rtype = cg->method()->return_type(); 518 ciType* rtype = cg->method()->return_type();
511 if (Bytecodes::has_optional_appendix(iter().cur_bc_raw())) { 519 ciType* ctype = declared_signature->return_type();
520
521 if (Bytecodes::has_optional_appendix(iter().cur_bc_raw()) || is_signature_polymorphic) {
512 // Be careful here with return types. 522 // Be careful here with return types.
513 ciType* ctype = declared_signature->return_type();
514 if (ctype != rtype) { 523 if (ctype != rtype) {
515 BasicType rt = rtype->basic_type(); 524 BasicType rt = rtype->basic_type();
516 BasicType ct = ctype->basic_type(); 525 BasicType ct = ctype->basic_type();
517 Node* retnode = peek();
518 if (ct == T_VOID) { 526 if (ct == T_VOID) {
519 // It's OK for a method to return a value that is discarded. 527 // It's OK for a method to return a value that is discarded.
520 // The discarding does not require any special action from the caller. 528 // The discarding does not require any special action from the caller.
521 // The Java code knows this, at VerifyType.isNullConversion. 529 // The Java code knows this, at VerifyType.isNullConversion.
522 pop_node(rt); // whatever it was, pop it 530 pop_node(rt); // whatever it was, pop it
523 retnode = top();
524 } else if (rt == T_INT || is_subword_type(rt)) { 531 } else if (rt == T_INT || is_subword_type(rt)) {
525 // FIXME: This logic should be factored out. 532 // Nothing. These cases are handled in lambda form bytecode.
526 if (ct == T_BOOLEAN) { 533 assert(ct == T_INT || is_subword_type(ct), err_msg_res("must match: rt=%s, ct=%s", type2name(rt), type2name(ct)));
527 retnode = _gvn.transform( new (C) AndINode(retnode, intcon(0x1)) );
528 } else if (ct == T_CHAR) {
529 retnode = _gvn.transform( new (C) AndINode(retnode, intcon(0xFFFF)) );
530 } else if (ct == T_BYTE) {
531 retnode = _gvn.transform( new (C) LShiftINode(retnode, intcon(24)) );
532 retnode = _gvn.transform( new (C) RShiftINode(retnode, intcon(24)) );
533 } else if (ct == T_SHORT) {
534 retnode = _gvn.transform( new (C) LShiftINode(retnode, intcon(16)) );
535 retnode = _gvn.transform( new (C) RShiftINode(retnode, intcon(16)) );
536 } else {
537 assert(ct == T_INT, err_msg_res("rt=%s, ct=%s", type2name(rt), type2name(ct)));
538 }
539 } else if (rt == T_OBJECT || rt == T_ARRAY) { 534 } else if (rt == T_OBJECT || rt == T_ARRAY) {
540 assert(ct == T_OBJECT || ct == T_ARRAY, err_msg_res("rt=%s, ct=%s", type2name(rt), type2name(ct))); 535 assert(ct == T_OBJECT || ct == T_ARRAY, err_msg_res("rt=%s, ct=%s", type2name(rt), type2name(ct)));
541 if (ctype->is_loaded()) { 536 if (ctype->is_loaded()) {
542 const TypeOopPtr* arg_type = TypeOopPtr::make_from_klass(rtype->as_klass()); 537 const TypeOopPtr* arg_type = TypeOopPtr::make_from_klass(rtype->as_klass());
543 const Type* sig_type = TypeOopPtr::make_from_klass(ctype->as_klass()); 538 const Type* sig_type = TypeOopPtr::make_from_klass(ctype->as_klass());
544 if (arg_type != NULL && !arg_type->higher_equal(sig_type)) { 539 if (arg_type != NULL && !arg_type->higher_equal(sig_type)) {
540 Node* retnode = pop();
545 Node* cast_obj = _gvn.transform(new (C) CheckCastPPNode(control(), retnode, sig_type)); 541 Node* cast_obj = _gvn.transform(new (C) CheckCastPPNode(control(), retnode, sig_type));
546 pop();
547 push(cast_obj); 542 push(cast_obj);
548 } 543 }
549 } 544 }
550 } else { 545 } else {
551 assert(ct == rt, err_msg("unexpected mismatch rt=%d, ct=%d", rt, ct)); 546 assert(rt == ct, err_msg_res("unexpected mismatch: rt=%s, ct=%s", type2name(rt), type2name(ct)));
552 // push a zero; it's better than getting an oop/int mismatch 547 // push a zero; it's better than getting an oop/int mismatch
553 retnode = pop_node(rt); 548 pop_node(rt);
554 retnode = zerocon(ct); 549 Node* retnode = zerocon(ct);
555 push_node(ct, retnode); 550 push_node(ct, retnode);
556 } 551 }
557 // Now that the value is well-behaved, continue with the call-site type. 552 // Now that the value is well-behaved, continue with the call-site type.
558 rtype = ctype; 553 rtype = ctype;
559 } 554 }
555 } else {
556 assert(rtype == ctype, "mismatched return types"); // symbolic resolution enforces this
560 } 557 }
561 558
562 // If the return type of the method is not loaded, assert that the 559 // If the return type of the method is not loaded, assert that the
563 // value we got is a null. Otherwise, we need to recompile. 560 // value we got is a null. Otherwise, we need to recompile.
564 if (!rtype->is_loaded()) { 561 if (!rtype->is_loaded()) {
872 } 869 }
873 } 870 }
874 #endif //PRODUCT 871 #endif //PRODUCT
875 872
876 873
874 ciMethod* Compile::optimize_virtual_call(ciMethod* caller, int bci, ciInstanceKlass* klass,
875 ciMethod* callee, const TypeOopPtr* receiver_type,
876 bool is_virtual,
877 bool& call_does_dispatch, int& vtable_index) {
878 // Set default values for out-parameters.
879 call_does_dispatch = true;
880 vtable_index = Method::invalid_vtable_index;
881
882 // Choose call strategy.
883 ciMethod* optimized_virtual_method = optimize_inlining(caller, bci, klass, callee, receiver_type);
884
885 // Have the call been sufficiently improved such that it is no longer a virtual?
886 if (optimized_virtual_method != NULL) {
887 callee = optimized_virtual_method;
888 call_does_dispatch = false;
889 } else if (!UseInlineCaches && is_virtual && callee->is_loaded()) {
890 // We can make a vtable call at this site
891 vtable_index = callee->resolve_vtable_index(caller->holder(), klass);
892 }
893 return callee;
894 }
895
877 // Identify possible target method and inlining style 896 // Identify possible target method and inlining style
878 ciMethod* Parse::optimize_inlining(ciMethod* caller, int bci, ciInstanceKlass* klass, 897 ciMethod* Compile::optimize_inlining(ciMethod* caller, int bci, ciInstanceKlass* klass,
879 ciMethod *dest_method, const TypeOopPtr* receiver_type) { 898 ciMethod* callee, const TypeOopPtr* receiver_type) {
880 // only use for virtual or interface calls 899 // only use for virtual or interface calls
881 900
882 // If it is obviously final, do not bother to call find_monomorphic_target, 901 // If it is obviously final, do not bother to call find_monomorphic_target,
883 // because the class hierarchy checks are not needed, and may fail due to 902 // because the class hierarchy checks are not needed, and may fail due to
884 // incompletely loaded classes. Since we do our own class loading checks 903 // incompletely loaded classes. Since we do our own class loading checks
885 // in this module, we may confidently bind to any method. 904 // in this module, we may confidently bind to any method.
886 if (dest_method->can_be_statically_bound()) { 905 if (callee->can_be_statically_bound()) {
887 return dest_method; 906 return callee;
888 } 907 }
889 908
890 // Attempt to improve the receiver 909 // Attempt to improve the receiver
891 bool actual_receiver_is_exact = false; 910 bool actual_receiver_is_exact = false;
892 ciInstanceKlass* actual_receiver = klass; 911 ciInstanceKlass* actual_receiver = klass;
893 if (receiver_type != NULL) { 912 if (receiver_type != NULL) {
894 // Array methods are all inherited from Object, and are monomorphic. 913 // Array methods are all inherited from Object, and are monomorphic.
895 if (receiver_type->isa_aryptr() && 914 if (receiver_type->isa_aryptr() &&
896 dest_method->holder() == env()->Object_klass()) { 915 callee->holder() == env()->Object_klass()) {
897 return dest_method; 916 return callee;
898 } 917 }
899 918
900 // All other interesting cases are instance klasses. 919 // All other interesting cases are instance klasses.
901 if (!receiver_type->isa_instptr()) { 920 if (!receiver_type->isa_instptr()) {
902 return NULL; 921 return NULL;
912 actual_receiver_is_exact = receiver_type->klass_is_exact(); 931 actual_receiver_is_exact = receiver_type->klass_is_exact();
913 } 932 }
914 } 933 }
915 934
916 ciInstanceKlass* calling_klass = caller->holder(); 935 ciInstanceKlass* calling_klass = caller->holder();
917 ciMethod* cha_monomorphic_target = dest_method->find_monomorphic_target(calling_klass, klass, actual_receiver); 936 ciMethod* cha_monomorphic_target = callee->find_monomorphic_target(calling_klass, klass, actual_receiver);
918 if (cha_monomorphic_target != NULL) { 937 if (cha_monomorphic_target != NULL) {
919 assert(!cha_monomorphic_target->is_abstract(), ""); 938 assert(!cha_monomorphic_target->is_abstract(), "");
920 // Look at the method-receiver type. Does it add "too much information"? 939 // Look at the method-receiver type. Does it add "too much information"?
921 ciKlass* mr_klass = cha_monomorphic_target->holder(); 940 ciKlass* mr_klass = cha_monomorphic_target->holder();
922 const Type* mr_type = TypeInstPtr::make(TypePtr::BotPTR, mr_klass); 941 const Type* mr_type = TypeInstPtr::make(TypePtr::BotPTR, mr_klass);
930 tty->print_cr("found unique CHA method, but could not cast up"); 949 tty->print_cr("found unique CHA method, but could not cast up");
931 tty->print(" method = "); 950 tty->print(" method = ");
932 cha_monomorphic_target->print(); 951 cha_monomorphic_target->print();
933 tty->cr(); 952 tty->cr();
934 } 953 }
935 if (C->log() != NULL) { 954 if (log() != NULL) {
936 C->log()->elem("missed_CHA_opportunity klass='%d' method='%d'", 955 log()->elem("missed_CHA_opportunity klass='%d' method='%d'",
937 C->log()->identify(klass), 956 log()->identify(klass),
938 C->log()->identify(cha_monomorphic_target)); 957 log()->identify(cha_monomorphic_target));
939 } 958 }
940 cha_monomorphic_target = NULL; 959 cha_monomorphic_target = NULL;
941 } 960 }
942 } 961 }
943 if (cha_monomorphic_target != NULL) { 962 if (cha_monomorphic_target != NULL) {
945 // If we inlined because CHA revealed only a single target method, 964 // If we inlined because CHA revealed only a single target method,
946 // then we are dependent on that target method not getting overridden 965 // then we are dependent on that target method not getting overridden
947 // by dynamic class loading. Be sure to test the "static" receiver 966 // by dynamic class loading. Be sure to test the "static" receiver
948 // dest_method here, as opposed to the actual receiver, which may 967 // dest_method here, as opposed to the actual receiver, which may
949 // falsely lead us to believe that the receiver is final or private. 968 // falsely lead us to believe that the receiver is final or private.
950 C->dependencies()->assert_unique_concrete_method(actual_receiver, cha_monomorphic_target); 969 dependencies()->assert_unique_concrete_method(actual_receiver, cha_monomorphic_target);
951 return cha_monomorphic_target; 970 return cha_monomorphic_target;
952 } 971 }
953 972
954 // If the type is exact, we can still bind the method w/o a vcall. 973 // If the type is exact, we can still bind the method w/o a vcall.
955 // (This case comes after CHA so we can see how much extra work it does.) 974 // (This case comes after CHA so we can see how much extra work it does.)
956 if (actual_receiver_is_exact) { 975 if (actual_receiver_is_exact) {
957 // In case of evolution, there is a dependence on every inlined method, since each 976 // In case of evolution, there is a dependence on every inlined method, since each
958 // such method can be changed when its class is redefined. 977 // such method can be changed when its class is redefined.
959 ciMethod* exact_method = dest_method->resolve_invoke(calling_klass, actual_receiver); 978 ciMethod* exact_method = callee->resolve_invoke(calling_klass, actual_receiver);
960 if (exact_method != NULL) { 979 if (exact_method != NULL) {
961 #ifndef PRODUCT 980 #ifndef PRODUCT
962 if (PrintOpto) { 981 if (PrintOpto) {
963 tty->print(" Calling method via exact type @%d --- ", bci); 982 tty->print(" Calling method via exact type @%d --- ", bci);
964 exact_method->print_name(); 983 exact_method->print_name();