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


< prev index next >