comparison src/share/vm/opto/doCall.cpp @ 6634:7f813940ac35

7192406: JSR 292: C2 needs exact return type information for invokedynamic and invokehandle call sites Reviewed-by: kvn
author twisti
date Tue, 28 Aug 2012 15:24:39 -0700
parents b72784e722ff
children da91efe96a93
comparison
equal deleted inserted replaced
6633:a5dd6e3ef9f3 6634:7f813940ac35
339 // Also, if we inline a guy who eventually needs debug info for this JVMS, 339 // Also, if we inline a guy who eventually needs debug info for this JVMS,
340 // our contribution to it is cleaned up right here. 340 // our contribution to it is cleaned up right here.
341 kill_dead_locals(); 341 kill_dead_locals();
342 342
343 // Set frequently used booleans 343 // Set frequently used booleans
344 bool is_virtual = bc() == Bytecodes::_invokevirtual; 344 const bool is_virtual = bc() == Bytecodes::_invokevirtual;
345 bool is_virtual_or_interface = is_virtual || bc() == Bytecodes::_invokeinterface; 345 const bool is_virtual_or_interface = is_virtual || bc() == Bytecodes::_invokeinterface;
346 bool has_receiver = is_virtual_or_interface || bc() == Bytecodes::_invokespecial; 346 const bool has_receiver = is_virtual_or_interface || bc() == Bytecodes::_invokespecial;
347 bool is_invokedynamic = bc() == Bytecodes::_invokedynamic;
348 347
349 // Find target being called 348 // Find target being called
350 bool will_link; 349 bool will_link;
351 ciMethod* bc_callee = iter().get_method(will_link); // actual callee from bytecode 350 ciSignature* declared_signature = NULL;
352 ciInstanceKlass* holder_klass = bc_callee->holder(); 351 ciMethod* orig_callee = iter().get_method(will_link, &declared_signature); // callee in the bytecode
353 ciKlass* holder = iter().get_declared_method_holder(); 352 ciInstanceKlass* holder_klass = orig_callee->holder();
353 ciKlass* holder = iter().get_declared_method_holder();
354 ciInstanceKlass* klass = ciEnv::get_instance_klass_for_declared_method_holder(holder); 354 ciInstanceKlass* klass = ciEnv::get_instance_klass_for_declared_method_holder(holder);
355 assert(declared_signature != NULL, "cannot be null");
355 356
356 // uncommon-trap when callee is unloaded, uninitialized or will not link 357 // uncommon-trap when callee is unloaded, uninitialized or will not link
357 // bailout when too many arguments for register representation 358 // bailout when too many arguments for register representation
358 if (!will_link || can_not_compile_call_site(bc_callee, klass)) { 359 if (!will_link || can_not_compile_call_site(orig_callee, klass)) {
359 #ifndef PRODUCT 360 #ifndef PRODUCT
360 if (PrintOpto && (Verbose || WizardMode)) { 361 if (PrintOpto && (Verbose || WizardMode)) {
361 method()->print_name(); tty->print_cr(" can not compile call at bci %d to:", bci()); 362 method()->print_name(); tty->print_cr(" can not compile call at bci %d to:", bci());
362 bc_callee->print_name(); tty->cr(); 363 orig_callee->print_name(); tty->cr();
363 } 364 }
364 #endif 365 #endif
365 return; 366 return;
366 } 367 }
367 assert(holder_klass->is_loaded(), ""); 368 assert(holder_klass->is_loaded(), "");
370 // which should be invokevirtuals but according to the VM spec may be invokeinterfaces 371 // which should be invokevirtuals but according to the VM spec may be invokeinterfaces
371 assert(holder_klass->is_interface() || holder_klass->super() == NULL || (bc() != Bytecodes::_invokeinterface), "must match bc"); 372 assert(holder_klass->is_interface() || holder_klass->super() == NULL || (bc() != Bytecodes::_invokeinterface), "must match bc");
372 // Note: In the absence of miranda methods, an abstract class K can perform 373 // Note: In the absence of miranda methods, an abstract class K can perform
373 // an invokevirtual directly on an interface method I.m if K implements I. 374 // an invokevirtual directly on an interface method I.m if K implements I.
374 375
375 const int nargs = bc_callee->arg_size(); 376 const int nargs = orig_callee->arg_size();
376 377
377 // Push appendix argument (MethodType, CallSite, etc.), if one. 378 // Push appendix argument (MethodType, CallSite, etc.), if one.
378 if (iter().has_appendix()) { 379 if (iter().has_appendix()) {
379 ciObject* appendix_arg = iter().get_appendix(); 380 ciObject* appendix_arg = iter().get_appendix();
380 const TypeOopPtr* appendix_arg_type = TypeOopPtr::make_from_constant(appendix_arg); 381 const TypeOopPtr* appendix_arg_type = TypeOopPtr::make_from_constant(appendix_arg);
390 // The other path may uncommon_trap, check for another receiver, or do a v-call. 391 // The other path may uncommon_trap, check for another receiver, or do a v-call.
391 392
392 // Choose call strategy. 393 // Choose call strategy.
393 bool call_is_virtual = is_virtual_or_interface; 394 bool call_is_virtual = is_virtual_or_interface;
394 int vtable_index = methodOopDesc::invalid_vtable_index; 395 int vtable_index = methodOopDesc::invalid_vtable_index;
395 ciMethod* callee = bc_callee; 396 ciMethod* callee = orig_callee;
396 397
397 // Try to get the most accurate receiver type 398 // Try to get the most accurate receiver type
398 if (is_virtual_or_interface) { 399 if (is_virtual_or_interface) {
399 Node* receiver_node = stack(sp() - nargs); 400 Node* receiver_node = stack(sp() - nargs);
400 const TypeOopPtr* receiver_type = _gvn.type(receiver_node)->isa_oopptr(); 401 const TypeOopPtr* receiver_type = _gvn.type(receiver_node)->isa_oopptr();
401 ciMethod* optimized_virtual_method = optimize_inlining(method(), bci(), klass, bc_callee, receiver_type); 402 ciMethod* optimized_virtual_method = optimize_inlining(method(), bci(), klass, orig_callee, receiver_type);
402 403
403 // Have the call been sufficiently improved such that it is no longer a virtual? 404 // Have the call been sufficiently improved such that it is no longer a virtual?
404 if (optimized_virtual_method != NULL) { 405 if (optimized_virtual_method != NULL) {
405 callee = optimized_virtual_method; 406 callee = optimized_virtual_method;
406 call_is_virtual = false; 407 call_is_virtual = false;
423 // Decide call tactic. 424 // Decide call tactic.
424 // This call checks with CHA, the interpreter profile, intrinsics table, etc. 425 // This call checks with CHA, the interpreter profile, intrinsics table, etc.
425 // It decides whether inlining is desirable or not. 426 // It decides whether inlining is desirable or not.
426 CallGenerator* cg = C->call_generator(callee, vtable_index, call_is_virtual, jvms, try_inline, prof_factor()); 427 CallGenerator* cg = C->call_generator(callee, vtable_index, call_is_virtual, jvms, try_inline, prof_factor());
427 428
428 bc_callee = callee = NULL; // don't use bc_callee and callee after this point 429 // NOTE: Don't use orig_callee and callee after this point! Use cg->method() instead.
430 orig_callee = callee = NULL;
429 431
430 // --------------------- 432 // ---------------------
431 // Round double arguments before call 433 // Round double arguments before call
432 round_double_arguments(cg->method()); 434 round_double_arguments(cg->method());
433 435
495 497
496 // Round double result after a call from strict to non-strict code 498 // Round double result after a call from strict to non-strict code
497 round_double_result(cg->method()); 499 round_double_result(cg->method());
498 500
499 ciType* rtype = cg->method()->return_type(); 501 ciType* rtype = cg->method()->return_type();
500 if (iter().cur_bc_raw() == Bytecodes::_invokehandle || is_invokedynamic) { 502 if (Bytecodes::has_optional_appendix(iter().cur_bc_raw())) {
501 // Be careful here with return types. 503 // Be careful here with return types.
502 ciType* ctype = iter().get_declared_method_signature()->return_type(); 504 ciType* ctype = declared_signature->return_type();
503 if (ctype != rtype) { 505 if (ctype != rtype) {
504 BasicType rt = rtype->basic_type(); 506 BasicType rt = rtype->basic_type();
505 BasicType ct = ctype->basic_type(); 507 BasicType ct = ctype->basic_type();
506 Node* retnode = peek(); 508 Node* retnode = peek();
507 if (ct == T_VOID) { 509 if (ct == T_VOID) {
526 assert(ct == T_INT, err_msg_res("rt=%s, ct=%s", type2name(rt), type2name(ct))); 528 assert(ct == T_INT, err_msg_res("rt=%s, ct=%s", type2name(rt), type2name(ct)));
527 } 529 }
528 } else if (rt == T_OBJECT || rt == T_ARRAY) { 530 } else if (rt == T_OBJECT || rt == T_ARRAY) {
529 assert(ct == T_OBJECT || ct == T_ARRAY, err_msg_res("rt=%s, ct=%s", type2name(rt), type2name(ct))); 531 assert(ct == T_OBJECT || ct == T_ARRAY, err_msg_res("rt=%s, ct=%s", type2name(rt), type2name(ct)));
530 if (ctype->is_loaded()) { 532 if (ctype->is_loaded()) {
531 Node* if_fail = top(); 533 const TypeOopPtr* arg_type = TypeOopPtr::make_from_klass(rtype->as_klass());
532 retnode = gen_checkcast(retnode, makecon(TypeKlassPtr::make(ctype->as_klass())), &if_fail); 534 const Type* sig_type = TypeOopPtr::make_from_klass(ctype->as_klass());
533 if (if_fail != top()) { 535 if (arg_type != NULL && !arg_type->higher_equal(sig_type)) {
534 PreserveJVMState pjvms(this); 536 Node* cast_obj = _gvn.transform(new (C, 2) CheckCastPPNode(control(), retnode, sig_type));
535 set_control(if_fail); 537 pop();
536 builtin_throw(Deoptimization::Reason_class_check); 538 push(cast_obj);
537 } 539 }
538 pop();
539 push(retnode);
540 } 540 }
541 } else { 541 } else {
542 assert(ct == rt, err_msg_res("unexpected mismatch rt=%d, ct=%d", rt, ct)); 542 assert(ct == rt, err_msg_res("unexpected mismatch rt=%d, ct=%d", rt, ct));
543 // push a zero; it's better than getting an oop/int mismatch 543 // push a zero; it's better than getting an oop/int mismatch
544 retnode = pop_node(rt); 544 retnode = pop_node(rt);