src/hotspot/share/code/nmethod.cpp
changeset 52661 4f45c682eab0
parent 52659 8b26bd8b1832
child 52781 436097b038a1
equal deleted inserted replaced
52660:9cb53c505acd 52661:4f45c682eab0
  1017 
  1017 
  1018 // Tell if a non-entrant method can be converted to a zombie (i.e.,
  1018 // Tell if a non-entrant method can be converted to a zombie (i.e.,
  1019 // there are no activations on the stack, not in use by the VM,
  1019 // there are no activations on the stack, not in use by the VM,
  1020 // and not in use by the ServiceThread)
  1020 // and not in use by the ServiceThread)
  1021 bool nmethod::can_convert_to_zombie() {
  1021 bool nmethod::can_convert_to_zombie() {
  1022   assert(is_not_entrant(), "must be a non-entrant method");
  1022   // Note that this is called when the sweeper has observed the nmethod to be
       
  1023   // not_entrant. However, with concurrent code cache unloading, the state
       
  1024   // might have moved on to unloaded if it is_unloading(), due to racing
       
  1025   // concurrent GC threads.
       
  1026   assert(is_not_entrant() || is_unloading(), "must be a non-entrant method");
  1023 
  1027 
  1024   // Since the nmethod sweeper only does partial sweep the sweeper's traversal
  1028   // Since the nmethod sweeper only does partial sweep the sweeper's traversal
  1025   // count can be greater than the stack traversal count before it hits the
  1029   // count can be greater than the stack traversal count before it hits the
  1026   // nmethod for the second time.
  1030   // nmethod for the second time.
  1027   return stack_traversal_mark()+1 < NMethodSweeper::traversal_count() &&
  1031   // If an is_unloading() nmethod is still not_entrant, then it is not safe to
  1028          !is_locked_by_vm();
  1032   // convert it to zombie due to GC unloading interactions. However, if it
       
  1033   // has become unloaded, then it is okay to convert such nmethods to zombie.
       
  1034   return stack_traversal_mark() + 1 < NMethodSweeper::traversal_count() &&
       
  1035          !is_locked_by_vm() && (!is_unloading() || is_unloaded());
  1029 }
  1036 }
  1030 
  1037 
  1031 void nmethod::inc_decompile_count() {
  1038 void nmethod::inc_decompile_count() {
  1032   if (!is_compiled_by_c2() && !is_compiled_by_jvmci()) return;
  1039   if (!is_compiled_by_c2() && !is_compiled_by_jvmci()) return;
  1033   // Could be gated by ProfileTraps, but do not bother...
  1040   // Could be gated by ProfileTraps, but do not bother...
  1091   assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
  1098   assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
  1092 
  1099 
  1093   // Unregister must be done before the state change
  1100   // Unregister must be done before the state change
  1094   Universe::heap()->unregister_nmethod(this);
  1101   Universe::heap()->unregister_nmethod(this);
  1095 
  1102 
  1096   _state = unloaded;
       
  1097 
       
  1098   // Log the unloading.
  1103   // Log the unloading.
  1099   log_state_change();
  1104   log_state_change();
  1100 
  1105 
  1101 #if INCLUDE_JVMCI
  1106 #if INCLUDE_JVMCI
  1102   // The method can only be unloaded after the pointer to the installed code
  1107   // The method can only be unloaded after the pointer to the installed code
  1108   // The Method* is gone at this point
  1113   // The Method* is gone at this point
  1109   assert(_method == NULL, "Tautology");
  1114   assert(_method == NULL, "Tautology");
  1110 
  1115 
  1111   set_osr_link(NULL);
  1116   set_osr_link(NULL);
  1112   NMethodSweeper::report_state_change(this);
  1117   NMethodSweeper::report_state_change(this);
       
  1118 
       
  1119   // The release is only needed for compile-time ordering, as accesses
       
  1120   // into the nmethod after the store are not safe due to the sweeper
       
  1121   // being allowed to free it when the store is observed, during
       
  1122   // concurrent nmethod unloading. Therefore, there is no need for
       
  1123   // acquire on the loader side.
       
  1124   OrderAccess::release_store(&_state, (signed char)unloaded);
  1113 }
  1125 }
  1114 
  1126 
  1115 void nmethod::invalidate_osr_method() {
  1127 void nmethod::invalidate_osr_method() {
  1116   assert(_entry_bci != InvocationEntryBci, "wrong kind of nmethod");
  1128   assert(_entry_bci != InvocationEntryBci, "wrong kind of nmethod");
  1117   // Remove from list of active nmethods
  1129   // Remove from list of active nmethods
  1911 
  1923 
  1912   DepTable* table = new DepTable();
  1924   DepTable* table = new DepTable();
  1913 
  1925 
  1914   // Iterate over live nmethods and check dependencies of all nmethods that are not
  1926   // Iterate over live nmethods and check dependencies of all nmethods that are not
  1915   // marked for deoptimization. A particular dependency is only checked once.
  1927   // marked for deoptimization. A particular dependency is only checked once.
  1916   NMethodIterator iter;
  1928   NMethodIterator iter(NMethodIterator::only_alive_and_not_unloading);
  1917   while(iter.next()) {
  1929   while(iter.next()) {
  1918     nmethod* nm = iter.method();
  1930     nmethod* nm = iter.method();
  1919     // Only notify for live nmethods
  1931     // Only notify for live nmethods
  1920     if (nm->is_alive() && !nm->is_marked_for_deoptimization()) {
  1932     if (!nm->is_marked_for_deoptimization()) {
  1921       for (Dependencies::DepStream deps(nm); deps.next(); ) {
  1933       for (Dependencies::DepStream deps(nm); deps.next(); ) {
  1922         // Construct abstraction of a dependency.
  1934         // Construct abstraction of a dependency.
  1923         DependencySignature* current_sig = new DependencySignature(deps);
  1935         DependencySignature* current_sig = new DependencySignature(deps);
  1924 
  1936 
  1925         // Determine if dependency is already checked. table->put(...) returns
  1937         // Determine if dependency is already checked. table->put(...) returns
  2910   oop installed_code = JNIHandles::resolve(_jvmci_installed_code);
  2922   oop installed_code = JNIHandles::resolve(_jvmci_installed_code);
  2911   if (installed_code != NULL) {
  2923   if (installed_code != NULL) {
  2912     // Update the values in the InstalledCode instance if it still refers to this nmethod
  2924     // Update the values in the InstalledCode instance if it still refers to this nmethod
  2913     nmethod* nm = (nmethod*)InstalledCode::address(installed_code);
  2925     nmethod* nm = (nmethod*)InstalledCode::address(installed_code);
  2914     if (nm == this) {
  2926     if (nm == this) {
  2915       if (!is_alive()) {
  2927       if (!is_alive() || is_unloading()) {
  2916         // Break the link between nmethod and InstalledCode such that the nmethod
  2928         // Break the link between nmethod and InstalledCode such that the nmethod
  2917         // can subsequently be flushed safely.  The link must be maintained while
  2929         // can subsequently be flushed safely.  The link must be maintained while
  2918         // the method could have live activations since invalidateInstalledCode
  2930         // the method could have live activations since invalidateInstalledCode
  2919         // might want to invalidate all existing activations.
  2931         // might want to invalidate all existing activations.
  2920         InstalledCode::set_address(installed_code, 0);
  2932         InstalledCode::set_address(installed_code, 0);
  2925         // be invalidated.
  2937         // be invalidated.
  2926         InstalledCode::set_entryPoint(installed_code, 0);
  2938         InstalledCode::set_entryPoint(installed_code, 0);
  2927       }
  2939       }
  2928     }
  2940     }
  2929   }
  2941   }
  2930   if (!is_alive()) {
  2942   if (!is_alive() || is_unloading()) {
  2931     // Clear these out after the nmethod has been unregistered and any
  2943     // Clear these out after the nmethod has been unregistered and any
  2932     // updates to the InstalledCode instance have been performed.
  2944     // updates to the InstalledCode instance have been performed.
  2933     clear_jvmci_installed_code();
  2945     clear_jvmci_installed_code();
  2934     clear_speculation_log();
  2946     clear_speculation_log();
  2935   }
  2947   }
  2949   nmethodLocker nml(nm);
  2961   nmethodLocker nml(nm);
  2950 #ifdef ASSERT
  2962 #ifdef ASSERT
  2951   {
  2963   {
  2952     MutexLockerEx pl(Patching_lock, Mutex::_no_safepoint_check_flag);
  2964     MutexLockerEx pl(Patching_lock, Mutex::_no_safepoint_check_flag);
  2953     // This relationship can only be checked safely under a lock
  2965     // This relationship can only be checked safely under a lock
  2954     assert(!nm->is_alive() || nm->jvmci_installed_code() == installedCode(), "sanity check");
  2966     assert(!nm->is_alive() || nm->is_unloading() || nm->jvmci_installed_code() == installedCode(), "sanity check");
  2955   }
  2967   }
  2956 #endif
  2968 #endif
  2957 
  2969 
  2958   if (nm->is_alive()) {
  2970   if (nm->is_alive()) {
  2959     // Invalidating the InstalledCode means we want the nmethod
  2971     // Invalidating the InstalledCode means we want the nmethod