src/share/vm/code/compiledIC.cpp

Wed, 31 Jan 2018 19:24:57 -0500

author
dbuck
date
Wed, 31 Jan 2018 19:24:57 -0500
changeset 9289
427b2fb1944f
parent 8075
be740540f60c
child 8604
04d83ba48607
child 8997
f8a45a60bc6b
permissions
-rw-r--r--

8189170: Add option to disable stack overflow checking in primordial thread for use with JNI_CreateJavaJVM
Reviewed-by: dcubed

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

mercurial