src/share/vm/c1/c1_GraphBuilder.cpp

changeset 3498
f067b4e0e04b
parent 3497
2f5980b127e3
child 3570
80107dc493db
equal deleted inserted replaced
3497:2f5980b127e3 3498:f067b4e0e04b
1590 // I've added the target-is_loaded() test below but I don't really understand 1590 // I've added the target-is_loaded() test below but I don't really understand
1591 // how klass->is_loaded() can be true and yet target->is_loaded() is false. 1591 // how klass->is_loaded() can be true and yet target->is_loaded() is false.
1592 // this happened while running the JCK invokevirtual tests under doit. TKR 1592 // this happened while running the JCK invokevirtual tests under doit. TKR
1593 ciMethod* cha_monomorphic_target = NULL; 1593 ciMethod* cha_monomorphic_target = NULL;
1594 ciMethod* exact_target = NULL; 1594 ciMethod* exact_target = NULL;
1595 Value better_receiver = NULL;
1595 if (UseCHA && DeoptC1 && klass->is_loaded() && target->is_loaded() && 1596 if (UseCHA && DeoptC1 && klass->is_loaded() && target->is_loaded() &&
1596 !target->is_method_handle_invoke()) { 1597 !target->is_method_handle_invoke()) {
1597 Value receiver = NULL; 1598 Value receiver = NULL;
1598 ciInstanceKlass* receiver_klass = NULL; 1599 ciInstanceKlass* receiver_klass = NULL;
1599 bool type_is_exact = false; 1600 bool type_is_exact = false;
1651 // expect. Interface types are not checked by the verifier so 1652 // expect. Interface types are not checked by the verifier so
1652 // they are roughly equivalent to Object. 1653 // they are roughly equivalent to Object.
1653 ciInstanceKlass* singleton = NULL; 1654 ciInstanceKlass* singleton = NULL;
1654 if (target->holder()->nof_implementors() == 1) { 1655 if (target->holder()->nof_implementors() == 1) {
1655 singleton = target->holder()->implementor(0); 1656 singleton = target->holder()->implementor(0);
1657
1658 assert(holder->is_interface(), "invokeinterface to non interface?");
1659 ciInstanceKlass* decl_interface = (ciInstanceKlass*)holder;
1660 // the number of implementors for decl_interface is less or
1661 // equal to the number of implementors for target->holder() so
1662 // if number of implementors of target->holder() == 1 then
1663 // number of implementors for decl_interface is 0 or 1. If
1664 // it's 0 then no class implements decl_interface and there's
1665 // no point in inlining.
1666 if (!holder->is_loaded() || decl_interface->nof_implementors() != 1) {
1667 singleton = NULL;
1668 }
1656 } 1669 }
1657 if (singleton) { 1670 if (singleton) {
1658 cha_monomorphic_target = target->find_monomorphic_target(calling_klass, target->holder(), singleton); 1671 cha_monomorphic_target = target->find_monomorphic_target(calling_klass, target->holder(), singleton);
1659 if (cha_monomorphic_target != NULL) { 1672 if (cha_monomorphic_target != NULL) {
1660 // If CHA is able to bind this invoke then update the class 1673 // If CHA is able to bind this invoke then update the class
1665 1678
1666 // insert a check it's really the expected class. 1679 // insert a check it's really the expected class.
1667 CheckCast* c = new CheckCast(klass, receiver, copy_state_for_exception()); 1680 CheckCast* c = new CheckCast(klass, receiver, copy_state_for_exception());
1668 c->set_incompatible_class_change_check(); 1681 c->set_incompatible_class_change_check();
1669 c->set_direct_compare(klass->is_final()); 1682 c->set_direct_compare(klass->is_final());
1670 append_split(c); 1683 // pass the result of the checkcast so that the compiler has
1684 // more accurate type info in the inlinee
1685 better_receiver = append_split(c);
1671 } 1686 }
1672 } 1687 }
1673 } 1688 }
1674 } 1689 }
1675 1690
1707 // method handle invokes 1722 // method handle invokes
1708 success = !is_invokedynamic ? for_method_handle_inline(target) : for_invokedynamic_inline(target); 1723 success = !is_invokedynamic ? for_method_handle_inline(target) : for_invokedynamic_inline(target);
1709 } 1724 }
1710 if (!success) { 1725 if (!success) {
1711 // static binding => check if callee is ok 1726 // static binding => check if callee is ok
1712 success = try_inline(inline_target, (cha_monomorphic_target != NULL) || (exact_target != NULL)); 1727 success = try_inline(inline_target, (cha_monomorphic_target != NULL) || (exact_target != NULL), better_receiver);
1713 } 1728 }
1714 CHECK_BAILOUT(); 1729 CHECK_BAILOUT();
1715 1730
1716 #ifndef PRODUCT 1731 #ifndef PRODUCT
1717 // printing 1732 // printing
3032 } 3047 }
3033 return recur_level; 3048 return recur_level;
3034 } 3049 }
3035 3050
3036 3051
3037 bool GraphBuilder::try_inline(ciMethod* callee, bool holder_known) { 3052 bool GraphBuilder::try_inline(ciMethod* callee, bool holder_known, Value receiver) {
3038 // Clear out any existing inline bailout condition 3053 // Clear out any existing inline bailout condition
3039 clear_inline_bailout(); 3054 clear_inline_bailout();
3040 3055
3041 if (callee->should_exclude()) { 3056 if (callee->should_exclude()) {
3042 // callee is excluded 3057 // callee is excluded
3054 // non-intrinsic natives cannot be inlined 3069 // non-intrinsic natives cannot be inlined
3055 INLINE_BAILOUT("non-intrinsic native") 3070 INLINE_BAILOUT("non-intrinsic native")
3056 } else if (callee->is_abstract()) { 3071 } else if (callee->is_abstract()) {
3057 INLINE_BAILOUT("abstract") 3072 INLINE_BAILOUT("abstract")
3058 } else { 3073 } else {
3059 return try_inline_full(callee, holder_known); 3074 return try_inline_full(callee, holder_known, NULL, receiver);
3060 } 3075 }
3061 } 3076 }
3062 3077
3063 3078
3064 bool GraphBuilder::try_inline_intrinsics(ciMethod* callee) { 3079 bool GraphBuilder::try_inline_intrinsics(ciMethod* callee) {
3403 _state = orig_state; 3418 _state = orig_state;
3404 _last = orig_last; 3419 _last = orig_last;
3405 } 3420 }
3406 3421
3407 3422
3408 bool GraphBuilder::try_inline_full(ciMethod* callee, bool holder_known, BlockBegin* cont_block) { 3423 bool GraphBuilder::try_inline_full(ciMethod* callee, bool holder_known, BlockBegin* cont_block, Value receiver) {
3409 assert(!callee->is_native(), "callee must not be native"); 3424 assert(!callee->is_native(), "callee must not be native");
3410 if (CompilationPolicy::policy()->should_not_inline(compilation()->env(), callee)) { 3425 if (CompilationPolicy::policy()->should_not_inline(compilation()->env(), callee)) {
3411 INLINE_BAILOUT("inlining prohibited by policy"); 3426 INLINE_BAILOUT("inlining prohibited by policy");
3412 } 3427 }
3413 // first perform tests of things it's not possible to inline 3428 // first perform tests of things it's not possible to inline
3539 while (i < caller_state->stack_size()) { 3554 while (i < caller_state->stack_size()) {
3540 const int par_no = i - args_base; 3555 const int par_no = i - args_base;
3541 Value arg = caller_state->stack_at_inc(i); 3556 Value arg = caller_state->stack_at_inc(i);
3542 // NOTE: take base() of arg->type() to avoid problems storing 3557 // NOTE: take base() of arg->type() to avoid problems storing
3543 // constants 3558 // constants
3559 if (receiver != NULL && par_no == 0) {
3560 arg = receiver;
3561 }
3544 store_local(callee_state, arg, arg->type()->base(), par_no); 3562 store_local(callee_state, arg, arg->type()->base(), par_no);
3545 } 3563 }
3546 } 3564 }
3547 3565
3548 // Remove args from stack. 3566 // Remove args from stack.
3718 // Save the state for the second inlinee 3736 // Save the state for the second inlinee
3719 ValueStack* state_before = copy_state_before(); 3737 ValueStack* state_before = copy_state_before();
3720 3738
3721 // Parse first adapter 3739 // Parse first adapter
3722 _last = _block = one; 3740 _last = _block = one;
3723 if (!try_inline_full(mh1_adapter, /*holder_known=*/ true, end)) { 3741 if (!try_inline_full(mh1_adapter, /*holder_known=*/ true, end, NULL)) {
3724 restore_inline_cleanup_info(); 3742 restore_inline_cleanup_info();
3725 block()->clear_end(); // remove appended iff 3743 block()->clear_end(); // remove appended iff
3726 return false; 3744 return false;
3727 } 3745 }
3728 3746
3729 // Parse second adapter 3747 // Parse second adapter
3730 _last = _block = two; 3748 _last = _block = two;
3731 _state = state_before; 3749 _state = state_before;
3732 if (!try_inline_full(mh2_adapter, /*holder_known=*/ true, end)) { 3750 if (!try_inline_full(mh2_adapter, /*holder_known=*/ true, end, NULL)) {
3733 restore_inline_cleanup_info(); 3751 restore_inline_cleanup_info();
3734 block()->clear_end(); // remove appended iff 3752 block()->clear_end(); // remove appended iff
3735 return false; 3753 return false;
3736 } 3754 }
3737 3755

mercurial