bool CompiledIC::is_call_to_interpreted() const { assert (CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), ""); // Call to interpreter if destination is either calling to a stub (if it // is optimized), or calling to an I2C bool is_call_to_interpreted = false; #ifdef COMPILER1 if (!is_optimized()) { is_call_to_interpreted = Runtime1::blob_for(Runtime1::interpreter_entries_id)->contains(ic_destination()); } else { // Check if we are calling into our own codeblob (i.e., to a stub) CodeBlob* cb = CodeCache::find_blob(_ic_call->instruction_address()); is_call_to_interpreted = cb->contains(ic_destination()); } #else if (!is_optimized()) { CodeBlob* cb = CodeCache::find_blob(ic_destination()); is_call_to_interpreted = (cb != NULL && cb->is_c2i_adapter()); } else { // Check if we are calling into our own codeblob (i.e., to a stub) CodeBlob* cb = CodeCache::find_blob(_ic_call->instruction_address()); is_call_to_interpreted = cb->contains(ic_destination()); } #endif // COMPILER1 assert(!is_call_to_interpreted || is_optimized() || (cached_oop() != NULL && cached_oop()->is_compiledICHolder()), "sanity check"); return is_call_to_interpreted; }
void CompiledIC::internal_set_ic_destination(address entry_point, bool is_icstub, void* cache, bool is_icholder) { assert(entry_point != NULL, "must set legal entry point"); assert(CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), ""); assert (!is_optimized() || cache == NULL, "an optimized virtual call does not have a cached metadata"); assert (cache == NULL || cache != (Metadata*)badOopVal, "invalid metadata"); assert(!is_icholder || is_icholder_entry(entry_point), "must be"); // Don't use ic_destination for this test since that forwards // through ICBuffer instead of returning the actual current state of // the CompiledIC. if (is_icholder_entry(_ic_call->destination())) { // When patching for the ICStub case the cached value isn't // overwritten until the ICStub copied into the CompiledIC during // the next safepoint. Make sure that the CompiledICHolder* is // marked for release at this point since it won't be identifiable // once the entry point is overwritten. InlineCacheBuffer::queue_for_release((CompiledICHolder*)_value->data()); } if (TraceCompiledIC) { tty->print(" "); print_compiled_ic(); tty->print(" changing destination to " INTPTR_FORMAT, p2i(entry_point)); if (!is_optimized()) { tty->print(" changing cached %s to " INTPTR_FORMAT, is_icholder ? "icholder" : "metadata", p2i((address)cache)); } if (is_icstub) { tty->print(" (icstub)"); } tty->cr(); } { MutexLockerEx pl(SafepointSynchronize::is_at_safepoint() ? NULL : Patching_lock, Mutex::_no_safepoint_check_flag); #ifdef ASSERT CodeBlob* cb = CodeCache::find_blob_unsafe(_ic_call); assert(cb != NULL && cb->is_nmethod(), "must be nmethod"); #endif _ic_call->set_destination_mt_safe(entry_point); } if (is_optimized() || is_icstub) { // Optimized call sites don't have a cache value and ICStub call // sites only change the entry point. Changing the value in that // case could lead to MT safety issues. assert(cache == NULL, "must be null"); return; } if (cache == NULL) cache = (void*)Universe::non_oop_word(); _value->set_data((intptr_t)cache); }
void CompiledIC::set_cached_oop(oop cache) { assert (CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), ""); assert (!is_optimized(), "an optimized virtual call does not have a cached oop"); assert (cache == NULL || cache != badOop, "invalid oop"); if (TraceCompiledIC) { tty->print(" "); print_compiled_ic(); tty->print_cr(" changing oop to " INTPTR_FORMAT, cache); } if (cache == NULL) cache = (oop)Universe::non_oop_word(); *_oop_addr = cache; // fix up the relocations RelocIterator iter = _oops; while (iter.next()) { if (iter.type() == relocInfo::oop_type) { oop_Relocation* r = iter.oop_reloc(); if (r->oop_addr() == _oop_addr) r->fix_oop_relocation(); } } return; }
// true if destination is megamorphic stub bool CompiledIC::is_megamorphic() const { assert(CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), ""); assert(!is_optimized(), "an optimized call cannot be megamorphic"); // Cannot rely on cached_oop. It is either an interface or a method. return VtableStubs::is_entry_point(ic_destination()); }
bool CompiledIC::is_call_to_interpreted() const { assert (CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), ""); // Call to interpreter if destination is either calling to a stub (if it // is optimized), or calling to an I2C blob bool is_call_to_interpreted = false; if (!is_optimized()) { // must use unsafe because the destination can be a zombie (and we're cleaning) // and the print_compiled_ic code wants to know if site (in the non-zombie) // is to the interpreter. CodeBlob* cb = CodeCache::find_blob_unsafe(ic_destination()); is_call_to_interpreted = (cb != NULL && cb->is_adapter_blob()); assert(!is_call_to_interpreted || (is_icholder_call() && cached_icholder() != NULL), "sanity check"); } else { // Check if we are calling into our own codeblob (i.e., to a stub) CodeBlob* cb = CodeCache::find_blob(_ic_call->instruction_address()); address dest = ic_destination(); #ifdef ASSERT { CodeBlob* db = CodeCache::find_blob_unsafe(dest); assert(!db->is_adapter_blob(), "must use stub!"); } #endif /* ASSERT */ is_call_to_interpreted = cb->contains(dest); } return is_call_to_interpreted; }
bool CompiledIC::is_call_to_compiled() const { assert (CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), ""); // Use unsafe, since an inline cache might point to a zombie method. However, the zombie // method is guaranteed to still exist, since we only remove methods after all inline caches // has been cleaned up CodeBlob* cb = CodeCache::find_blob_unsafe(ic_destination()); bool is_monomorphic = (cb != NULL && cb->is_nmethod()); // Check that the cached_oop is a klass for non-optimized monomorphic calls // This assertion is invalid for compiler1: a call that does not look optimized (no static stub) can be used // for calling directly to vep without using the inline cache (i.e., cached_oop == NULL) #ifdef ASSERT #ifdef TIERED CodeBlob* caller = CodeCache::find_blob_unsafe(instruction_address()); bool is_c1_method = caller->is_compiled_by_c1(); #else #ifdef COMPILER1 bool is_c1_method = true; #else bool is_c1_method = false; #endif // COMPILER1 #endif // TIERED assert( is_c1_method || !is_monomorphic || is_optimized() || (cached_oop() != NULL && cached_oop()->is_klass()), "sanity check"); #endif // ASSERT return is_monomorphic; }
void CompiledIC::verify() { // make sure code pattern is actually a call imm32 instruction _ic_call->verify(); if (os::is_MP()) { _ic_call->verify_alignment(); } assert(is_clean() || is_call_to_compiled() || is_call_to_interpreted() || is_optimized() || is_megamorphic(), "sanity check"); }
bool CompiledIC::is_clean() const { assert (CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), ""); bool is_clean = false; address dest = ic_destination(); is_clean = dest == SharedRuntime::get_resolve_opt_virtual_call_stub() || dest == SharedRuntime::get_resolve_virtual_call_stub(); assert(!is_clean || is_optimized() || cached_value() == NULL, "sanity check"); return is_clean; }
void CompiledIC::set_to_clean() { assert(SafepointSynchronize::is_at_safepoint() || CompiledIC_lock->is_locked() , "MT-unsafe call"); if (TraceInlineCacheClearing || TraceICs) { tty->print_cr("IC@" INTPTR_FORMAT ": set to clean", instruction_address()); print(); } address entry; #ifdef COMPILER1 entry = is_optimized() ? Runtime1::entry_for(Runtime1::resolve_invoke_opt_virtual_id) : Runtime1::entry_for(Runtime1::resolve_invokevirtual_id); #else entry = is_optimized() ? OptoRuntime::resolve_opt_virtual_call_Java() : OptoRuntime::resolve_virtual_call_Java(); #endif // A zombie transition will always be safe, since the oop has already been set to NULL, so // we only need to patch the destination bool safe_transition = is_optimized() || SafepointSynchronize::is_at_safepoint(); if (safe_transition) { if (!is_optimized()) set_cached_oop(NULL); // Kill any leftover stub we might have too if (is_in_transition_state()) { ICStub* old_stub = ICStub_from_destination_address(stub_address()); old_stub->clear(); } set_ic_destination(entry); } else { // Unsafe transition - create stub. InlineCacheBuffer::create_transition_stub(this, NULL, entry); } // We can't check this anymore. With lazy deopt we could have already // cleaned this IC entry before we even return. This is possible if // we ran out of space in the inline cache buffer trying to do the // set_next and we safepointed to free up space. This is a benign // race because the IC entry was complete when we safepointed so // cleaning it immediately is harmless. // assert(is_clean(), "sanity check"); }
void CompiledIC::set_to_clean(bool in_use) { assert(SafepointSynchronize::is_at_safepoint() || CompiledIC_lock->is_locked() , "MT-unsafe call"); if (TraceInlineCacheClearing || TraceICs) { tty->print_cr("IC@" INTPTR_FORMAT ": set to clean", p2i(instruction_address())); print(); } address entry; if (is_optimized()) { entry = SharedRuntime::get_resolve_opt_virtual_call_stub(); } else { entry = SharedRuntime::get_resolve_virtual_call_stub(); } // A zombie transition will always be safe, since the metadata has already been set to NULL, so // we only need to patch the destination bool safe_transition = !in_use || is_optimized() || SafepointSynchronize::is_at_safepoint(); if (safe_transition) { // Kill any leftover stub we might have too clear_ic_stub(); if (is_optimized()) { set_ic_destination(entry); } else { set_ic_destination_and_value(entry, (void*)NULL); } } else { // Unsafe transition - create stub. InlineCacheBuffer::create_transition_stub(this, NULL, entry); } // We can't check this anymore. With lazy deopt we could have already // cleaned this IC entry before we even return. This is possible if // we ran out of space in the inline cache buffer trying to do the // set_next and we safepointed to free up space. This is a benign // race because the IC entry was complete when we safepointed so // cleaning it immediately is harmless. // assert(is_clean(), "sanity check"); }
bool CompiledIC::set_to_megamorphic(CallInfo* call_info, Bytecodes::Code bytecode, TRAPS) { assert(CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), ""); assert(!is_optimized(), "cannot set an optimized virtual call to megamorphic"); assert(is_call_to_compiled() || is_call_to_interpreted(), "going directly to megamorphic?"); address entry; if (call_info->call_kind() == CallInfo::itable_call) { assert(bytecode == Bytecodes::_invokeinterface, ""); int itable_index = call_info->itable_index(); entry = VtableStubs::find_itable_stub(itable_index); if (entry == false) { return false; } #ifdef ASSERT int index = call_info->resolved_method()->itable_index(); assert(index == itable_index, "CallInfo pre-computes this"); InstanceKlass* k = call_info->resolved_method()->method_holder(); assert(k->verify_itable_index(itable_index), "sanity check"); #endif //ASSERT CompiledICHolder* holder = new CompiledICHolder(call_info->resolved_method()->method_holder(), call_info->resolved_klass()(), false); holder->claim(); InlineCacheBuffer::create_transition_stub(this, holder, entry); } else { assert(call_info->call_kind() == CallInfo::vtable_call, "either itable or vtable"); // Can be different than selected_method->vtable_index(), due to package-private etc. int vtable_index = call_info->vtable_index(); assert(call_info->resolved_klass()->verify_vtable_index(vtable_index), "sanity check"); entry = VtableStubs::find_vtable_stub(vtable_index); if (entry == NULL) { return false; } InlineCacheBuffer::create_transition_stub(this, NULL, entry); } if (TraceICs) { ResourceMark rm; tty->print_cr ("IC@" INTPTR_FORMAT ": to megamorphic %s entry: " INTPTR_FORMAT, p2i(instruction_address()), call_info->selected_method()->print_value_string(), p2i(entry)); } // We can't check this anymore. With lazy deopt we could have already // cleaned this IC entry before we even return. This is possible if // we ran out of space in the inline cache buffer trying to do the // set_next and we safepointed to free up space. This is a benign // race because the IC entry was complete when we safepointed so // cleaning it immediately is harmless. // assert(is_megamorphic(), "sanity check"); return true; }
oop CompiledIC::cached_oop() const { assert (CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), ""); assert (!is_optimized(), "an optimized virtual call does not have a cached oop"); if (!is_in_transition_state()) { oop data = *_oop_addr; // If we let the oop value here be initialized to zero... assert(data != NULL || Universe::non_oop_word() == NULL, "no raw nulls in CompiledIC oops, because of patching races"); return (data == (oop)Universe::non_oop_word()) ? NULL : data; } else { return InlineCacheBuffer::cached_oop_for((CompiledIC *)this); } }
bool CompiledIC::is_clean() const { assert (CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), ""); bool is_clean = false; address dest = ic_destination(); #ifdef COMPILER1 is_clean = dest == Runtime1::entry_for(Runtime1::resolve_invokevirtual_id) || dest == Runtime1::entry_for(Runtime1::resolve_invoke_opt_virtual_id); #else is_clean = dest == OptoRuntime::resolve_virtual_call_Java() || dest == OptoRuntime::resolve_opt_virtual_call_Java(); #endif assert(!is_clean || is_optimized() || cached_oop() == NULL, "sanity check"); return is_clean; }
void CompiledIC::set_to_megamorphic(CallInfo* call_info, Bytecodes::Code bytecode, TRAPS) { methodHandle method = call_info->selected_method(); bool is_invoke_interface = (bytecode == Bytecodes::_invokeinterface && !call_info->has_vtable_index()); assert(CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), ""); assert(method->is_oop(), "cannot be NULL and must be oop"); assert(!is_optimized(), "cannot set an optimized virtual call to megamorphic"); assert(is_call_to_compiled() || is_call_to_interpreted(), "going directly to megamorphic?"); address entry; if (is_invoke_interface) { int index = klassItable::compute_itable_index(call_info->resolved_method()()); entry = VtableStubs::create_stub(false, index, method()); assert(entry != NULL, "entry not computed"); klassOop k = call_info->resolved_method()->method_holder(); assert(Klass::cast(k)->is_interface(), "sanity check"); InlineCacheBuffer::create_transition_stub(this, k, entry); } else { // Can be different than method->vtable_index(), due to package-private etc. int vtable_index = call_info->vtable_index(); entry = VtableStubs::create_stub(true, vtable_index, method()); InlineCacheBuffer::create_transition_stub(this, method(), entry); } if (TraceICs) { ResourceMark rm; tty->print_cr ("IC@" INTPTR_FORMAT ": to megamorphic %s entry: " INTPTR_FORMAT, instruction_address(), method->print_value_string(), entry); } Events::log("compiledIC " INTPTR_FORMAT " --> megamorphic " INTPTR_FORMAT, this, method()); // We can't check this anymore. With lazy deopt we could have already // cleaned this IC entry before we even return. This is possible if // we ran out of space in the inline cache buffer trying to do the // set_next and we safepointed to free up space. This is a benign // race because the IC entry was complete when we safepointed so // cleaning it immediately is harmless. // assert(is_megamorphic(), "sanity check"); }
bool CompiledIC::is_call_to_compiled() const { assert (CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), ""); // Use unsafe, since an inline cache might point to a zombie method. However, the zombie // method is guaranteed to still exist, since we only remove methods after all inline caches // has been cleaned up CodeBlob* cb = CodeCache::find_blob_unsafe(ic_destination()); bool is_monomorphic = (cb != NULL && cb->is_nmethod()); // Check that the cached_value is a klass for non-optimized monomorphic calls // This assertion is invalid for compiler1: a call that does not look optimized (no static stub) can be used // for calling directly to vep without using the inline cache (i.e., cached_value == NULL). // For JVMCI this occurs because CHA is only used to improve inlining so call sites which could be optimized // virtuals because there are no currently loaded subclasses of a type are left as virtual call sites. #ifdef ASSERT CodeBlob* caller = CodeCache::find_blob_unsafe(instruction_address()); bool is_c1_or_jvmci_method = caller->is_compiled_by_c1() || caller->is_compiled_by_jvmci(); assert( is_c1_or_jvmci_method || !is_monomorphic || is_optimized() || !caller->is_alive() || (cached_metadata() != NULL && cached_metadata()->is_klass()), "sanity check"); #endif // ASSERT return is_monomorphic; }
void CompiledIC::print_compiled_ic() { tty->print("Inline cache at " INTPTR_FORMAT ", calling %s " INTPTR_FORMAT " cached_value " INTPTR_FORMAT, p2i(instruction_address()), is_call_to_interpreted() ? "interpreted " : "", p2i(ic_destination()), p2i(is_optimized() ? NULL : cached_value())); }
void CompiledIC::set_to_monomorphic(CompiledICInfo& info) { assert (CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), ""); // Updating a cache to the wrong entry can cause bugs that are very hard // to track down - if cache entry gets invalid - we just clean it. In // this way it is always the same code path that is responsible for // updating and resolving an inline cache // // The above is no longer true. SharedRuntime::fixup_callers_callsite will change optimized // callsites. In addition ic_miss code will update a site to monomorphic if it determines // that an monomorphic call to the interpreter can now be monomorphic to compiled code. // // In both of these cases the only thing being modifed is the jump/call target and these // transitions are mt_safe Thread *thread = Thread::current(); if (info.to_interpreter()) { // Call to interpreter if (info.is_optimized() && is_optimized()) { assert(is_clean(), "unsafe IC path"); MutexLockerEx pl(Patching_lock, Mutex::_no_safepoint_check_flag); // the call analysis (callee structure) specifies that the call is optimized // (either because of CHA or the static target is final) // At code generation time, this call has been emitted as static call // Call via stub assert(info.cached_metadata() != NULL && info.cached_metadata()->is_method(), "sanity check"); CompiledStaticCall* csc = compiledStaticCall_at(instruction_address()); methodHandle method (thread, (Method*)info.cached_metadata()); csc->set_to_interpreted(method, info.entry()); if (TraceICs) { ResourceMark rm(thread); tty->print_cr ("IC@" INTPTR_FORMAT ": monomorphic to interpreter: %s", p2i(instruction_address()), method->print_value_string()); } } else { // Call via method-klass-holder InlineCacheBuffer::create_transition_stub(this, info.claim_cached_icholder(), info.entry()); if (TraceICs) { ResourceMark rm(thread); tty->print_cr ("IC@" INTPTR_FORMAT ": monomorphic to interpreter via icholder ", p2i(instruction_address())); } } } else { // Call to compiled code bool static_bound = info.is_optimized() || (info.cached_metadata() == NULL); #ifdef ASSERT CodeBlob* cb = CodeCache::find_blob_unsafe(info.entry()); assert (cb->is_nmethod(), "must be compiled!"); #endif /* ASSERT */ // This is MT safe if we come from a clean-cache and go through a // non-verified entry point bool safe = SafepointSynchronize::is_at_safepoint() || (!is_in_transition_state() && (info.is_optimized() || static_bound || is_clean())); if (!safe) { InlineCacheBuffer::create_transition_stub(this, info.cached_metadata(), info.entry()); } else { if (is_optimized()) { set_ic_destination(info.entry()); } else { set_ic_destination_and_value(info.entry(), info.cached_metadata()); } } if (TraceICs) { ResourceMark rm(thread); assert(info.cached_metadata() == NULL || info.cached_metadata()->is_klass(), "must be"); tty->print_cr ("IC@" INTPTR_FORMAT ": monomorphic to compiled (rcvr klass) %s: %s", p2i(instruction_address()), ((Klass*)info.cached_metadata())->print_value_string(), (safe) ? "" : "via stub"); } } // We can't check this anymore. With lazy deopt we could have already // cleaned this IC entry before we even return. This is possible if // we ran out of space in the inline cache buffer trying to do the // set_next and we safepointed to free up space. This is a benign // race because the IC entry was complete when we safepointed so // cleaning it immediately is harmless. // assert(is_call_to_compiled() || is_call_to_interpreted(), "sanity check"); }