comparison src/share/vm/c1/c1_GraphBuilder.cpp @ 13086:096c224171c4

Merge with http://hg.openjdk.java.net/hsx/hsx25/hotspot/
author Doug Simon <doug.simon@oracle.com>
date Wed, 20 Nov 2013 00:10:38 +0100
parents cefad50507d8 144b23411b51
children 0097301f34fa
comparison
equal deleted inserted replaced
12782:92b7ec34ddfa 13086:096c224171c4
1464 } 1464 }
1465 1465
1466 // State at end of inlined method is the state of the caller 1466 // State at end of inlined method is the state of the caller
1467 // without the method parameters on stack, including the 1467 // without the method parameters on stack, including the
1468 // return value, if any, of the inlined method on operand stack. 1468 // return value, if any, of the inlined method on operand stack.
1469 int invoke_bci = state()->caller_state()->bci();
1469 set_state(state()->caller_state()->copy_for_parsing()); 1470 set_state(state()->caller_state()->copy_for_parsing());
1470 if (x != NULL) { 1471 if (x != NULL) {
1471 state()->push(x->type(), x); 1472 state()->push(x->type(), x);
1473 if (profile_return() && x->type()->is_object_kind()) {
1474 ciMethod* caller = state()->scope()->method();
1475 ciMethodData* md = caller->method_data_or_null();
1476 ciProfileData* data = md->bci_to_data(invoke_bci);
1477 if (data->is_CallTypeData() || data->is_VirtualCallTypeData()) {
1478 bool has_return = data->is_CallTypeData() ? ((ciCallTypeData*)data)->has_return() : ((ciVirtualCallTypeData*)data)->has_return();
1479 // May not be true in case of an inlined call through a method handle intrinsic.
1480 if (has_return) {
1481 profile_return_type(x, method(), caller, invoke_bci);
1482 }
1483 }
1484 }
1472 } 1485 }
1473 Goto* goto_callee = new Goto(continuation(), false); 1486 Goto* goto_callee = new Goto(continuation(), false);
1474 1487
1475 // See whether this is the first return; if so, store off some 1488 // See whether this is the first return; if so, store off some
1476 // of the state for later examination 1489 // of the state for later examination
1656 Dependencies* GraphBuilder::dependency_recorder() const { 1669 Dependencies* GraphBuilder::dependency_recorder() const {
1657 assert(DeoptC1, "need debug information"); 1670 assert(DeoptC1, "need debug information");
1658 return compilation()->dependency_recorder(); 1671 return compilation()->dependency_recorder();
1659 } 1672 }
1660 1673
1674 // How many arguments do we want to profile?
1675 Values* GraphBuilder::args_list_for_profiling(ciMethod* target, int& start, bool may_have_receiver) {
1676 int n = 0;
1677 bool has_receiver = may_have_receiver && Bytecodes::has_receiver(method()->java_code_at_bci(bci()));
1678 start = has_receiver ? 1 : 0;
1679 if (profile_arguments()) {
1680 ciProfileData* data = method()->method_data()->bci_to_data(bci());
1681 if (data->is_CallTypeData() || data->is_VirtualCallTypeData()) {
1682 n = data->is_CallTypeData() ? data->as_CallTypeData()->number_of_arguments() : data->as_VirtualCallTypeData()->number_of_arguments();
1683 }
1684 }
1685 // If we are inlining then we need to collect arguments to profile parameters for the target
1686 if (profile_parameters() && target != NULL) {
1687 if (target->method_data() != NULL && target->method_data()->parameters_type_data() != NULL) {
1688 // The receiver is profiled on method entry so it's included in
1689 // the number of parameters but here we're only interested in
1690 // actual arguments.
1691 n = MAX2(n, target->method_data()->parameters_type_data()->number_of_parameters() - start);
1692 }
1693 }
1694 if (n > 0) {
1695 return new Values(n);
1696 }
1697 return NULL;
1698 }
1699
1700 // Collect arguments that we want to profile in a list
1701 Values* GraphBuilder::collect_args_for_profiling(Values* args, ciMethod* target, bool may_have_receiver) {
1702 int start = 0;
1703 Values* obj_args = args_list_for_profiling(target, start, may_have_receiver);
1704 if (obj_args == NULL) {
1705 return NULL;
1706 }
1707 int s = obj_args->size();
1708 for (int i = start, j = 0; j < s; i++) {
1709 if (args->at(i)->type()->is_object_kind()) {
1710 obj_args->push(args->at(i));
1711 j++;
1712 }
1713 }
1714 assert(s == obj_args->length(), "missed on arg?");
1715 return obj_args;
1716 }
1717
1661 1718
1662 void GraphBuilder::invoke(Bytecodes::Code code) { 1719 void GraphBuilder::invoke(Bytecodes::Code code) {
1663 bool will_link; 1720 bool will_link;
1664 ciSignature* declared_signature = NULL; 1721 ciSignature* declared_signature = NULL;
1665 ciMethod* target = stream()->get_method(will_link, &declared_signature); 1722 ciMethod* target = stream()->get_method(will_link, &declared_signature);
1814 // equal to the number of implementors for target->holder() so 1871 // equal to the number of implementors for target->holder() so
1815 // if number of implementors of target->holder() == 1 then 1872 // if number of implementors of target->holder() == 1 then
1816 // number of implementors for decl_interface is 0 or 1. If 1873 // number of implementors for decl_interface is 0 or 1. If
1817 // it's 0 then no class implements decl_interface and there's 1874 // it's 0 then no class implements decl_interface and there's
1818 // no point in inlining. 1875 // no point in inlining.
1819 if (!holder->is_loaded() || decl_interface->nof_implementors() != 1) { 1876 if (!holder->is_loaded() || decl_interface->nof_implementors() != 1 || decl_interface->has_default_methods()) {
1820 singleton = NULL; 1877 singleton = NULL;
1821 } 1878 }
1822 } 1879 }
1823 if (singleton) { 1880 if (singleton) {
1824 cha_monomorphic_target = target->find_monomorphic_target(calling_klass, target->holder(), singleton); 1881 cha_monomorphic_target = target->find_monomorphic_target(calling_klass, target->holder(), singleton);
1955 if (cha_monomorphic_target != NULL) { 2012 if (cha_monomorphic_target != NULL) {
1956 target_klass = cha_monomorphic_target->holder(); 2013 target_klass = cha_monomorphic_target->holder();
1957 } else if (exact_target != NULL) { 2014 } else if (exact_target != NULL) {
1958 target_klass = exact_target->holder(); 2015 target_klass = exact_target->holder();
1959 } 2016 }
1960 profile_call(target, recv, target_klass); 2017 profile_call(target, recv, target_klass, collect_args_for_profiling(args, NULL, false), false);
1961 } 2018 }
1962 } 2019 }
1963 2020
1964 Invoke* result = new Invoke(code, result_type, recv, args, vtable_index, target, state_before); 2021 Invoke* result = new Invoke(code, result_type, recv, args, vtable_index, target, state_before);
1965 // push result 2022 // push result
1969 if (method()->is_strict()) { 2026 if (method()->is_strict()) {
1970 push(result_type, round_fp(result)); 2027 push(result_type, round_fp(result));
1971 } else { 2028 } else {
1972 push(result_type, result); 2029 push(result_type, result);
1973 } 2030 }
2031 }
2032 if (profile_return() && result_type->is_object_kind()) {
2033 profile_return_type(result, target);
1974 } 2034 }
1975 } 2035 }
1976 2036
1977 2037
1978 void GraphBuilder::new_instance(int klass_index) { 2038 void GraphBuilder::new_instance(int klass_index) {
3509 Value recv = NULL; 3569 Value recv = NULL;
3510 if (has_receiver) { 3570 if (has_receiver) {
3511 recv = args->at(0); 3571 recv = args->at(0);
3512 null_check(recv); 3572 null_check(recv);
3513 } 3573 }
3514 profile_call(callee, recv, NULL); 3574 profile_call(callee, recv, NULL, collect_args_for_profiling(args, callee, true), true);
3515 } 3575 }
3516 } 3576 }
3517 } 3577 }
3518 3578
3519 Intrinsic* result = new Intrinsic(result_type, id, args, has_receiver, state_before, 3579 Intrinsic* result = new Intrinsic(result_type, id, args, has_receiver, state_before,
3520 preserves_state, cantrap); 3580 preserves_state, cantrap);
3521 // append instruction & push result 3581 // append instruction & push result
3522 Value value = append_split(result); 3582 Value value = append_split(result);
3523 if (result_type != voidType) push(result_type, value); 3583 if (result_type != voidType) push(result_type, value);
3584
3585 if (callee != method() && profile_return() && result_type->is_object_kind()) {
3586 profile_return_type(result, callee);
3587 }
3524 3588
3525 // done 3589 // done
3526 return true; 3590 return true;
3527 } 3591 }
3528 3592
3704 INLINE_BAILOUT("mdo allocation failed"); 3768 INLINE_BAILOUT("mdo allocation failed");
3705 } 3769 }
3706 3770
3707 // now perform tests that are based on flag settings 3771 // now perform tests that are based on flag settings
3708 if (callee->force_inline()) { 3772 if (callee->force_inline()) {
3773 if (inline_level() > MaxForceInlineLevel) INLINE_BAILOUT("MaxForceInlineLevel");
3709 print_inlining(callee, "force inline by annotation"); 3774 print_inlining(callee, "force inline by annotation");
3710 } else if (callee->should_inline()) { 3775 } else if (callee->should_inline()) {
3711 print_inlining(callee, "force inline by CompileOracle"); 3776 print_inlining(callee, "force inline by CompileOracle");
3712 } else { 3777 } else {
3713 // use heuristic controls on inlining 3778 // use heuristic controls on inlining
3763 // Note that we'd collect profile data in this method if we wanted it. 3828 // Note that we'd collect profile data in this method if we wanted it.
3764 // this may be redundant here... 3829 // this may be redundant here...
3765 compilation()->set_would_profile(true); 3830 compilation()->set_would_profile(true);
3766 3831
3767 if (profile_calls()) { 3832 if (profile_calls()) {
3768 profile_call(callee, recv, holder_known ? callee->holder() : NULL); 3833 int start = 0;
3834 Values* obj_args = args_list_for_profiling(callee, start, has_receiver);
3835 if (obj_args != NULL) {
3836 int s = obj_args->size();
3837 // if called through method handle invoke, some arguments may have been popped
3838 for (int i = args_base+start, j = 0; j < obj_args->size() && i < state()->stack_size(); ) {
3839 Value v = state()->stack_at_inc(i);
3840 if (v->type()->is_object_kind()) {
3841 obj_args->push(v);
3842 j++;
3843 }
3844 }
3845 #ifdef ASSERT
3846 {
3847 bool ignored_will_link;
3848 ciSignature* declared_signature = NULL;
3849 ciMethod* real_target = method()->get_method_at_bci(bci(), ignored_will_link, &declared_signature);
3850 assert(s == obj_args->length() || real_target->is_method_handle_intrinsic(), "missed on arg?");
3851 }
3852 #endif
3853 }
3854 profile_call(callee, recv, holder_known ? callee->holder() : NULL, obj_args, true);
3769 } 3855 }
3770 } 3856 }
3771 3857
3772 // Introduce a new callee continuation point - if the callee has 3858 // Introduce a new callee continuation point - if the callee has
3773 // more than one return instruction or the return does not allow 3859 // more than one return instruction or the return does not allow
4251 void GraphBuilder::print_stats() { 4337 void GraphBuilder::print_stats() {
4252 vmap()->print(); 4338 vmap()->print();
4253 } 4339 }
4254 #endif // PRODUCT 4340 #endif // PRODUCT
4255 4341
4256 void GraphBuilder::profile_call(ciMethod* callee, Value recv, ciKlass* known_holder) { 4342 void GraphBuilder::profile_call(ciMethod* callee, Value recv, ciKlass* known_holder, Values* obj_args, bool inlined) {
4257 append(new ProfileCall(method(), bci(), callee, recv, known_holder)); 4343 // A default method's holder is an interface
4344 if (known_holder != NULL && known_holder->is_interface()) {
4345 assert(known_holder->is_instance_klass() && ((ciInstanceKlass*)known_holder)->has_default_methods(), "should be default method");
4346 known_holder = NULL;
4347 }
4348 append(new ProfileCall(method(), bci(), callee, recv, known_holder, obj_args, inlined));
4349 }
4350
4351 void GraphBuilder::profile_return_type(Value ret, ciMethod* callee, ciMethod* m, int invoke_bci) {
4352 assert((m == NULL) == (invoke_bci < 0), "invalid method and invalid bci together");
4353 if (m == NULL) {
4354 m = method();
4355 }
4356 if (invoke_bci < 0) {
4357 invoke_bci = bci();
4358 }
4359 ciMethodData* md = m->method_data_or_null();
4360 ciProfileData* data = md->bci_to_data(invoke_bci);
4361 if (data->is_CallTypeData() || data->is_VirtualCallTypeData()) {
4362 append(new ProfileReturnType(m , invoke_bci, callee, ret));
4363 }
4258 } 4364 }
4259 4365
4260 void GraphBuilder::profile_invocation(ciMethod* callee, ValueStack* state) { 4366 void GraphBuilder::profile_invocation(ciMethod* callee, ValueStack* state) {
4261 append(new ProfileInvoke(callee, state)); 4367 append(new ProfileInvoke(callee, state));
4262 } 4368 }