1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/code/compiledIC.cpp Wed Apr 27 01:25:04 2016 +0800 1.3 @@ -0,0 +1,618 @@ 1.4 +/* 1.5 + * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +#include "precompiled.hpp" 1.29 +#include "classfile/systemDictionary.hpp" 1.30 +#include "code/codeCache.hpp" 1.31 +#include "code/compiledIC.hpp" 1.32 +#include "code/icBuffer.hpp" 1.33 +#include "code/nmethod.hpp" 1.34 +#include "code/vtableStubs.hpp" 1.35 +#include "interpreter/interpreter.hpp" 1.36 +#include "interpreter/linkResolver.hpp" 1.37 +#include "memory/metadataFactory.hpp" 1.38 +#include "memory/oopFactory.hpp" 1.39 +#include "oops/method.hpp" 1.40 +#include "oops/oop.inline.hpp" 1.41 +#include "oops/symbol.hpp" 1.42 +#include "runtime/icache.hpp" 1.43 +#include "runtime/sharedRuntime.hpp" 1.44 +#include "runtime/stubRoutines.hpp" 1.45 +#include "utilities/events.hpp" 1.46 + 1.47 + 1.48 +// Every time a compiled IC is changed or its type is being accessed, 1.49 +// either the CompiledIC_lock must be set or we must be at a safe point. 1.50 + 1.51 +//----------------------------------------------------------------------------- 1.52 +// Low-level access to an inline cache. Private, since they might not be 1.53 +// MT-safe to use. 1.54 + 1.55 +void* CompiledIC::cached_value() const { 1.56 + assert (CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), ""); 1.57 + assert (!is_optimized(), "an optimized virtual call does not have a cached metadata"); 1.58 + 1.59 + if (!is_in_transition_state()) { 1.60 + void* data = (void*)_value->data(); 1.61 + // If we let the metadata value here be initialized to zero... 1.62 + assert(data != NULL || Universe::non_oop_word() == NULL, 1.63 + "no raw nulls in CompiledIC metadatas, because of patching races"); 1.64 + return (data == (void*)Universe::non_oop_word()) ? NULL : data; 1.65 + } else { 1.66 + return InlineCacheBuffer::cached_value_for((CompiledIC *)this); 1.67 + } 1.68 +} 1.69 + 1.70 + 1.71 +void CompiledIC::internal_set_ic_destination(address entry_point, bool is_icstub, void* cache, bool is_icholder) { 1.72 + assert(entry_point != NULL, "must set legal entry point"); 1.73 + assert(CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), ""); 1.74 + assert (!is_optimized() || cache == NULL, "an optimized virtual call does not have a cached metadata"); 1.75 + assert (cache == NULL || cache != (Metadata*)badOopVal, "invalid metadata"); 1.76 + 1.77 + assert(!is_icholder || is_icholder_entry(entry_point), "must be"); 1.78 + 1.79 + // Don't use ic_destination for this test since that forwards 1.80 + // through ICBuffer instead of returning the actual current state of 1.81 + // the CompiledIC. 1.82 + if (is_icholder_entry(_ic_call->destination())) { 1.83 + // When patching for the ICStub case the cached value isn't 1.84 + // overwritten until the ICStub copied into the CompiledIC during 1.85 + // the next safepoint. Make sure that the CompiledICHolder* is 1.86 + // marked for release at this point since it won't be identifiable 1.87 + // once the entry point is overwritten. 1.88 + InlineCacheBuffer::queue_for_release((CompiledICHolder*)_value->data()); 1.89 + } 1.90 + 1.91 + if (TraceCompiledIC) { 1.92 + tty->print(" "); 1.93 + print_compiled_ic(); 1.94 + tty->print(" changing destination to " INTPTR_FORMAT, p2i(entry_point)); 1.95 + if (!is_optimized()) { 1.96 + tty->print(" changing cached %s to " INTPTR_FORMAT, is_icholder ? "icholder" : "metadata", p2i((address)cache)); 1.97 + } 1.98 + if (is_icstub) { 1.99 + tty->print(" (icstub)"); 1.100 + } 1.101 + tty->cr(); 1.102 + } 1.103 + 1.104 + { 1.105 + MutexLockerEx pl(Patching_lock, Mutex::_no_safepoint_check_flag); 1.106 +#ifdef ASSERT 1.107 + CodeBlob* cb = CodeCache::find_blob_unsafe(_ic_call); 1.108 + assert(cb != NULL && cb->is_nmethod(), "must be nmethod"); 1.109 +#endif 1.110 + _ic_call->set_destination_mt_safe(entry_point); 1.111 +} 1.112 + 1.113 + if (is_optimized() || is_icstub) { 1.114 + // Optimized call sites don't have a cache value and ICStub call 1.115 + // sites only change the entry point. Changing the value in that 1.116 + // case could lead to MT safety issues. 1.117 + assert(cache == NULL, "must be null"); 1.118 + return; 1.119 + } 1.120 + 1.121 + if (cache == NULL) cache = (void*)Universe::non_oop_word(); 1.122 + 1.123 + _value->set_data((intptr_t)cache); 1.124 +} 1.125 + 1.126 + 1.127 +void CompiledIC::set_ic_destination(ICStub* stub) { 1.128 + internal_set_ic_destination(stub->code_begin(), true, NULL, false); 1.129 +} 1.130 + 1.131 + 1.132 + 1.133 +address CompiledIC::ic_destination() const { 1.134 + assert (CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), ""); 1.135 + if (!is_in_transition_state()) { 1.136 + return _ic_call->destination(); 1.137 + } else { 1.138 + return InlineCacheBuffer::ic_destination_for((CompiledIC *)this); 1.139 + } 1.140 +} 1.141 + 1.142 + 1.143 +bool CompiledIC::is_in_transition_state() const { 1.144 + assert (CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), ""); 1.145 + return InlineCacheBuffer::contains(_ic_call->destination()); 1.146 +} 1.147 + 1.148 + 1.149 +bool CompiledIC::is_icholder_call() const { 1.150 + assert (CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), ""); 1.151 + return !_is_optimized && is_icholder_entry(ic_destination()); 1.152 +} 1.153 + 1.154 +// Returns native address of 'call' instruction in inline-cache. Used by 1.155 +// the InlineCacheBuffer when it needs to find the stub. 1.156 +address CompiledIC::stub_address() const { 1.157 + assert(is_in_transition_state(), "should only be called when we are in a transition state"); 1.158 + return _ic_call->destination(); 1.159 +} 1.160 + 1.161 + 1.162 +//----------------------------------------------------------------------------- 1.163 +// High-level access to an inline cache. Guaranteed to be MT-safe. 1.164 + 1.165 + 1.166 +bool CompiledIC::set_to_megamorphic(CallInfo* call_info, Bytecodes::Code bytecode, TRAPS) { 1.167 + assert(CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), ""); 1.168 + assert(!is_optimized(), "cannot set an optimized virtual call to megamorphic"); 1.169 + assert(is_call_to_compiled() || is_call_to_interpreted(), "going directly to megamorphic?"); 1.170 + 1.171 + address entry; 1.172 + if (call_info->call_kind() == CallInfo::itable_call) { 1.173 + assert(bytecode == Bytecodes::_invokeinterface, ""); 1.174 + int itable_index = call_info->itable_index(); 1.175 + entry = VtableStubs::find_itable_stub(itable_index); 1.176 + if (entry == false) { 1.177 + return false; 1.178 + } 1.179 +#ifdef ASSERT 1.180 + int index = call_info->resolved_method()->itable_index(); 1.181 + assert(index == itable_index, "CallInfo pre-computes this"); 1.182 +#endif //ASSERT 1.183 + InstanceKlass* k = call_info->resolved_method()->method_holder(); 1.184 + assert(k->verify_itable_index(itable_index), "sanity check"); 1.185 + InlineCacheBuffer::create_transition_stub(this, k, entry); 1.186 + } else { 1.187 + assert(call_info->call_kind() == CallInfo::vtable_call, "either itable or vtable"); 1.188 + // Can be different than selected_method->vtable_index(), due to package-private etc. 1.189 + int vtable_index = call_info->vtable_index(); 1.190 + assert(call_info->resolved_klass()->verify_vtable_index(vtable_index), "sanity check"); 1.191 + entry = VtableStubs::find_vtable_stub(vtable_index); 1.192 + if (entry == NULL) { 1.193 + return false; 1.194 + } 1.195 + InlineCacheBuffer::create_transition_stub(this, NULL, entry); 1.196 + } 1.197 + 1.198 + if (TraceICs) { 1.199 + ResourceMark rm; 1.200 + tty->print_cr ("IC@" INTPTR_FORMAT ": to megamorphic %s entry: " INTPTR_FORMAT, 1.201 + p2i(instruction_address()), call_info->selected_method()->print_value_string(), p2i(entry)); 1.202 + } 1.203 + 1.204 + // We can't check this anymore. With lazy deopt we could have already 1.205 + // cleaned this IC entry before we even return. This is possible if 1.206 + // we ran out of space in the inline cache buffer trying to do the 1.207 + // set_next and we safepointed to free up space. This is a benign 1.208 + // race because the IC entry was complete when we safepointed so 1.209 + // cleaning it immediately is harmless. 1.210 + // assert(is_megamorphic(), "sanity check"); 1.211 + return true; 1.212 +} 1.213 + 1.214 + 1.215 +// true if destination is megamorphic stub 1.216 +bool CompiledIC::is_megamorphic() const { 1.217 + assert(CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), ""); 1.218 + assert(!is_optimized(), "an optimized call cannot be megamorphic"); 1.219 + 1.220 + // Cannot rely on cached_value. It is either an interface or a method. 1.221 + return VtableStubs::is_entry_point(ic_destination()); 1.222 +} 1.223 + 1.224 +bool CompiledIC::is_call_to_compiled() const { 1.225 + assert (CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), ""); 1.226 + 1.227 + // Use unsafe, since an inline cache might point to a zombie method. However, the zombie 1.228 + // method is guaranteed to still exist, since we only remove methods after all inline caches 1.229 + // has been cleaned up 1.230 + CodeBlob* cb = CodeCache::find_blob_unsafe(ic_destination()); 1.231 + bool is_monomorphic = (cb != NULL && cb->is_nmethod()); 1.232 + // Check that the cached_value is a klass for non-optimized monomorphic calls 1.233 + // This assertion is invalid for compiler1: a call that does not look optimized (no static stub) can be used 1.234 + // for calling directly to vep without using the inline cache (i.e., cached_value == NULL) 1.235 +#ifdef ASSERT 1.236 + CodeBlob* caller = CodeCache::find_blob_unsafe(instruction_address()); 1.237 + bool is_c1_method = caller->is_compiled_by_c1(); 1.238 + assert( is_c1_method || 1.239 + !is_monomorphic || 1.240 + is_optimized() || 1.241 + (cached_metadata() != NULL && cached_metadata()->is_klass()), "sanity check"); 1.242 +#endif // ASSERT 1.243 + return is_monomorphic; 1.244 +} 1.245 + 1.246 + 1.247 +bool CompiledIC::is_call_to_interpreted() const { 1.248 + assert (CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), ""); 1.249 + // Call to interpreter if destination is either calling to a stub (if it 1.250 + // is optimized), or calling to an I2C blob 1.251 + bool is_call_to_interpreted = false; 1.252 + if (!is_optimized()) { 1.253 + // must use unsafe because the destination can be a zombie (and we're cleaning) 1.254 + // and the print_compiled_ic code wants to know if site (in the non-zombie) 1.255 + // is to the interpreter. 1.256 + CodeBlob* cb = CodeCache::find_blob_unsafe(ic_destination()); 1.257 + is_call_to_interpreted = (cb != NULL && cb->is_adapter_blob()); 1.258 + assert(!is_call_to_interpreted || (is_icholder_call() && cached_icholder() != NULL), "sanity check"); 1.259 + } else { 1.260 + // Check if we are calling into our own codeblob (i.e., to a stub) 1.261 + CodeBlob* cb = CodeCache::find_blob(_ic_call->instruction_address()); 1.262 + address dest = ic_destination(); 1.263 +#ifdef ASSERT 1.264 + { 1.265 + CodeBlob* db = CodeCache::find_blob_unsafe(dest); 1.266 + assert(!db->is_adapter_blob(), "must use stub!"); 1.267 + } 1.268 +#endif /* ASSERT */ 1.269 + is_call_to_interpreted = cb->contains(dest); 1.270 + } 1.271 + return is_call_to_interpreted; 1.272 +} 1.273 + 1.274 + 1.275 +void CompiledIC::set_to_clean() { 1.276 + assert(SafepointSynchronize::is_at_safepoint() || CompiledIC_lock->is_locked() , "MT-unsafe call"); 1.277 + if (TraceInlineCacheClearing || TraceICs) { 1.278 + tty->print_cr("IC@" INTPTR_FORMAT ": set to clean", p2i(instruction_address())); 1.279 + print(); 1.280 + } 1.281 + 1.282 + address entry; 1.283 + if (is_optimized()) { 1.284 + entry = SharedRuntime::get_resolve_opt_virtual_call_stub(); 1.285 + } else { 1.286 + entry = SharedRuntime::get_resolve_virtual_call_stub(); 1.287 + } 1.288 + 1.289 + // A zombie transition will always be safe, since the metadata has already been set to NULL, so 1.290 + // we only need to patch the destination 1.291 + bool safe_transition = is_optimized() || SafepointSynchronize::is_at_safepoint(); 1.292 + 1.293 + if (safe_transition) { 1.294 + // Kill any leftover stub we might have too 1.295 + if (is_in_transition_state()) { 1.296 + ICStub* old_stub = ICStub_from_destination_address(stub_address()); 1.297 + old_stub->clear(); 1.298 + } 1.299 + if (is_optimized()) { 1.300 + set_ic_destination(entry); 1.301 + } else { 1.302 + set_ic_destination_and_value(entry, (void*)NULL); 1.303 + } 1.304 + } else { 1.305 + // Unsafe transition - create stub. 1.306 + InlineCacheBuffer::create_transition_stub(this, NULL, entry); 1.307 + } 1.308 + // We can't check this anymore. With lazy deopt we could have already 1.309 + // cleaned this IC entry before we even return. This is possible if 1.310 + // we ran out of space in the inline cache buffer trying to do the 1.311 + // set_next and we safepointed to free up space. This is a benign 1.312 + // race because the IC entry was complete when we safepointed so 1.313 + // cleaning it immediately is harmless. 1.314 + // assert(is_clean(), "sanity check"); 1.315 +} 1.316 + 1.317 + 1.318 +bool CompiledIC::is_clean() const { 1.319 + assert (CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), ""); 1.320 + bool is_clean = false; 1.321 + address dest = ic_destination(); 1.322 + is_clean = dest == SharedRuntime::get_resolve_opt_virtual_call_stub() || 1.323 + dest == SharedRuntime::get_resolve_virtual_call_stub(); 1.324 + assert(!is_clean || is_optimized() || cached_value() == NULL, "sanity check"); 1.325 + return is_clean; 1.326 +} 1.327 + 1.328 + 1.329 +void CompiledIC::set_to_monomorphic(CompiledICInfo& info) { 1.330 + assert (CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), ""); 1.331 + // Updating a cache to the wrong entry can cause bugs that are very hard 1.332 + // to track down - if cache entry gets invalid - we just clean it. In 1.333 + // this way it is always the same code path that is responsible for 1.334 + // updating and resolving an inline cache 1.335 + // 1.336 + // The above is no longer true. SharedRuntime::fixup_callers_callsite will change optimized 1.337 + // callsites. In addition ic_miss code will update a site to monomorphic if it determines 1.338 + // that an monomorphic call to the interpreter can now be monomorphic to compiled code. 1.339 + // 1.340 + // In both of these cases the only thing being modifed is the jump/call target and these 1.341 + // transitions are mt_safe 1.342 + 1.343 + Thread *thread = Thread::current(); 1.344 + if (info.to_interpreter()) { 1.345 + // Call to interpreter 1.346 + if (info.is_optimized() && is_optimized()) { 1.347 + assert(is_clean(), "unsafe IC path"); 1.348 + MutexLockerEx pl(Patching_lock, Mutex::_no_safepoint_check_flag); 1.349 + // the call analysis (callee structure) specifies that the call is optimized 1.350 + // (either because of CHA or the static target is final) 1.351 + // At code generation time, this call has been emitted as static call 1.352 + // Call via stub 1.353 + assert(info.cached_metadata() != NULL && info.cached_metadata()->is_method(), "sanity check"); 1.354 + CompiledStaticCall* csc = compiledStaticCall_at(instruction_address()); 1.355 + methodHandle method (thread, (Method*)info.cached_metadata()); 1.356 + csc->set_to_interpreted(method, info.entry()); 1.357 + if (TraceICs) { 1.358 + ResourceMark rm(thread); 1.359 + tty->print_cr ("IC@" INTPTR_FORMAT ": monomorphic to interpreter: %s", 1.360 + p2i(instruction_address()), 1.361 + method->print_value_string()); 1.362 + } 1.363 + } else { 1.364 + // Call via method-klass-holder 1.365 + InlineCacheBuffer::create_transition_stub(this, info.claim_cached_icholder(), info.entry()); 1.366 + if (TraceICs) { 1.367 + ResourceMark rm(thread); 1.368 + tty->print_cr ("IC@" INTPTR_FORMAT ": monomorphic to interpreter via icholder ", p2i(instruction_address())); 1.369 + } 1.370 + } 1.371 + } else { 1.372 + // Call to compiled code 1.373 + bool static_bound = info.is_optimized() || (info.cached_metadata() == NULL); 1.374 +#ifdef ASSERT 1.375 + CodeBlob* cb = CodeCache::find_blob_unsafe(info.entry()); 1.376 + assert (cb->is_nmethod(), "must be compiled!"); 1.377 +#endif /* ASSERT */ 1.378 + 1.379 + // This is MT safe if we come from a clean-cache and go through a 1.380 + // non-verified entry point 1.381 + bool safe = SafepointSynchronize::is_at_safepoint() || 1.382 + (!is_in_transition_state() && (info.is_optimized() || static_bound || is_clean())); 1.383 + 1.384 + if (!safe) { 1.385 + InlineCacheBuffer::create_transition_stub(this, info.cached_metadata(), info.entry()); 1.386 + } else { 1.387 + if (is_optimized()) { 1.388 + set_ic_destination(info.entry()); 1.389 + } else { 1.390 + set_ic_destination_and_value(info.entry(), info.cached_metadata()); 1.391 + } 1.392 + } 1.393 + 1.394 + if (TraceICs) { 1.395 + ResourceMark rm(thread); 1.396 + assert(info.cached_metadata() == NULL || info.cached_metadata()->is_klass(), "must be"); 1.397 + tty->print_cr ("IC@" INTPTR_FORMAT ": monomorphic to compiled (rcvr klass) %s: %s", 1.398 + p2i(instruction_address()), 1.399 + ((Klass*)info.cached_metadata())->print_value_string(), 1.400 + (safe) ? "" : "via stub"); 1.401 + } 1.402 + } 1.403 + // We can't check this anymore. With lazy deopt we could have already 1.404 + // cleaned this IC entry before we even return. This is possible if 1.405 + // we ran out of space in the inline cache buffer trying to do the 1.406 + // set_next and we safepointed to free up space. This is a benign 1.407 + // race because the IC entry was complete when we safepointed so 1.408 + // cleaning it immediately is harmless. 1.409 + // assert(is_call_to_compiled() || is_call_to_interpreted(), "sanity check"); 1.410 +} 1.411 + 1.412 + 1.413 +// is_optimized: Compiler has generated an optimized call (i.e., no inline 1.414 +// cache) static_bound: The call can be static bound (i.e, no need to use 1.415 +// inline cache) 1.416 +void CompiledIC::compute_monomorphic_entry(methodHandle method, 1.417 + KlassHandle receiver_klass, 1.418 + bool is_optimized, 1.419 + bool static_bound, 1.420 + CompiledICInfo& info, 1.421 + TRAPS) { 1.422 + nmethod* method_code = method->code(); 1.423 + address entry = NULL; 1.424 + if (method_code != NULL && method_code->is_in_use()) { 1.425 + // Call to compiled code 1.426 + if (static_bound || is_optimized) { 1.427 + entry = method_code->verified_entry_point(); 1.428 + } else { 1.429 + entry = method_code->entry_point(); 1.430 + } 1.431 + } 1.432 + if (entry != NULL) { 1.433 + // Call to compiled code 1.434 + info.set_compiled_entry(entry, (static_bound || is_optimized) ? NULL : receiver_klass(), is_optimized); 1.435 + } else { 1.436 + // Note: the following problem exists with Compiler1: 1.437 + // - at compile time we may or may not know if the destination is final 1.438 + // - if we know that the destination is final, we will emit an optimized 1.439 + // virtual call (no inline cache), and need a Method* to make a call 1.440 + // to the interpreter 1.441 + // - if we do not know if the destination is final, we emit a standard 1.442 + // virtual call, and use CompiledICHolder to call interpreted code 1.443 + // (no static call stub has been generated) 1.444 + // However in that case we will now notice it is static_bound 1.445 + // and convert the call into what looks to be an optimized 1.446 + // virtual call. This causes problems in verifying the IC because 1.447 + // it look vanilla but is optimized. Code in is_call_to_interpreted 1.448 + // is aware of this and weakens its asserts. 1.449 + 1.450 + // static_bound should imply is_optimized -- otherwise we have a 1.451 + // performance bug (statically-bindable method is called via 1.452 + // dynamically-dispatched call note: the reverse implication isn't 1.453 + // necessarily true -- the call may have been optimized based on compiler 1.454 + // analysis (static_bound is only based on "final" etc.) 1.455 +#ifdef COMPILER2 1.456 +#ifdef TIERED 1.457 +#if defined(ASSERT) 1.458 + // can't check the assert because we don't have the CompiledIC with which to 1.459 + // find the address if the call instruction. 1.460 + // 1.461 + // CodeBlob* cb = find_blob_unsafe(instruction_address()); 1.462 + // assert(cb->is_compiled_by_c1() || !static_bound || is_optimized, "static_bound should imply is_optimized"); 1.463 +#endif // ASSERT 1.464 +#else 1.465 + assert(!static_bound || is_optimized, "static_bound should imply is_optimized"); 1.466 +#endif // TIERED 1.467 +#endif // COMPILER2 1.468 + if (is_optimized) { 1.469 + // Use stub entry 1.470 + info.set_interpreter_entry(method()->get_c2i_entry(), method()); 1.471 + } else { 1.472 + // Use icholder entry 1.473 + CompiledICHolder* holder = new CompiledICHolder(method(), receiver_klass()); 1.474 + info.set_icholder_entry(method()->get_c2i_unverified_entry(), holder); 1.475 + } 1.476 + } 1.477 + assert(info.is_optimized() == is_optimized, "must agree"); 1.478 +} 1.479 + 1.480 + 1.481 +bool CompiledIC::is_icholder_entry(address entry) { 1.482 + CodeBlob* cb = CodeCache::find_blob_unsafe(entry); 1.483 + return (cb != NULL && cb->is_adapter_blob()); 1.484 +} 1.485 + 1.486 +// ---------------------------------------------------------------------------- 1.487 + 1.488 +void CompiledStaticCall::set_to_clean() { 1.489 + assert (CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), "mt unsafe call"); 1.490 + // Reset call site 1.491 + MutexLockerEx pl(Patching_lock, Mutex::_no_safepoint_check_flag); 1.492 +#ifdef ASSERT 1.493 + CodeBlob* cb = CodeCache::find_blob_unsafe(this); 1.494 + assert(cb != NULL && cb->is_nmethod(), "must be nmethod"); 1.495 +#endif 1.496 + set_destination_mt_safe(SharedRuntime::get_resolve_static_call_stub()); 1.497 + 1.498 + // Do not reset stub here: It is too expensive to call find_stub. 1.499 + // Instead, rely on caller (nmethod::clear_inline_caches) to clear 1.500 + // both the call and its stub. 1.501 +} 1.502 + 1.503 + 1.504 +bool CompiledStaticCall::is_clean() const { 1.505 + return destination() == SharedRuntime::get_resolve_static_call_stub(); 1.506 +} 1.507 + 1.508 +bool CompiledStaticCall::is_call_to_compiled() const { 1.509 + return CodeCache::contains(destination()); 1.510 +} 1.511 + 1.512 + 1.513 +bool CompiledStaticCall::is_call_to_interpreted() const { 1.514 + // It is a call to interpreted, if it calls to a stub. Hence, the destination 1.515 + // must be in the stub part of the nmethod that contains the call 1.516 + nmethod* nm = CodeCache::find_nmethod(instruction_address()); 1.517 + return nm->stub_contains(destination()); 1.518 +} 1.519 + 1.520 +void CompiledStaticCall::set(const StaticCallInfo& info) { 1.521 + assert (CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), "mt unsafe call"); 1.522 + MutexLockerEx pl(Patching_lock, Mutex::_no_safepoint_check_flag); 1.523 + // Updating a cache to the wrong entry can cause bugs that are very hard 1.524 + // to track down - if cache entry gets invalid - we just clean it. In 1.525 + // this way it is always the same code path that is responsible for 1.526 + // updating and resolving an inline cache 1.527 + assert(is_clean(), "do not update a call entry - use clean"); 1.528 + 1.529 + if (info._to_interpreter) { 1.530 + // Call to interpreted code 1.531 + set_to_interpreted(info.callee(), info.entry()); 1.532 + } else { 1.533 + if (TraceICs) { 1.534 + ResourceMark rm; 1.535 + tty->print_cr("CompiledStaticCall@" INTPTR_FORMAT ": set_to_compiled " INTPTR_FORMAT, 1.536 + p2i(instruction_address()), 1.537 + p2i(info.entry())); 1.538 + } 1.539 + // Call to compiled code 1.540 + assert (CodeCache::contains(info.entry()), "wrong entry point"); 1.541 + set_destination_mt_safe(info.entry()); 1.542 + } 1.543 +} 1.544 + 1.545 + 1.546 +// Compute settings for a CompiledStaticCall. Since we might have to set 1.547 +// the stub when calling to the interpreter, we need to return arguments. 1.548 +void CompiledStaticCall::compute_entry(methodHandle m, StaticCallInfo& info) { 1.549 + nmethod* m_code = m->code(); 1.550 + info._callee = m; 1.551 + if (m_code != NULL && m_code->is_in_use()) { 1.552 + info._to_interpreter = false; 1.553 + info._entry = m_code->verified_entry_point(); 1.554 + } else { 1.555 + // Callee is interpreted code. In any case entering the interpreter 1.556 + // puts a converter-frame on the stack to save arguments. 1.557 + info._to_interpreter = true; 1.558 + info._entry = m()->get_c2i_entry(); 1.559 + } 1.560 +} 1.561 + 1.562 +address CompiledStaticCall::find_stub() { 1.563 + // Find reloc. information containing this call-site 1.564 + RelocIterator iter((nmethod*)NULL, instruction_address()); 1.565 + while (iter.next()) { 1.566 + if (iter.addr() == instruction_address()) { 1.567 + switch(iter.type()) { 1.568 + case relocInfo::static_call_type: 1.569 + return iter.static_call_reloc()->static_stub(); 1.570 + // We check here for opt_virtual_call_type, since we reuse the code 1.571 + // from the CompiledIC implementation 1.572 + case relocInfo::opt_virtual_call_type: 1.573 + return iter.opt_virtual_call_reloc()->static_stub(); 1.574 + case relocInfo::poll_type: 1.575 + case relocInfo::poll_return_type: // A safepoint can't overlap a call. 1.576 + default: 1.577 + ShouldNotReachHere(); 1.578 + } 1.579 + } 1.580 + } 1.581 + return NULL; 1.582 +} 1.583 + 1.584 + 1.585 +//----------------------------------------------------------------------------- 1.586 +// Non-product mode code 1.587 +#ifndef PRODUCT 1.588 + 1.589 +void CompiledIC::verify() { 1.590 + // make sure code pattern is actually a call imm32 instruction 1.591 + _ic_call->verify(); 1.592 + if (os::is_MP()) { 1.593 + _ic_call->verify_alignment(); 1.594 + } 1.595 + assert(is_clean() || is_call_to_compiled() || is_call_to_interpreted() 1.596 + || is_optimized() || is_megamorphic(), "sanity check"); 1.597 +} 1.598 + 1.599 +void CompiledIC::print() { 1.600 + print_compiled_ic(); 1.601 + tty->cr(); 1.602 +} 1.603 + 1.604 +void CompiledIC::print_compiled_ic() { 1.605 + tty->print("Inline cache at " INTPTR_FORMAT ", calling %s " INTPTR_FORMAT " cached_value " INTPTR_FORMAT, 1.606 + p2i(instruction_address()), is_call_to_interpreted() ? "interpreted " : "", p2i(ic_destination()), p2i(is_optimized() ? NULL : cached_value())); 1.607 +} 1.608 + 1.609 +void CompiledStaticCall::print() { 1.610 + tty->print("static call at " INTPTR_FORMAT " -> ", p2i(instruction_address())); 1.611 + if (is_clean()) { 1.612 + tty->print("clean"); 1.613 + } else if (is_call_to_compiled()) { 1.614 + tty->print("compiled"); 1.615 + } else if (is_call_to_interpreted()) { 1.616 + tty->print("interpreted"); 1.617 + } 1.618 + tty->cr(); 1.619 +} 1.620 + 1.621 +#endif // !PRODUCT