0N/A/*
3157N/A * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
0N/A *
0N/A */
0N/A
1879N/A#include "precompiled.hpp"
1879N/A#include "classfile/systemDictionary.hpp"
1879N/A#include "code/codeCache.hpp"
1879N/A#include "code/compiledIC.hpp"
1879N/A#include "code/icBuffer.hpp"
1879N/A#include "code/nmethod.hpp"
1879N/A#include "code/vtableStubs.hpp"
1879N/A#include "interpreter/interpreter.hpp"
1879N/A#include "interpreter/linkResolver.hpp"
1879N/A#include "memory/oopFactory.hpp"
1879N/A#include "oops/methodOop.hpp"
1879N/A#include "oops/oop.inline.hpp"
2062N/A#include "oops/symbol.hpp"
1879N/A#include "runtime/icache.hpp"
1879N/A#include "runtime/sharedRuntime.hpp"
1879N/A#include "runtime/stubRoutines.hpp"
1879N/A#include "utilities/events.hpp"
0N/A
0N/A
0N/A// Every time a compiled IC is changed or its type is being accessed,
0N/A// either the CompiledIC_lock must be set or we must be at a safe point.
0N/A
0N/A//-----------------------------------------------------------------------------
0N/A// Low-level access to an inline cache. Private, since they might not be
0N/A// MT-safe to use.
0N/A
0N/Avoid CompiledIC::set_cached_oop(oop cache) {
0N/A assert (CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), "");
0N/A assert (!is_optimized(), "an optimized virtual call does not have a cached oop");
0N/A assert (cache == NULL || cache != badOop, "invalid oop");
0N/A
0N/A if (TraceCompiledIC) {
0N/A tty->print(" ");
0N/A print_compiled_ic();
0N/A tty->print_cr(" changing oop to " INTPTR_FORMAT, (address)cache);
0N/A }
0N/A
0N/A if (cache == NULL) cache = (oop)Universe::non_oop_word();
0N/A
0N/A *_oop_addr = cache;
0N/A // fix up the relocations
0N/A RelocIterator iter = _oops;
0N/A while (iter.next()) {
0N/A if (iter.type() == relocInfo::oop_type) {
0N/A oop_Relocation* r = iter.oop_reloc();
0N/A if (r->oop_addr() == _oop_addr)
0N/A r->fix_oop_relocation();
0N/A }
0N/A }
0N/A return;
0N/A}
0N/A
0N/A
0N/Aoop CompiledIC::cached_oop() const {
0N/A assert (CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), "");
0N/A assert (!is_optimized(), "an optimized virtual call does not have a cached oop");
0N/A
0N/A if (!is_in_transition_state()) {
0N/A oop data = *_oop_addr;
0N/A // If we let the oop value here be initialized to zero...
0N/A assert(data != NULL || Universe::non_oop_word() == NULL,
0N/A "no raw nulls in CompiledIC oops, because of patching races");
0N/A return (data == (oop)Universe::non_oop_word()) ? (oop)NULL : data;
0N/A } else {
0N/A return InlineCacheBuffer::cached_oop_for((CompiledIC *)this);
0N/A }
0N/A}
0N/A
0N/A
0N/Avoid CompiledIC::set_ic_destination(address entry_point) {
0N/A assert(entry_point != NULL, "must set legal entry point");
0N/A assert(CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), "");
0N/A if (TraceCompiledIC) {
0N/A tty->print(" ");
0N/A print_compiled_ic();
0N/A tty->print_cr(" changing destination to " INTPTR_FORMAT, entry_point);
0N/A }
0N/A MutexLockerEx pl(Patching_lock, Mutex::_no_safepoint_check_flag);
0N/A#ifdef ASSERT
0N/A CodeBlob* cb = CodeCache::find_blob_unsafe(_ic_call);
0N/A assert(cb != NULL && cb->is_nmethod(), "must be nmethod");
0N/A#endif
0N/A _ic_call->set_destination_mt_safe(entry_point);
0N/A}
0N/A
0N/A
0N/Aaddress CompiledIC::ic_destination() const {
0N/A assert (CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), "");
0N/A if (!is_in_transition_state()) {
0N/A return _ic_call->destination();
0N/A } else {
0N/A return InlineCacheBuffer::ic_destination_for((CompiledIC *)this);
0N/A }
0N/A}
0N/A
0N/A
0N/Abool CompiledIC::is_in_transition_state() const {
0N/A assert (CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), "");
0N/A return InlineCacheBuffer::contains(_ic_call->destination());
0N/A}
0N/A
0N/A
0N/A// Returns native address of 'call' instruction in inline-cache. Used by
0N/A// the InlineCacheBuffer when it needs to find the stub.
0N/Aaddress CompiledIC::stub_address() const {
0N/A assert(is_in_transition_state(), "should only be called when we are in a transition state");
0N/A return _ic_call->destination();
0N/A}
0N/A
0N/A
0N/A//-----------------------------------------------------------------------------
0N/A// High-level access to an inline cache. Guaranteed to be MT-safe.
0N/A
0N/A
0N/Avoid CompiledIC::set_to_megamorphic(CallInfo* call_info, Bytecodes::Code bytecode, TRAPS) {
0N/A methodHandle method = call_info->selected_method();
0N/A bool is_invoke_interface = (bytecode == Bytecodes::_invokeinterface && !call_info->has_vtable_index());
0N/A assert(CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), "");
0N/A assert(method->is_oop(), "cannot be NULL and must be oop");
0N/A assert(!is_optimized(), "cannot set an optimized virtual call to megamorphic");
0N/A assert(is_call_to_compiled() || is_call_to_interpreted(), "going directly to megamorphic?");
0N/A
0N/A address entry;
0N/A if (is_invoke_interface) {
0N/A int index = klassItable::compute_itable_index(call_info->resolved_method()());
0N/A entry = VtableStubs::create_stub(false, index, method());
0N/A assert(entry != NULL, "entry not computed");
0N/A klassOop k = call_info->resolved_method()->method_holder();
0N/A assert(Klass::cast(k)->is_interface(), "sanity check");
0N/A InlineCacheBuffer::create_transition_stub(this, k, entry);
0N/A } else {
0N/A // Can be different than method->vtable_index(), due to package-private etc.
0N/A int vtable_index = call_info->vtable_index();
0N/A entry = VtableStubs::create_stub(true, vtable_index, method());
0N/A InlineCacheBuffer::create_transition_stub(this, method(), entry);
0N/A }
0N/A
0N/A if (TraceICs) {
0N/A ResourceMark rm;
0N/A tty->print_cr ("IC@" INTPTR_FORMAT ": to megamorphic %s entry: " INTPTR_FORMAT,
0N/A instruction_address(), method->print_value_string(), entry);
0N/A }
0N/A
0N/A // We can't check this anymore. With lazy deopt we could have already
0N/A // cleaned this IC entry before we even return. This is possible if
0N/A // we ran out of space in the inline cache buffer trying to do the
0N/A // set_next and we safepointed to free up space. This is a benign
0N/A // race because the IC entry was complete when we safepointed so
0N/A // cleaning it immediately is harmless.
0N/A // assert(is_megamorphic(), "sanity check");
0N/A}
0N/A
0N/A
0N/A// true if destination is megamorphic stub
0N/Abool CompiledIC::is_megamorphic() const {
0N/A assert(CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), "");
0N/A assert(!is_optimized(), "an optimized call cannot be megamorphic");
0N/A
0N/A // Cannot rely on cached_oop. It is either an interface or a method.
0N/A return VtableStubs::is_entry_point(ic_destination());
0N/A}
0N/A
0N/Abool CompiledIC::is_call_to_compiled() const {
0N/A assert (CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), "");
0N/A
0N/A // Use unsafe, since an inline cache might point to a zombie method. However, the zombie
0N/A // method is guaranteed to still exist, since we only remove methods after all inline caches
0N/A // has been cleaned up
0N/A CodeBlob* cb = CodeCache::find_blob_unsafe(ic_destination());
0N/A bool is_monomorphic = (cb != NULL && cb->is_nmethod());
0N/A // Check that the cached_oop is a klass for non-optimized monomorphic calls
0N/A // This assertion is invalid for compiler1: a call that does not look optimized (no static stub) can be used
0N/A // for calling directly to vep without using the inline cache (i.e., cached_oop == NULL)
0N/A#ifdef ASSERT
0N/A#ifdef TIERED
0N/A CodeBlob* caller = CodeCache::find_blob_unsafe(instruction_address());
0N/A bool is_c1_method = caller->is_compiled_by_c1();
0N/A#else
0N/A#ifdef COMPILER1
0N/A bool is_c1_method = true;
0N/A#else
0N/A bool is_c1_method = false;
0N/A#endif // COMPILER1
0N/A#endif // TIERED
0N/A assert( is_c1_method ||
0N/A !is_monomorphic ||
0N/A is_optimized() ||
0N/A (cached_oop() != NULL && cached_oop()->is_klass()), "sanity check");
0N/A#endif // ASSERT
0N/A return is_monomorphic;
0N/A}
0N/A
0N/A
0N/Abool CompiledIC::is_call_to_interpreted() const {
0N/A assert (CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), "");
0N/A // Call to interpreter if destination is either calling to a stub (if it
0N/A // is optimized), or calling to an I2C blob
0N/A bool is_call_to_interpreted = false;
0N/A if (!is_optimized()) {
0N/A // must use unsafe because the destination can be a zombie (and we're cleaning)
0N/A // and the print_compiled_ic code wants to know if site (in the non-zombie)
0N/A // is to the interpreter.
0N/A CodeBlob* cb = CodeCache::find_blob_unsafe(ic_destination());
0N/A is_call_to_interpreted = (cb != NULL && cb->is_adapter_blob());
0N/A assert(!is_call_to_interpreted || (cached_oop() != NULL && cached_oop()->is_compiledICHolder()), "sanity check");
0N/A } else {
0N/A // Check if we are calling into our own codeblob (i.e., to a stub)
0N/A CodeBlob* cb = CodeCache::find_blob(_ic_call->instruction_address());
0N/A address dest = ic_destination();
0N/A#ifdef ASSERT
0N/A {
0N/A CodeBlob* db = CodeCache::find_blob_unsafe(dest);
0N/A assert(!db->is_adapter_blob(), "must use stub!");
0N/A }
0N/A#endif /* ASSERT */
0N/A is_call_to_interpreted = cb->contains(dest);
0N/A }
0N/A return is_call_to_interpreted;
0N/A}
0N/A
0N/A
0N/Avoid CompiledIC::set_to_clean() {
0N/A assert(SafepointSynchronize::is_at_safepoint() || CompiledIC_lock->is_locked() , "MT-unsafe call");
0N/A if (TraceInlineCacheClearing || TraceICs) {
0N/A tty->print_cr("IC@" INTPTR_FORMAT ": set to clean", instruction_address());
0N/A print();
0N/A }
0N/A
0N/A address entry;
0N/A if (is_optimized()) {
0N/A entry = SharedRuntime::get_resolve_opt_virtual_call_stub();
0N/A } else {
0N/A entry = SharedRuntime::get_resolve_virtual_call_stub();
0N/A }
0N/A
0N/A // A zombie transition will always be safe, since the oop has already been set to NULL, so
0N/A // we only need to patch the destination
0N/A bool safe_transition = is_optimized() || SafepointSynchronize::is_at_safepoint();
0N/A
0N/A if (safe_transition) {
0N/A if (!is_optimized()) set_cached_oop(NULL);
0N/A // Kill any leftover stub we might have too
0N/A if (is_in_transition_state()) {
0N/A ICStub* old_stub = ICStub_from_destination_address(stub_address());
0N/A old_stub->clear();
0N/A }
0N/A set_ic_destination(entry);
0N/A } else {
0N/A // Unsafe transition - create stub.
0N/A InlineCacheBuffer::create_transition_stub(this, NULL, entry);
0N/A }
0N/A // We can't check this anymore. With lazy deopt we could have already
0N/A // cleaned this IC entry before we even return. This is possible if
0N/A // we ran out of space in the inline cache buffer trying to do the
0N/A // set_next and we safepointed to free up space. This is a benign
0N/A // race because the IC entry was complete when we safepointed so
0N/A // cleaning it immediately is harmless.
0N/A // assert(is_clean(), "sanity check");
0N/A}
0N/A
0N/A
0N/Abool CompiledIC::is_clean() const {
0N/A assert (CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), "");
0N/A bool is_clean = false;
0N/A address dest = ic_destination();
0N/A is_clean = dest == SharedRuntime::get_resolve_opt_virtual_call_stub() ||
0N/A dest == SharedRuntime::get_resolve_virtual_call_stub();
0N/A assert(!is_clean || is_optimized() || cached_oop() == NULL, "sanity check");
0N/A return is_clean;
0N/A}
0N/A
0N/A
0N/Avoid CompiledIC::set_to_monomorphic(const CompiledICInfo& info) {
0N/A assert (CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), "");
0N/A // Updating a cache to the wrong entry can cause bugs that are very hard
0N/A // to track down - if cache entry gets invalid - we just clean it. In
0N/A // this way it is always the same code path that is responsible for
0N/A // updating and resolving an inline cache
0N/A //
0N/A // The above is no longer true. SharedRuntime::fixup_callers_callsite will change optimized
0N/A // callsites. In addition ic_miss code will update a site to monomorphic if it determines
0N/A // that an monomorphic call to the interpreter can now be monomorphic to compiled code.
0N/A //
0N/A // In both of these cases the only thing being modifed is the jump/call target and these
0N/A // transitions are mt_safe
0N/A
0N/A Thread *thread = Thread::current();
0N/A if (info._to_interpreter) {
0N/A // Call to interpreter
0N/A if (info.is_optimized() && is_optimized()) {
0N/A assert(is_clean(), "unsafe IC path");
0N/A MutexLockerEx pl(Patching_lock, Mutex::_no_safepoint_check_flag);
0N/A // the call analysis (callee structure) specifies that the call is optimized
0N/A // (either because of CHA or the static target is final)
0N/A // At code generation time, this call has been emitted as static call
0N/A // Call via stub
0N/A assert(info.cached_oop().not_null() && info.cached_oop()->is_method(), "sanity check");
0N/A CompiledStaticCall* csc = compiledStaticCall_at(instruction_address());
0N/A methodHandle method (thread, (methodOop)info.cached_oop()());
0N/A csc->set_to_interpreted(method, info.entry());
0N/A if (TraceICs) {
0N/A ResourceMark rm(thread);
0N/A tty->print_cr ("IC@" INTPTR_FORMAT ": monomorphic to interpreter: %s",
0N/A instruction_address(),
0N/A method->print_value_string());
0N/A }
0N/A } else {
0N/A // Call via method-klass-holder
0N/A assert(info.cached_oop().not_null(), "must be set");
0N/A InlineCacheBuffer::create_transition_stub(this, info.cached_oop()(), info.entry());
0N/A
0N/A if (TraceICs) {
0N/A ResourceMark rm(thread);
0N/A tty->print_cr ("IC@" INTPTR_FORMAT ": monomorphic to interpreter via mkh", instruction_address());
0N/A }
0N/A }
0N/A } else {
0N/A // Call to compiled code
0N/A bool static_bound = info.is_optimized() || (info.cached_oop().is_null());
0N/A#ifdef ASSERT
0N/A CodeBlob* cb = CodeCache::find_blob_unsafe(info.entry());
0N/A assert (cb->is_nmethod(), "must be compiled!");
0N/A#endif /* ASSERT */
0N/A
0N/A // This is MT safe if we come from a clean-cache and go through a
0N/A // non-verified entry point
0N/A bool safe = SafepointSynchronize::is_at_safepoint() ||
0N/A (!is_in_transition_state() && (info.is_optimized() || static_bound || is_clean()));
0N/A
0N/A if (!safe) {
0N/A InlineCacheBuffer::create_transition_stub(this, info.cached_oop()(), info.entry());
0N/A } else {
0N/A set_ic_destination(info.entry());
0N/A if (!is_optimized()) set_cached_oop(info.cached_oop()());
0N/A }
0N/A
0N/A if (TraceICs) {
0N/A ResourceMark rm(thread);
0N/A assert(info.cached_oop() == NULL || info.cached_oop()()->is_klass(), "must be");
0N/A tty->print_cr ("IC@" INTPTR_FORMAT ": monomorphic to compiled (rcvr klass) %s: %s",
0N/A instruction_address(),
0N/A ((klassOop)info.cached_oop()())->print_value_string(),
0N/A (safe) ? "" : "via stub");
0N/A }
0N/A }
0N/A // We can't check this anymore. With lazy deopt we could have already
0N/A // cleaned this IC entry before we even return. This is possible if
0N/A // we ran out of space in the inline cache buffer trying to do the
0N/A // set_next and we safepointed to free up space. This is a benign
0N/A // race because the IC entry was complete when we safepointed so
0N/A // cleaning it immediately is harmless.
0N/A // assert(is_call_to_compiled() || is_call_to_interpreted(), "sanity check");
0N/A}
0N/A
0N/A
0N/A// is_optimized: Compiler has generated an optimized call (i.e., no inline
0N/A// cache) static_bound: The call can be static bound (i.e, no need to use
0N/A// inline cache)
0N/Avoid CompiledIC::compute_monomorphic_entry(methodHandle method,
0N/A KlassHandle receiver_klass,
0N/A bool is_optimized,
0N/A bool static_bound,
0N/A CompiledICInfo& info,
0N/A TRAPS) {
0N/A info._is_optimized = is_optimized;
0N/A
0N/A nmethod* method_code = method->code();
0N/A address entry = NULL;
0N/A if (method_code != NULL) {
0N/A // Call to compiled code
0N/A if (static_bound || is_optimized) {
0N/A entry = method_code->verified_entry_point();
0N/A } else {
0N/A entry = method_code->entry_point();
0N/A }
0N/A }
0N/A if (entry != NULL) {
0N/A // Call to compiled code
0N/A info._entry = entry;
0N/A if (static_bound || is_optimized) {
0N/A info._cached_oop = Handle(THREAD, (oop)NULL);
0N/A } else {
0N/A info._cached_oop = receiver_klass;
0N/A }
0N/A info._to_interpreter = false;
0N/A } else {
0N/A // Note: the following problem exists with Compiler1:
0N/A // - at compile time we may or may not know if the destination is final
0N/A // - if we know that the destination is final, we will emit an optimized
0N/A // virtual call (no inline cache), and need a methodOop to make a call
0N/A // to the interpreter
0N/A // - if we do not know if the destination is final, we emit a standard
0N/A // virtual call, and use CompiledICHolder to call interpreted code
0N/A // (no static call stub has been generated)
0N/A // However in that case we will now notice it is static_bound
0N/A // and convert the call into what looks to be an optimized
0N/A // virtual call. This causes problems in verifying the IC because
0N/A // it look vanilla but is optimized. Code in is_call_to_interpreted
0N/A // is aware of this and weakens its asserts.
0N/A
0N/A info._to_interpreter = true;
0N/A // static_bound should imply is_optimized -- otherwise we have a
0N/A // performance bug (statically-bindable method is called via
0N/A // dynamically-dispatched call note: the reverse implication isn't
0N/A // necessarily true -- the call may have been optimized based on compiler
0N/A // analysis (static_bound is only based on "final" etc.)
0N/A#ifdef COMPILER2
0N/A#ifdef TIERED
0N/A#if defined(ASSERT)
0N/A // can't check the assert because we don't have the CompiledIC with which to
0N/A // find the address if the call instruction.
0N/A //
0N/A // CodeBlob* cb = find_blob_unsafe(instruction_address());
0N/A // assert(cb->is_compiled_by_c1() || !static_bound || is_optimized, "static_bound should imply is_optimized");
0N/A#endif // ASSERT
0N/A#else
0N/A assert(!static_bound || is_optimized, "static_bound should imply is_optimized");
0N/A#endif // TIERED
0N/A#endif // COMPILER2
0N/A if (is_optimized) {
0N/A // Use stub entry
0N/A info._entry = method()->get_c2i_entry();
0N/A info._cached_oop = method;
0N/A } else {
0N/A // Use mkh entry
0N/A oop holder = oopFactory::new_compiledICHolder(method, receiver_klass, CHECK);
0N/A info._cached_oop = Handle(THREAD, holder);
0N/A info._entry = method()->get_c2i_unverified_entry();
0N/A }
0N/A }
0N/A}
0N/A
0N/A
1483N/Ainline static RelocIterator parse_ic(nmethod* nm, address ic_call, oop* &_oop_addr, bool *is_optimized) {
0N/A address first_oop = NULL;
0N/A // Mergers please note: Sun SC5.x CC insists on an lvalue for a reference parameter.
1483N/A nmethod* tmp_nm = nm;
1483N/A return virtual_call_Relocation::parse_ic(tmp_nm, ic_call, first_oop, _oop_addr, is_optimized);
0N/A}
0N/A
0N/ACompiledIC::CompiledIC(NativeCall* ic_call)
0N/A : _ic_call(ic_call),
0N/A _oops(parse_ic(NULL, ic_call->instruction_address(), _oop_addr, &_is_optimized))
0N/A{
0N/A}
0N/A
0N/A
0N/ACompiledIC::CompiledIC(Relocation* ic_reloc)
0N/A : _ic_call(nativeCall_at(ic_reloc->addr())),
0N/A _oops(parse_ic(ic_reloc->code(), ic_reloc->addr(), _oop_addr, &_is_optimized))
0N/A{
0N/A assert(ic_reloc->type() == relocInfo::virtual_call_type ||
0N/A ic_reloc->type() == relocInfo::opt_virtual_call_type, "wrong reloc. info");
0N/A}
0N/A
0N/A
0N/A// ----------------------------------------------------------------------------
0N/A
0N/Avoid CompiledStaticCall::set_to_clean() {
0N/A assert (CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), "mt unsafe call");
0N/A // Reset call site
0N/A MutexLockerEx pl(Patching_lock, Mutex::_no_safepoint_check_flag);
0N/A#ifdef ASSERT
0N/A CodeBlob* cb = CodeCache::find_blob_unsafe(this);
0N/A assert(cb != NULL && cb->is_nmethod(), "must be nmethod");
0N/A#endif
0N/A set_destination_mt_safe(SharedRuntime::get_resolve_static_call_stub());
0N/A
0N/A // Do not reset stub here: It is too expensive to call find_stub.
0N/A // Instead, rely on caller (nmethod::clear_inline_caches) to clear
0N/A // both the call and its stub.
0N/A}
0N/A
0N/A
0N/Abool CompiledStaticCall::is_clean() const {
0N/A return destination() == SharedRuntime::get_resolve_static_call_stub();
0N/A}
0N/A
0N/Abool CompiledStaticCall::is_call_to_compiled() const {
0N/A return CodeCache::contains(destination());
0N/A}
0N/A
0N/A
0N/Abool CompiledStaticCall::is_call_to_interpreted() const {
0N/A // It is a call to interpreted, if it calls to a stub. Hence, the destination
0N/A // must be in the stub part of the nmethod that contains the call
0N/A nmethod* nm = CodeCache::find_nmethod(instruction_address());
0N/A return nm->stub_contains(destination());
0N/A}
0N/A
0N/A
0N/Avoid CompiledStaticCall::set_to_interpreted(methodHandle callee, address entry) {
0N/A address stub=find_stub();
0N/A assert(stub!=NULL, "stub not found");
0N/A
0N/A if (TraceICs) {
0N/A ResourceMark rm;
0N/A tty->print_cr("CompiledStaticCall@" INTPTR_FORMAT ": set_to_interpreted %s",
0N/A instruction_address(),
0N/A callee->name_and_sig_as_C_string());
0N/A }
0N/A
0N/A NativeMovConstReg* method_holder = nativeMovConstReg_at(stub); // creation also verifies the object
0N/A NativeJump* jump = nativeJump_at(method_holder->next_instruction_address());
0N/A
0N/A assert(method_holder->data() == 0 || method_holder->data() == (intptr_t)callee(), "a) MT-unsafe modification of inline cache");
0N/A assert(jump->jump_destination() == (address)-1 || jump->jump_destination() == entry, "b) MT-unsafe modification of inline cache");
0N/A
0N/A // Update stub
0N/A method_holder->set_data((intptr_t)callee());
0N/A jump->set_jump_destination(entry);
0N/A
0N/A // Update jump to call
0N/A set_destination_mt_safe(stub);
0N/A}
0N/A
0N/A
0N/Avoid CompiledStaticCall::set(const StaticCallInfo& info) {
0N/A assert (CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), "mt unsafe call");
0N/A MutexLockerEx pl(Patching_lock, Mutex::_no_safepoint_check_flag);
0N/A // Updating a cache to the wrong entry can cause bugs that are very hard
0N/A // to track down - if cache entry gets invalid - we just clean it. In
0N/A // this way it is always the same code path that is responsible for
0N/A // updating and resolving an inline cache
0N/A assert(is_clean(), "do not update a call entry - use clean");
0N/A
0N/A if (info._to_interpreter) {
0N/A // Call to interpreted code
0N/A set_to_interpreted(info.callee(), info.entry());
0N/A } else {
0N/A if (TraceICs) {
0N/A ResourceMark rm;
0N/A tty->print_cr("CompiledStaticCall@" INTPTR_FORMAT ": set_to_compiled " INTPTR_FORMAT,
0N/A instruction_address(),
0N/A info.entry());
0N/A }
0N/A // Call to compiled code
0N/A assert (CodeCache::contains(info.entry()), "wrong entry point");
0N/A set_destination_mt_safe(info.entry());
0N/A }
0N/A}
0N/A
0N/A
0N/A// Compute settings for a CompiledStaticCall. Since we might have to set
0N/A// the stub when calling to the interpreter, we need to return arguments.
0N/Avoid CompiledStaticCall::compute_entry(methodHandle m, StaticCallInfo& info) {
0N/A nmethod* m_code = m->code();
0N/A info._callee = m;
0N/A if (m_code != NULL) {
0N/A info._to_interpreter = false;
0N/A info._entry = m_code->verified_entry_point();
0N/A } else {
0N/A // Callee is interpreted code. In any case entering the interpreter
0N/A // puts a converter-frame on the stack to save arguments.
0N/A info._to_interpreter = true;
0N/A info._entry = m()->get_c2i_entry();
0N/A }
0N/A}
0N/A
0N/A
0N/Avoid CompiledStaticCall::set_stub_to_clean(static_stub_Relocation* static_stub) {
0N/A assert (CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), "mt unsafe call");
0N/A // Reset stub
0N/A address stub = static_stub->addr();
0N/A assert(stub!=NULL, "stub not found");
0N/A NativeMovConstReg* method_holder = nativeMovConstReg_at(stub); // creation also verifies the object
0N/A NativeJump* jump = nativeJump_at(method_holder->next_instruction_address());
0N/A method_holder->set_data(0);
0N/A jump->set_jump_destination((address)-1);
0N/A}
0N/A
0N/A
0N/Aaddress CompiledStaticCall::find_stub() {
0N/A // Find reloc. information containing this call-site
0N/A RelocIterator iter((nmethod*)NULL, instruction_address());
0N/A while (iter.next()) {
0N/A if (iter.addr() == instruction_address()) {
0N/A switch(iter.type()) {
0N/A case relocInfo::static_call_type:
0N/A return iter.static_call_reloc()->static_stub();
0N/A // We check here for opt_virtual_call_type, since we reuse the code
0N/A // from the CompiledIC implementation
0N/A case relocInfo::opt_virtual_call_type:
0N/A return iter.opt_virtual_call_reloc()->static_stub();
0N/A case relocInfo::poll_type:
0N/A case relocInfo::poll_return_type: // A safepoint can't overlap a call.
0N/A default:
0N/A ShouldNotReachHere();
0N/A }
0N/A }
0N/A }
0N/A return NULL;
0N/A}
0N/A
0N/A
0N/A//-----------------------------------------------------------------------------
0N/A// Non-product mode code
0N/A#ifndef PRODUCT
0N/A
0N/Avoid CompiledIC::verify() {
0N/A // make sure code pattern is actually a call imm32 instruction
0N/A _ic_call->verify();
0N/A if (os::is_MP()) {
0N/A _ic_call->verify_alignment();
0N/A }
0N/A assert(is_clean() || is_call_to_compiled() || is_call_to_interpreted()
0N/A || is_optimized() || is_megamorphic(), "sanity check");
0N/A}
0N/A
0N/A
0N/Avoid CompiledIC::print() {
0N/A print_compiled_ic();
0N/A tty->cr();
0N/A}
0N/A
0N/A
0N/Avoid CompiledIC::print_compiled_ic() {
0N/A tty->print("Inline cache at " INTPTR_FORMAT ", calling %s " INTPTR_FORMAT,
0N/A instruction_address(), is_call_to_interpreted() ? "interpreted " : "", ic_destination());
0N/A}
0N/A
0N/A
0N/Avoid CompiledStaticCall::print() {
0N/A tty->print("static call at " INTPTR_FORMAT " -> ", instruction_address());
0N/A if (is_clean()) {
0N/A tty->print("clean");
0N/A } else if (is_call_to_compiled()) {
0N/A tty->print("compiled");
0N/A } else if (is_call_to_interpreted()) {
0N/A tty->print("interpreted");
0N/A }
0N/A tty->cr();
0N/A}
0N/A
0N/Avoid CompiledStaticCall::verify() {
0N/A // Verify call
0N/A NativeCall::verify();
0N/A if (os::is_MP()) {
0N/A verify_alignment();
0N/A }
0N/A
0N/A // Verify stub
0N/A address stub = find_stub();
0N/A assert(stub != NULL, "no stub found for static call");
0N/A NativeMovConstReg* method_holder = nativeMovConstReg_at(stub); // creation also verifies the object
0N/A NativeJump* jump = nativeJump_at(method_holder->next_instruction_address());
0N/A
0N/A // Verify state
0N/A assert(is_clean() || is_call_to_compiled() || is_call_to_interpreted(), "sanity check");
0N/A}
0N/A
0N/A#endif