138 ShouldNotReachHere();
139 }
140 }
141
142 void ShenandoahCodeRoots::flush_nmethod(nmethod* nm) {
143 switch (ShenandoahCodeRootsStyle) {
144 case 0:
145 case 1: {
146 break;
147 }
148 case 2: {
149 assert_locked_or_safepoint(CodeCache_lock);
150 _nmethod_table->flush_nmethod(nm);
151 break;
152 }
153 default:
154 ShouldNotReachHere();
155 }
156 }
157
158 void ShenandoahCodeRoots::prepare_concurrent_unloading() {
159 assert(SafepointSynchronize::is_at_safepoint(), "Must be at a safepoint");
160 _disarmed_value ++;
161 // 0 is reserved for new nmethod
162 if (_disarmed_value == 0) {
163 _disarmed_value = 1;
164 }
165
166 JavaThreadIteratorWithHandle jtiwh;
167 for (JavaThread *thr = jtiwh.next(); thr != NULL; thr = jtiwh.next()) {
168 ShenandoahThreadLocalData::set_disarmed_value(thr, _disarmed_value);
169 }
170 }
171
172 class ShenandoahNMethodUnlinkClosure : public NMethodClosure {
173 private:
174 bool _unloading_occurred;
175 volatile bool _failed;
176 ShenandoahHeap* _heap;
177
178 void set_failed() {
207 }
208
209 ShenandoahNMethod* nm_data = ShenandoahNMethod::gc_data(nm);
210 assert(!nm_data->is_unregistered(), "Should not see unregistered entry");
211
212 if (!nm->is_alive()) {
213 return;
214 }
215
216 if (nm->is_unloading()) {
217 ShenandoahReentrantLocker locker(nm_data->lock());
218 ShenandoahEvacOOMScope evac_scope;
219 unlink(nm);
220 return;
221 }
222
223 ShenandoahReentrantLocker locker(nm_data->lock());
224
225 // Heal oops and disarm
226 ShenandoahEvacOOMScope evac_scope;
227 ShenandoahNMethod::heal_nmethod(nm);
228 ShenandoahNMethod::disarm_nmethod(nm);
229
230 // Clear compiled ICs and exception caches
231 if (!nm->unload_nmethod_caches(_unloading_occurred)) {
232 set_failed();
233 }
234 }
235
236 bool failed() const {
237 return Atomic::load(&_failed);
238 }
239 };
240
241 class ShenandoahUnlinkTask : public AbstractGangTask {
242 private:
243 ShenandoahNMethodUnlinkClosure _cl;
244 ICRefillVerifier* _verifier;
245 ShenandoahConcurrentNMethodIterator _iterator;
246
247 public:
|
138 ShouldNotReachHere();
139 }
140 }
141
142 void ShenandoahCodeRoots::flush_nmethod(nmethod* nm) {
143 switch (ShenandoahCodeRootsStyle) {
144 case 0:
145 case 1: {
146 break;
147 }
148 case 2: {
149 assert_locked_or_safepoint(CodeCache_lock);
150 _nmethod_table->flush_nmethod(nm);
151 break;
152 }
153 default:
154 ShouldNotReachHere();
155 }
156 }
157
158 void ShenandoahCodeRoots::arm_nmethods() {
159 assert(SafepointSynchronize::is_at_safepoint(), "Must be at a safepoint");
160 _disarmed_value ++;
161 // 0 is reserved for new nmethod
162 if (_disarmed_value == 0) {
163 _disarmed_value = 1;
164 }
165
166 JavaThreadIteratorWithHandle jtiwh;
167 for (JavaThread *thr = jtiwh.next(); thr != NULL; thr = jtiwh.next()) {
168 ShenandoahThreadLocalData::set_disarmed_value(thr, _disarmed_value);
169 }
170 }
171
172 class ShenandoahNMethodUnlinkClosure : public NMethodClosure {
173 private:
174 bool _unloading_occurred;
175 volatile bool _failed;
176 ShenandoahHeap* _heap;
177
178 void set_failed() {
207 }
208
209 ShenandoahNMethod* nm_data = ShenandoahNMethod::gc_data(nm);
210 assert(!nm_data->is_unregistered(), "Should not see unregistered entry");
211
212 if (!nm->is_alive()) {
213 return;
214 }
215
216 if (nm->is_unloading()) {
217 ShenandoahReentrantLocker locker(nm_data->lock());
218 ShenandoahEvacOOMScope evac_scope;
219 unlink(nm);
220 return;
221 }
222
223 ShenandoahReentrantLocker locker(nm_data->lock());
224
225 // Heal oops and disarm
226 ShenandoahEvacOOMScope evac_scope;
227 if (_heap->is_evacuation_in_progress()) {
228 ShenandoahNMethod::heal_nmethod(nm);
229 }
230 ShenandoahNMethod::disarm_nmethod(nm);
231
232 // Clear compiled ICs and exception caches
233 if (!nm->unload_nmethod_caches(_unloading_occurred)) {
234 set_failed();
235 }
236 }
237
238 bool failed() const {
239 return Atomic::load(&_failed);
240 }
241 };
242
243 class ShenandoahUnlinkTask : public AbstractGangTask {
244 private:
245 ShenandoahNMethodUnlinkClosure _cl;
246 ICRefillVerifier* _verifier;
247 ShenandoahConcurrentNMethodIterator _iterator;
248
249 public:
|