53 void* CompiledIC::cached_value() const { |
53 void* CompiledIC::cached_value() const { |
54 assert (CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), ""); |
54 assert (CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), ""); |
55 assert (!is_optimized(), "an optimized virtual call does not have a cached metadata"); |
55 assert (!is_optimized(), "an optimized virtual call does not have a cached metadata"); |
56 |
56 |
57 if (!is_in_transition_state()) { |
57 if (!is_in_transition_state()) { |
58 void* data = (void*)_value->data(); |
58 void* data = get_data(); |
59 // If we let the metadata value here be initialized to zero... |
59 // If we let the metadata value here be initialized to zero... |
60 assert(data != NULL || Universe::non_oop_word() == NULL, |
60 assert(data != NULL || Universe::non_oop_word() == NULL, |
61 "no raw nulls in CompiledIC metadatas, because of patching races"); |
61 "no raw nulls in CompiledIC metadatas, because of patching races"); |
62 return (data == (void*)Universe::non_oop_word()) ? NULL : data; |
62 return (data == (void*)Universe::non_oop_word()) ? NULL : data; |
63 } else { |
63 } else { |
75 assert(!is_icholder || is_icholder_entry(entry_point), "must be"); |
75 assert(!is_icholder || is_icholder_entry(entry_point), "must be"); |
76 |
76 |
77 // Don't use ic_destination for this test since that forwards |
77 // Don't use ic_destination for this test since that forwards |
78 // through ICBuffer instead of returning the actual current state of |
78 // through ICBuffer instead of returning the actual current state of |
79 // the CompiledIC. |
79 // the CompiledIC. |
80 if (is_icholder_entry(_ic_call->destination())) { |
80 if (is_icholder_entry(_call->destination())) { |
81 // When patching for the ICStub case the cached value isn't |
81 // When patching for the ICStub case the cached value isn't |
82 // overwritten until the ICStub copied into the CompiledIC during |
82 // overwritten until the ICStub copied into the CompiledIC during |
83 // the next safepoint. Make sure that the CompiledICHolder* is |
83 // the next safepoint. Make sure that the CompiledICHolder* is |
84 // marked for release at this point since it won't be identifiable |
84 // marked for release at this point since it won't be identifiable |
85 // once the entry point is overwritten. |
85 // once the entry point is overwritten. |
86 InlineCacheBuffer::queue_for_release((CompiledICHolder*)_value->data()); |
86 InlineCacheBuffer::queue_for_release((CompiledICHolder*)get_data()); |
87 } |
87 } |
88 |
88 |
89 if (TraceCompiledIC) { |
89 if (TraceCompiledIC) { |
90 tty->print(" "); |
90 tty->print(" "); |
91 print_compiled_ic(); |
91 print_compiled_ic(); |
129 |
129 |
130 |
130 |
131 address CompiledIC::ic_destination() const { |
131 address CompiledIC::ic_destination() const { |
132 assert (CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), ""); |
132 assert (CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), ""); |
133 if (!is_in_transition_state()) { |
133 if (!is_in_transition_state()) { |
134 return _ic_call->destination(); |
134 return _call->destination(); |
135 } else { |
135 } else { |
136 return InlineCacheBuffer::ic_destination_for((CompiledIC *)this); |
136 return InlineCacheBuffer::ic_destination_for((CompiledIC *)this); |
137 } |
137 } |
138 } |
138 } |
139 |
139 |
140 |
140 |
141 bool CompiledIC::is_in_transition_state() const { |
141 bool CompiledIC::is_in_transition_state() const { |
142 assert (CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), ""); |
142 assert (CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), ""); |
143 return InlineCacheBuffer::contains(_ic_call->destination()); |
143 return InlineCacheBuffer::contains(_call->destination());; |
144 } |
144 } |
145 |
145 |
146 |
146 |
147 bool CompiledIC::is_icholder_call() const { |
147 bool CompiledIC::is_icholder_call() const { |
148 assert (CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), ""); |
148 assert (CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), ""); |
151 |
151 |
152 // Returns native address of 'call' instruction in inline-cache. Used by |
152 // Returns native address of 'call' instruction in inline-cache. Used by |
153 // the InlineCacheBuffer when it needs to find the stub. |
153 // the InlineCacheBuffer when it needs to find the stub. |
154 address CompiledIC::stub_address() const { |
154 address CompiledIC::stub_address() const { |
155 assert(is_in_transition_state(), "should only be called when we are in a transition state"); |
155 assert(is_in_transition_state(), "should only be called when we are in a transition state"); |
156 return _ic_call->destination(); |
156 return _call->destination(); |
157 } |
157 } |
158 |
158 |
159 // Clears the IC stub if the compiled IC is in transition state |
159 // Clears the IC stub if the compiled IC is in transition state |
160 void CompiledIC::clear_ic_stub() { |
160 void CompiledIC::clear_ic_stub() { |
161 if (is_in_transition_state()) { |
161 if (is_in_transition_state()) { |
162 ICStub* stub = ICStub_from_destination_address(stub_address()); |
162 ICStub* stub = ICStub_from_destination_address(stub_address()); |
163 stub->clear(); |
163 stub->clear(); |
164 } |
164 } |
165 } |
165 } |
166 |
166 |
167 |
|
168 //----------------------------------------------------------------------------- |
167 //----------------------------------------------------------------------------- |
169 // High-level access to an inline cache. Guaranteed to be MT-safe. |
168 // High-level access to an inline cache. Guaranteed to be MT-safe. |
170 |
169 |
171 void CompiledIC::initialize_from_iter(RelocIterator* iter) { |
170 void CompiledIC::initialize_from_iter(RelocIterator* iter) { |
172 assert(iter->addr() == _ic_call->instruction_address(), "must find ic_call"); |
171 assert(iter->addr() == _call->instruction_address(), "must find ic_call"); |
173 |
172 |
174 if (iter->type() == relocInfo::virtual_call_type) { |
173 if (iter->type() == relocInfo::virtual_call_type) { |
175 virtual_call_Relocation* r = iter->virtual_call_reloc(); |
174 virtual_call_Relocation* r = iter->virtual_call_reloc(); |
176 _is_optimized = false; |
175 _is_optimized = false; |
177 _value = nativeMovConstReg_at(r->cached_value()); |
176 _value = _call->get_load_instruction(r); |
178 } else { |
177 } else { |
179 assert(iter->type() == relocInfo::opt_virtual_call_type, "must be a virtual call"); |
178 assert(iter->type() == relocInfo::opt_virtual_call_type, "must be a virtual call"); |
180 _is_optimized = true; |
179 _is_optimized = true; |
181 _value = NULL; |
180 _value = NULL; |
182 } |
181 } |
183 } |
182 } |
184 |
183 |
185 CompiledIC::CompiledIC(CompiledMethod* cm, NativeCall* call) |
184 CompiledIC::CompiledIC(CompiledMethod* cm, NativeCall* call) |
186 : _ic_call(call) |
185 : _method(cm) |
187 { |
186 { |
188 address ic_call = _ic_call->instruction_address(); |
187 _call = _method->call_wrapper_at((address) call); |
|
188 address ic_call = _call->instruction_address(); |
189 |
189 |
190 assert(ic_call != NULL, "ic_call address must be set"); |
190 assert(ic_call != NULL, "ic_call address must be set"); |
191 assert(cm != NULL, "must pass compiled method"); |
191 assert(cm != NULL, "must pass compiled method"); |
192 assert(cm->contains(ic_call), "must be in compiled method"); |
192 assert(cm->contains(ic_call), "must be in compiled method"); |
193 |
193 |
309 CodeBlob* cb = CodeCache::find_blob_unsafe(ic_destination()); |
310 CodeBlob* cb = CodeCache::find_blob_unsafe(ic_destination()); |
310 is_call_to_interpreted = (cb != NULL && cb->is_adapter_blob()); |
311 is_call_to_interpreted = (cb != NULL && cb->is_adapter_blob()); |
311 assert(!is_call_to_interpreted || (is_icholder_call() && cached_icholder() != NULL), "sanity check"); |
312 assert(!is_call_to_interpreted || (is_icholder_call() && cached_icholder() != NULL), "sanity check"); |
312 } else { |
313 } else { |
313 // Check if we are calling into our own codeblob (i.e., to a stub) |
314 // Check if we are calling into our own codeblob (i.e., to a stub) |
314 CodeBlob* cb = CodeCache::find_blob(_ic_call->instruction_address()); |
|
315 address dest = ic_destination(); |
315 address dest = ic_destination(); |
316 #ifdef ASSERT |
316 #ifdef ASSERT |
317 { |
317 { |
318 CodeBlob* db = CodeCache::find_blob_unsafe(dest); |
318 _call->verify_resolve_call(dest); |
319 assert(!db->is_adapter_blob(), "must use stub!"); |
|
320 } |
319 } |
321 #endif /* ASSERT */ |
320 #endif /* ASSERT */ |
322 is_call_to_interpreted = cb->contains(dest); |
321 is_call_to_interpreted = _call->is_call_to_interpreted(dest); |
323 } |
322 } |
324 return is_call_to_interpreted; |
323 return is_call_to_interpreted; |
325 } |
324 } |
326 |
|
327 |
325 |
328 void CompiledIC::set_to_clean(bool in_use) { |
326 void CompiledIC::set_to_clean(bool in_use) { |
329 assert(SafepointSynchronize::is_at_safepoint() || CompiledIC_lock->is_locked() , "MT-unsafe call"); |
327 assert(SafepointSynchronize::is_at_safepoint() || CompiledIC_lock->is_locked() , "MT-unsafe call"); |
330 if (TraceInlineCacheClearing || TraceICs) { |
328 if (TraceInlineCacheClearing || TraceICs) { |
331 tty->print_cr("IC@" INTPTR_FORMAT ": set to clean", p2i(instruction_address())); |
329 tty->print_cr("IC@" INTPTR_FORMAT ": set to clean", p2i(instruction_address())); |
332 print(); |
330 print(); |
333 } |
331 } |
334 |
332 |
335 address entry; |
333 address entry = _call->get_resolve_call_stub(is_optimized()); |
336 if (is_optimized()) { |
|
337 entry = SharedRuntime::get_resolve_opt_virtual_call_stub(); |
|
338 } else { |
|
339 entry = SharedRuntime::get_resolve_virtual_call_stub(); |
|
340 } |
|
341 |
334 |
342 // A zombie transition will always be safe, since the metadata has already been set to NULL, so |
335 // A zombie transition will always be safe, since the metadata has already been set to NULL, so |
343 // we only need to patch the destination |
336 // we only need to patch the destination |
344 bool safe_transition = !in_use || is_optimized() || SafepointSynchronize::is_at_safepoint(); |
337 bool safe_transition = _call->is_safe_for_patching() || !in_use || is_optimized() || SafepointSynchronize::is_at_safepoint(); |
345 |
338 |
346 if (safe_transition) { |
339 if (safe_transition) { |
347 // Kill any leftover stub we might have too |
340 // Kill any leftover stub we might have too |
348 clear_ic_stub(); |
341 clear_ic_stub(); |
349 if (is_optimized()) { |
342 if (is_optimized()) { |
362 // race because the IC entry was complete when we safepointed so |
355 // race because the IC entry was complete when we safepointed so |
363 // cleaning it immediately is harmless. |
356 // cleaning it immediately is harmless. |
364 // assert(is_clean(), "sanity check"); |
357 // assert(is_clean(), "sanity check"); |
365 } |
358 } |
366 |
359 |
367 |
|
368 bool CompiledIC::is_clean() const { |
360 bool CompiledIC::is_clean() const { |
369 assert (CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), ""); |
361 assert (CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), ""); |
370 bool is_clean = false; |
362 bool is_clean = false; |
371 address dest = ic_destination(); |
363 address dest = ic_destination(); |
372 is_clean = dest == SharedRuntime::get_resolve_opt_virtual_call_stub() || |
364 is_clean = dest == _call->get_resolve_call_stub(is_optimized()); |
373 dest == SharedRuntime::get_resolve_virtual_call_stub(); |
|
374 assert(!is_clean || is_optimized() || cached_value() == NULL, "sanity check"); |
365 assert(!is_clean || is_optimized() || cached_value() == NULL, "sanity check"); |
375 return is_clean; |
366 return is_clean; |
376 } |
367 } |
377 |
|
378 |
368 |
379 void CompiledIC::set_to_monomorphic(CompiledICInfo& info) { |
369 void CompiledIC::set_to_monomorphic(CompiledICInfo& info) { |
380 assert (CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), ""); |
370 assert (CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), ""); |
381 // Updating a cache to the wrong entry can cause bugs that are very hard |
371 // Updating a cache to the wrong entry can cause bugs that are very hard |
382 // to track down - if cache entry gets invalid - we just clean it. In |
372 // to track down - if cache entry gets invalid - we just clean it. In |
389 // |
379 // |
390 // In both of these cases the only thing being modifed is the jump/call target and these |
380 // In both of these cases the only thing being modifed is the jump/call target and these |
391 // transitions are mt_safe |
381 // transitions are mt_safe |
392 |
382 |
393 Thread *thread = Thread::current(); |
383 Thread *thread = Thread::current(); |
394 if (info.to_interpreter()) { |
384 if (info.to_interpreter() || info.to_aot()) { |
395 // Call to interpreter |
385 // Call to interpreter |
396 if (info.is_optimized() && is_optimized()) { |
386 if (info.is_optimized() && is_optimized()) { |
397 assert(is_clean(), "unsafe IC path"); |
387 assert(is_clean(), "unsafe IC path"); |
398 MutexLockerEx pl(Patching_lock, Mutex::_no_safepoint_check_flag); |
388 MutexLockerEx pl(Patching_lock, Mutex::_no_safepoint_check_flag); |
399 // the call analysis (callee structure) specifies that the call is optimized |
389 // the call analysis (callee structure) specifies that the call is optimized |
400 // (either because of CHA or the static target is final) |
390 // (either because of CHA or the static target is final) |
401 // At code generation time, this call has been emitted as static call |
391 // At code generation time, this call has been emitted as static call |
402 // Call via stub |
392 // Call via stub |
403 assert(info.cached_metadata() != NULL && info.cached_metadata()->is_method(), "sanity check"); |
393 assert(info.cached_metadata() != NULL && info.cached_metadata()->is_method(), "sanity check"); |
404 CompiledStaticCall* csc = compiledStaticCall_at(instruction_address()); |
|
405 methodHandle method (thread, (Method*)info.cached_metadata()); |
394 methodHandle method (thread, (Method*)info.cached_metadata()); |
406 csc->set_to_interpreted(method, info.entry()); |
395 _call->set_to_interpreted(method, info); |
|
396 |
407 if (TraceICs) { |
397 if (TraceICs) { |
408 ResourceMark rm(thread); |
398 ResourceMark rm(thread); |
409 tty->print_cr ("IC@" INTPTR_FORMAT ": monomorphic to interpreter: %s", |
399 tty->print_cr ("IC@" INTPTR_FORMAT ": monomorphic to %s: %s", |
410 p2i(instruction_address()), |
400 p2i(instruction_address()), |
|
401 (info.to_aot() ? "aot" : "interpreter"), |
411 method->print_value_string()); |
402 method->print_value_string()); |
412 } |
403 } |
413 } else { |
404 } else { |
414 // Call via method-klass-holder |
405 // Call via method-klass-holder |
415 InlineCacheBuffer::create_transition_stub(this, info.claim_cached_icholder(), info.entry()); |
406 InlineCacheBuffer::create_transition_stub(this, info.claim_cached_icholder(), info.entry()); |
497 entry = method_code->verified_entry_point(); |
489 entry = method_code->verified_entry_point(); |
498 } else { |
490 } else { |
499 entry = method_code->entry_point(); |
491 entry = method_code->entry_point(); |
500 } |
492 } |
501 } |
493 } |
502 if (entry != NULL) { |
494 bool far_c2a = entry != NULL && caller_is_nmethod && method_code->is_far_code(); |
503 // Call to compiled code |
495 if (entry != NULL && !far_c2a) { |
|
496 // Call to near compiled code (nmethod or aot). |
504 info.set_compiled_entry(entry, (static_bound || is_optimized) ? NULL : receiver_klass(), is_optimized); |
497 info.set_compiled_entry(entry, (static_bound || is_optimized) ? NULL : receiver_klass(), is_optimized); |
505 } else { |
498 } else { |
506 if (is_optimized) { |
499 if (is_optimized) { |
507 // Use stub entry |
500 if (far_c2a) { |
508 info.set_interpreter_entry(method()->get_c2i_entry(), method()); |
501 // Call to aot code from nmethod. |
|
502 info.set_aot_entry(entry, method()); |
|
503 } else { |
|
504 // Use stub entry |
|
505 info.set_interpreter_entry(method()->get_c2i_entry(), method()); |
|
506 } |
509 } else { |
507 } else { |
510 // Use icholder entry |
508 // Use icholder entry |
511 assert(method_code == NULL || method_code->is_compiled(), "must be compiled"); |
509 assert(method_code == NULL || method_code->is_compiled(), "must be compiled"); |
512 CompiledICHolder* holder = new CompiledICHolder(method(), receiver_klass()); |
510 CompiledICHolder* holder = new CompiledICHolder(method(), receiver_klass()); |
513 info.set_icholder_entry(method()->get_c2i_unverified_entry(), holder); |
511 info.set_icholder_entry(method()->get_c2i_unverified_entry(), holder); |
520 bool CompiledIC::is_icholder_entry(address entry) { |
518 bool CompiledIC::is_icholder_entry(address entry) { |
521 CodeBlob* cb = CodeCache::find_blob_unsafe(entry); |
519 CodeBlob* cb = CodeCache::find_blob_unsafe(entry); |
522 return (cb != NULL && cb->is_adapter_blob()); |
520 return (cb != NULL && cb->is_adapter_blob()); |
523 } |
521 } |
524 |
522 |
|
523 bool CompiledIC::is_icholder_call_site(virtual_call_Relocation* call_site, const CompiledMethod* cm) { |
|
524 // This call site might have become stale so inspect it carefully. |
|
525 address dest = cm->call_wrapper_at(call_site->addr())->destination(); |
|
526 return is_icholder_entry(dest); |
|
527 } |
|
528 |
525 // Release the CompiledICHolder* associated with this call site is there is one. |
529 // Release the CompiledICHolder* associated with this call site is there is one. |
526 void CompiledIC::cleanup_call_site(virtual_call_Relocation* call_site) { |
530 void CompiledIC::cleanup_call_site(virtual_call_Relocation* call_site, const CompiledMethod* cm) { |
|
531 assert(cm->is_nmethod(), "must be nmethod"); |
527 // This call site might have become stale so inspect it carefully. |
532 // This call site might have become stale so inspect it carefully. |
528 NativeCall* call = nativeCall_at(call_site->addr()); |
533 NativeCall* call = nativeCall_at(call_site->addr()); |
529 if (is_icholder_entry(call->destination())) { |
534 if (is_icholder_entry(call->destination())) { |
530 NativeMovConstReg* value = nativeMovConstReg_at(call_site->cached_value()); |
535 NativeMovConstReg* value = nativeMovConstReg_at(call_site->cached_value()); |
531 InlineCacheBuffer::queue_for_release((CompiledICHolder*)value->data()); |
536 InlineCacheBuffer::queue_for_release((CompiledICHolder*)value->data()); |
532 } |
537 } |
533 } |
538 } |
534 |
539 |
535 bool CompiledIC::is_icholder_call_site(virtual_call_Relocation* call_site) { |
|
536 // This call site might have become stale so inspect it carefully. |
|
537 NativeCall* call = nativeCall_at(call_site->addr()); |
|
538 return is_icholder_entry(call->destination()); |
|
539 } |
|
540 |
|
541 // ---------------------------------------------------------------------------- |
540 // ---------------------------------------------------------------------------- |
542 |
541 |
543 void CompiledStaticCall::set_to_clean() { |
542 void CompiledStaticCall::set_to_clean() { |
544 assert (CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), "mt unsafe call"); |
543 assert (CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), "mt unsafe call"); |
545 // Reset call site |
544 // Reset call site |
546 MutexLockerEx pl(SafepointSynchronize::is_at_safepoint() ? NULL : Patching_lock, Mutex::_no_safepoint_check_flag); |
545 MutexLockerEx pl(SafepointSynchronize::is_at_safepoint() ? NULL : Patching_lock, Mutex::_no_safepoint_check_flag); |
547 #ifdef ASSERT |
546 #ifdef ASSERT |
548 CodeBlob* cb = CodeCache::find_blob_unsafe(this); |
547 CodeBlob* cb = CodeCache::find_blob_unsafe(instruction_address()); |
549 assert(cb != NULL && cb->is_compiled(), "must be compiled"); |
548 assert(cb != NULL && cb->is_compiled(), "must be compiled"); |
550 #endif |
549 #endif |
551 set_destination_mt_safe(SharedRuntime::get_resolve_static_call_stub()); |
550 |
|
551 set_destination_mt_safe(resolve_call_stub()); |
552 |
552 |
553 // Do not reset stub here: It is too expensive to call find_stub. |
553 // Do not reset stub here: It is too expensive to call find_stub. |
554 // Instead, rely on caller (nmethod::clear_inline_caches) to clear |
554 // Instead, rely on caller (nmethod::clear_inline_caches) to clear |
555 // both the call and its stub. |
555 // both the call and its stub. |
556 } |
556 } |
557 |
557 |
558 |
|
559 bool CompiledStaticCall::is_clean() const { |
558 bool CompiledStaticCall::is_clean() const { |
560 return destination() == SharedRuntime::get_resolve_static_call_stub(); |
559 return destination() == resolve_call_stub(); |
561 } |
560 } |
562 |
561 |
563 bool CompiledStaticCall::is_call_to_compiled() const { |
562 bool CompiledStaticCall::is_call_to_compiled() const { |
564 return CodeCache::contains(destination()); |
563 return CodeCache::contains(destination()); |
565 } |
564 } |
566 |
565 |
567 |
566 bool CompiledDirectStaticCall::is_call_to_interpreted() const { |
568 bool CompiledStaticCall::is_call_to_interpreted() const { |
|
569 // It is a call to interpreted, if it calls to a stub. Hence, the destination |
567 // It is a call to interpreted, if it calls to a stub. Hence, the destination |
570 // must be in the stub part of the nmethod that contains the call |
568 // must be in the stub part of the nmethod that contains the call |
571 CompiledMethod* cm = CodeCache::find_compiled(instruction_address()); |
569 CompiledMethod* cm = CodeCache::find_compiled(instruction_address()); |
572 return cm->stub_contains(destination()); |
570 return cm->stub_contains(destination()); |
|
571 } |
|
572 |
|
573 bool CompiledDirectStaticCall::is_call_to_far() const { |
|
574 // It is a call to aot method, if it calls to a stub. Hence, the destination |
|
575 // must be in the stub part of the nmethod that contains the call |
|
576 CodeBlob* desc = CodeCache::find_blob(instruction_address()); |
|
577 return desc->as_compiled_method()->stub_contains(destination()); |
|
578 } |
|
579 |
|
580 void CompiledStaticCall::set_to_compiled(address entry) { |
|
581 if (TraceICs) { |
|
582 ResourceMark rm; |
|
583 tty->print_cr("%s@" INTPTR_FORMAT ": set_to_compiled " INTPTR_FORMAT, |
|
584 name(), |
|
585 p2i(instruction_address()), |
|
586 p2i(entry)); |
|
587 } |
|
588 // Call to compiled code |
|
589 assert(CodeCache::contains(entry), "wrong entry point"); |
|
590 set_destination_mt_safe(entry); |
573 } |
591 } |
574 |
592 |
575 void CompiledStaticCall::set(const StaticCallInfo& info) { |
593 void CompiledStaticCall::set(const StaticCallInfo& info) { |
576 assert (CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), "mt unsafe call"); |
594 assert (CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), "mt unsafe call"); |
577 MutexLockerEx pl(Patching_lock, Mutex::_no_safepoint_check_flag); |
595 MutexLockerEx pl(Patching_lock, Mutex::_no_safepoint_check_flag); |
582 assert(is_clean(), "do not update a call entry - use clean"); |
600 assert(is_clean(), "do not update a call entry - use clean"); |
583 |
601 |
584 if (info._to_interpreter) { |
602 if (info._to_interpreter) { |
585 // Call to interpreted code |
603 // Call to interpreted code |
586 set_to_interpreted(info.callee(), info.entry()); |
604 set_to_interpreted(info.callee(), info.entry()); |
587 } else { |
605 #if INCLUDE_AOT |
588 if (TraceICs) { |
606 } else if (info._to_aot) { |
589 ResourceMark rm; |
607 // Call to far code |
590 tty->print_cr("CompiledStaticCall@" INTPTR_FORMAT ": set_to_compiled " INTPTR_FORMAT, |
608 set_to_far(info.callee(), info.entry()); |
591 p2i(instruction_address()), |
609 #endif |
592 p2i(info.entry())); |
610 } else { |
593 } |
611 set_to_compiled(info.entry()); |
594 // Call to compiled code |
612 } |
595 assert (CodeCache::contains(info.entry()), "wrong entry point"); |
613 } |
596 set_destination_mt_safe(info.entry()); |
|
597 } |
|
598 } |
|
599 |
|
600 |
614 |
601 // Compute settings for a CompiledStaticCall. Since we might have to set |
615 // Compute settings for a CompiledStaticCall. Since we might have to set |
602 // the stub when calling to the interpreter, we need to return arguments. |
616 // the stub when calling to the interpreter, we need to return arguments. |
603 void CompiledStaticCall::compute_entry(const methodHandle& m, StaticCallInfo& info) { |
617 void CompiledStaticCall::compute_entry(const methodHandle& m, bool caller_is_nmethod, StaticCallInfo& info) { |
604 CompiledMethod* m_code = m->code(); |
618 CompiledMethod* m_code = m->code(); |
605 info._callee = m; |
619 info._callee = m; |
606 if (m_code != NULL && m_code->is_in_use()) { |
620 if (m_code != NULL && m_code->is_in_use()) { |
|
621 if (caller_is_nmethod && m_code->is_far_code()) { |
|
622 // Call to far aot code from nmethod. |
|
623 info._to_aot = true; |
|
624 } else { |
|
625 info._to_aot = false; |
|
626 } |
607 info._to_interpreter = false; |
627 info._to_interpreter = false; |
608 info._entry = m_code->verified_entry_point(); |
628 info._entry = m_code->verified_entry_point(); |
609 } else { |
629 } else { |
610 // Callee is interpreted code. In any case entering the interpreter |
630 // Callee is interpreted code. In any case entering the interpreter |
611 // puts a converter-frame on the stack to save arguments. |
631 // puts a converter-frame on the stack to save arguments. |
613 info._to_interpreter = true; |
633 info._to_interpreter = true; |
614 info._entry = m()->get_c2i_entry(); |
634 info._entry = m()->get_c2i_entry(); |
615 } |
635 } |
616 } |
636 } |
617 |
637 |
618 address CompiledStaticCall::find_stub() { |
638 address CompiledDirectStaticCall::find_stub_for(address instruction, bool is_aot) { |
619 // Find reloc. information containing this call-site |
639 // Find reloc. information containing this call-site |
620 RelocIterator iter((nmethod*)NULL, instruction_address()); |
640 RelocIterator iter((nmethod*)NULL, instruction); |
621 while (iter.next()) { |
641 while (iter.next()) { |
622 if (iter.addr() == instruction_address()) { |
642 if (iter.addr() == instruction) { |
623 switch(iter.type()) { |
643 switch(iter.type()) { |
624 case relocInfo::static_call_type: |
644 case relocInfo::static_call_type: |
625 return iter.static_call_reloc()->static_stub(); |
645 return iter.static_call_reloc()->static_stub(is_aot); |
626 // We check here for opt_virtual_call_type, since we reuse the code |
646 // We check here for opt_virtual_call_type, since we reuse the code |
627 // from the CompiledIC implementation |
647 // from the CompiledIC implementation |
628 case relocInfo::opt_virtual_call_type: |
648 case relocInfo::opt_virtual_call_type: |
629 return iter.opt_virtual_call_reloc()->static_stub(); |
649 return iter.opt_virtual_call_reloc()->static_stub(is_aot); |
630 case relocInfo::poll_type: |
650 case relocInfo::poll_type: |
631 case relocInfo::poll_return_type: // A safepoint can't overlap a call. |
651 case relocInfo::poll_return_type: // A safepoint can't overlap a call. |
632 default: |
652 default: |
633 ShouldNotReachHere(); |
653 ShouldNotReachHere(); |
634 } |
654 } |
635 } |
655 } |
636 } |
656 } |
637 return NULL; |
657 return NULL; |
638 } |
658 } |
639 |
659 |
|
660 address CompiledDirectStaticCall::find_stub(bool is_aot) { |
|
661 return CompiledDirectStaticCall::find_stub_for(instruction_address(), is_aot); |
|
662 } |
|
663 |
|
664 address CompiledDirectStaticCall::resolve_call_stub() const { |
|
665 return SharedRuntime::get_resolve_static_call_stub(); |
|
666 } |
640 |
667 |
641 //----------------------------------------------------------------------------- |
668 //----------------------------------------------------------------------------- |
642 // Non-product mode code |
669 // Non-product mode code |
643 #ifndef PRODUCT |
670 #ifndef PRODUCT |
644 |
671 |
645 void CompiledIC::verify() { |
672 void CompiledIC::verify() { |
646 // make sure code pattern is actually a call imm32 instruction |
673 _call->verify(); |
647 _ic_call->verify(); |
|
648 if (os::is_MP()) { |
|
649 _ic_call->verify_alignment(); |
|
650 } |
|
651 assert(is_clean() || is_call_to_compiled() || is_call_to_interpreted() |
674 assert(is_clean() || is_call_to_compiled() || is_call_to_interpreted() |
652 || is_optimized() || is_megamorphic(), "sanity check"); |
675 || is_optimized() || is_megamorphic(), "sanity check"); |
653 } |
676 } |
654 |
677 |
655 void CompiledIC::print() { |
678 void CompiledIC::print() { |
660 void CompiledIC::print_compiled_ic() { |
683 void CompiledIC::print_compiled_ic() { |
661 tty->print("Inline cache at " INTPTR_FORMAT ", calling %s " INTPTR_FORMAT " cached_value " INTPTR_FORMAT, |
684 tty->print("Inline cache at " INTPTR_FORMAT ", calling %s " INTPTR_FORMAT " cached_value " INTPTR_FORMAT, |
662 p2i(instruction_address()), is_call_to_interpreted() ? "interpreted " : "", p2i(ic_destination()), p2i(is_optimized() ? NULL : cached_value())); |
685 p2i(instruction_address()), is_call_to_interpreted() ? "interpreted " : "", p2i(ic_destination()), p2i(is_optimized() ? NULL : cached_value())); |
663 } |
686 } |
664 |
687 |
665 void CompiledStaticCall::print() { |
688 void CompiledDirectStaticCall::print() { |
666 tty->print("static call at " INTPTR_FORMAT " -> ", p2i(instruction_address())); |
689 tty->print("static call at " INTPTR_FORMAT " -> ", p2i(instruction_address())); |
667 if (is_clean()) { |
690 if (is_clean()) { |
668 tty->print("clean"); |
691 tty->print("clean"); |
669 } else if (is_call_to_compiled()) { |
692 } else if (is_call_to_compiled()) { |
670 tty->print("compiled"); |
693 tty->print("compiled"); |
|
694 } else if (is_call_to_far()) { |
|
695 tty->print("far"); |
671 } else if (is_call_to_interpreted()) { |
696 } else if (is_call_to_interpreted()) { |
672 tty->print("interpreted"); |
697 tty->print("interpreted"); |
673 } |
698 } |
674 tty->cr(); |
699 tty->cr(); |
675 } |
700 } |