< prev index next >

src/hotspot/share/gc/shenandoah/shenandoahNMethod.cpp

Print this page
rev 58076 : 8237780: Shenandoah: More reliable nmethod verification


 220   }
 221   void do_oop(narrowOop* o) {
 222     fatal("NMethods should not have compressed oops embedded.");
 223   }
 224 
 225   GrowableArray<oop*>* oops() {
 226     return &_oops;
 227   }
 228 
 229   bool has_oops() {
 230     return !_oops.is_empty();
 231   }
 232 };
 233 
 234 void ShenandoahNMethod::assert_same_oops(bool allow_dead) {
 235   ShenandoahNMethodOopDetector detector;
 236   nm()->oops_do(&detector, allow_dead);
 237 
 238   GrowableArray<oop*>* oops = detector.oops();
 239 
 240   assert(oops->length() == oop_count(), "Must match");
 241 
 242   for (int index = 0; index < _oops_count; index ++) {
 243     assert(oops->contains(_oops[index]), "Must contain this oop");
 244   }
 245 
 246   for (oop* p = nm()->oops_begin(); p < nm()->oops_end(); p ++) {


 247     assert(oops->contains(p), "Must contain this oop");
 248   }





















 249 }
 250 
 251 void ShenandoahNMethod::assert_no_oops(nmethod* nm, bool allow_dead) {
 252   ShenandoahNMethodOopDetector detector;
 253   nm->oops_do(&detector, allow_dead);
 254   assert(detector.oops()->length() == 0, "Should not have oops");
 255 }
 256 #endif
 257 
 258 ShenandoahNMethodTable::ShenandoahNMethodTable() :
 259   _heap(ShenandoahHeap::heap()),
 260   _size(minSize),
 261   _index(0),
 262   _iteration_in_progress(false) {
 263   _array = NEW_C_HEAP_ARRAY(ShenandoahNMethod*, _size, mtGC);
 264 }
 265 
 266 ShenandoahNMethodTable::~ShenandoahNMethodTable() {
 267   assert(_array != NULL, "Sanity");
 268   FREE_C_HEAP_ARRAY(ShenandoahNMethod*, _array);
 269 }
 270 
 271 void ShenandoahNMethodTable::register_nmethod(nmethod* nm) {
 272   assert(CodeCache_lock->owned_by_self(), "Must have CodeCache_lock held");
 273   assert(_index >= 0 && _index <= _size, "Sanity");
 274 
 275   ShenandoahNMethod* data = ShenandoahNMethod::gc_data(nm);
 276   ShenandoahReentrantLocker data_locker(data != NULL ? data->lock() : NULL);
 277 
 278   if (data != NULL) {
 279     assert(contain(nm), "Must have been registered");

 280     data->update();
 281   } else {
 282     data = ShenandoahNMethod::for_nmethod(nm);
 283     if (data == NULL) {
 284       assert(!ShenandoahConcurrentRoots::can_do_concurrent_class_unloading(),
 285              "Only possible when concurrent class unloading is off");
 286       return;
 287     }
 288     ShenandoahNMethod::attach_gc_data(nm, data);
 289     ShenandoahLocker locker(&_lock);
 290     log_register_nmethod(nm);
 291     append(data);
 292   }
 293   // Disarm new nmethod
 294   ShenandoahNMethod::disarm_nmethod(nm);
 295 }
 296 
 297 void ShenandoahNMethodTable::unregister_nmethod(nmethod* nm) {
 298   assert_locked_or_safepoint(CodeCache_lock);
 299 




 220   }
 221   void do_oop(narrowOop* o) {
 222     fatal("NMethods should not have compressed oops embedded.");
 223   }
 224 
 225   GrowableArray<oop*>* oops() {
 226     return &_oops;
 227   }
 228 
 229   bool has_oops() {
 230     return !_oops.is_empty();
 231   }
 232 };
 233 
 234 void ShenandoahNMethod::assert_same_oops(bool allow_dead) {
 235   ShenandoahNMethodOopDetector detector;
 236   nm()->oops_do(&detector, allow_dead);
 237 
 238   GrowableArray<oop*>* oops = detector.oops();
 239 
 240   int count = _oops_count;

 241   for (int index = 0; index < _oops_count; index ++) {
 242     assert(oops->contains(_oops[index]), "Must contain this oop");
 243   }
 244 
 245   for (oop* p = nm()->oops_begin(); p < nm()->oops_end(); p ++) {
 246     if (*p == Universe::non_oop_word()) continue;
 247     count++;
 248     assert(oops->contains(p), "Must contain this oop");
 249   }
 250 
 251 #ifdef ASSERT
 252   if (oops->length() < count) {
 253     tty->print_cr("detected locs: %d", oops->length());
 254     for (int i = 0; i < oops->length(); i++) {
 255       tty->print_cr("-> " PTR_FORMAT, p2i(oops->at(i)));
 256     }
 257     tty->print_cr("recorded oops: %d", _oops_count);
 258     for (int i = 0; i < _oops_count; i++) {
 259       tty->print_cr("-> " PTR_FORMAT, p2i(_oops[i]));
 260     }
 261     GrowableArray<oop*> check;
 262     bool non_immed;
 263     detect_reloc_oops(nm(), check, non_immed);
 264     tty->print_cr("check oops: %d", check.length());
 265     for (int i = 0; i < check.length(); i++) {
 266       tty->print_cr("-> " PTR_FORMAT, p2i(check.at(i)));
 267     }
 268     fatal("Must match #detected: %d, #recorded: %d, #total: %d, begin: " PTR_FORMAT ", end: " PTR_FORMAT, oops->length(), _oops_count, count, p2i(nm()->oops_begin()), p2i(nm()->oops_end()));
 269   }
 270 #endif
 271 }
 272 
 273 void ShenandoahNMethod::assert_no_oops(nmethod* nm, bool allow_dead) {
 274   ShenandoahNMethodOopDetector detector;
 275   nm->oops_do(&detector, allow_dead);
 276   assert(detector.oops()->length() == 0, "Should not have oops");
 277 }
 278 #endif
 279 
 280 ShenandoahNMethodTable::ShenandoahNMethodTable() :
 281   _heap(ShenandoahHeap::heap()),
 282   _size(minSize),
 283   _index(0),
 284   _iteration_in_progress(false) {
 285   _array = NEW_C_HEAP_ARRAY(ShenandoahNMethod*, _size, mtGC);
 286 }
 287 
 288 ShenandoahNMethodTable::~ShenandoahNMethodTable() {
 289   assert(_array != NULL, "Sanity");
 290   FREE_C_HEAP_ARRAY(ShenandoahNMethod*, _array);
 291 }
 292 
 293 void ShenandoahNMethodTable::register_nmethod(nmethod* nm) {
 294   assert(CodeCache_lock->owned_by_self(), "Must have CodeCache_lock held");
 295   assert(_index >= 0 && _index <= _size, "Sanity");
 296 
 297   ShenandoahNMethod* data = ShenandoahNMethod::gc_data(nm);
 298   ShenandoahReentrantLocker data_locker(data != NULL ? data->lock() : NULL);
 299 
 300   if (data != NULL) {
 301     assert(contain(nm), "Must have been registered");
 302     assert(nm == data->nm(), "Must be same nmethod");
 303     data->update();
 304   } else {
 305     data = ShenandoahNMethod::for_nmethod(nm);
 306     if (data == NULL) {
 307       assert(!ShenandoahConcurrentRoots::can_do_concurrent_class_unloading(),
 308              "Only possible when concurrent class unloading is off");
 309       return;
 310     }
 311     ShenandoahNMethod::attach_gc_data(nm, data);
 312     ShenandoahLocker locker(&_lock);
 313     log_register_nmethod(nm);
 314     append(data);
 315   }
 316   // Disarm new nmethod
 317   ShenandoahNMethod::disarm_nmethod(nm);
 318 }
 319 
 320 void ShenandoahNMethodTable::unregister_nmethod(nmethod* nm) {
 321   assert_locked_or_safepoint(CodeCache_lock);
 322 


< prev index next >