< prev index next >

src/hotspot/share/code/compiledIC.cpp

Print this page

185   return CompiledIC_at(nm, call_site);
186 }
187 
188 CompiledIC* CompiledIC_at(RelocIterator* reloc_iter) {
189   CompiledIC* c_ic = new CompiledIC(reloc_iter);
190   c_ic->verify();
191   return c_ic;
192 }
193 
194 void CompiledIC::ensure_initialized(CallInfo* call_info, Klass* receiver_klass) {
195   if (!_data->is_initialized()) {
196     _data->initialize(call_info, receiver_klass);
197   }
198 }
199 
200 void CompiledIC::set_to_clean() {
201   log_debug(inlinecache)("IC@" INTPTR_FORMAT ": set to clean", p2i(_call->instruction_address()));
202   _call->set_destination_mt_safe(SharedRuntime::get_resolve_virtual_call_stub());
203 }
204 
205 void CompiledIC::set_to_monomorphic() {
206   assert(data()->is_initialized(), "must be initialized");
207   Method* method = data()->speculated_method();
208   nmethod* code = method->code();
209   address entry;
210   bool to_compiled = code != nullptr && code->is_in_use() && !code->is_unloading();
211 
212   if (to_compiled) {
213     entry = code->entry_point();
214   } else {
215     entry = method->get_c2i_unverified_entry();
216   }
217 
218   log_trace(inlinecache)("IC@" INTPTR_FORMAT ": monomorphic to %s: %s",
219                          p2i(_call->instruction_address()),
220                          to_compiled ? "compiled" : "interpreter",
221                          method->print_value_string());
222 
223   _call->set_destination_mt_safe(entry);
224 }
225 
226 void CompiledIC::set_to_megamorphic(CallInfo* call_info) {
227   assert(data()->is_initialized(), "must be initialized");
228 
229   address entry;
230   if (call_info->call_kind() == CallInfo::direct_call) {
231     // C1 sometimes compiles a callsite before the target method is loaded, resulting in
232     // dynamically bound callsites that should really be statically bound. However, the
233     // target method might not have a vtable or itable. We just wait for better code to arrive
234     return;
235   } else if (call_info->call_kind() == CallInfo::itable_call) {
236     int itable_index = call_info->itable_index();
237     entry = VtableStubs::find_itable_stub(itable_index);
238     if (entry == nullptr) {
239       return;
240     }
241 #ifdef ASSERT
242     assert(call_info->resolved_method() != nullptr, "virtual or interface method must be found");
243     int index = call_info->resolved_method()->itable_index();
244     assert(index == itable_index, "CallInfo pre-computes this");
245     InstanceKlass* k = call_info->resolved_method()->method_holder();
246     assert(k->verify_itable_index(itable_index), "sanity check");
247 #endif //ASSERT
248   } else {
249     assert(call_info->call_kind() == CallInfo::vtable_call, "what else?");
250     // Can be different than selected_method->vtable_index(), due to package-private etc.
251     int vtable_index = call_info->vtable_index();
252     assert(call_info->resolved_klass()->verify_vtable_index(vtable_index), "sanity check");
253     entry = VtableStubs::find_vtable_stub(vtable_index);
254     if (entry == nullptr) {
255       return;
256     }
257   }
258 
259   assert(call_info->selected_method() != nullptr, "virtual or interface method must be found");
260   log_trace(inlinecache)("IC@" INTPTR_FORMAT ": to megamorphic %s entry: " INTPTR_FORMAT,
261                          p2i(_call->instruction_address()), call_info->selected_method()->print_value_string(), p2i(entry));
262 
263   _call->set_destination_mt_safe(entry);
264   assert(is_megamorphic(), "sanity check");
265 }
266 
267 void CompiledIC::update(CallInfo* call_info, Klass* receiver_klass) {
268   // If this is the first time we fix the inline cache, we ensure it's initialized
269   ensure_initialized(call_info, receiver_klass);
270 
271   if (is_megamorphic()) {
272     // Terminal state for the inline cache
273     return;
274   }
275 
276   if (is_speculated_klass(receiver_klass)) {
277     // If the speculated class matches the receiver klass, we can speculate that will
278     // continue to be the case with a monomorphic inline cache
279     set_to_monomorphic();
280   } else {
281     // If the dynamic type speculation fails, we try to transform to a megamorphic state
282     // for the inline cache using stubs to dispatch in tables
283     set_to_megamorphic(call_info);
284   }
285 }
286 
287 bool CompiledIC::is_clean() const {
288   return destination() == SharedRuntime::get_resolve_virtual_call_stub();
289 }
290 
291 bool CompiledIC::is_monomorphic() const {
292   return !is_clean() && !is_megamorphic();
293 }
294 
295 bool CompiledIC::is_megamorphic() const {
296   return VtableStubs::entry_point(destination()) != nullptr;
297 }
298 
299 bool CompiledIC::is_speculated_klass(Klass* receiver_klass) {
300   return data()->speculated_klass() == receiver_klass;
301 }
302 
303 // GC support

328   assert(CompiledICLocker::is_safe(instruction_address()), "mt unsafe call");
329   // Reset call site
330   RelocIterator iter((nmethod*)nullptr, instruction_address(), instruction_address() + 1);
331   while (iter.next()) {
332     switch(iter.type()) {
333     case relocInfo::static_call_type:
334       _call->set_destination_mt_safe(SharedRuntime::get_resolve_static_call_stub());
335       break;
336     case relocInfo::opt_virtual_call_type:
337       _call->set_destination_mt_safe(SharedRuntime::get_resolve_opt_virtual_call_stub());
338       break;
339     default:
340       ShouldNotReachHere();
341     }
342   }
343   assert(is_clean(), "should be clean after cleaning");
344 
345   log_debug(inlinecache)("DC@" INTPTR_FORMAT ": set to clean", p2i(_call->instruction_address()));
346 }
347 
348 void CompiledDirectCall::set(const methodHandle& callee_method) {
349   nmethod* code = callee_method->code();
350   nmethod* caller = CodeCache::find_nmethod(instruction_address());
351   assert(caller != nullptr, "did not find caller nmethod");
352 
353   bool to_interp_cont_enter = caller->method()->is_continuation_enter_intrinsic() &&
354                               ContinuationEntry::is_interpreted_call(instruction_address());
355 
356   bool to_compiled = !to_interp_cont_enter && code != nullptr && code->is_in_use() && !code->is_unloading();
357 
358   if (to_compiled) {
359     _call->set_destination_mt_safe(code->verified_entry_point());
360     assert(is_call_to_compiled(), "should be compiled after set to compiled");
361   } else {
362     // Patch call site to C2I adapter if code is deoptimized or unloaded.
363     // We also need to patch the static call stub to set the rmethod register
364     // to the callee_method so the c2i adapter knows how to build the frame
365     set_to_interpreted(callee_method, callee_method->get_c2i_entry());
366     assert(is_call_to_interpreted(), "should be interpreted after set to interpreted");
367   }
368 
369   log_trace(inlinecache)("DC@" INTPTR_FORMAT ": set to %s: %s: " INTPTR_FORMAT,
370                          p2i(_call->instruction_address()),
371                          to_compiled ? "compiled" : "interpreter",
372                          callee_method->print_value_string(),
373                          p2i(_call->destination()));
374 }
375 
376 bool CompiledDirectCall::is_clean() const {
377   return destination() == SharedRuntime::get_resolve_static_call_stub() ||
378          destination() == SharedRuntime::get_resolve_opt_virtual_call_stub();
379 }
380 
381 bool CompiledDirectCall::is_call_to_interpreted() const {
382   // It is a call to interpreted, if it calls to a stub. Hence, the destination
383   // must be in the stub part of the nmethod that contains the call
384   nmethod* nm = CodeCache::find_nmethod(instruction_address());
385   assert(nm != nullptr, "did not find nmethod");

185   return CompiledIC_at(nm, call_site);
186 }
187 
188 CompiledIC* CompiledIC_at(RelocIterator* reloc_iter) {
189   CompiledIC* c_ic = new CompiledIC(reloc_iter);
190   c_ic->verify();
191   return c_ic;
192 }
193 
194 void CompiledIC::ensure_initialized(CallInfo* call_info, Klass* receiver_klass) {
195   if (!_data->is_initialized()) {
196     _data->initialize(call_info, receiver_klass);
197   }
198 }
199 
200 void CompiledIC::set_to_clean() {
201   log_debug(inlinecache)("IC@" INTPTR_FORMAT ": set to clean", p2i(_call->instruction_address()));
202   _call->set_destination_mt_safe(SharedRuntime::get_resolve_virtual_call_stub());
203 }
204 
205 void CompiledIC::set_to_monomorphic(bool caller_is_c1) {
206   assert(data()->is_initialized(), "must be initialized");
207   Method* method = data()->speculated_method();
208   nmethod* code = method->code();
209   address entry;
210   bool to_compiled = code != nullptr && code->is_in_use() && !code->is_unloading();
211 
212   if (to_compiled) {
213     entry = caller_is_c1 ? code->inline_entry_point() : code->entry_point();
214   } else {
215     entry = caller_is_c1 ? method->get_c2i_unverified_inline_entry() : method->get_c2i_unverified_entry();
216   }
217 
218   log_trace(inlinecache)("IC@" INTPTR_FORMAT ": monomorphic to %s: %s",
219                          p2i(_call->instruction_address()),
220                          to_compiled ? "compiled" : "interpreter",
221                          method->print_value_string());
222 
223   _call->set_destination_mt_safe(entry);
224 }
225 
226 void CompiledIC::set_to_megamorphic(CallInfo* call_info, bool caller_is_c1) {
227   assert(data()->is_initialized(), "must be initialized");
228 
229   address entry;
230   if (call_info->call_kind() == CallInfo::direct_call) {
231     // C1 sometimes compiles a callsite before the target method is loaded, resulting in
232     // dynamically bound callsites that should really be statically bound. However, the
233     // target method might not have a vtable or itable. We just wait for better code to arrive
234     return;
235   } else if (call_info->call_kind() == CallInfo::itable_call) {
236     int itable_index = call_info->itable_index();
237     entry = VtableStubs::find_itable_stub(itable_index, caller_is_c1);
238     if (entry == nullptr) {
239       return;
240     }
241 #ifdef ASSERT
242     assert(call_info->resolved_method() != nullptr, "virtual or interface method must be found");
243     int index = call_info->resolved_method()->itable_index();
244     assert(index == itable_index, "CallInfo pre-computes this");
245     InstanceKlass* k = call_info->resolved_method()->method_holder();
246     assert(k->verify_itable_index(itable_index), "sanity check");
247 #endif //ASSERT
248   } else {
249     assert(call_info->call_kind() == CallInfo::vtable_call, "what else?");
250     // Can be different than selected_method->vtable_index(), due to package-private etc.
251     int vtable_index = call_info->vtable_index();
252     assert(call_info->resolved_klass()->verify_vtable_index(vtable_index), "sanity check");
253     entry = VtableStubs::find_vtable_stub(vtable_index, caller_is_c1);
254     if (entry == nullptr) {
255       return;
256     }
257   }
258 
259   assert(call_info->selected_method() != nullptr, "virtual or interface method must be found");
260   log_trace(inlinecache)("IC@" INTPTR_FORMAT ": to megamorphic %s entry: " INTPTR_FORMAT,
261                          p2i(_call->instruction_address()), call_info->selected_method()->print_value_string(), p2i(entry));
262 
263   _call->set_destination_mt_safe(entry);
264   assert(is_megamorphic(), "sanity check");
265 }
266 
267 void CompiledIC::update(CallInfo* call_info, Klass* receiver_klass, bool caller_is_c1) {
268   // If this is the first time we fix the inline cache, we ensure it's initialized
269   ensure_initialized(call_info, receiver_klass);
270 
271   if (is_megamorphic()) {
272     // Terminal state for the inline cache
273     return;
274   }
275 
276   if (is_speculated_klass(receiver_klass)) {
277     // If the speculated class matches the receiver klass, we can speculate that will
278     // continue to be the case with a monomorphic inline cache
279     set_to_monomorphic(caller_is_c1);
280   } else {
281     // If the dynamic type speculation fails, we try to transform to a megamorphic state
282     // for the inline cache using stubs to dispatch in tables
283     set_to_megamorphic(call_info, caller_is_c1);
284   }
285 }
286 
287 bool CompiledIC::is_clean() const {
288   return destination() == SharedRuntime::get_resolve_virtual_call_stub();
289 }
290 
291 bool CompiledIC::is_monomorphic() const {
292   return !is_clean() && !is_megamorphic();
293 }
294 
295 bool CompiledIC::is_megamorphic() const {
296   return VtableStubs::entry_point(destination()) != nullptr;
297 }
298 
299 bool CompiledIC::is_speculated_klass(Klass* receiver_klass) {
300   return data()->speculated_klass() == receiver_klass;
301 }
302 
303 // GC support

328   assert(CompiledICLocker::is_safe(instruction_address()), "mt unsafe call");
329   // Reset call site
330   RelocIterator iter((nmethod*)nullptr, instruction_address(), instruction_address() + 1);
331   while (iter.next()) {
332     switch(iter.type()) {
333     case relocInfo::static_call_type:
334       _call->set_destination_mt_safe(SharedRuntime::get_resolve_static_call_stub());
335       break;
336     case relocInfo::opt_virtual_call_type:
337       _call->set_destination_mt_safe(SharedRuntime::get_resolve_opt_virtual_call_stub());
338       break;
339     default:
340       ShouldNotReachHere();
341     }
342   }
343   assert(is_clean(), "should be clean after cleaning");
344 
345   log_debug(inlinecache)("DC@" INTPTR_FORMAT ": set to clean", p2i(_call->instruction_address()));
346 }
347 
348 void CompiledDirectCall::set(const methodHandle& callee_method, bool caller_is_c1) {
349   nmethod* code = callee_method->code();
350   nmethod* caller = CodeCache::find_nmethod(instruction_address());
351   assert(caller != nullptr, "did not find caller nmethod");
352 
353   bool to_interp_cont_enter = caller->method()->is_continuation_enter_intrinsic() &&
354                               ContinuationEntry::is_interpreted_call(instruction_address());
355 
356   bool to_compiled = !to_interp_cont_enter && code != nullptr && code->is_in_use() && !code->is_unloading();
357 
358   if (to_compiled) {
359     _call->set_destination_mt_safe(caller_is_c1 ? code->verified_inline_entry_point() : code->verified_entry_point());
360     assert(is_call_to_compiled(), "should be compiled after set to compiled");
361   } else {
362     // Patch call site to C2I adapter if code is deoptimized or unloaded.
363     // We also need to patch the static call stub to set the rmethod register
364     // to the callee_method so the c2i adapter knows how to build the frame
365     set_to_interpreted(callee_method, caller_is_c1 ? callee_method->get_c2i_inline_entry() : callee_method->get_c2i_entry());
366     assert(is_call_to_interpreted(), "should be interpreted after set to interpreted");
367   }
368 
369   log_trace(inlinecache)("DC@" INTPTR_FORMAT ": set to %s: %s: " INTPTR_FORMAT,
370                          p2i(_call->instruction_address()),
371                          to_compiled ? "compiled" : "interpreter",
372                          callee_method->print_value_string(),
373                          p2i(_call->destination()));
374 }
375 
376 bool CompiledDirectCall::is_clean() const {
377   return destination() == SharedRuntime::get_resolve_static_call_stub() ||
378          destination() == SharedRuntime::get_resolve_opt_virtual_call_stub();
379 }
380 
381 bool CompiledDirectCall::is_call_to_interpreted() const {
382   // It is a call to interpreted, if it calls to a stub. Hence, the destination
383   // must be in the stub part of the nmethod that contains the call
384   nmethod* nm = CodeCache::find_nmethod(instruction_address());
385   assert(nm != nullptr, "did not find nmethod");
< prev index next >