hotspot/src/share/vm/c1/c1_GraphBuilder.cpp
changeset 42544 58de8aaf9365
parent 41703 fb19bea93d16
child 42553 2aeb79d952f3
equal deleted inserted replaced
42543:9e7ac7aff2d1 42544:58de8aaf9365
  1811   ciSignature* declared_signature = NULL;
  1811   ciSignature* declared_signature = NULL;
  1812   ciMethod*             target = stream()->get_method(will_link, &declared_signature);
  1812   ciMethod*             target = stream()->get_method(will_link, &declared_signature);
  1813   ciKlass*              holder = stream()->get_declared_method_holder();
  1813   ciKlass*              holder = stream()->get_declared_method_holder();
  1814   const Bytecodes::Code bc_raw = stream()->cur_bc_raw();
  1814   const Bytecodes::Code bc_raw = stream()->cur_bc_raw();
  1815   assert(declared_signature != NULL, "cannot be null");
  1815   assert(declared_signature != NULL, "cannot be null");
       
  1816   assert(will_link == target->is_loaded(), "");
  1816 
  1817 
  1817   ciInstanceKlass* klass = target->holder();
  1818   ciInstanceKlass* klass = target->holder();
  1818 
  1819   assert(!target->is_loaded() || klass->is_loaded(), "loaded target must imply loaded klass");
  1819   // Make sure there are no evident problems with linking the instruction.
       
  1820   bool is_resolved = true;
       
  1821   if (klass->is_loaded() && !target->is_loaded()) {
       
  1822     is_resolved = false; // method not found
       
  1823   }
       
  1824 
  1820 
  1825   // check if CHA possible: if so, change the code to invoke_special
  1821   // check if CHA possible: if so, change the code to invoke_special
  1826   ciInstanceKlass* calling_klass = method()->holder();
  1822   ciInstanceKlass* calling_klass = method()->holder();
  1827   ciInstanceKlass* callee_holder = ciEnv::get_instance_klass_for_declared_method_holder(holder);
  1823   ciInstanceKlass* callee_holder = ciEnv::get_instance_klass_for_declared_method_holder(holder);
  1828   ciInstanceKlass* actual_recv = callee_holder;
  1824   ciInstanceKlass* actual_recv = callee_holder;
  1866   }
  1862   }
  1867 
  1863 
  1868   ciMethod* cha_monomorphic_target = NULL;
  1864   ciMethod* cha_monomorphic_target = NULL;
  1869   ciMethod* exact_target = NULL;
  1865   ciMethod* exact_target = NULL;
  1870   Value better_receiver = NULL;
  1866   Value better_receiver = NULL;
  1871   if (UseCHA && DeoptC1 && klass->is_loaded() && target->is_loaded() &&
  1867   if (UseCHA && DeoptC1 && target->is_loaded() &&
  1872       !(// %%% FIXME: Are both of these relevant?
  1868       !(// %%% FIXME: Are both of these relevant?
  1873         target->is_method_handle_intrinsic() ||
  1869         target->is_method_handle_intrinsic() ||
  1874         target->is_compiled_lambda_form()) &&
  1870         target->is_compiled_lambda_form()) &&
  1875       !patch_for_appendix) {
  1871       !patch_for_appendix) {
  1876     Value receiver = NULL;
  1872     Value receiver = NULL;
  1986     }
  1982     }
  1987     code = Bytecodes::_invokespecial;
  1983     code = Bytecodes::_invokespecial;
  1988   }
  1984   }
  1989 
  1985 
  1990   // check if we could do inlining
  1986   // check if we could do inlining
  1991   if (!PatchALot && Inline && is_resolved &&
  1987   if (!PatchALot && Inline && target->is_loaded() &&
  1992       klass->is_loaded() && target->is_loaded() &&
       
  1993       (klass->is_initialized() || klass->is_interface() && target->holder()->is_initialized())
  1988       (klass->is_initialized() || klass->is_interface() && target->holder()->is_initialized())
  1994       && !patch_for_appendix) {
  1989       && !patch_for_appendix) {
  1995     // callee is known => check if we have static binding
  1990     // callee is known => check if we have static binding
  1996     if (code == Bytecodes::_invokestatic  ||
  1991     if (code == Bytecodes::_invokestatic  ||
  1997         code == Bytecodes::_invokespecial ||
  1992         code == Bytecodes::_invokespecial ||
  2030   // corrupting the graph. (We currently bail out with a non-empty
  2025   // corrupting the graph. (We currently bail out with a non-empty
  2031   // stack at a ret in these situations.)
  2026   // stack at a ret in these situations.)
  2032   CHECK_BAILOUT();
  2027   CHECK_BAILOUT();
  2033 
  2028 
  2034   // inlining not successful => standard invoke
  2029   // inlining not successful => standard invoke
  2035   bool is_loaded = target->is_loaded();
       
  2036   ValueType* result_type = as_ValueType(declared_signature->return_type());
  2030   ValueType* result_type = as_ValueType(declared_signature->return_type());
  2037   ValueStack* state_before = copy_state_exhandling();
  2031   ValueStack* state_before = copy_state_exhandling();
  2038 
  2032 
  2039   // The bytecode (code) might change in this method so we are checking this very late.
  2033   // The bytecode (code) might change in this method so we are checking this very late.
  2040   const bool has_receiver =
  2034   const bool has_receiver =
  2047 
  2041 
  2048 #ifdef SPARC
  2042 #ifdef SPARC
  2049   // Currently only supported on Sparc.
  2043   // Currently only supported on Sparc.
  2050   // The UseInlineCaches only controls dispatch to invokevirtuals for
  2044   // The UseInlineCaches only controls dispatch to invokevirtuals for
  2051   // loaded classes which we weren't able to statically bind.
  2045   // loaded classes which we weren't able to statically bind.
  2052   if (!UseInlineCaches && is_resolved && is_loaded && code == Bytecodes::_invokevirtual
  2046   if (!UseInlineCaches && target->is_loaded() && code == Bytecodes::_invokevirtual
  2053       && !target->can_be_statically_bound()) {
  2047       && !target->can_be_statically_bound()) {
  2054     // Find a vtable index if one is available
  2048     // Find a vtable index if one is available
  2055     // For arrays, callee_holder is Object. Resolving the call with
  2049     // For arrays, callee_holder is Object. Resolving the call with
  2056     // Object would allow an illegal call to finalize() on an
  2050     // Object would allow an illegal call to finalize() on an
  2057     // array. We use holder instead: illegal calls to finalize() won't
  2051     // array. We use holder instead: illegal calls to finalize() won't
  2060     // either.
  2054     // either.
  2061     vtable_index = target->resolve_vtable_index(calling_klass, holder);
  2055     vtable_index = target->resolve_vtable_index(calling_klass, holder);
  2062   }
  2056   }
  2063 #endif
  2057 #endif
  2064 
  2058 
  2065   if (is_resolved) {
  2059   // invokespecial always needs a NULL check. invokevirtual where the target is
  2066     // invokespecial always needs a NULL check. invokevirtual where the target is
  2060   // final or where it's not known whether the target is final requires a NULL check.
  2067     // final or where it's not known whether the target is final requires a NULL check.
  2061   // Otherwise normal invokevirtual will perform the null check during the lookup
  2068     // Otherwise normal invokevirtual will perform the null check during the lookup
  2062   // logic or the unverified entry point.  Profiling of calls requires that
  2069     // logic or the unverified entry point.  Profiling of calls requires that
  2063   // the null check is performed in all cases.
  2070     // the null check is performed in all cases.
  2064 
  2071     bool do_null_check = (recv != NULL) &&
  2065   bool do_null_check = (recv != NULL) &&
  2072         (code == Bytecodes::_invokespecial || !is_loaded || target->is_final() || (is_profiling() && profile_calls()));
  2066         (code == Bytecodes::_invokespecial || (target->is_loaded() && (target->is_final() || (is_profiling() && profile_calls()))));
  2073 
  2067 
  2074     if (do_null_check) {
  2068   if (do_null_check) {
  2075       null_check(recv);
  2069     null_check(recv);
  2076     }
       
  2077 
  2070 
  2078     if (is_profiling()) {
  2071     if (is_profiling()) {
  2079       // Note that we'd collect profile data in this method if we wanted it.
  2072       // Note that we'd collect profile data in this method if we wanted it.
  2080       compilation()->set_would_profile(true);
  2073       compilation()->set_would_profile(true);
  2081 
  2074 
  2088           target_klass = exact_target->holder();
  2081           target_klass = exact_target->holder();
  2089         }
  2082         }
  2090         profile_call(target, recv, target_klass, collect_args_for_profiling(args, NULL, false), false);
  2083         profile_call(target, recv, target_klass, collect_args_for_profiling(args, NULL, false), false);
  2091       }
  2084       }
  2092     }
  2085     }
  2093   } else {
       
  2094     // No need in null check or profiling: linkage error will be thrown at runtime
       
  2095     // during resolution.
       
  2096   }
  2086   }
  2097 
  2087 
  2098   Invoke* result = new Invoke(code, result_type, recv, args, vtable_index, target, state_before);
  2088   Invoke* result = new Invoke(code, result_type, recv, args, vtable_index, target, state_before);
  2099   // push result
  2089   // push result
  2100   append_split(result);
  2090   append_split(result);