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