1 /*
  2  * Copyright (c) 2015, 2024, 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/exceptionHandlerTable.hpp"
 29 #include "code/scopeDesc.hpp"
 30 #include "code/codeCache.hpp"
 31 #include "gc/shared/barrierSet.hpp"
 32 #include "gc/shared/barrierSetNMethod.hpp"
 33 #include "gc/shared/gcBehaviours.hpp"
 34 #include "interpreter/bytecode.inline.hpp"
 35 #include "logging/log.hpp"
 36 #include "logging/logTag.hpp"
 37 #include "memory/resourceArea.hpp"
 38 #include "oops/klass.inline.hpp"
 39 #include "oops/methodData.hpp"
 40 #include "oops/method.inline.hpp"
 41 #include "oops/weakHandle.inline.hpp"
 42 #include "prims/methodHandles.hpp"
 43 #include "runtime/atomic.hpp"
 44 #include "runtime/deoptimization.hpp"
 45 #include "runtime/frame.inline.hpp"
 46 #include "runtime/jniHandles.inline.hpp"
 47 #include "runtime/handles.inline.hpp"
 48 #include "runtime/mutexLocker.hpp"
 49 #include "runtime/sharedRuntime.hpp"
 50 
 51 CompiledMethod::CompiledMethod(Method* method, const char* name, CompilerType type, const CodeBlobLayout& layout,
 52                                int frame_complete_offset, int frame_size, ImmutableOopMapSet* oop_maps,
 53                                bool caller_must_gc_arguments, bool compiled)
 54   : CodeBlob(name, type, layout, frame_complete_offset, frame_size, oop_maps, caller_must_gc_arguments, compiled),
 55     _deoptimization_status(not_marked),
 56     _deoptimization_generation(0),
 57     _method(method),
 58     _gc_data(nullptr)
 59 {
 60   init_defaults();
 61 }
 62 
 63 CompiledMethod::CompiledMethod(Method* method, const char* name, CompilerType type, int size,
 64                                int header_size, CodeBuffer* cb, int frame_complete_offset, int frame_size,
 65                                OopMapSet* oop_maps, bool caller_must_gc_arguments, bool compiled)
 66   : CodeBlob(name, type, CodeBlobLayout((address) this, size, header_size, cb), cb,
 67              frame_complete_offset, frame_size, oop_maps, caller_must_gc_arguments, compiled),
 68     _deoptimization_status(not_marked),
 69     _deoptimization_generation(0),
 70     _method(method),
 71     _gc_data(nullptr)
 72 {
 73   init_defaults();
 74 }
 75 
 76 void CompiledMethod::init_defaults() {
 77   { // avoid uninitialized fields, even for short time periods
 78     _scopes_data_begin          = nullptr;
 79     _deopt_handler_begin        = nullptr;
 80     _deopt_mh_handler_begin     = nullptr;
 81     _exception_cache            = nullptr;
 82   }
 83   _has_unsafe_access          = 0;
 84   _has_method_handle_invokes  = 0;
 85   _has_wide_vectors           = 0;
 86   _has_monitors               = 0;
 87   _preloaded                  = 0;
 88   _has_clinit_barriers        = 0;
 89 }
 90 
 91 bool CompiledMethod::is_method_handle_return(address return_pc) {
 92   if (!has_method_handle_invokes())  return false;
 93   PcDesc* pd = pc_desc_at(return_pc);
 94   if (pd == nullptr)
 95     return false;
 96   return pd->is_method_handle_invoke();
 97 }
 98 
 99 // Returns a string version of the method state.
100 const char* CompiledMethod::state() const {
101   int state = get_state();
102   switch (state) {
103   case not_installed:
104     return "not installed";
105   case in_use:
106     return "in use";
107   case not_used:
108     return "not_used";
109   case not_entrant:
110     return "not_entrant";
111   default:
112     fatal("unexpected method state: %d", state);
113     return nullptr;
114   }
115 }
116 
117 //-----------------------------------------------------------------------------
118 void CompiledMethod::set_deoptimized_done() {
119   ConditionalMutexLocker ml(CompiledMethod_lock, !CompiledMethod_lock->owned_by_self(), Mutex::_no_safepoint_check_flag);
120   if (_deoptimization_status != deoptimize_done) { // can't go backwards
121     Atomic::store(&_deoptimization_status, deoptimize_done);
122   }
123 }
124 
125 //-----------------------------------------------------------------------------
126 
127 ExceptionCache* CompiledMethod::exception_cache_acquire() const {
128   return Atomic::load_acquire(&_exception_cache);
129 }
130 
131 void CompiledMethod::add_exception_cache_entry(ExceptionCache* new_entry) {
132   assert(ExceptionCache_lock->owned_by_self(),"Must hold the ExceptionCache_lock");
133   assert(new_entry != nullptr,"Must be non null");
134   assert(new_entry->next() == nullptr, "Must be null");
135 
136   for (;;) {
137     ExceptionCache *ec = exception_cache();
138     if (ec != nullptr) {
139       Klass* ex_klass = ec->exception_type();
140       if (!ex_klass->is_loader_alive()) {
141         // We must guarantee that entries are not inserted with new next pointer
142         // edges to ExceptionCache entries with dead klasses, due to bad interactions
143         // with concurrent ExceptionCache cleanup. Therefore, the inserts roll
144         // the head pointer forward to the first live ExceptionCache, so that the new
145         // next pointers always point at live ExceptionCaches, that are not removed due
146         // to concurrent ExceptionCache cleanup.
147         ExceptionCache* next = ec->next();
148         if (Atomic::cmpxchg(&_exception_cache, ec, next) == ec) {
149           CodeCache::release_exception_cache(ec);
150         }
151         continue;
152       }
153       ec = exception_cache();
154       if (ec != nullptr) {
155         new_entry->set_next(ec);
156       }
157     }
158     if (Atomic::cmpxchg(&_exception_cache, ec, new_entry) == ec) {
159       return;
160     }
161   }
162 }
163 
164 void CompiledMethod::clean_exception_cache() {
165   // For each nmethod, only a single thread may call this cleanup function
166   // at the same time, whether called in STW cleanup or concurrent cleanup.
167   // Note that if the GC is processing exception cache cleaning in a concurrent phase,
168   // then a single writer may contend with cleaning up the head pointer to the
169   // first ExceptionCache node that has a Klass* that is alive. That is fine,
170   // as long as there is no concurrent cleanup of next pointers from concurrent writers.
171   // And the concurrent writers do not clean up next pointers, only the head.
172   // Also note that concurrent readers will walk through Klass* pointers that are not
173   // alive. That does not cause ABA problems, because Klass* is deleted after
174   // a handshake with all threads, after all stale ExceptionCaches have been
175   // unlinked. That is also when the CodeCache::exception_cache_purge_list()
176   // is deleted, with all ExceptionCache entries that were cleaned concurrently.
177   // That similarly implies that CAS operations on ExceptionCache entries do not
178   // suffer from ABA problems as unlinking and deletion is separated by a global
179   // handshake operation.
180   ExceptionCache* prev = nullptr;
181   ExceptionCache* curr = exception_cache_acquire();
182 
183   while (curr != nullptr) {
184     ExceptionCache* next = curr->next();
185 
186     if (!curr->exception_type()->is_loader_alive()) {
187       if (prev == nullptr) {
188         // Try to clean head; this is contended by concurrent inserts, that
189         // both lazily clean the head, and insert entries at the head. If
190         // the CAS fails, the operation is restarted.
191         if (Atomic::cmpxchg(&_exception_cache, curr, next) != curr) {
192           prev = nullptr;
193           curr = exception_cache_acquire();
194           continue;
195         }
196       } else {
197         // It is impossible to during cleanup connect the next pointer to
198         // an ExceptionCache that has not been published before a safepoint
199         // prior to the cleanup. Therefore, release is not required.
200         prev->set_next(next);
201       }
202       // prev stays the same.
203 
204       CodeCache::release_exception_cache(curr);
205     } else {
206       prev = curr;
207     }
208 
209     curr = next;
210   }
211 }
212 
213 // public method for accessing the exception cache
214 // These are the public access methods.
215 address CompiledMethod::handler_for_exception_and_pc(Handle exception, address pc) {
216   // We never grab a lock to read the exception cache, so we may
217   // have false negatives. This is okay, as it can only happen during
218   // the first few exception lookups for a given nmethod.
219   ExceptionCache* ec = exception_cache_acquire();
220   while (ec != nullptr) {
221     address ret_val;
222     if ((ret_val = ec->match(exception,pc)) != nullptr) {
223       return ret_val;
224     }
225     ec = ec->next();
226   }
227   return nullptr;
228 }
229 
230 void CompiledMethod::add_handler_for_exception_and_pc(Handle exception, address pc, address handler) {
231   // There are potential race conditions during exception cache updates, so we
232   // must own the ExceptionCache_lock before doing ANY modifications. Because
233   // we don't lock during reads, it is possible to have several threads attempt
234   // to update the cache with the same data. We need to check for already inserted
235   // copies of the current data before adding it.
236 
237   MutexLocker ml(ExceptionCache_lock);
238   ExceptionCache* target_entry = exception_cache_entry_for_exception(exception);
239 
240   if (target_entry == nullptr || !target_entry->add_address_and_handler(pc,handler)) {
241     target_entry = new ExceptionCache(exception,pc,handler);
242     add_exception_cache_entry(target_entry);
243   }
244 }
245 
246 // private method for handling exception cache
247 // These methods are private, and used to manipulate the exception cache
248 // directly.
249 ExceptionCache* CompiledMethod::exception_cache_entry_for_exception(Handle exception) {
250   ExceptionCache* ec = exception_cache_acquire();
251   while (ec != nullptr) {
252     if (ec->match_exception_with_space(exception)) {
253       return ec;
254     }
255     ec = ec->next();
256   }
257   return nullptr;
258 }
259 
260 //-------------end of code for ExceptionCache--------------
261 
262 bool CompiledMethod::is_at_poll_return(address pc) {
263   RelocIterator iter(this, pc, pc+1);
264   while (iter.next()) {
265     if (iter.type() == relocInfo::poll_return_type)
266       return true;
267   }
268   return false;
269 }
270 
271 
272 bool CompiledMethod::is_at_poll_or_poll_return(address pc) {
273   RelocIterator iter(this, pc, pc+1);
274   while (iter.next()) {
275     relocInfo::relocType t = iter.type();
276     if (t == relocInfo::poll_return_type || t == relocInfo::poll_type)
277       return true;
278   }
279   return false;
280 }
281 
282 void CompiledMethod::verify_oop_relocations() {
283   // Ensure sure that the code matches the current oop values
284   RelocIterator iter(this, nullptr, nullptr);
285   while (iter.next()) {
286     if (iter.type() == relocInfo::oop_type) {
287       oop_Relocation* reloc = iter.oop_reloc();
288       if (!reloc->oop_is_immediate()) {
289         reloc->verify_oop_relocation();
290       }
291     }
292   }
293 }
294 
295 
296 ScopeDesc* CompiledMethod::scope_desc_at(address pc) {
297   PcDesc* pd = pc_desc_at(pc);
298   guarantee(pd != nullptr, "scope must be present");
299   return new ScopeDesc(this, pd);
300 }
301 
302 ScopeDesc* CompiledMethod::scope_desc_near(address pc) {
303   PcDesc* pd = pc_desc_near(pc);
304   guarantee(pd != nullptr, "scope must be present");
305   return new ScopeDesc(this, pd);
306 }
307 
308 address CompiledMethod::oops_reloc_begin() const {
309   // If the method is not entrant then a JMP is plastered over the
310   // first few bytes.  If an oop in the old code was there, that oop
311   // should not get GC'd.  Skip the first few bytes of oops on
312   // not-entrant methods.
313   if (frame_complete_offset() != CodeOffsets::frame_never_safe &&
314       code_begin() + frame_complete_offset() >
315       verified_entry_point() + NativeJump::instruction_size)
316   {
317     // If we have a frame_complete_offset after the native jump, then there
318     // is no point trying to look for oops before that. This is a requirement
319     // for being allowed to scan oops concurrently.
320     return code_begin() + frame_complete_offset();
321   }
322 
323   // It is not safe to read oops concurrently using entry barriers, if their
324   // location depend on whether the nmethod is entrant or not.
325   // assert(BarrierSet::barrier_set()->barrier_set_nmethod() == nullptr, "Not safe oop scan");
326 
327   address low_boundary = verified_entry_point();
328   if (!is_in_use() && is_nmethod()) {
329     low_boundary += NativeJump::instruction_size;
330     // %%% Note:  On SPARC we patch only a 4-byte trap, not a full NativeJump.
331     // This means that the low_boundary is going to be a little too high.
332     // This shouldn't matter, since oops of non-entrant methods are never used.
333     // In fact, why are we bothering to look at oops in a non-entrant method??
334   }
335   return low_boundary;
336 }
337 
338 // Method that knows how to preserve outgoing arguments at call. This method must be
339 // called with a frame corresponding to a Java invoke
340 void CompiledMethod::preserve_callee_argument_oops(frame fr, const RegisterMap *reg_map, OopClosure* f) {
341   if (method() == nullptr) {
342     return;
343   }
344 
345   // handle the case of an anchor explicitly set in continuation code that doesn't have a callee
346   JavaThread* thread = reg_map->thread();
347   if (thread->has_last_Java_frame() && fr.sp() == thread->last_Java_sp()) {
348     return;
349   }
350 
351   if (!method()->is_native()) {
352     address pc = fr.pc();
353     bool has_receiver, has_appendix;
354     Symbol* signature;
355 
356     // The method attached by JIT-compilers should be used, if present.
357     // Bytecode can be inaccurate in such case.
358     Method* callee = attached_method_before_pc(pc);
359     if (callee != nullptr) {
360       has_receiver = !(callee->access_flags().is_static());
361       has_appendix = false;
362       signature    = callee->signature();
363     } else {
364       SimpleScopeDesc ssd(this, pc);
365 
366       Bytecode_invoke call(methodHandle(Thread::current(), ssd.method()), ssd.bci());
367       has_receiver = call.has_receiver();
368       has_appendix = call.has_appendix();
369       signature    = call.signature();
370     }
371 
372     fr.oops_compiled_arguments_do(signature, has_receiver, has_appendix, reg_map, f);
373   } else if (method()->is_continuation_enter_intrinsic()) {
374     // This method only calls Continuation.enter()
375     Symbol* signature = vmSymbols::continuationEnter_signature();
376     fr.oops_compiled_arguments_do(signature, false, false, reg_map, f);
377   }
378 }
379 
380 Method* CompiledMethod::attached_method(address call_instr) {
381   assert(code_contains(call_instr), "not part of the nmethod");
382   RelocIterator iter(this, call_instr, call_instr + 1);
383   while (iter.next()) {
384     if (iter.addr() == call_instr) {
385       switch(iter.type()) {
386         case relocInfo::static_call_type:      return iter.static_call_reloc()->method_value();
387         case relocInfo::opt_virtual_call_type: return iter.opt_virtual_call_reloc()->method_value();
388         case relocInfo::virtual_call_type:     return iter.virtual_call_reloc()->method_value();
389         default:                               break;
390       }
391     }
392   }
393   return nullptr; // not found
394 }
395 
396 Method* CompiledMethod::attached_method_before_pc(address pc) {
397   if (NativeCall::is_call_before(pc)) {
398     NativeCall* ncall = nativeCall_before(pc);
399     return attached_method(ncall->instruction_address());
400   }
401   return nullptr; // not a call
402 }
403 
404 void CompiledMethod::clear_inline_caches() {
405   assert(SafepointSynchronize::is_at_safepoint(), "clearing of IC's only allowed at safepoint");
406   RelocIterator iter(this);
407   while (iter.next()) {
408     iter.reloc()->clear_inline_cache();
409   }
410 }
411 
412 #ifdef ASSERT
413 // Check class_loader is alive for this bit of metadata.
414 class CheckClass : public MetadataClosure {
415   void do_metadata(Metadata* md) {
416     Klass* klass = nullptr;
417     if (md->is_klass()) {
418       klass = ((Klass*)md);
419     } else if (md->is_method()) {
420       klass = ((Method*)md)->method_holder();
421     } else if (md->is_methodData()) {
422       klass = ((MethodData*)md)->method()->method_holder();
423     } else if (md->is_methodCounters()) {
424       klass = ((MethodCounters*)md)->method()->method_holder();
425     } else {
426       md->print();
427       ShouldNotReachHere();
428     }
429     assert(klass->is_loader_alive(), "must be alive");
430   }
431 };
432 #endif // ASSERT
433 
434 
435 static void clean_ic_if_metadata_is_dead(CompiledIC *ic) {
436   ic->clean_metadata();
437 }
438 
439 // Clean references to unloaded nmethods at addr from this one, which is not unloaded.
440 template <typename CallsiteT>
441 static void clean_if_nmethod_is_unloaded(CallsiteT* callsite, CompiledMethod* from,
442                                          bool clean_all) {
443   CodeBlob* cb = CodeCache::find_blob(callsite->destination());
444   if (!cb->is_compiled()) {
445     return;
446   }
447   CompiledMethod* cm = cb->as_compiled_method();
448   if (clean_all || !cm->is_in_use() || cm->is_unloading() || cm->method()->code() != cm) {
449     callsite->set_to_clean();
450   }
451 }
452 
453 // Cleans caches in nmethods that point to either classes that are unloaded
454 // or nmethods that are unloaded.
455 //
456 // Can be called either in parallel by G1 currently or after all
457 // nmethods are unloaded.  Return postponed=true in the parallel case for
458 // inline caches found that point to nmethods that are not yet visited during
459 // the do_unloading walk.
460 void CompiledMethod::unload_nmethod_caches(bool unloading_occurred) {
461   ResourceMark rm;
462 
463   // Exception cache only needs to be called if unloading occurred
464   if (unloading_occurred) {
465     clean_exception_cache();
466   }
467 
468   cleanup_inline_caches_impl(unloading_occurred, false);
469 
470 #ifdef ASSERT
471   // Check that the metadata embedded in the nmethod is alive
472   CheckClass check_class;
473   metadata_do(&check_class);
474 #endif
475 }
476 
477 void CompiledMethod::run_nmethod_entry_barrier() {
478   BarrierSetNMethod* bs_nm = BarrierSet::barrier_set()->barrier_set_nmethod();
479   if (bs_nm != nullptr) {
480     // We want to keep an invariant that nmethods found through iterations of a Thread's
481     // nmethods found in safepoints have gone through an entry barrier and are not armed.
482     // By calling this nmethod entry barrier, it plays along and acts
483     // like any other nmethod found on the stack of a thread (fewer surprises).
484     nmethod* nm = as_nmethod_or_null();
485     if (nm != nullptr && bs_nm->is_armed(nm)) {
486       bool alive = bs_nm->nmethod_entry_barrier(nm);
487       assert(alive, "should be alive");
488     }
489   }
490 }
491 
492 // Only called by whitebox test
493 void CompiledMethod::cleanup_inline_caches_whitebox() {
494   assert_locked_or_safepoint(CodeCache_lock);
495   CompiledICLocker ic_locker(this);
496   cleanup_inline_caches_impl(false /* unloading_occurred */, true /* clean_all */);
497 }
498 
499 address* CompiledMethod::orig_pc_addr(const frame* fr) {
500   return (address*) ((address)fr->unextended_sp() + orig_pc_offset());
501 }
502 
503 // Called to clean up after class unloading for live nmethods
504 void CompiledMethod::cleanup_inline_caches_impl(bool unloading_occurred, bool clean_all) {
505   assert(CompiledICLocker::is_safe(this), "mt unsafe call");
506   ResourceMark rm;
507 
508   // Find all calls in an nmethod and clear the ones that point to bad nmethods.
509   RelocIterator iter(this, oops_reloc_begin());
510   bool is_in_static_stub = false;
511   while(iter.next()) {
512 
513     switch (iter.type()) {
514 
515     case relocInfo::virtual_call_type:
516       if (unloading_occurred) {
517         // If class unloading occurred we first clear ICs where the cached metadata
518         // is referring to an unloaded klass or method.
519         clean_ic_if_metadata_is_dead(CompiledIC_at(&iter));
520       }
521 
522       clean_if_nmethod_is_unloaded(CompiledIC_at(&iter), this, clean_all);
523       break;
524 
525     case relocInfo::opt_virtual_call_type:
526     case relocInfo::static_call_type:
527       clean_if_nmethod_is_unloaded(CompiledDirectCall::at(iter.reloc()), this, clean_all);
528       break;
529 
530     case relocInfo::static_stub_type: {
531       is_in_static_stub = true;
532       break;
533     }
534 
535     case relocInfo::metadata_type: {
536       // Only the metadata relocations contained in static/opt virtual call stubs
537       // contains the Method* passed to c2i adapters. It is the only metadata
538       // relocation that needs to be walked, as it is the one metadata relocation
539       // that violates the invariant that all metadata relocations have an oop
540       // in the compiled method (due to deferred resolution and code patching).
541 
542       // This causes dead metadata to remain in compiled methods that are not
543       // unloading. Unless these slippery metadata relocations of the static
544       // stubs are at least cleared, subsequent class redefinition operations
545       // will access potentially free memory, and JavaThread execution
546       // concurrent to class unloading may call c2i adapters with dead methods.
547       if (!is_in_static_stub) {
548         // The first metadata relocation after a static stub relocation is the
549         // metadata relocation of the static stub used to pass the Method* to
550         // c2i adapters.
551         continue;
552       }
553       is_in_static_stub = false;
554       if (is_unloading()) {
555         // If the nmethod itself is dying, then it may point at dead metadata.
556         // Nobody should follow that metadata; it is strictly unsafe.
557         continue;
558       }
559       metadata_Relocation* r = iter.metadata_reloc();
560       Metadata* md = r->metadata_value();
561       if (md != nullptr && md->is_method()) {
562         Method* method = static_cast<Method*>(md);
563         if (!method->method_holder()->is_loader_alive()) {
564           Atomic::store(r->metadata_addr(), (Method*)nullptr);
565 
566           if (!r->metadata_is_immediate()) {
567             r->fix_metadata_relocation();
568           }
569         }
570       }
571       break;
572     }
573 
574     default:
575       break;
576     }
577   }
578 }
579 
580 address CompiledMethod::continuation_for_implicit_exception(address pc, bool for_div0_check) {
581   // Exception happened outside inline-cache check code => we are inside
582   // an active nmethod => use cpc to determine a return address
583   int exception_offset = int(pc - code_begin());
584   int cont_offset = ImplicitExceptionTable(this).continuation_offset( exception_offset );
585 #ifdef ASSERT
586   if (cont_offset == 0) {
587     Thread* thread = Thread::current();
588     ResourceMark rm(thread);
589     CodeBlob* cb = CodeCache::find_blob(pc);
590     assert(cb != nullptr && cb == this, "");
591 
592     // Keep tty output consistent. To avoid ttyLocker, we buffer in stream, and print all at once.
593     stringStream ss;
594     ss.print_cr("implicit exception happened at " INTPTR_FORMAT, p2i(pc));
595     print_on(&ss);
596     method()->print_codes_on(&ss);
597     print_code_on(&ss);
598     print_pcs_on(&ss);
599     tty->print("%s", ss.as_string()); // print all at once
600   }
601 #endif
602   if (cont_offset == 0) {
603     // Let the normal error handling report the exception
604     return nullptr;
605   }
606   if (cont_offset == exception_offset) {
607 #if INCLUDE_JVMCI
608     Deoptimization::DeoptReason deopt_reason = for_div0_check ? Deoptimization::Reason_div0_check : Deoptimization::Reason_null_check;
609     JavaThread *thread = JavaThread::current();
610     thread->set_jvmci_implicit_exception_pc(pc);
611     thread->set_pending_deoptimization(Deoptimization::make_trap_request(deopt_reason,
612                                                                          Deoptimization::Action_reinterpret));
613     return (SharedRuntime::deopt_blob()->implicit_exception_uncommon_trap());
614 #else
615     ShouldNotReachHere();
616 #endif
617   }
618   return code_begin() + cont_offset;
619 }
620 
621 class HasEvolDependency : public MetadataClosure {
622   bool _has_evol_dependency;
623  public:
624   HasEvolDependency() : _has_evol_dependency(false) {}
625   void do_metadata(Metadata* md) {
626     if (md->is_method()) {
627       Method* method = (Method*)md;
628       if (method->is_old()) {
629         _has_evol_dependency = true;
630       }
631     }
632   }
633   bool has_evol_dependency() const { return _has_evol_dependency; }
634 };
635 
636 bool CompiledMethod::has_evol_metadata() {
637   // Check the metadata in relocIter and CompiledIC and also deoptimize
638   // any nmethod that has reference to old methods.
639   HasEvolDependency check_evol;
640   metadata_do(&check_evol);
641   if (check_evol.has_evol_dependency() && log_is_enabled(Debug, redefine, class, nmethod)) {
642     ResourceMark rm;
643     log_debug(redefine, class, nmethod)
644             ("Found evol dependency of nmethod %s.%s(%s) compile_id=%d on in nmethod metadata",
645              _method->method_holder()->external_name(),
646              _method->name()->as_C_string(),
647              _method->signature()->as_C_string(),
648              compile_id());
649   }
650   return check_evol.has_evol_dependency();
651 }