< prev index next >

src/share/vm/gc_implementation/g1/g1CodeCacheRemSet.cpp

Print this page




 335   if (_table != NULL) {
 336     int removed = _table->remove_if(should_clean);
 337     assert((size_t)removed <= _length, "impossible");
 338     _length -= removed;
 339   }
 340   if (_length == 0) {
 341     clear();
 342   }
 343 }
 344 
 345 #ifndef PRODUCT
 346 
 347 class G1CodeRootSetTest {
 348  public:
 349   static void test() {
 350     {
 351       G1CodeRootSet set1;
 352       assert(set1.is_empty(), "Code root set must be initially empty but is not.");
 353 
 354       assert(G1CodeRootSet::static_mem_size() == sizeof(void*),
 355           err_msg("The code root set's static memory usage is incorrect, "SIZE_FORMAT" bytes", G1CodeRootSet::static_mem_size()));
 356 
 357       set1.add((nmethod*)1);
 358       assert(set1.length() == 1, err_msg("Added exactly one element, but set contains "
 359           SIZE_FORMAT" elements", set1.length()));
 360 
 361       const size_t num_to_add = (size_t)G1CodeRootSet::Threshold + 1;
 362 
 363       for (size_t i = 1; i <= num_to_add; i++) {
 364         set1.add((nmethod*)1);
 365       }
 366       assert(set1.length() == 1,
 367           err_msg("Duplicate detection should not have increased the set size but "
 368               "is "SIZE_FORMAT, set1.length()));
 369 
 370       for (size_t i = 2; i <= num_to_add; i++) {
 371         set1.add((nmethod*)(uintptr_t)(i));
 372       }
 373       assert(set1.length() == num_to_add,
 374           err_msg("After adding in total "SIZE_FORMAT" distinct code roots, they "
 375               "need to be in the set, but there are only "SIZE_FORMAT,
 376               num_to_add, set1.length()));
 377 
 378       assert(CodeRootSetTable::_purge_list != NULL, "should have grown to large hashtable");
 379 
 380       size_t num_popped = 0;
 381       for (size_t i = 1; i <= num_to_add; i++) {
 382         bool removed = set1.remove((nmethod*)i);
 383         if (removed) {
 384           num_popped += 1;
 385         } else {
 386           break;
 387         }
 388       }
 389       assert(num_popped == num_to_add,
 390           err_msg("Managed to pop "SIZE_FORMAT" code roots, but only "SIZE_FORMAT" "
 391               "were added", num_popped, num_to_add));
 392       assert(CodeRootSetTable::_purge_list != NULL, "should have grown to large hashtable");
 393 
 394       G1CodeRootSet::purge();
 395 
 396       assert(CodeRootSetTable::_purge_list == NULL, "should have purged old small tables");
 397 
 398     }
 399 
 400   }
 401 };
 402 
 403 void TestCodeCacheRemSet_test() {
 404   G1CodeRootSetTest::test();
 405 }
 406 
 407 #endif


 335   if (_table != NULL) {
 336     int removed = _table->remove_if(should_clean);
 337     assert((size_t)removed <= _length, "impossible");
 338     _length -= removed;
 339   }
 340   if (_length == 0) {
 341     clear();
 342   }
 343 }
 344 
 345 #ifndef PRODUCT
 346 
 347 class G1CodeRootSetTest {
 348  public:
 349   static void test() {
 350     {
 351       G1CodeRootSet set1;
 352       assert(set1.is_empty(), "Code root set must be initially empty but is not.");
 353 
 354       assert(G1CodeRootSet::static_mem_size() == sizeof(void*),
 355           err_msg("The code root set's static memory usage is incorrect, " SIZE_FORMAT " bytes", G1CodeRootSet::static_mem_size()));
 356 
 357       set1.add((nmethod*)1);
 358       assert(set1.length() == 1, err_msg("Added exactly one element, but set contains "
 359           SIZE_FORMAT " elements", set1.length()));
 360 
 361       const size_t num_to_add = (size_t)G1CodeRootSet::Threshold + 1;
 362 
 363       for (size_t i = 1; i <= num_to_add; i++) {
 364         set1.add((nmethod*)1);
 365       }
 366       assert(set1.length() == 1,
 367           err_msg("Duplicate detection should not have increased the set size but "
 368               "is " SIZE_FORMAT, set1.length()));
 369 
 370       for (size_t i = 2; i <= num_to_add; i++) {
 371         set1.add((nmethod*)(uintptr_t)(i));
 372       }
 373       assert(set1.length() == num_to_add,
 374           err_msg("After adding in total " SIZE_FORMAT " distinct code roots, they "
 375               "need to be in the set, but there are only " SIZE_FORMAT,
 376               num_to_add, set1.length()));
 377 
 378       assert(CodeRootSetTable::_purge_list != NULL, "should have grown to large hashtable");
 379 
 380       size_t num_popped = 0;
 381       for (size_t i = 1; i <= num_to_add; i++) {
 382         bool removed = set1.remove((nmethod*)i);
 383         if (removed) {
 384           num_popped += 1;
 385         } else {
 386           break;
 387         }
 388       }
 389       assert(num_popped == num_to_add,
 390           err_msg("Managed to pop " SIZE_FORMAT " code roots, but only " SIZE_FORMAT " "
 391               "were added", num_popped, num_to_add));
 392       assert(CodeRootSetTable::_purge_list != NULL, "should have grown to large hashtable");
 393 
 394       G1CodeRootSet::purge();
 395 
 396       assert(CodeRootSetTable::_purge_list == NULL, "should have purged old small tables");
 397 
 398     }
 399 
 400   }
 401 };
 402 
 403 void TestCodeCacheRemSet_test() {
 404   G1CodeRootSetTest::test();
 405 }
 406 
 407 #endif
< prev index next >