1 /*
   2  * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "code/compiledIC.hpp"
  27 #include "code/compiledMethod.inline.hpp"
  28 #include "code/scopeDesc.hpp"
  29 #include "code/codeCache.hpp"
  30 #include "gc/shared/barrierSet.hpp"
  31 #include "gc/shared/gcBehaviours.hpp"
  32 #include "interpreter/bytecode.inline.hpp"
  33 #include "logging/log.hpp"
  34 #include "logging/logTag.hpp"
  35 #include "memory/resourceArea.hpp"
  36 #include "oops/methodData.hpp"
  37 #include "oops/method.inline.hpp"
  38 #include "prims/methodHandles.hpp"
  39 #include "runtime/handles.inline.hpp"
  40 #include "runtime/mutexLocker.hpp"
  41 #include "runtime/sharedRuntime.hpp"
  42 
  43 CompiledMethod::CompiledMethod(Method* method, const char* name, CompilerType type, const CodeBlobLayout& layout,
  44                                int frame_complete_offset, int frame_size, ImmutableOopMapSet* oop_maps,
  45                                bool caller_must_gc_arguments)
  46   : CodeBlob(name, type, layout, frame_complete_offset, frame_size, oop_maps, caller_must_gc_arguments),
  47     _mark_for_deoptimization_status(not_marked),
  48     _method(method),
  49     _gc_data(NULL)
  50 {
  51   init_defaults();
  52 }
  53 
  54 CompiledMethod::CompiledMethod(Method* method, const char* name, CompilerType type, int size,
  55                                int header_size, CodeBuffer* cb, int frame_complete_offset, int frame_size,
  56                                OopMapSet* oop_maps, bool caller_must_gc_arguments)
  57   : CodeBlob(name, type, CodeBlobLayout((address) this, size, header_size, cb), cb,
  58              frame_complete_offset, frame_size, oop_maps, caller_must_gc_arguments),
  59     _mark_for_deoptimization_status(not_marked),
  60     _method(method),
  61     _gc_data(NULL)
  62 {
  63   init_defaults();
  64 }
  65 
  66 void CompiledMethod::init_defaults() {
  67   _has_unsafe_access          = 0;
  68   _has_method_handle_invokes  = 0;
  69   _lazy_critical_native       = 0;
  70   _has_wide_vectors           = 0;
  71 }
  72 
  73 bool CompiledMethod::is_method_handle_return(address return_pc) {
  74   if (!has_method_handle_invokes())  return false;
  75   PcDesc* pd = pc_desc_at(return_pc);
  76   if (pd == NULL)
  77     return false;
  78   return pd->is_method_handle_invoke();
  79 }
  80 
  81 // Returns a string version of the method state.
  82 const char* CompiledMethod::state() const {
  83   int state = get_state();
  84   switch (state) {
  85   case not_installed:
  86     return "not installed";
  87   case in_use:
  88     return "in use";
  89   case not_used:
  90     return "not_used";
  91   case not_entrant:
  92     return "not_entrant";
  93   case zombie:
  94     return "zombie";
  95   case unloaded:
  96     return "unloaded";
  97   default:
  98     fatal("unexpected method state: %d", state);
  99     return NULL;
 100   }
 101 }
 102 
 103 //-----------------------------------------------------------------------------
 104 
 105 ExceptionCache* CompiledMethod::exception_cache_acquire() const {
 106   return OrderAccess::load_acquire(&_exception_cache);
 107 }
 108 
 109 void CompiledMethod::add_exception_cache_entry(ExceptionCache* new_entry) {
 110   assert(ExceptionCache_lock->owned_by_self(),"Must hold the ExceptionCache_lock");
 111   assert(new_entry != NULL,"Must be non null");
 112   assert(new_entry->next() == NULL, "Must be null");
 113 
 114   for (;;) {
 115     ExceptionCache *ec = exception_cache();
 116     if (ec != NULL) {
 117       Klass* ex_klass = ec->exception_type();
 118       if (!ex_klass->is_loader_alive()) {
 119         // We must guarantee that entries are not inserted with new next pointer
 120         // edges to ExceptionCache entries with dead klasses, due to bad interactions
 121         // with concurrent ExceptionCache cleanup. Therefore, the inserts roll
 122         // the head pointer forward to the first live ExceptionCache, so that the new
 123         // next pointers always point at live ExceptionCaches, that are not removed due
 124         // to concurrent ExceptionCache cleanup.
 125         ExceptionCache* next = ec->next();
 126         if (Atomic::cmpxchg(next, &_exception_cache, ec) == ec) {
 127           CodeCache::release_exception_cache(ec);
 128         }
 129         continue;
 130       }
 131       ec = exception_cache();
 132       if (ec != NULL) {
 133         new_entry->set_next(ec);
 134       }
 135     }
 136     if (Atomic::cmpxchg(new_entry, &_exception_cache, ec) == ec) {
 137       return;
 138     }
 139   }
 140 }
 141 
 142 void CompiledMethod::clean_exception_cache() {
 143   // For each nmethod, only a single thread may call this cleanup function
 144   // at the same time, whether called in STW cleanup or concurrent cleanup.
 145   // Note that if the GC is processing exception cache cleaning in a concurrent phase,
 146   // then a single writer may contend with cleaning up the head pointer to the
 147   // first ExceptionCache node that has a Klass* that is alive. That is fine,
 148   // as long as there is no concurrent cleanup of next pointers from concurrent writers.
 149   // And the concurrent writers do not clean up next pointers, only the head.
 150   // Also note that concurent readers will walk through Klass* pointers that are not
 151   // alive. That does not cause ABA problems, because Klass* is deleted after
 152   // a handshake with all threads, after all stale ExceptionCaches have been
 153   // unlinked. That is also when the CodeCache::exception_cache_purge_list()
 154   // is deleted, with all ExceptionCache entries that were cleaned concurrently.
 155   // That similarly implies that CAS operations on ExceptionCache entries do not
 156   // suffer from ABA problems as unlinking and deletion is separated by a global
 157   // handshake operation.
 158   ExceptionCache* prev = NULL;
 159   ExceptionCache* curr = exception_cache_acquire();
 160 
 161   while (curr != NULL) {
 162     ExceptionCache* next = curr->next();
 163 
 164     if (!curr->exception_type()->is_loader_alive()) {
 165       if (prev == NULL) {
 166         // Try to clean head; this is contended by concurrent inserts, that
 167         // both lazily clean the head, and insert entries at the head. If
 168         // the CAS fails, the operation is restarted.
 169         if (Atomic::cmpxchg(next, &_exception_cache, curr) != curr) {
 170           prev = NULL;
 171           curr = exception_cache_acquire();
 172           continue;
 173         }
 174       } else {
 175         // It is impossible to during cleanup connect the next pointer to
 176         // an ExceptionCache that has not been published before a safepoint
 177         // prior to the cleanup. Therefore, release is not required.
 178         prev->set_next(next);
 179       }
 180       // prev stays the same.
 181 
 182       CodeCache::release_exception_cache(curr);
 183     } else {
 184       prev = curr;
 185     }
 186 
 187     curr = next;
 188   }
 189 }
 190 
 191 // public method for accessing the exception cache
 192 // These are the public access methods.
 193 address CompiledMethod::handler_for_exception_and_pc(Handle exception, address pc) {
 194   // We never grab a lock to read the exception cache, so we may
 195   // have false negatives. This is okay, as it can only happen during
 196   // the first few exception lookups for a given nmethod.
 197   ExceptionCache* ec = exception_cache_acquire();
 198   while (ec != NULL) {
 199     address ret_val;
 200     if ((ret_val = ec->match(exception,pc)) != NULL) {
 201       return ret_val;
 202     }
 203     ec = ec->next();
 204   }
 205   return NULL;
 206 }
 207 
 208 void CompiledMethod::add_handler_for_exception_and_pc(Handle exception, address pc, address handler) {
 209   // There are potential race conditions during exception cache updates, so we
 210   // must own the ExceptionCache_lock before doing ANY modifications. Because
 211   // we don't lock during reads, it is possible to have several threads attempt
 212   // to update the cache with the same data. We need to check for already inserted
 213   // copies of the current data before adding it.
 214 
 215   MutexLocker ml(ExceptionCache_lock);
 216   ExceptionCache* target_entry = exception_cache_entry_for_exception(exception);
 217 
 218   if (target_entry == NULL || !target_entry->add_address_and_handler(pc,handler)) {
 219     target_entry = new ExceptionCache(exception,pc,handler);
 220     add_exception_cache_entry(target_entry);
 221   }
 222 }
 223 
 224 // private method for handling exception cache
 225 // These methods are private, and used to manipulate the exception cache
 226 // directly.
 227 ExceptionCache* CompiledMethod::exception_cache_entry_for_exception(Handle exception) {
 228   ExceptionCache* ec = exception_cache_acquire();
 229   while (ec != NULL) {
 230     if (ec->match_exception_with_space(exception)) {
 231       return ec;
 232     }
 233     ec = ec->next();
 234   }
 235   return NULL;
 236 }
 237 
 238 //-------------end of code for ExceptionCache--------------
 239 
 240 bool CompiledMethod::is_at_poll_return(address pc) {
 241   RelocIterator iter(this, pc, pc+1);
 242   while (iter.next()) {
 243     if (iter.type() == relocInfo::poll_return_type)
 244       return true;
 245   }
 246   return false;
 247 }
 248 
 249 
 250 bool CompiledMethod::is_at_poll_or_poll_return(address pc) {
 251   RelocIterator iter(this, pc, pc+1);
 252   while (iter.next()) {
 253     relocInfo::relocType t = iter.type();
 254     if (t == relocInfo::poll_return_type || t == relocInfo::poll_type)
 255       return true;
 256   }
 257   return false;
 258 }
 259 
 260 void CompiledMethod::verify_oop_relocations() {
 261   // Ensure sure that the code matches the current oop values
 262   RelocIterator iter(this, NULL, NULL);
 263   while (iter.next()) {
 264     if (iter.type() == relocInfo::oop_type) {
 265       oop_Relocation* reloc = iter.oop_reloc();
 266       if (!reloc->oop_is_immediate()) {
 267         reloc->verify_oop_relocation();
 268       }
 269     }
 270   }
 271 }
 272 
 273 
 274 ScopeDesc* CompiledMethod::scope_desc_at(address pc) {
 275   PcDesc* pd = pc_desc_at(pc);
 276   guarantee(pd != NULL, "scope must be present");
 277   return new ScopeDesc(this, pd->scope_decode_offset(),
 278                        pd->obj_decode_offset(), pd->should_reexecute(), pd->rethrow_exception(),
 279                        pd->return_oop(), pd->return_vt());
 280 }
 281 
 282 ScopeDesc* CompiledMethod::scope_desc_near(address pc) {
 283   PcDesc* pd = pc_desc_near(pc);
 284   guarantee(pd != NULL, "scope must be present");
 285   return new ScopeDesc(this, pd->scope_decode_offset(),
 286                        pd->obj_decode_offset(), pd->should_reexecute(), pd->rethrow_exception(),
 287                        pd->return_oop(), pd->return_vt());
 288 }
 289 
 290 address CompiledMethod::oops_reloc_begin() const {
 291   // If the method is not entrant or zombie then a JMP is plastered over the
 292   // first few bytes.  If an oop in the old code was there, that oop
 293   // should not get GC'd.  Skip the first few bytes of oops on
 294   // not-entrant methods.
 295   if (frame_complete_offset() != CodeOffsets::frame_never_safe &&
 296       code_begin() + frame_complete_offset() >
 297       verified_entry_point() + NativeJump::instruction_size)
 298   {
 299     // If we have a frame_complete_offset after the native jump, then there
 300     // is no point trying to look for oops before that. This is a requirement
 301     // for being allowed to scan oops concurrently.
 302     return code_begin() + frame_complete_offset();
 303   }
 304 
 305   // It is not safe to read oops concurrently using entry barriers, if their
 306   // location depend on whether the nmethod is entrant or not.
 307   assert(BarrierSet::barrier_set()->barrier_set_nmethod() == NULL, "Not safe oop scan");
 308 
 309   address low_boundary = verified_entry_point();
 310   if (!is_in_use() && is_nmethod()) {
 311     low_boundary += NativeJump::instruction_size;
 312     // %%% Note:  On SPARC we patch only a 4-byte trap, not a full NativeJump.
 313     // This means that the low_boundary is going to be a little too high.
 314     // This shouldn't matter, since oops of non-entrant methods are never used.
 315     // In fact, why are we bothering to look at oops in a non-entrant method??
 316   }
 317   return low_boundary;
 318 }
 319 
 320 int CompiledMethod::verify_icholder_relocations() {
 321   ResourceMark rm;
 322   int count = 0;
 323 
 324   RelocIterator iter(this);
 325   while(iter.next()) {
 326     if (iter.type() == relocInfo::virtual_call_type) {
 327       if (CompiledIC::is_icholder_call_site(iter.virtual_call_reloc(), this)) {
 328         CompiledIC *ic = CompiledIC_at(&iter);
 329         if (TraceCompiledIC) {
 330           tty->print("noticed icholder " INTPTR_FORMAT " ", p2i(ic->cached_icholder()));
 331           ic->print();
 332         }
 333         assert(ic->cached_icholder() != NULL, "must be non-NULL");
 334         count++;
 335       }
 336     }
 337   }
 338 
 339   return count;
 340 }
 341 
 342 // Method that knows how to preserve outgoing arguments at call. This method must be
 343 // called with a frame corresponding to a Java invoke
 344 void CompiledMethod::preserve_callee_argument_oops(frame fr, const RegisterMap *reg_map, OopClosure* f) {
 345   if (method() != NULL && !method()->is_native()) {
 346     address pc = fr.pc();
 347     SimpleScopeDesc ssd(this, pc);
 348     Bytecode_invoke call(ssd.method(), ssd.bci());
 349     bool has_receiver = call.has_receiver();
 350     bool has_appendix = call.has_appendix();
 351     Symbol* signature = call.signature();
 352 
 353     // The method attached by JIT-compilers should be used, if present.
 354     // Bytecode can be inaccurate in such case.
 355     Method* callee = attached_method_before_pc(pc);
 356     if (callee != NULL) {
 357       has_receiver = !(callee->access_flags().is_static());
 358       has_appendix = false;
 359       signature = callee->signature();
 360     }
 361 
 362     // If value types are passed as fields, use the extended signature
 363     // which contains the types of all (oop) fields of the value type.
 364     if (ValueTypePassFieldsAsArgs && callee != NULL) {
 365       // Get the extended signature from the callee's adapter through the attached method
 366       Symbol* sig_ext = callee->adapter()->get_sig_extended();
 367 #ifdef ASSERT
 368       // Check if receiver or one of the arguments is a value type
 369       bool has_value_receiver = has_receiver && callee->method_holder()->is_value();
 370       bool has_value_argument = has_value_receiver;
 371       for (SignatureStream ss(signature); !has_value_argument && !ss.at_return_type(); ss.next()) {
 372         if (ss.type() == T_VALUETYPE) {
 373           has_value_argument = true;
 374           break;
 375         }
 376       }
 377       assert(has_value_argument == (sig_ext != NULL), "Signature is inconsistent");
 378 #endif
 379       if (sig_ext != NULL) {
 380         signature = sig_ext;
 381         has_receiver = false; // The extended signature contains the receiver type
 382       }
 383     }
 384 
 385     fr.oops_compiled_arguments_do(signature, has_receiver, has_appendix, reg_map, f);
 386   }
 387 }
 388 
 389 Method* CompiledMethod::attached_method(address call_instr) {
 390   assert(code_contains(call_instr), "not part of the nmethod");
 391   RelocIterator iter(this, call_instr, call_instr + 1);
 392   while (iter.next()) {
 393     if (iter.addr() == call_instr) {
 394       switch(iter.type()) {
 395         case relocInfo::static_call_type:      return iter.static_call_reloc()->method_value();
 396         case relocInfo::opt_virtual_call_type: return iter.opt_virtual_call_reloc()->method_value();
 397         case relocInfo::virtual_call_type:     return iter.virtual_call_reloc()->method_value();
 398         default:                               break;
 399       }
 400     }
 401   }
 402   return NULL; // not found
 403 }
 404 
 405 Method* CompiledMethod::attached_method_before_pc(address pc) {
 406   if (NativeCall::is_call_before(pc)) {
 407     NativeCall* ncall = nativeCall_before(pc);
 408     return attached_method(ncall->instruction_address());
 409   }
 410   return NULL; // not a call
 411 }
 412 
 413 void CompiledMethod::clear_inline_caches() {
 414   assert(SafepointSynchronize::is_at_safepoint(), "cleaning of IC's only allowed at safepoint");
 415   if (is_zombie()) {
 416     return;
 417   }
 418 
 419   RelocIterator iter(this);
 420   while (iter.next()) {
 421     iter.reloc()->clear_inline_cache();
 422   }
 423 }
 424 
 425 // Clear ICStubs of all compiled ICs
 426 void CompiledMethod::clear_ic_stubs() {
 427   assert(CompiledICLocker::is_safe(this), "mt unsafe call");
 428   ResourceMark rm;
 429   RelocIterator iter(this);
 430   while(iter.next()) {
 431     if (iter.type() == relocInfo::virtual_call_type) {
 432       CompiledIC* ic = CompiledIC_at(&iter);
 433       ic->clear_ic_stub();
 434     }
 435   }
 436 }
 437 
 438 #ifdef ASSERT
 439 // Check class_loader is alive for this bit of metadata.
 440 static void check_class(Metadata* md) {
 441    Klass* klass = NULL;
 442    if (md->is_klass()) {
 443      klass = ((Klass*)md);
 444    } else if (md->is_method()) {
 445      klass = ((Method*)md)->method_holder();
 446    } else if (md->is_methodData()) {
 447      klass = ((MethodData*)md)->method()->method_holder();
 448    } else {
 449      md->print();
 450      ShouldNotReachHere();
 451    }
 452    assert(klass->is_loader_alive(), "must be alive");
 453 }
 454 #endif // ASSERT
 455 
 456 
 457 void CompiledMethod::clean_ic_if_metadata_is_dead(CompiledIC *ic) {
 458   if (ic->is_icholder_call()) {
 459     // The only exception is compiledICHolder metdata which may
 460     // yet be marked below. (We check this further below).
 461     CompiledICHolder* cichk_metdata = ic->cached_icholder();
 462 
 463     if (cichk_metdata->is_loader_alive()) {
 464       return;
 465     }
 466   } else {
 467     Metadata* ic_metdata = ic->cached_metadata();
 468     if (ic_metdata != NULL) {
 469       if (ic_metdata->is_klass()) {
 470         if (((Klass*)ic_metdata)->is_loader_alive()) {
 471           return;
 472         }
 473       } else if (ic_metdata->is_method()) {
 474         Method* method = (Method*)ic_metdata;
 475         assert(!method->is_old(), "old method should have been cleaned");
 476         if (method->method_holder()->is_loader_alive()) {
 477           return;
 478         }
 479       } else {
 480         ShouldNotReachHere();
 481       }
 482     }
 483   }
 484 
 485   ic->set_to_clean();
 486 }
 487 
 488 // static_stub_Relocations may have dangling references to
 489 // nmethods so trim them out here.  Otherwise it looks like
 490 // compiled code is maintaining a link to dead metadata.
 491 void CompiledMethod::clean_ic_stubs() {
 492 #ifdef ASSERT
 493   address low_boundary = oops_reloc_begin();
 494   RelocIterator iter(this, low_boundary);
 495   while (iter.next()) {
 496     address static_call_addr = NULL;
 497     if (iter.type() == relocInfo::opt_virtual_call_type) {
 498       CompiledIC* cic = CompiledIC_at(&iter);
 499       if (!cic->is_call_to_interpreted()) {
 500         static_call_addr = iter.addr();
 501       }
 502     } else if (iter.type() == relocInfo::static_call_type) {
 503       CompiledStaticCall* csc = compiledStaticCall_at(iter.reloc());
 504       if (!csc->is_call_to_interpreted()) {
 505         static_call_addr = iter.addr();
 506       }
 507     }
 508     if (static_call_addr != NULL) {
 509       RelocIterator sciter(this, low_boundary);
 510       while (sciter.next()) {
 511         if (sciter.type() == relocInfo::static_stub_type &&
 512             sciter.static_stub_reloc()->static_call() == static_call_addr) {
 513           sciter.static_stub_reloc()->clear_inline_cache();
 514         }
 515       }
 516     }
 517   }
 518 #endif
 519 }
 520 
 521 // Clean references to unloaded nmethods at addr from this one, which is not unloaded.
 522 template <class CompiledICorStaticCall>
 523 static void clean_if_nmethod_is_unloaded(CompiledICorStaticCall *ic, address addr, CompiledMethod* from,
 524                                          bool clean_all) {
 525   // Ok, to lookup references to zombies here
 526   CodeBlob *cb = CodeCache::find_blob_unsafe(addr);
 527   CompiledMethod* nm = (cb != NULL) ? cb->as_compiled_method_or_null() : NULL;
 528   if (nm != NULL) {
 529     // Clean inline caches pointing to both zombie and not_entrant methods
 530     if (clean_all || !nm->is_in_use() || nm->is_unloading() || (nm->method()->code() != nm)) {
 531       ic->set_to_clean(from->is_alive());
 532       assert(ic->is_clean(), "nmethod " PTR_FORMAT "not clean %s", p2i(from), from->method()->name_and_sig_as_C_string());
 533     }
 534   }
 535 }
 536 
 537 static void clean_if_nmethod_is_unloaded(CompiledIC *ic, CompiledMethod* from,
 538                                          bool clean_all) {
 539   clean_if_nmethod_is_unloaded(ic, ic->ic_destination(), from, clean_all);
 540 }
 541 
 542 static void clean_if_nmethod_is_unloaded(CompiledStaticCall *csc, CompiledMethod* from,
 543                                          bool clean_all) {
 544   clean_if_nmethod_is_unloaded(csc, csc->destination(), from, clean_all);
 545 }
 546 
 547 // Cleans caches in nmethods that point to either classes that are unloaded
 548 // or nmethods that are unloaded.
 549 //
 550 // Can be called either in parallel by G1 currently or after all
 551 // nmethods are unloaded.  Return postponed=true in the parallel case for
 552 // inline caches found that point to nmethods that are not yet visited during
 553 // the do_unloading walk.
 554 void CompiledMethod::unload_nmethod_caches(bool unloading_occurred) {
 555   ResourceMark rm;
 556 
 557   // Exception cache only needs to be called if unloading occurred
 558   if (unloading_occurred) {
 559     clean_exception_cache();
 560   }
 561 
 562   cleanup_inline_caches_impl(unloading_occurred, false);
 563 
 564   // All static stubs need to be cleaned.
 565   clean_ic_stubs();
 566 
 567   // Check that the metadata embedded in the nmethod is alive
 568   DEBUG_ONLY(metadata_do(check_class));
 569 }
 570 
 571 // Called to clean up after class unloading for live nmethods and from the sweeper
 572 // for all methods.
 573 void CompiledMethod::cleanup_inline_caches_impl(bool unloading_occurred, bool clean_all) {
 574   assert(CompiledICLocker::is_safe(this), "mt unsafe call");
 575   ResourceMark rm;
 576 
 577   // Find all calls in an nmethod and clear the ones that point to non-entrant,
 578   // zombie and unloaded nmethods.
 579   RelocIterator iter(this, oops_reloc_begin());
 580   while(iter.next()) {
 581 
 582     switch (iter.type()) {
 583 
 584     case relocInfo::virtual_call_type:
 585       if (unloading_occurred) {
 586         // If class unloading occurred we first clear ICs where the cached metadata
 587         // is referring to an unloaded klass or method.
 588         clean_ic_if_metadata_is_dead(CompiledIC_at(&iter));
 589       }
 590 
 591       clean_if_nmethod_is_unloaded(CompiledIC_at(&iter), this, clean_all);
 592       break;
 593 
 594     case relocInfo::opt_virtual_call_type:
 595       clean_if_nmethod_is_unloaded(CompiledIC_at(&iter), this, clean_all);
 596       break;
 597 
 598     case relocInfo::static_call_type:
 599       clean_if_nmethod_is_unloaded(compiledStaticCall_at(iter.reloc()), this, clean_all);
 600       break;
 601 
 602     case relocInfo::oop_type:
 603       break;
 604 
 605     case relocInfo::metadata_type:
 606       break; // nothing to do.
 607 
 608     default:
 609       break;
 610     }
 611   }
 612 }
 613 
 614 // Iterating over all nmethods, e.g. with the help of CodeCache::nmethods_do(fun) was found
 615 // to not be inherently safe. There is a chance that fields are seen which are not properly
 616 // initialized. This happens despite the fact that nmethods_do() asserts the CodeCache_lock
 617 // to be held.
 618 // To bundle knowledge about necessary checks in one place, this function was introduced.
 619 // It is not claimed that these checks are sufficient, but they were found to be necessary.
 620 bool CompiledMethod::nmethod_access_is_safe(nmethod* nm) {
 621   Method* method = (nm == NULL) ? NULL : nm->method();  // nm->method() may be uninitialized, i.e. != NULL, but invalid
 622   return (nm != NULL) && (method != NULL) && (method->signature() != NULL) &&
 623          !nm->is_zombie() && !nm->is_not_installed() &&
 624          os::is_readable_pointer(method) &&
 625          os::is_readable_pointer(method->constants()) &&
 626          os::is_readable_pointer(method->signature());
 627 }