1104 }
1105 // Unlink the osr method, so we do not look this up again
1106 if (is_osr_method()) {
1107 // Invalidate the osr nmethod only once
1108 if (is_in_use()) {
1109 invalidate_osr_method();
1110 }
1111 #ifdef ASSERT
1112 if (method() != NULL) {
1113 // Make sure osr nmethod is invalidated, i.e. not on the list
1114 bool found = method()->method_holder()->remove_osr_nmethod(this);
1115 assert(!found, "osr nmethod should have been invalidated");
1116 }
1117 #endif
1118 }
1119
1120 // If _method is already NULL the Method* is about to be unloaded,
1121 // so we don't have to break the cycle. Note that it is possible to
1122 // have the Method* live here, in case we unload the nmethod because
1123 // it is pointing to some oop (other than the Method*) being unloaded.
1124 Method::unlink_code(_method, this); // Break a cycle
1125
1126 // Make the class unloaded - i.e., change state and notify sweeper
1127 assert(SafepointSynchronize::is_at_safepoint() || Thread::current()->is_ConcurrentGC_thread(),
1128 "must be at safepoint");
1129
1130 {
1131 // Clear ICStubs and release any CompiledICHolders.
1132 CompiledICLocker ml(this);
1133 clear_ic_callsites();
1134 }
1135
1136 // Unregister must be done before the state change
1137 {
1138 MutexLocker ml(SafepointSynchronize::is_at_safepoint() ? NULL : CodeCache_lock,
1139 Mutex::_no_safepoint_check_flag);
1140 Universe::heap()->unregister_nmethod(this);
1141 CodeCache::unregister_old_nmethod(this);
1142 }
1143
1144 // Clear the method of this dead nmethod
1187 os::current_thread_id());
1188 } else {
1189 xtty->begin_elem("make_not_entrant thread='" UINTX_FORMAT "'%s",
1190 os::current_thread_id(),
1191 (_state == zombie ? " zombie='1'" : ""));
1192 }
1193 log_identity(xtty);
1194 xtty->stamp();
1195 xtty->end_elem();
1196 }
1197 }
1198
1199 const char *state_msg = _state == zombie ? "made zombie" : "made not entrant";
1200 CompileTask::print_ul(this, state_msg);
1201 if (PrintCompilation && _state != unloaded) {
1202 print_on(tty, state_msg);
1203 }
1204 }
1205
1206 void nmethod::unlink_from_method() {
1207 // We need to check if both the _code and _from_compiled_code_entry_point
1208 // refer to this nmethod because there is a race in setting these two fields
1209 // in Method* as seen in bugid 4947125.
1210 // If the vep() points to the zombie nmethod, the memory for the nmethod
1211 // could be flushed and the compiler and vtable stubs could still call
1212 // through it.
1213 Method::unlink_code(method(), this);
1214 }
1215
1216 /**
1217 * Common functionality for both make_not_entrant and make_zombie
1218 */
1219 bool nmethod::make_not_entrant_or_zombie(int state) {
1220 assert(state == zombie || state == not_entrant, "must be zombie or not_entrant");
1221 assert(!is_zombie(), "should not already be a zombie");
1222
1223 if (_state == state) {
1224 // Avoid taking the lock if already in required state.
1225 // This is safe from races because the state is an end-state,
1226 // which the nmethod cannot back out of once entered.
1227 // No need for fencing either.
1228 return false;
1229 }
1230
1231 // Make sure neither the nmethod nor the method is flushed in case of a safepoint in code below.
1232 nmethodLocker nml(this);
1233 methodHandle the_method(method());
|
1104 }
1105 // Unlink the osr method, so we do not look this up again
1106 if (is_osr_method()) {
1107 // Invalidate the osr nmethod only once
1108 if (is_in_use()) {
1109 invalidate_osr_method();
1110 }
1111 #ifdef ASSERT
1112 if (method() != NULL) {
1113 // Make sure osr nmethod is invalidated, i.e. not on the list
1114 bool found = method()->method_holder()->remove_osr_nmethod(this);
1115 assert(!found, "osr nmethod should have been invalidated");
1116 }
1117 #endif
1118 }
1119
1120 // If _method is already NULL the Method* is about to be unloaded,
1121 // so we don't have to break the cycle. Note that it is possible to
1122 // have the Method* live here, in case we unload the nmethod because
1123 // it is pointing to some oop (other than the Method*) being unloaded.
1124 if (_method != NULL) {
1125 _method->unlink_code(this);
1126 }
1127
1128 // Make the class unloaded - i.e., change state and notify sweeper
1129 assert(SafepointSynchronize::is_at_safepoint() || Thread::current()->is_ConcurrentGC_thread(),
1130 "must be at safepoint");
1131
1132 {
1133 // Clear ICStubs and release any CompiledICHolders.
1134 CompiledICLocker ml(this);
1135 clear_ic_callsites();
1136 }
1137
1138 // Unregister must be done before the state change
1139 {
1140 MutexLocker ml(SafepointSynchronize::is_at_safepoint() ? NULL : CodeCache_lock,
1141 Mutex::_no_safepoint_check_flag);
1142 Universe::heap()->unregister_nmethod(this);
1143 CodeCache::unregister_old_nmethod(this);
1144 }
1145
1146 // Clear the method of this dead nmethod
1189 os::current_thread_id());
1190 } else {
1191 xtty->begin_elem("make_not_entrant thread='" UINTX_FORMAT "'%s",
1192 os::current_thread_id(),
1193 (_state == zombie ? " zombie='1'" : ""));
1194 }
1195 log_identity(xtty);
1196 xtty->stamp();
1197 xtty->end_elem();
1198 }
1199 }
1200
1201 const char *state_msg = _state == zombie ? "made zombie" : "made not entrant";
1202 CompileTask::print_ul(this, state_msg);
1203 if (PrintCompilation && _state != unloaded) {
1204 print_on(tty, state_msg);
1205 }
1206 }
1207
1208 void nmethod::unlink_from_method() {
1209 if (method() != NULL) {
1210 method()->unlink_code();
1211 }
1212 }
1213
1214 /**
1215 * Common functionality for both make_not_entrant and make_zombie
1216 */
1217 bool nmethod::make_not_entrant_or_zombie(int state) {
1218 assert(state == zombie || state == not_entrant, "must be zombie or not_entrant");
1219 assert(!is_zombie(), "should not already be a zombie");
1220
1221 if (_state == state) {
1222 // Avoid taking the lock if already in required state.
1223 // This is safe from races because the state is an end-state,
1224 // which the nmethod cannot back out of once entered.
1225 // No need for fencing either.
1226 return false;
1227 }
1228
1229 // Make sure neither the nmethod nor the method is flushed in case of a safepoint in code below.
1230 nmethodLocker nml(this);
1231 methodHandle the_method(method());
|