annotate src/share/vm/code/compiledIC.cpp @ 1879:f95d63e2154a

6989984: Use standard include model for Hospot Summary: Replaced MakeDeps and the includeDB files with more standardized solutions. Reviewed-by: coleenp, kvn, kamg
author stefank
date Tue, 23 Nov 2010 13:22:55 -0800
parents e9ff18c4ace7
children 3582bf76420e
rev   line source
duke@0 1 /*
jrose@1499 2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
duke@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@0 4 *
duke@0 5 * This code is free software; you can redistribute it and/or modify it
duke@0 6 * under the terms of the GNU General Public License version 2 only, as
duke@0 7 * published by the Free Software Foundation.
duke@0 8 *
duke@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@0 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@0 13 * accompanied this code).
duke@0 14 *
duke@0 15 * You should have received a copy of the GNU General Public License version
duke@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@0 18 *
trims@1472 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1472 20 * or visit www.oracle.com if you need additional information or have any
trims@1472 21 * questions.
duke@0 22 *
duke@0 23 */
duke@0 24
stefank@1879 25 #include "precompiled.hpp"
stefank@1879 26 #include "classfile/systemDictionary.hpp"
stefank@1879 27 #include "code/codeCache.hpp"
stefank@1879 28 #include "code/compiledIC.hpp"
stefank@1879 29 #include "code/icBuffer.hpp"
stefank@1879 30 #include "code/nmethod.hpp"
stefank@1879 31 #include "code/vtableStubs.hpp"
stefank@1879 32 #include "interpreter/interpreter.hpp"
stefank@1879 33 #include "interpreter/linkResolver.hpp"
stefank@1879 34 #include "memory/oopFactory.hpp"
stefank@1879 35 #include "oops/methodOop.hpp"
stefank@1879 36 #include "oops/oop.inline.hpp"
stefank@1879 37 #include "oops/symbolOop.hpp"
stefank@1879 38 #include "runtime/icache.hpp"
stefank@1879 39 #include "runtime/sharedRuntime.hpp"
stefank@1879 40 #include "runtime/stubRoutines.hpp"
stefank@1879 41 #include "utilities/events.hpp"
duke@0 42
duke@0 43
duke@0 44 // Every time a compiled IC is changed or its type is being accessed,
duke@0 45 // either the CompiledIC_lock must be set or we must be at a safe point.
duke@0 46
duke@0 47 //-----------------------------------------------------------------------------
duke@0 48 // Low-level access to an inline cache. Private, since they might not be
duke@0 49 // MT-safe to use.
duke@0 50
duke@0 51 void CompiledIC::set_cached_oop(oop cache) {
duke@0 52 assert (CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), "");
duke@0 53 assert (!is_optimized(), "an optimized virtual call does not have a cached oop");
duke@0 54 assert (cache == NULL || cache != badOop, "invalid oop");
duke@0 55
duke@0 56 if (TraceCompiledIC) {
duke@0 57 tty->print(" ");
duke@0 58 print_compiled_ic();
duke@0 59 tty->print_cr(" changing oop to " INTPTR_FORMAT, (address)cache);
duke@0 60 }
duke@0 61
duke@0 62 if (cache == NULL) cache = (oop)Universe::non_oop_word();
duke@0 63
duke@0 64 *_oop_addr = cache;
duke@0 65 // fix up the relocations
duke@0 66 RelocIterator iter = _oops;
duke@0 67 while (iter.next()) {
duke@0 68 if (iter.type() == relocInfo::oop_type) {
duke@0 69 oop_Relocation* r = iter.oop_reloc();
duke@0 70 if (r->oop_addr() == _oop_addr)
duke@0 71 r->fix_oop_relocation();
duke@0 72 }
duke@0 73 }
duke@0 74 return;
duke@0 75 }
duke@0 76
duke@0 77
duke@0 78 oop CompiledIC::cached_oop() const {
duke@0 79 assert (CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), "");
duke@0 80 assert (!is_optimized(), "an optimized virtual call does not have a cached oop");
duke@0 81
duke@0 82 if (!is_in_transition_state()) {
duke@0 83 oop data = *_oop_addr;
duke@0 84 // If we let the oop value here be initialized to zero...
duke@0 85 assert(data != NULL || Universe::non_oop_word() == NULL,
duke@0 86 "no raw nulls in CompiledIC oops, because of patching races");
duke@0 87 return (data == (oop)Universe::non_oop_word()) ? (oop)NULL : data;
duke@0 88 } else {
duke@0 89 return InlineCacheBuffer::cached_oop_for((CompiledIC *)this);
duke@0 90 }
duke@0 91 }
duke@0 92
duke@0 93
duke@0 94 void CompiledIC::set_ic_destination(address entry_point) {
duke@0 95 assert(entry_point != NULL, "must set legal entry point");
duke@0 96 assert(CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), "");
duke@0 97 if (TraceCompiledIC) {
duke@0 98 tty->print(" ");
duke@0 99 print_compiled_ic();
duke@0 100 tty->print_cr(" changing destination to " INTPTR_FORMAT, entry_point);
duke@0 101 }
duke@0 102 MutexLockerEx pl(Patching_lock, Mutex::_no_safepoint_check_flag);
duke@0 103 #ifdef ASSERT
duke@0 104 CodeBlob* cb = CodeCache::find_blob_unsafe(_ic_call);
duke@0 105 assert(cb != NULL && cb->is_nmethod(), "must be nmethod");
duke@0 106 #endif
duke@0 107 _ic_call->set_destination_mt_safe(entry_point);
duke@0 108 }
duke@0 109
duke@0 110
duke@0 111 address CompiledIC::ic_destination() const {
duke@0 112 assert (CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), "");
duke@0 113 if (!is_in_transition_state()) {
duke@0 114 return _ic_call->destination();
duke@0 115 } else {
duke@0 116 return InlineCacheBuffer::ic_destination_for((CompiledIC *)this);
duke@0 117 }
duke@0 118 }
duke@0 119
duke@0 120
duke@0 121 bool CompiledIC::is_in_transition_state() const {
duke@0 122 assert (CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), "");
duke@0 123 return InlineCacheBuffer::contains(_ic_call->destination());
duke@0 124 }
duke@0 125
duke@0 126
duke@0 127 // Returns native address of 'call' instruction in inline-cache. Used by
duke@0 128 // the InlineCacheBuffer when it needs to find the stub.
duke@0 129 address CompiledIC::stub_address() const {
duke@0 130 assert(is_in_transition_state(), "should only be called when we are in a transition state");
duke@0 131 return _ic_call->destination();
duke@0 132 }
duke@0 133
duke@0 134
duke@0 135 //-----------------------------------------------------------------------------
duke@0 136 // High-level access to an inline cache. Guaranteed to be MT-safe.
duke@0 137
duke@0 138
duke@0 139 void CompiledIC::set_to_megamorphic(CallInfo* call_info, Bytecodes::Code bytecode, TRAPS) {
duke@0 140 methodHandle method = call_info->selected_method();
duke@0 141 bool is_invoke_interface = (bytecode == Bytecodes::_invokeinterface && !call_info->has_vtable_index());
duke@0 142 assert(CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), "");
duke@0 143 assert(method->is_oop(), "cannot be NULL and must be oop");
duke@0 144 assert(!is_optimized(), "cannot set an optimized virtual call to megamorphic");
duke@0 145 assert(is_call_to_compiled() || is_call_to_interpreted(), "going directly to megamorphic?");
duke@0 146
duke@0 147 address entry;
duke@0 148 if (is_invoke_interface) {
duke@0 149 int index = klassItable::compute_itable_index(call_info->resolved_method()());
duke@0 150 entry = VtableStubs::create_stub(false, index, method());
duke@0 151 assert(entry != NULL, "entry not computed");
duke@0 152 klassOop k = call_info->resolved_method()->method_holder();
duke@0 153 assert(Klass::cast(k)->is_interface(), "sanity check");
duke@0 154 InlineCacheBuffer::create_transition_stub(this, k, entry);
duke@0 155 } else {
duke@0 156 // Can be different than method->vtable_index(), due to package-private etc.
duke@0 157 int vtable_index = call_info->vtable_index();
duke@0 158 entry = VtableStubs::create_stub(true, vtable_index, method());
duke@0 159 InlineCacheBuffer::create_transition_stub(this, method(), entry);
duke@0 160 }
duke@0 161
duke@0 162 if (TraceICs) {
duke@0 163 ResourceMark rm;
duke@0 164 tty->print_cr ("IC@" INTPTR_FORMAT ": to megamorphic %s entry: " INTPTR_FORMAT,
duke@0 165 instruction_address(), method->print_value_string(), entry);
duke@0 166 }
duke@0 167
duke@0 168 Events::log("compiledIC " INTPTR_FORMAT " --> megamorphic " INTPTR_FORMAT, this, (address)method());
duke@0 169 // We can't check this anymore. With lazy deopt we could have already
duke@0 170 // cleaned this IC entry before we even return. This is possible if
duke@0 171 // we ran out of space in the inline cache buffer trying to do the
duke@0 172 // set_next and we safepointed to free up space. This is a benign
duke@0 173 // race because the IC entry was complete when we safepointed so
duke@0 174 // cleaning it immediately is harmless.
duke@0 175 // assert(is_megamorphic(), "sanity check");
duke@0 176 }
duke@0 177
duke@0 178
duke@0 179 // true if destination is megamorphic stub
duke@0 180 bool CompiledIC::is_megamorphic() const {
duke@0 181 assert(CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), "");
duke@0 182 assert(!is_optimized(), "an optimized call cannot be megamorphic");
duke@0 183
duke@0 184 // Cannot rely on cached_oop. It is either an interface or a method.
duke@0 185 return VtableStubs::is_entry_point(ic_destination());
duke@0 186 }
duke@0 187
duke@0 188 bool CompiledIC::is_call_to_compiled() const {
duke@0 189 assert (CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), "");
duke@0 190
duke@0 191 // Use unsafe, since an inline cache might point to a zombie method. However, the zombie
duke@0 192 // method is guaranteed to still exist, since we only remove methods after all inline caches
duke@0 193 // has been cleaned up
duke@0 194 CodeBlob* cb = CodeCache::find_blob_unsafe(ic_destination());
duke@0 195 bool is_monomorphic = (cb != NULL && cb->is_nmethod());
duke@0 196 // Check that the cached_oop is a klass for non-optimized monomorphic calls
duke@0 197 // This assertion is invalid for compiler1: a call that does not look optimized (no static stub) can be used
duke@0 198 // for calling directly to vep without using the inline cache (i.e., cached_oop == NULL)
duke@0 199 #ifdef ASSERT
duke@0 200 #ifdef TIERED
duke@0 201 CodeBlob* caller = CodeCache::find_blob_unsafe(instruction_address());
duke@0 202 bool is_c1_method = caller->is_compiled_by_c1();
duke@0 203 #else
duke@0 204 #ifdef COMPILER1
duke@0 205 bool is_c1_method = true;
duke@0 206 #else
duke@0 207 bool is_c1_method = false;
duke@0 208 #endif // COMPILER1
duke@0 209 #endif // TIERED
duke@0 210 assert( is_c1_method ||
duke@0 211 !is_monomorphic ||
duke@0 212 is_optimized() ||
duke@0 213 (cached_oop() != NULL && cached_oop()->is_klass()), "sanity check");
duke@0 214 #endif // ASSERT
duke@0 215 return is_monomorphic;
duke@0 216 }
duke@0 217
duke@0 218
duke@0 219 bool CompiledIC::is_call_to_interpreted() const {
duke@0 220 assert (CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), "");
duke@0 221 // Call to interpreter if destination is either calling to a stub (if it
duke@0 222 // is optimized), or calling to an I2C blob
duke@0 223 bool is_call_to_interpreted = false;
duke@0 224 if (!is_optimized()) {
duke@0 225 // must use unsafe because the destination can be a zombie (and we're cleaning)
duke@0 226 // and the print_compiled_ic code wants to know if site (in the non-zombie)
duke@0 227 // is to the interpreter.
duke@0 228 CodeBlob* cb = CodeCache::find_blob_unsafe(ic_destination());
duke@0 229 is_call_to_interpreted = (cb != NULL && cb->is_adapter_blob());
duke@0 230 assert(!is_call_to_interpreted || (cached_oop() != NULL && cached_oop()->is_compiledICHolder()), "sanity check");
duke@0 231 } else {
duke@0 232 // Check if we are calling into our own codeblob (i.e., to a stub)
duke@0 233 CodeBlob* cb = CodeCache::find_blob(_ic_call->instruction_address());
duke@0 234 address dest = ic_destination();
duke@0 235 #ifdef ASSERT
duke@0 236 {
duke@0 237 CodeBlob* db = CodeCache::find_blob_unsafe(dest);
duke@0 238 assert(!db->is_adapter_blob(), "must use stub!");
duke@0 239 }
duke@0 240 #endif /* ASSERT */
duke@0 241 is_call_to_interpreted = cb->contains(dest);
duke@0 242 }
duke@0 243 return is_call_to_interpreted;
duke@0 244 }
duke@0 245
duke@0 246
duke@0 247 void CompiledIC::set_to_clean() {
duke@0 248 assert(SafepointSynchronize::is_at_safepoint() || CompiledIC_lock->is_locked() , "MT-unsafe call");
duke@0 249 if (TraceInlineCacheClearing || TraceICs) {
duke@0 250 tty->print_cr("IC@" INTPTR_FORMAT ": set to clean", instruction_address());
duke@0 251 print();
duke@0 252 }
duke@0 253
duke@0 254 address entry;
duke@0 255 if (is_optimized()) {
duke@0 256 entry = SharedRuntime::get_resolve_opt_virtual_call_stub();
duke@0 257 } else {
duke@0 258 entry = SharedRuntime::get_resolve_virtual_call_stub();
duke@0 259 }
duke@0 260
duke@0 261 // A zombie transition will always be safe, since the oop has already been set to NULL, so
duke@0 262 // we only need to patch the destination
duke@0 263 bool safe_transition = is_optimized() || SafepointSynchronize::is_at_safepoint();
duke@0 264
duke@0 265 if (safe_transition) {
duke@0 266 if (!is_optimized()) set_cached_oop(NULL);
duke@0 267 // Kill any leftover stub we might have too
duke@0 268 if (is_in_transition_state()) {
duke@0 269 ICStub* old_stub = ICStub_from_destination_address(stub_address());
duke@0 270 old_stub->clear();
duke@0 271 }
duke@0 272 set_ic_destination(entry);
duke@0 273 } else {
duke@0 274 // Unsafe transition - create stub.
duke@0 275 InlineCacheBuffer::create_transition_stub(this, NULL, entry);
duke@0 276 }
duke@0 277 // We can't check this anymore. With lazy deopt we could have already
duke@0 278 // cleaned this IC entry before we even return. This is possible if
duke@0 279 // we ran out of space in the inline cache buffer trying to do the
duke@0 280 // set_next and we safepointed to free up space. This is a benign
duke@0 281 // race because the IC entry was complete when we safepointed so
duke@0 282 // cleaning it immediately is harmless.
duke@0 283 // assert(is_clean(), "sanity check");
duke@0 284 }
duke@0 285
duke@0 286
duke@0 287 bool CompiledIC::is_clean() const {
duke@0 288 assert (CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), "");
duke@0 289 bool is_clean = false;
duke@0 290 address dest = ic_destination();
duke@0 291 is_clean = dest == SharedRuntime::get_resolve_opt_virtual_call_stub() ||
duke@0 292 dest == SharedRuntime::get_resolve_virtual_call_stub();
duke@0 293 assert(!is_clean || is_optimized() || cached_oop() == NULL, "sanity check");
duke@0 294 return is_clean;
duke@0 295 }
duke@0 296
duke@0 297
duke@0 298 void CompiledIC::set_to_monomorphic(const CompiledICInfo& info) {
duke@0 299 assert (CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), "");
duke@0 300 // Updating a cache to the wrong entry can cause bugs that are very hard
duke@0 301 // to track down - if cache entry gets invalid - we just clean it. In
duke@0 302 // this way it is always the same code path that is responsible for
duke@0 303 // updating and resolving an inline cache
duke@0 304 //
duke@0 305 // The above is no longer true. SharedRuntime::fixup_callers_callsite will change optimized
duke@0 306 // callsites. In addition ic_miss code will update a site to monomorphic if it determines
duke@0 307 // that an monomorphic call to the interpreter can now be monomorphic to compiled code.
duke@0 308 //
duke@0 309 // In both of these cases the only thing being modifed is the jump/call target and these
duke@0 310 // transitions are mt_safe
duke@0 311
duke@0 312 Thread *thread = Thread::current();
duke@0 313 if (info._to_interpreter) {
duke@0 314 // Call to interpreter
duke@0 315 if (info.is_optimized() && is_optimized()) {
duke@0 316 assert(is_clean(), "unsafe IC path");
duke@0 317 MutexLockerEx pl(Patching_lock, Mutex::_no_safepoint_check_flag);
duke@0 318 // the call analysis (callee structure) specifies that the call is optimized
duke@0 319 // (either because of CHA or the static target is final)
duke@0 320 // At code generation time, this call has been emitted as static call
duke@0 321 // Call via stub
duke@0 322 assert(info.cached_oop().not_null() && info.cached_oop()->is_method(), "sanity check");
duke@0 323 CompiledStaticCall* csc = compiledStaticCall_at(instruction_address());
duke@0 324 methodHandle method (thread, (methodOop)info.cached_oop()());
duke@0 325 csc->set_to_interpreted(method, info.entry());
duke@0 326 if (TraceICs) {
duke@0 327 ResourceMark rm(thread);
duke@0 328 tty->print_cr ("IC@" INTPTR_FORMAT ": monomorphic to interpreter: %s",
duke@0 329 instruction_address(),
duke@0 330 method->print_value_string());
duke@0 331 }
duke@0 332 } else {
duke@0 333 // Call via method-klass-holder
duke@0 334 assert(info.cached_oop().not_null(), "must be set");
duke@0 335 InlineCacheBuffer::create_transition_stub(this, info.cached_oop()(), info.entry());
duke@0 336
duke@0 337 if (TraceICs) {
duke@0 338 ResourceMark rm(thread);
duke@0 339 tty->print_cr ("IC@" INTPTR_FORMAT ": monomorphic to interpreter via mkh", instruction_address());
duke@0 340 }
duke@0 341 }
duke@0 342 } else {
duke@0 343 // Call to compiled code
duke@0 344 bool static_bound = info.is_optimized() || (info.cached_oop().is_null());
duke@0 345 #ifdef ASSERT
duke@0 346 CodeBlob* cb = CodeCache::find_blob_unsafe(info.entry());
duke@0 347 assert (cb->is_nmethod(), "must be compiled!");
duke@0 348 #endif /* ASSERT */
duke@0 349
duke@0 350 // This is MT safe if we come from a clean-cache and go through a
duke@0 351 // non-verified entry point
duke@0 352 bool safe = SafepointSynchronize::is_at_safepoint() ||
duke@0 353 (!is_in_transition_state() && (info.is_optimized() || static_bound || is_clean()));
duke@0 354
duke@0 355 if (!safe) {
duke@0 356 InlineCacheBuffer::create_transition_stub(this, info.cached_oop()(), info.entry());
duke@0 357 } else {
duke@0 358 set_ic_destination(info.entry());
duke@0 359 if (!is_optimized()) set_cached_oop(info.cached_oop()());
duke@0 360 }
duke@0 361
duke@0 362 if (TraceICs) {
duke@0 363 ResourceMark rm(thread);
duke@0 364 assert(info.cached_oop() == NULL || info.cached_oop()()->is_klass(), "must be");
duke@0 365 tty->print_cr ("IC@" INTPTR_FORMAT ": monomorphic to compiled (rcvr klass) %s: %s",
duke@0 366 instruction_address(),
duke@0 367 ((klassOop)info.cached_oop()())->print_value_string(),
duke@0 368 (safe) ? "" : "via stub");
duke@0 369 }
duke@0 370 }
duke@0 371 // We can't check this anymore. With lazy deopt we could have already
duke@0 372 // cleaned this IC entry before we even return. This is possible if
duke@0 373 // we ran out of space in the inline cache buffer trying to do the
duke@0 374 // set_next and we safepointed to free up space. This is a benign
duke@0 375 // race because the IC entry was complete when we safepointed so
duke@0 376 // cleaning it immediately is harmless.
duke@0 377 // assert(is_call_to_compiled() || is_call_to_interpreted(), "sanity check");
duke@0 378 }
duke@0 379
duke@0 380
duke@0 381 // is_optimized: Compiler has generated an optimized call (i.e., no inline
duke@0 382 // cache) static_bound: The call can be static bound (i.e, no need to use
duke@0 383 // inline cache)
duke@0 384 void CompiledIC::compute_monomorphic_entry(methodHandle method,
duke@0 385 KlassHandle receiver_klass,
duke@0 386 bool is_optimized,
duke@0 387 bool static_bound,
duke@0 388 CompiledICInfo& info,
duke@0 389 TRAPS) {
duke@0 390 info._is_optimized = is_optimized;
duke@0 391
duke@0 392 nmethod* method_code = method->code();
duke@0 393 address entry = NULL;
duke@0 394 if (method_code != NULL) {
duke@0 395 // Call to compiled code
duke@0 396 if (static_bound || is_optimized) {
duke@0 397 entry = method_code->verified_entry_point();
duke@0 398 } else {
duke@0 399 entry = method_code->entry_point();
duke@0 400 }
duke@0 401 }
duke@0 402 if (entry != NULL) {
duke@0 403 // Call to compiled code
duke@0 404 info._entry = entry;
duke@0 405 if (static_bound || is_optimized) {
duke@0 406 info._cached_oop = Handle(THREAD, (oop)NULL);
duke@0 407 } else {
duke@0 408 info._cached_oop = receiver_klass;
duke@0 409 }
duke@0 410 info._to_interpreter = false;
duke@0 411 } else {
duke@0 412 // Note: the following problem exists with Compiler1:
duke@0 413 // - at compile time we may or may not know if the destination is final
duke@0 414 // - if we know that the destination is final, we will emit an optimized
duke@0 415 // virtual call (no inline cache), and need a methodOop to make a call
duke@0 416 // to the interpreter
duke@0 417 // - if we do not know if the destination is final, we emit a standard
duke@0 418 // virtual call, and use CompiledICHolder to call interpreted code
duke@0 419 // (no static call stub has been generated)
duke@0 420 // However in that case we will now notice it is static_bound
duke@0 421 // and convert the call into what looks to be an optimized
duke@0 422 // virtual call. This causes problems in verifying the IC because
duke@0 423 // it look vanilla but is optimized. Code in is_call_to_interpreted
duke@0 424 // is aware of this and weakens its asserts.
duke@0 425
duke@0 426 info._to_interpreter = true;
duke@0 427 // static_bound should imply is_optimized -- otherwise we have a
duke@0 428 // performance bug (statically-bindable method is called via
duke@0 429 // dynamically-dispatched call note: the reverse implication isn't
duke@0 430 // necessarily true -- the call may have been optimized based on compiler
duke@0 431 // analysis (static_bound is only based on "final" etc.)
duke@0 432 #ifdef COMPILER2
duke@0 433 #ifdef TIERED
duke@0 434 #if defined(ASSERT)
duke@0 435 // can't check the assert because we don't have the CompiledIC with which to
duke@0 436 // find the address if the call instruction.
duke@0 437 //
duke@0 438 // CodeBlob* cb = find_blob_unsafe(instruction_address());
duke@0 439 // assert(cb->is_compiled_by_c1() || !static_bound || is_optimized, "static_bound should imply is_optimized");
duke@0 440 #endif // ASSERT
duke@0 441 #else
duke@0 442 assert(!static_bound || is_optimized, "static_bound should imply is_optimized");
duke@0 443 #endif // TIERED
duke@0 444 #endif // COMPILER2
duke@0 445 if (is_optimized) {
duke@0 446 // Use stub entry
duke@0 447 info._entry = method()->get_c2i_entry();
duke@0 448 info._cached_oop = method;
duke@0 449 } else {
duke@0 450 // Use mkh entry
duke@0 451 oop holder = oopFactory::new_compiledICHolder(method, receiver_klass, CHECK);
duke@0 452 info._cached_oop = Handle(THREAD, holder);
duke@0 453 info._entry = method()->get_c2i_unverified_entry();
duke@0 454 }
duke@0 455 }
duke@0 456 }
duke@0 457
duke@0 458
twisti@1483 459 inline static RelocIterator parse_ic(nmethod* nm, address ic_call, oop* &_oop_addr, bool *is_optimized) {
duke@0 460 address first_oop = NULL;
duke@0 461 // Mergers please note: Sun SC5.x CC insists on an lvalue for a reference parameter.
twisti@1483 462 nmethod* tmp_nm = nm;
twisti@1483 463 return virtual_call_Relocation::parse_ic(tmp_nm, ic_call, first_oop, _oop_addr, is_optimized);
duke@0 464 }
duke@0 465
duke@0 466 CompiledIC::CompiledIC(NativeCall* ic_call)
duke@0 467 : _ic_call(ic_call),
duke@0 468 _oops(parse_ic(NULL, ic_call->instruction_address(), _oop_addr, &_is_optimized))
duke@0 469 {
duke@0 470 }
duke@0 471
duke@0 472
duke@0 473 CompiledIC::CompiledIC(Relocation* ic_reloc)
duke@0 474 : _ic_call(nativeCall_at(ic_reloc->addr())),
duke@0 475 _oops(parse_ic(ic_reloc->code(), ic_reloc->addr(), _oop_addr, &_is_optimized))
duke@0 476 {
duke@0 477 assert(ic_reloc->type() == relocInfo::virtual_call_type ||
duke@0 478 ic_reloc->type() == relocInfo::opt_virtual_call_type, "wrong reloc. info");
duke@0 479 }
duke@0 480
duke@0 481
duke@0 482 // ----------------------------------------------------------------------------
duke@0 483
duke@0 484 void CompiledStaticCall::set_to_clean() {
duke@0 485 assert (CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), "mt unsafe call");
duke@0 486 // Reset call site
duke@0 487 MutexLockerEx pl(Patching_lock, Mutex::_no_safepoint_check_flag);
duke@0 488 #ifdef ASSERT
duke@0 489 CodeBlob* cb = CodeCache::find_blob_unsafe(this);
duke@0 490 assert(cb != NULL && cb->is_nmethod(), "must be nmethod");
duke@0 491 #endif
duke@0 492 set_destination_mt_safe(SharedRuntime::get_resolve_static_call_stub());
duke@0 493
duke@0 494 // Do not reset stub here: It is too expensive to call find_stub.
duke@0 495 // Instead, rely on caller (nmethod::clear_inline_caches) to clear
duke@0 496 // both the call and its stub.
duke@0 497 }
duke@0 498
duke@0 499
duke@0 500 bool CompiledStaticCall::is_clean() const {
duke@0 501 return destination() == SharedRuntime::get_resolve_static_call_stub();
duke@0 502 }
duke@0 503
duke@0 504 bool CompiledStaticCall::is_call_to_compiled() const {
duke@0 505 return CodeCache::contains(destination());
duke@0 506 }
duke@0 507
duke@0 508
duke@0 509 bool CompiledStaticCall::is_call_to_interpreted() const {
duke@0 510 // It is a call to interpreted, if it calls to a stub. Hence, the destination
duke@0 511 // must be in the stub part of the nmethod that contains the call
duke@0 512 nmethod* nm = CodeCache::find_nmethod(instruction_address());
duke@0 513 return nm->stub_contains(destination());
duke@0 514 }
duke@0 515
duke@0 516
duke@0 517 void CompiledStaticCall::set_to_interpreted(methodHandle callee, address entry) {
duke@0 518 address stub=find_stub();
duke@0 519 assert(stub!=NULL, "stub not found");
duke@0 520
duke@0 521 if (TraceICs) {
duke@0 522 ResourceMark rm;
duke@0 523 tty->print_cr("CompiledStaticCall@" INTPTR_FORMAT ": set_to_interpreted %s",
duke@0 524 instruction_address(),
duke@0 525 callee->name_and_sig_as_C_string());
duke@0 526 }
duke@0 527
duke@0 528 NativeMovConstReg* method_holder = nativeMovConstReg_at(stub); // creation also verifies the object
duke@0 529 NativeJump* jump = nativeJump_at(method_holder->next_instruction_address());
duke@0 530
duke@0 531 assert(method_holder->data() == 0 || method_holder->data() == (intptr_t)callee(), "a) MT-unsafe modification of inline cache");
duke@0 532 assert(jump->jump_destination() == (address)-1 || jump->jump_destination() == entry, "b) MT-unsafe modification of inline cache");
duke@0 533
duke@0 534 // Update stub
duke@0 535 method_holder->set_data((intptr_t)callee());
duke@0 536 jump->set_jump_destination(entry);
duke@0 537
duke@0 538 // Update jump to call
duke@0 539 set_destination_mt_safe(stub);
duke@0 540 }
duke@0 541
duke@0 542
duke@0 543 void CompiledStaticCall::set(const StaticCallInfo& info) {
duke@0 544 assert (CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), "mt unsafe call");
duke@0 545 MutexLockerEx pl(Patching_lock, Mutex::_no_safepoint_check_flag);
duke@0 546 // Updating a cache to the wrong entry can cause bugs that are very hard
duke@0 547 // to track down - if cache entry gets invalid - we just clean it. In
duke@0 548 // this way it is always the same code path that is responsible for
duke@0 549 // updating and resolving an inline cache
duke@0 550 assert(is_clean(), "do not update a call entry - use clean");
duke@0 551
duke@0 552 if (info._to_interpreter) {
duke@0 553 // Call to interpreted code
duke@0 554 set_to_interpreted(info.callee(), info.entry());
duke@0 555 } else {
duke@0 556 if (TraceICs) {
duke@0 557 ResourceMark rm;
duke@0 558 tty->print_cr("CompiledStaticCall@" INTPTR_FORMAT ": set_to_compiled " INTPTR_FORMAT,
duke@0 559 instruction_address(),
duke@0 560 info.entry());
duke@0 561 }
duke@0 562 // Call to compiled code
duke@0 563 assert (CodeCache::contains(info.entry()), "wrong entry point");
duke@0 564 set_destination_mt_safe(info.entry());
duke@0 565 }
duke@0 566 }
duke@0 567
duke@0 568
duke@0 569 // Compute settings for a CompiledStaticCall. Since we might have to set
duke@0 570 // the stub when calling to the interpreter, we need to return arguments.
duke@0 571 void CompiledStaticCall::compute_entry(methodHandle m, StaticCallInfo& info) {
duke@0 572 nmethod* m_code = m->code();
duke@0 573 info._callee = m;
duke@0 574 if (m_code != NULL) {
duke@0 575 info._to_interpreter = false;
duke@0 576 info._entry = m_code->verified_entry_point();
duke@0 577 } else {
duke@0 578 // Callee is interpreted code. In any case entering the interpreter
duke@0 579 // puts a converter-frame on the stack to save arguments.
duke@0 580 info._to_interpreter = true;
duke@0 581 info._entry = m()->get_c2i_entry();
duke@0 582 }
duke@0 583 }
duke@0 584
duke@0 585
duke@0 586 void CompiledStaticCall::set_stub_to_clean(static_stub_Relocation* static_stub) {
duke@0 587 assert (CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), "mt unsafe call");
duke@0 588 // Reset stub
duke@0 589 address stub = static_stub->addr();
duke@0 590 assert(stub!=NULL, "stub not found");
duke@0 591 NativeMovConstReg* method_holder = nativeMovConstReg_at(stub); // creation also verifies the object
duke@0 592 NativeJump* jump = nativeJump_at(method_holder->next_instruction_address());
duke@0 593 method_holder->set_data(0);
duke@0 594 jump->set_jump_destination((address)-1);
duke@0 595 }
duke@0 596
duke@0 597
duke@0 598 address CompiledStaticCall::find_stub() {
duke@0 599 // Find reloc. information containing this call-site
duke@0 600 RelocIterator iter((nmethod*)NULL, instruction_address());
duke@0 601 while (iter.next()) {
duke@0 602 if (iter.addr() == instruction_address()) {
duke@0 603 switch(iter.type()) {
duke@0 604 case relocInfo::static_call_type:
duke@0 605 return iter.static_call_reloc()->static_stub();
duke@0 606 // We check here for opt_virtual_call_type, since we reuse the code
duke@0 607 // from the CompiledIC implementation
duke@0 608 case relocInfo::opt_virtual_call_type:
duke@0 609 return iter.opt_virtual_call_reloc()->static_stub();
duke@0 610 case relocInfo::poll_type:
duke@0 611 case relocInfo::poll_return_type: // A safepoint can't overlap a call.
duke@0 612 default:
duke@0 613 ShouldNotReachHere();
duke@0 614 }
duke@0 615 }
duke@0 616 }
duke@0 617 return NULL;
duke@0 618 }
duke@0 619
duke@0 620
duke@0 621 //-----------------------------------------------------------------------------
duke@0 622 // Non-product mode code
duke@0 623 #ifndef PRODUCT
duke@0 624
duke@0 625 void CompiledIC::verify() {
duke@0 626 // make sure code pattern is actually a call imm32 instruction
duke@0 627 _ic_call->verify();
duke@0 628 if (os::is_MP()) {
duke@0 629 _ic_call->verify_alignment();
duke@0 630 }
duke@0 631 assert(is_clean() || is_call_to_compiled() || is_call_to_interpreted()
duke@0 632 || is_optimized() || is_megamorphic(), "sanity check");
duke@0 633 }
duke@0 634
duke@0 635
duke@0 636 void CompiledIC::print() {
duke@0 637 print_compiled_ic();
duke@0 638 tty->cr();
duke@0 639 }
duke@0 640
duke@0 641
duke@0 642 void CompiledIC::print_compiled_ic() {
duke@0 643 tty->print("Inline cache at " INTPTR_FORMAT ", calling %s " INTPTR_FORMAT,
duke@0 644 instruction_address(), is_call_to_interpreted() ? "interpreted " : "", ic_destination());
duke@0 645 }
duke@0 646
duke@0 647
duke@0 648 void CompiledStaticCall::print() {
duke@0 649 tty->print("static call at " INTPTR_FORMAT " -> ", instruction_address());
duke@0 650 if (is_clean()) {
duke@0 651 tty->print("clean");
duke@0 652 } else if (is_call_to_compiled()) {
duke@0 653 tty->print("compiled");
duke@0 654 } else if (is_call_to_interpreted()) {
duke@0 655 tty->print("interpreted");
duke@0 656 }
duke@0 657 tty->cr();
duke@0 658 }
duke@0 659
duke@0 660 void CompiledStaticCall::verify() {
duke@0 661 // Verify call
duke@0 662 NativeCall::verify();
duke@0 663 if (os::is_MP()) {
duke@0 664 verify_alignment();
duke@0 665 }
duke@0 666
duke@0 667 // Verify stub
duke@0 668 address stub = find_stub();
duke@0 669 assert(stub != NULL, "no stub found for static call");
duke@0 670 NativeMovConstReg* method_holder = nativeMovConstReg_at(stub); // creation also verifies the object
duke@0 671 NativeJump* jump = nativeJump_at(method_holder->next_instruction_address());
duke@0 672
duke@0 673 // Verify state
duke@0 674 assert(is_clean() || is_call_to_compiled() || is_call_to_interpreted(), "sanity check");
duke@0 675 }
duke@0 676
duke@0 677 #endif