1650 ShouldNotReachHere();
1651 break;
1652 }
1653 }
1654
1655
1656 Dependencies* GraphBuilder::dependency_recorder() const {
1657 assert(DeoptC1, "need debug information");
1658 return compilation()->dependency_recorder();
1659 }
1660
1661
1662 void GraphBuilder::invoke(Bytecodes::Code code) {
1663 bool will_link;
1664 ciSignature* declared_signature = NULL;
1665 ciMethod* target = stream()->get_method(will_link, &declared_signature);
1666 ciKlass* holder = stream()->get_declared_method_holder();
1667 const Bytecodes::Code bc_raw = stream()->cur_bc_raw();
1668 assert(declared_signature != NULL, "cannot be null");
1669
1670 // FIXME bail out for now
1671 if (Bytecodes::has_optional_appendix(bc_raw) && !will_link) {
1672 BAILOUT("unlinked call site (FIXME needs patching or recompile support)");
1673 }
1674
1675 // we have to make sure the argument size (incl. the receiver)
1676 // is correct for compilation (the call would fail later during
1677 // linkage anyway) - was bug (gri 7/28/99)
1678 {
1679 // Use raw to get rewritten bytecode.
1680 const bool is_invokestatic = bc_raw == Bytecodes::_invokestatic;
1681 const bool allow_static =
1682 is_invokestatic ||
1683 bc_raw == Bytecodes::_invokehandle ||
1684 bc_raw == Bytecodes::_invokedynamic;
1685 if (target->is_loaded()) {
1686 if (( target->is_static() && !allow_static) ||
1687 (!target->is_static() && is_invokestatic)) {
1688 BAILOUT("will cause link error");
1689 }
1690 }
1691 }
1692 ciInstanceKlass* klass = target->holder();
1696 ciInstanceKlass* callee_holder = ciEnv::get_instance_klass_for_declared_method_holder(holder);
1697 ciInstanceKlass* actual_recv = callee_holder;
1698
1699 CompileLog* log = compilation()->log();
1700 if (log != NULL)
1701 log->elem("call method='%d' instr='%s'",
1702 log->identify(target),
1703 Bytecodes::name(code));
1704
1705 // Some methods are obviously bindable without any type checks so
1706 // convert them directly to an invokespecial or invokestatic.
1707 if (target->is_loaded() && !target->is_abstract() && target->can_be_statically_bound()) {
1708 switch (bc_raw) {
1709 case Bytecodes::_invokevirtual:
1710 code = Bytecodes::_invokespecial;
1711 break;
1712 case Bytecodes::_invokehandle:
1713 code = target->is_static() ? Bytecodes::_invokestatic : Bytecodes::_invokespecial;
1714 break;
1715 }
1716 }
1717
1718 // Push appendix argument (MethodType, CallSite, etc.), if one.
1719 if (stream()->has_appendix()) {
1720 ciObject* appendix = stream()->get_appendix();
1721 Value arg = append(new Constant(new ObjectConstant(appendix)));
1722 apush(arg);
1723 }
1724
1725 // NEEDS_CLEANUP
1726 // I've added the target->is_loaded() test below but I don't really understand
1727 // how klass->is_loaded() can be true and yet target->is_loaded() is false.
1728 // this happened while running the JCK invokevirtual tests under doit. TKR
1729 ciMethod* cha_monomorphic_target = NULL;
1730 ciMethod* exact_target = NULL;
1731 Value better_receiver = NULL;
1732 if (UseCHA && DeoptC1 && klass->is_loaded() && target->is_loaded() &&
1733 !(// %%% FIXME: Are both of these relevant?
1734 target->is_method_handle_intrinsic() ||
1735 target->is_compiled_lambda_form())) {
1736 Value receiver = NULL;
1737 ciInstanceKlass* receiver_klass = NULL;
1738 bool type_is_exact = false;
1739 // try to find a precise receiver type
1740 if (will_link && !target->is_static()) {
1741 int index = state()->stack_size() - (target->arg_size_no_receiver() + 1);
1742 receiver = state()->stack_at(index);
1743 ciType* type = receiver->exact_type();
1744 if (type != NULL && type->is_loaded() &&
1745 type->is_instance_klass() && !type->as_instance_klass()->is_interface()) {
1746 receiver_klass = (ciInstanceKlass*) type;
1747 type_is_exact = true;
1748 }
1749 if (type == NULL) {
1750 type = receiver->declared_type();
1751 if (type != NULL && type->is_loaded() &&
1752 type->is_instance_klass() && !type->as_instance_klass()->is_interface()) {
1753 receiver_klass = (ciInstanceKlass*) type;
1754 if (receiver_klass->is_leaf_type() && !receiver_klass->is_final()) {
1755 // Insert a dependency on this type since
1833 // Do not optimize for abstract methods
1834 cha_monomorphic_target = NULL;
1835 }
1836 }
1837
1838 if (cha_monomorphic_target != NULL) {
1839 if (!(target->is_final_method())) {
1840 // If we inlined because CHA revealed only a single target method,
1841 // then we are dependent on that target method not getting overridden
1842 // by dynamic class loading. Be sure to test the "static" receiver
1843 // dest_method here, as opposed to the actual receiver, which may
1844 // falsely lead us to believe that the receiver is final or private.
1845 dependency_recorder()->assert_unique_concrete_method(actual_recv, cha_monomorphic_target);
1846 }
1847 code = Bytecodes::_invokespecial;
1848 }
1849
1850 // check if we could do inlining
1851 if (!PatchALot && Inline && klass->is_loaded() &&
1852 (klass->is_initialized() || klass->is_interface() && target->holder()->is_initialized())
1853 && target->is_loaded()) {
1854 // callee is known => check if we have static binding
1855 assert(target->is_loaded(), "callee must be known");
1856 if (code == Bytecodes::_invokestatic ||
1857 code == Bytecodes::_invokespecial ||
1858 code == Bytecodes::_invokevirtual && target->is_final_method() ||
1859 code == Bytecodes::_invokedynamic) {
1860 ciMethod* inline_target = (cha_monomorphic_target != NULL) ? cha_monomorphic_target : target;
1861 // static binding => check if callee is ok
1862 bool success = try_inline(inline_target, (cha_monomorphic_target != NULL) || (exact_target != NULL), code, better_receiver);
1863
1864 CHECK_BAILOUT();
1865 clear_inline_bailout();
1866
1867 if (success) {
1868 // Register dependence if JVMTI has either breakpoint
1869 // setting or hotswapping of methods capabilities since they may
1870 // cause deoptimization.
1871 if (compilation()->env()->jvmti_can_hotswap_or_post_breakpoint()) {
1872 dependency_recorder()->assert_evol_method(inline_target);
1873 }
1884 // bailout during construction of the callee graph, the entire
1885 // compilation has to be aborted. This is fairly rare and currently
1886 // seems to only occur for jasm-generated classes which contain
1887 // jsr/ret pairs which are not associated with finally clauses and
1888 // do not have exception handlers in the containing method, and are
1889 // therefore not caught early enough to abort the inlining without
1890 // corrupting the graph. (We currently bail out with a non-empty
1891 // stack at a ret in these situations.)
1892 CHECK_BAILOUT();
1893
1894 // inlining not successful => standard invoke
1895 bool is_loaded = target->is_loaded();
1896 ValueType* result_type = as_ValueType(declared_signature->return_type());
1897 ValueStack* state_before = copy_state_exhandling();
1898
1899 // The bytecode (code) might change in this method so we are checking this very late.
1900 const bool has_receiver =
1901 code == Bytecodes::_invokespecial ||
1902 code == Bytecodes::_invokevirtual ||
1903 code == Bytecodes::_invokeinterface;
1904 Values* args = state()->pop_arguments(target->arg_size_no_receiver());
1905 Value recv = has_receiver ? apop() : NULL;
1906 int vtable_index = Method::invalid_vtable_index;
1907
1908 #ifdef SPARC
1909 // Currently only supported on Sparc.
1910 // The UseInlineCaches only controls dispatch to invokevirtuals for
1911 // loaded classes which we weren't able to statically bind.
1912 if (!UseInlineCaches && is_loaded && code == Bytecodes::_invokevirtual
1913 && !target->can_be_statically_bound()) {
1914 // Find a vtable index if one is available
1915 vtable_index = target->resolve_vtable_index(calling_klass, callee_holder);
1916 }
1917 #endif
1918
1919 if (recv != NULL &&
1920 (code == Bytecodes::_invokespecial ||
1921 !is_loaded || target->is_final())) {
1922 // invokespecial always needs a NULL check. invokevirtual where
1923 // the target is final or where it's not known that whether the
1924 // target is final requires a NULL check. Otherwise normal
|
1650 ShouldNotReachHere();
1651 break;
1652 }
1653 }
1654
1655
1656 Dependencies* GraphBuilder::dependency_recorder() const {
1657 assert(DeoptC1, "need debug information");
1658 return compilation()->dependency_recorder();
1659 }
1660
1661
1662 void GraphBuilder::invoke(Bytecodes::Code code) {
1663 bool will_link;
1664 ciSignature* declared_signature = NULL;
1665 ciMethod* target = stream()->get_method(will_link, &declared_signature);
1666 ciKlass* holder = stream()->get_declared_method_holder();
1667 const Bytecodes::Code bc_raw = stream()->cur_bc_raw();
1668 assert(declared_signature != NULL, "cannot be null");
1669
1670 if (!C1PatchInvokeDynamic && Bytecodes::has_optional_appendix(bc_raw) && !will_link) {
1671 BAILOUT("unlinked call site (C1PatchInvokeDynamic is off)");
1672 }
1673
1674 // we have to make sure the argument size (incl. the receiver)
1675 // is correct for compilation (the call would fail later during
1676 // linkage anyway) - was bug (gri 7/28/99)
1677 {
1678 // Use raw to get rewritten bytecode.
1679 const bool is_invokestatic = bc_raw == Bytecodes::_invokestatic;
1680 const bool allow_static =
1681 is_invokestatic ||
1682 bc_raw == Bytecodes::_invokehandle ||
1683 bc_raw == Bytecodes::_invokedynamic;
1684 if (target->is_loaded()) {
1685 if (( target->is_static() && !allow_static) ||
1686 (!target->is_static() && is_invokestatic)) {
1687 BAILOUT("will cause link error");
1688 }
1689 }
1690 }
1691 ciInstanceKlass* klass = target->holder();
1695 ciInstanceKlass* callee_holder = ciEnv::get_instance_klass_for_declared_method_holder(holder);
1696 ciInstanceKlass* actual_recv = callee_holder;
1697
1698 CompileLog* log = compilation()->log();
1699 if (log != NULL)
1700 log->elem("call method='%d' instr='%s'",
1701 log->identify(target),
1702 Bytecodes::name(code));
1703
1704 // Some methods are obviously bindable without any type checks so
1705 // convert them directly to an invokespecial or invokestatic.
1706 if (target->is_loaded() && !target->is_abstract() && target->can_be_statically_bound()) {
1707 switch (bc_raw) {
1708 case Bytecodes::_invokevirtual:
1709 code = Bytecodes::_invokespecial;
1710 break;
1711 case Bytecodes::_invokehandle:
1712 code = target->is_static() ? Bytecodes::_invokestatic : Bytecodes::_invokespecial;
1713 break;
1714 }
1715 } else {
1716 if (bc_raw == Bytecodes::_invokehandle) {
1717 assert(!will_link, "should come here only for unlinked call");
1718 code = Bytecodes::_invokespecial;
1719 }
1720 }
1721
1722 // Push appendix argument (MethodType, CallSite, etc.), if one.
1723 bool patch_for_appendix = false;
1724 int patching_appendix_arg = 0;
1725 if (C1PatchInvokeDynamic &&
1726 (Bytecodes::has_optional_appendix(bc_raw) && (!will_link || PatchALot))) {
1727 Value arg = append(new Constant(new ObjectConstant(compilation()->env()->unloaded_ciinstance()), copy_state_before()));
1728 apush(arg);
1729 patch_for_appendix = true;
1730 patching_appendix_arg = (will_link && stream()->has_appendix()) ? 0 : 1;
1731 } else if (stream()->has_appendix()) {
1732 ciObject* appendix = stream()->get_appendix();
1733 Value arg = append(new Constant(new ObjectConstant(appendix)));
1734 apush(arg);
1735 }
1736
1737 // NEEDS_CLEANUP
1738 // I've added the target->is_loaded() test below but I don't really understand
1739 // how klass->is_loaded() can be true and yet target->is_loaded() is false.
1740 // this happened while running the JCK invokevirtual tests under doit. TKR
1741 ciMethod* cha_monomorphic_target = NULL;
1742 ciMethod* exact_target = NULL;
1743 Value better_receiver = NULL;
1744 if (UseCHA && DeoptC1 && klass->is_loaded() && target->is_loaded() &&
1745 !(// %%% FIXME: Are both of these relevant?
1746 target->is_method_handle_intrinsic() ||
1747 target->is_compiled_lambda_form()) &&
1748 !patch_for_appendix) {
1749 Value receiver = NULL;
1750 ciInstanceKlass* receiver_klass = NULL;
1751 bool type_is_exact = false;
1752 // try to find a precise receiver type
1753 if (will_link && !target->is_static()) {
1754 int index = state()->stack_size() - (target->arg_size_no_receiver() + 1);
1755 receiver = state()->stack_at(index);
1756 ciType* type = receiver->exact_type();
1757 if (type != NULL && type->is_loaded() &&
1758 type->is_instance_klass() && !type->as_instance_klass()->is_interface()) {
1759 receiver_klass = (ciInstanceKlass*) type;
1760 type_is_exact = true;
1761 }
1762 if (type == NULL) {
1763 type = receiver->declared_type();
1764 if (type != NULL && type->is_loaded() &&
1765 type->is_instance_klass() && !type->as_instance_klass()->is_interface()) {
1766 receiver_klass = (ciInstanceKlass*) type;
1767 if (receiver_klass->is_leaf_type() && !receiver_klass->is_final()) {
1768 // Insert a dependency on this type since
1846 // Do not optimize for abstract methods
1847 cha_monomorphic_target = NULL;
1848 }
1849 }
1850
1851 if (cha_monomorphic_target != NULL) {
1852 if (!(target->is_final_method())) {
1853 // If we inlined because CHA revealed only a single target method,
1854 // then we are dependent on that target method not getting overridden
1855 // by dynamic class loading. Be sure to test the "static" receiver
1856 // dest_method here, as opposed to the actual receiver, which may
1857 // falsely lead us to believe that the receiver is final or private.
1858 dependency_recorder()->assert_unique_concrete_method(actual_recv, cha_monomorphic_target);
1859 }
1860 code = Bytecodes::_invokespecial;
1861 }
1862
1863 // check if we could do inlining
1864 if (!PatchALot && Inline && klass->is_loaded() &&
1865 (klass->is_initialized() || klass->is_interface() && target->holder()->is_initialized())
1866 && target->is_loaded()
1867 && !patch_for_appendix) {
1868 // callee is known => check if we have static binding
1869 assert(target->is_loaded(), "callee must be known");
1870 if (code == Bytecodes::_invokestatic ||
1871 code == Bytecodes::_invokespecial ||
1872 code == Bytecodes::_invokevirtual && target->is_final_method() ||
1873 code == Bytecodes::_invokedynamic) {
1874 ciMethod* inline_target = (cha_monomorphic_target != NULL) ? cha_monomorphic_target : target;
1875 // static binding => check if callee is ok
1876 bool success = try_inline(inline_target, (cha_monomorphic_target != NULL) || (exact_target != NULL), code, better_receiver);
1877
1878 CHECK_BAILOUT();
1879 clear_inline_bailout();
1880
1881 if (success) {
1882 // Register dependence if JVMTI has either breakpoint
1883 // setting or hotswapping of methods capabilities since they may
1884 // cause deoptimization.
1885 if (compilation()->env()->jvmti_can_hotswap_or_post_breakpoint()) {
1886 dependency_recorder()->assert_evol_method(inline_target);
1887 }
1898 // bailout during construction of the callee graph, the entire
1899 // compilation has to be aborted. This is fairly rare and currently
1900 // seems to only occur for jasm-generated classes which contain
1901 // jsr/ret pairs which are not associated with finally clauses and
1902 // do not have exception handlers in the containing method, and are
1903 // therefore not caught early enough to abort the inlining without
1904 // corrupting the graph. (We currently bail out with a non-empty
1905 // stack at a ret in these situations.)
1906 CHECK_BAILOUT();
1907
1908 // inlining not successful => standard invoke
1909 bool is_loaded = target->is_loaded();
1910 ValueType* result_type = as_ValueType(declared_signature->return_type());
1911 ValueStack* state_before = copy_state_exhandling();
1912
1913 // The bytecode (code) might change in this method so we are checking this very late.
1914 const bool has_receiver =
1915 code == Bytecodes::_invokespecial ||
1916 code == Bytecodes::_invokevirtual ||
1917 code == Bytecodes::_invokeinterface;
1918 Values* args = state()->pop_arguments(target->arg_size_no_receiver() + patching_appendix_arg);
1919 Value recv = has_receiver ? apop() : NULL;
1920 int vtable_index = Method::invalid_vtable_index;
1921
1922 #ifdef SPARC
1923 // Currently only supported on Sparc.
1924 // The UseInlineCaches only controls dispatch to invokevirtuals for
1925 // loaded classes which we weren't able to statically bind.
1926 if (!UseInlineCaches && is_loaded && code == Bytecodes::_invokevirtual
1927 && !target->can_be_statically_bound()) {
1928 // Find a vtable index if one is available
1929 vtable_index = target->resolve_vtable_index(calling_klass, callee_holder);
1930 }
1931 #endif
1932
1933 if (recv != NULL &&
1934 (code == Bytecodes::_invokespecial ||
1935 !is_loaded || target->is_final())) {
1936 // invokespecial always needs a NULL check. invokevirtual where
1937 // the target is final or where it's not known that whether the
1938 // target is final requires a NULL check. Otherwise normal
|