< prev index next >

hotspot/src/share/vm/c1/c1_GraphBuilder.cpp

Print this page
rev 11908 : 8160543: C1: Crash in java.lang.String.indexOf in some java.sql tests
Summary: C1 must use unverified entry point for unloaded methods.
Reviewed-by:


1782   int s = obj_args->max_length();
1783   // if called through method handle invoke, some arguments may have been popped
1784   for (int i = start, j = 0; j < s && i < args->length(); i++) {
1785     if (args->at(i)->type()->is_object_kind()) {
1786       obj_args->push(args->at(i));
1787       j++;
1788     }
1789   }
1790   check_args_for_profiling(obj_args, s);
1791   return obj_args;
1792 }
1793 
1794 
1795 void GraphBuilder::invoke(Bytecodes::Code code) {
1796   bool will_link;
1797   ciSignature* declared_signature = NULL;
1798   ciMethod*             target = stream()->get_method(will_link, &declared_signature);
1799   ciKlass*              holder = stream()->get_declared_method_holder();
1800   const Bytecodes::Code bc_raw = stream()->cur_bc_raw();
1801   assert(declared_signature != NULL, "cannot be null");

1802 
1803   ciInstanceKlass* klass = target->holder();
1804 
1805   // Make sure there are no evident problems with linking the instruction.
1806   bool is_resolved = true;
1807   if (klass->is_loaded() && !target->is_loaded()) {
1808     is_resolved = false; // method not found
1809   }
1810 
1811   // check if CHA possible: if so, change the code to invoke_special
1812   ciInstanceKlass* calling_klass = method()->holder();
1813   ciInstanceKlass* callee_holder = ciEnv::get_instance_klass_for_declared_method_holder(holder);
1814   ciInstanceKlass* actual_recv = callee_holder;
1815 




1816   CompileLog* log = compilation()->log();
1817   if (log != NULL)
1818       log->elem("call method='%d' instr='%s'",
1819                 log->identify(target),
1820                 Bytecodes::name(code));
1821 
1822   // Some methods are obviously bindable without any type checks so
1823   // convert them directly to an invokespecial or invokestatic.
1824   if (target->is_loaded() && !target->is_abstract() && target->can_be_statically_bound()) {
1825     switch (bc_raw) {
1826     case Bytecodes::_invokevirtual:
1827       code = Bytecodes::_invokespecial;
1828       break;
1829     case Bytecodes::_invokehandle:
1830       code = target->is_static() ? Bytecodes::_invokestatic : Bytecodes::_invokespecial;
1831       break;
1832     }
1833   } else {
1834     if (bc_raw == Bytecodes::_invokehandle) {
1835       assert(!will_link, "should come here only for unlinked call");


1957   if (cha_monomorphic_target != NULL) {
1958     if (cha_monomorphic_target->is_abstract()) {
1959       // Do not optimize for abstract methods
1960       cha_monomorphic_target = NULL;
1961     }
1962   }
1963 
1964   if (cha_monomorphic_target != NULL) {
1965     if (!(target->is_final_method())) {
1966       // If we inlined because CHA revealed only a single target method,
1967       // then we are dependent on that target method not getting overridden
1968       // by dynamic class loading.  Be sure to test the "static" receiver
1969       // dest_method here, as opposed to the actual receiver, which may
1970       // falsely lead us to believe that the receiver is final or private.
1971       dependency_recorder()->assert_unique_concrete_method(actual_recv, cha_monomorphic_target);
1972     }
1973     code = Bytecodes::_invokespecial;
1974   }
1975 
1976   // check if we could do inlining
1977   if (!PatchALot && Inline && is_resolved &&
1978       klass->is_loaded() && target->is_loaded() &&
1979       (klass->is_initialized() || klass->is_interface() && target->holder()->is_initialized())
1980       && !patch_for_appendix) {
1981     // callee is known => check if we have static binding
1982     if (code == Bytecodes::_invokestatic  ||
1983         code == Bytecodes::_invokespecial ||
1984         code == Bytecodes::_invokevirtual && target->is_final_method() ||
1985         code == Bytecodes::_invokedynamic) {
1986       ciMethod* inline_target = (cha_monomorphic_target != NULL) ? cha_monomorphic_target : target;
1987       // static binding => check if callee is ok
1988       bool success = try_inline(inline_target, (cha_monomorphic_target != NULL) || (exact_target != NULL), false, code, better_receiver);
1989 
1990       CHECK_BAILOUT();
1991       clear_inline_bailout();
1992 
1993       if (success) {
1994         // Register dependence if JVMTI has either breakpoint
1995         // setting or hotswapping of methods capabilities since they may
1996         // cause deoptimization.
1997         if (compilation()->env()->jvmti_can_hotswap_or_post_breakpoint()) {


2001       }
2002     } else {
2003       print_inlining(target, "no static binding", /*success*/ false);
2004     }
2005   } else {
2006     print_inlining(target, "not inlineable", /*success*/ false);
2007   }
2008 
2009   // If we attempted an inline which did not succeed because of a
2010   // bailout during construction of the callee graph, the entire
2011   // compilation has to be aborted. This is fairly rare and currently
2012   // seems to only occur for jasm-generated classes which contain
2013   // jsr/ret pairs which are not associated with finally clauses and
2014   // do not have exception handlers in the containing method, and are
2015   // therefore not caught early enough to abort the inlining without
2016   // corrupting the graph. (We currently bail out with a non-empty
2017   // stack at a ret in these situations.)
2018   CHECK_BAILOUT();
2019 
2020   // inlining not successful => standard invoke
2021   bool is_loaded = target->is_loaded();
2022   ValueType* result_type = as_ValueType(declared_signature->return_type());
2023   ValueStack* state_before = copy_state_exhandling();
2024 
2025   // The bytecode (code) might change in this method so we are checking this very late.
2026   const bool has_receiver =
2027     code == Bytecodes::_invokespecial   ||
2028     code == Bytecodes::_invokevirtual   ||
2029     code == Bytecodes::_invokeinterface;
2030   Values* args = state()->pop_arguments(target->arg_size_no_receiver() + patching_appendix_arg);
2031   Value recv = has_receiver ? apop() : NULL;
2032   int vtable_index = Method::invalid_vtable_index;
2033 
2034 #ifdef SPARC
2035   // Currently only supported on Sparc.
2036   // The UseInlineCaches only controls dispatch to invokevirtuals for
2037   // loaded classes which we weren't able to statically bind.
2038   if (!UseInlineCaches && is_resolved && is_loaded && code == Bytecodes::_invokevirtual
2039       && !target->can_be_statically_bound()) {
2040     // Find a vtable index if one is available
2041     // For arrays, callee_holder is Object. Resolving the call with
2042     // Object would allow an illegal call to finalize() on an
2043     // array. We use holder instead: illegal calls to finalize() won't
2044     // be compiled as vtable calls (IC call resolution will catch the
2045     // illegal call) and the few legal calls on array types won't be
2046     // either.
2047     vtable_index = target->resolve_vtable_index(calling_klass, holder);
2048   }
2049 #endif
2050 
2051   if (is_resolved) {
2052     // invokespecial always needs a NULL check. invokevirtual where the target is
2053     // final or where it's not known whether the target is final requires a NULL check.
2054     // Otherwise normal invokevirtual will perform the null check during the lookup
2055     // logic or the unverified entry point.  Profiling of calls requires that
2056     // the null check is performed in all cases.

2057     bool do_null_check = (recv != NULL) &&
2058         (code == Bytecodes::_invokespecial || !is_loaded || target->is_final() || (is_profiling() && profile_calls()));
2059 
2060     if (do_null_check) {
2061       null_check(recv);
2062     }
2063 
2064     if (is_profiling()) {
2065       // Note that we'd collect profile data in this method if we wanted it.
2066       compilation()->set_would_profile(true);
2067 
2068       if (profile_calls()) {
2069         assert(cha_monomorphic_target == NULL || exact_target == NULL, "both can not be set");
2070         ciKlass* target_klass = NULL;
2071         if (cha_monomorphic_target != NULL) {
2072           target_klass = cha_monomorphic_target->holder();
2073         } else if (exact_target != NULL) {
2074           target_klass = exact_target->holder();
2075         }
2076         profile_call(target, recv, target_klass, collect_args_for_profiling(args, NULL, false), false);
2077       }
2078     }
2079   } else {
2080     // No need in null check or profiling: linkage error will be thrown at runtime
2081     // during resolution.
2082   }
2083 
2084   Invoke* result = new Invoke(code, result_type, recv, args, vtable_index, target, state_before);
2085   // push result
2086   append_split(result);
2087 
2088   if (result_type != voidType) {
2089     if (method()->is_strict()) {
2090       push(result_type, round_fp(result));
2091     } else {
2092       push(result_type, result);
2093     }
2094   }
2095   if (profile_return() && result_type->is_object_kind()) {
2096     profile_return_type(result, target);
2097   }
2098 }
2099 
2100 
2101 void GraphBuilder::new_instance(int klass_index) {




1782   int s = obj_args->max_length();
1783   // if called through method handle invoke, some arguments may have been popped
1784   for (int i = start, j = 0; j < s && i < args->length(); i++) {
1785     if (args->at(i)->type()->is_object_kind()) {
1786       obj_args->push(args->at(i));
1787       j++;
1788     }
1789   }
1790   check_args_for_profiling(obj_args, s);
1791   return obj_args;
1792 }
1793 
1794 
1795 void GraphBuilder::invoke(Bytecodes::Code code) {
1796   bool will_link;
1797   ciSignature* declared_signature = NULL;
1798   ciMethod*             target = stream()->get_method(will_link, &declared_signature);
1799   ciKlass*              holder = stream()->get_declared_method_holder();
1800   const Bytecodes::Code bc_raw = stream()->cur_bc_raw();
1801   assert(declared_signature != NULL, "cannot be null");
1802   assert(will_link == target->is_loaded(), "Check");
1803 
1804   ciInstanceKlass* klass = target->holder();
1805 






1806   // check if CHA possible: if so, change the code to invoke_special
1807   ciInstanceKlass* calling_klass = method()->holder();
1808   ciInstanceKlass* callee_holder = ciEnv::get_instance_klass_for_declared_method_holder(holder);
1809   ciInstanceKlass* actual_recv = callee_holder;
1810 
1811   if (target->is_loaded()) {
1812     assert(klass->is_loaded(), "sanity");
1813   }
1814 
1815   CompileLog* log = compilation()->log();
1816   if (log != NULL)
1817       log->elem("call method='%d' instr='%s'",
1818                 log->identify(target),
1819                 Bytecodes::name(code));
1820 
1821   // Some methods are obviously bindable without any type checks so
1822   // convert them directly to an invokespecial or invokestatic.
1823   if (target->is_loaded() && !target->is_abstract() && target->can_be_statically_bound()) {
1824     switch (bc_raw) {
1825     case Bytecodes::_invokevirtual:
1826       code = Bytecodes::_invokespecial;
1827       break;
1828     case Bytecodes::_invokehandle:
1829       code = target->is_static() ? Bytecodes::_invokestatic : Bytecodes::_invokespecial;
1830       break;
1831     }
1832   } else {
1833     if (bc_raw == Bytecodes::_invokehandle) {
1834       assert(!will_link, "should come here only for unlinked call");


1956   if (cha_monomorphic_target != NULL) {
1957     if (cha_monomorphic_target->is_abstract()) {
1958       // Do not optimize for abstract methods
1959       cha_monomorphic_target = NULL;
1960     }
1961   }
1962 
1963   if (cha_monomorphic_target != NULL) {
1964     if (!(target->is_final_method())) {
1965       // If we inlined because CHA revealed only a single target method,
1966       // then we are dependent on that target method not getting overridden
1967       // by dynamic class loading.  Be sure to test the "static" receiver
1968       // dest_method here, as opposed to the actual receiver, which may
1969       // falsely lead us to believe that the receiver is final or private.
1970       dependency_recorder()->assert_unique_concrete_method(actual_recv, cha_monomorphic_target);
1971     }
1972     code = Bytecodes::_invokespecial;
1973   }
1974 
1975   // check if we could do inlining
1976   if (!PatchALot && Inline &&
1977       klass->is_loaded() && target->is_loaded() &&
1978       (klass->is_initialized() || klass->is_interface() && target->holder()->is_initialized())
1979       && !patch_for_appendix) {
1980     // callee is known => check if we have static binding
1981     if (code == Bytecodes::_invokestatic  ||
1982         code == Bytecodes::_invokespecial ||
1983         code == Bytecodes::_invokevirtual && target->is_final_method() ||
1984         code == Bytecodes::_invokedynamic) {
1985       ciMethod* inline_target = (cha_monomorphic_target != NULL) ? cha_monomorphic_target : target;
1986       // static binding => check if callee is ok
1987       bool success = try_inline(inline_target, (cha_monomorphic_target != NULL) || (exact_target != NULL), false, code, better_receiver);
1988 
1989       CHECK_BAILOUT();
1990       clear_inline_bailout();
1991 
1992       if (success) {
1993         // Register dependence if JVMTI has either breakpoint
1994         // setting or hotswapping of methods capabilities since they may
1995         // cause deoptimization.
1996         if (compilation()->env()->jvmti_can_hotswap_or_post_breakpoint()) {


2000       }
2001     } else {
2002       print_inlining(target, "no static binding", /*success*/ false);
2003     }
2004   } else {
2005     print_inlining(target, "not inlineable", /*success*/ false);
2006   }
2007 
2008   // If we attempted an inline which did not succeed because of a
2009   // bailout during construction of the callee graph, the entire
2010   // compilation has to be aborted. This is fairly rare and currently
2011   // seems to only occur for jasm-generated classes which contain
2012   // jsr/ret pairs which are not associated with finally clauses and
2013   // do not have exception handlers in the containing method, and are
2014   // therefore not caught early enough to abort the inlining without
2015   // corrupting the graph. (We currently bail out with a non-empty
2016   // stack at a ret in these situations.)
2017   CHECK_BAILOUT();
2018 
2019   // inlining not successful => standard invoke

2020   ValueType* result_type = as_ValueType(declared_signature->return_type());
2021   ValueStack* state_before = copy_state_exhandling();
2022 
2023   // The bytecode (code) might change in this method so we are checking this very late.
2024   const bool has_receiver =
2025     code == Bytecodes::_invokespecial   ||
2026     code == Bytecodes::_invokevirtual   ||
2027     code == Bytecodes::_invokeinterface;
2028   Values* args = state()->pop_arguments(target->arg_size_no_receiver() + patching_appendix_arg);
2029   Value recv = has_receiver ? apop() : NULL;
2030   int vtable_index = Method::invalid_vtable_index;
2031 
2032 #ifdef SPARC
2033   // Currently only supported on Sparc.
2034   // The UseInlineCaches only controls dispatch to invokevirtuals for
2035   // loaded classes which we weren't able to statically bind.
2036   if (!UseInlineCaches && target->is_loaded() && code == Bytecodes::_invokevirtual
2037       && !target->can_be_statically_bound()) {
2038     // Find a vtable index if one is available
2039     // For arrays, callee_holder is Object. Resolving the call with
2040     // Object would allow an illegal call to finalize() on an
2041     // array. We use holder instead: illegal calls to finalize() won't
2042     // be compiled as vtable calls (IC call resolution will catch the
2043     // illegal call) and the few legal calls on array types won't be
2044     // either.
2045     vtable_index = target->resolve_vtable_index(calling_klass, holder);
2046   }
2047 #endif
2048 
2049 
2050   // invokespecial always needs a NULL check. invokevirtual where the target is
2051   // final or where it's not known whether the target is final requires a NULL check.
2052   // Otherwise normal invokevirtual will perform the null check during the lookup
2053   // logic or the unverified entry point.  Profiling of calls requires that
2054   // the null check is performed in all cases.
2055 
2056   bool do_null_check = (recv != NULL) &&
2057       (code == Bytecodes::_invokespecial || (target->is_loaded() && (target->is_final() || (is_profiling() && profile_calls()))));
2058 
2059   if (do_null_check) {
2060     null_check(recv);

2061 
2062     if (is_profiling()) {
2063       // Note that we'd collect profile data in this method if we wanted it.
2064       compilation()->set_would_profile(true);
2065 
2066       if (profile_calls()) {
2067         assert(cha_monomorphic_target == NULL || exact_target == NULL, "both can not be set");
2068         ciKlass* target_klass = NULL;
2069         if (cha_monomorphic_target != NULL) {
2070           target_klass = cha_monomorphic_target->holder();
2071         } else if (exact_target != NULL) {
2072           target_klass = exact_target->holder();
2073         }
2074         profile_call(target, recv, target_klass, collect_args_for_profiling(args, NULL, false), false);
2075       }
2076     }



2077   }
2078 
2079   Invoke* result = new Invoke(code, result_type, recv, args, vtable_index, target, state_before);
2080   // push result
2081   append_split(result);
2082 
2083   if (result_type != voidType) {
2084     if (method()->is_strict()) {
2085       push(result_type, round_fp(result));
2086     } else {
2087       push(result_type, result);
2088     }
2089   }
2090   if (profile_return() && result_type->is_object_kind()) {
2091     profile_return_type(result, target);
2092   }
2093 }
2094 
2095 
2096 void GraphBuilder::new_instance(int klass_index) {


< prev index next >