src/share/vm/code/codeCache.cpp

Print this page




 314   FOR_ALL_ALIVE_NMETHODS(nm) {
 315     nm->do_unloading(is_alive, unloading_occurred);
 316   }
 317 }
 318 
 319 void CodeCache::blobs_do(CodeBlobClosure* f) {
 320   assert_locked_or_safepoint(CodeCache_lock);
 321   FOR_ALL_ALIVE_BLOBS(cb) {
 322     f->do_code_blob(cb);
 323 
 324 #ifdef ASSERT
 325     if (cb->is_nmethod())
 326       ((nmethod*)cb)->verify_scavenge_root_oops();
 327 #endif //ASSERT
 328   }
 329 }
 330 
 331 // Walk the list of methods which might contain non-perm oops.
 332 void CodeCache::scavenge_root_nmethods_do(CodeBlobClosure* f) {
 333   assert_locked_or_safepoint(CodeCache_lock);





 334   debug_only(mark_scavenge_root_nmethods());
 335 
 336   for (nmethod* cur = scavenge_root_nmethods(); cur != NULL; cur = cur->scavenge_root_link()) {
 337     debug_only(cur->clear_scavenge_root_marked());
 338     assert(cur->scavenge_root_not_marked(), "");
 339     assert(cur->on_scavenge_root_list(), "else shouldn't be on this list");
 340 
 341     bool is_live = (!cur->is_zombie() && !cur->is_unloaded());
 342 #ifndef PRODUCT
 343     if (TraceScavenge) {
 344       cur->print_on(tty, is_live ? "scavenge root" : "dead scavenge root"); tty->cr();
 345     }
 346 #endif //PRODUCT
 347     if (is_live) {
 348       // Perform cur->oops_do(f), maybe just once per nmethod.
 349       f->do_code_blob(cur);
 350     }
 351   }
 352 
 353   // Check for stray marks.
 354   debug_only(verify_perm_nmethods(NULL));
 355 }
 356 
 357 void CodeCache::add_scavenge_root_nmethod(nmethod* nm) {
 358   assert_locked_or_safepoint(CodeCache_lock);





 359   nm->set_on_scavenge_root_list();
 360   nm->set_scavenge_root_link(_scavenge_root_nmethods);
 361   set_scavenge_root_nmethods(nm);
 362   print_trace("add_scavenge_root", nm);
 363 }
 364 
 365 void CodeCache::drop_scavenge_root_nmethod(nmethod* nm) {
 366   assert_locked_or_safepoint(CodeCache_lock);





 367   print_trace("drop_scavenge_root", nm);
 368   nmethod* last = NULL;
 369   nmethod* cur = scavenge_root_nmethods();
 370   while (cur != NULL) {
 371     nmethod* next = cur->scavenge_root_link();
 372     if (cur == nm) {
 373       if (last != NULL)
 374             last->set_scavenge_root_link(next);
 375       else  set_scavenge_root_nmethods(next);
 376       nm->set_scavenge_root_link(NULL);
 377       nm->clear_on_scavenge_root_list();
 378       return;
 379     }
 380     last = cur;
 381     cur = next;
 382   }
 383   assert(false, "should have been on list");
 384 }
 385 
 386 void CodeCache::prune_scavenge_root_nmethods() {
 387   assert_locked_or_safepoint(CodeCache_lock);





 388   debug_only(mark_scavenge_root_nmethods());
 389 
 390   nmethod* last = NULL;
 391   nmethod* cur = scavenge_root_nmethods();
 392   while (cur != NULL) {
 393     nmethod* next = cur->scavenge_root_link();
 394     debug_only(cur->clear_scavenge_root_marked());
 395     assert(cur->scavenge_root_not_marked(), "");
 396     assert(cur->on_scavenge_root_list(), "else shouldn't be on this list");
 397 
 398     if (!cur->is_zombie() && !cur->is_unloaded()
 399         && cur->detect_scavenge_root_oops()) {
 400       // Keep it.  Advance 'last' to prevent deletion.
 401       last = cur;
 402     } else {
 403       // Prune it from the list, so we don't have to look at it any more.
 404       print_trace("prune_scavenge_root", cur);
 405       cur->set_scavenge_root_link(NULL);
 406       cur->clear_on_scavenge_root_list();
 407       if (last != NULL)
 408             last->set_scavenge_root_link(next);
 409       else  set_scavenge_root_nmethods(next);
 410     }
 411     cur = next;
 412   }
 413 
 414   // Check for stray marks.
 415   debug_only(verify_perm_nmethods(NULL));
 416 }
 417 
 418 #ifndef PRODUCT
 419 void CodeCache::asserted_non_scavengable_nmethods_do(CodeBlobClosure* f) {




 420   // While we are here, verify the integrity of the list.
 421   mark_scavenge_root_nmethods();
 422   for (nmethod* cur = scavenge_root_nmethods(); cur != NULL; cur = cur->scavenge_root_link()) {
 423     assert(cur->on_scavenge_root_list(), "else shouldn't be on this list");
 424     cur->clear_scavenge_root_marked();
 425   }
 426   verify_perm_nmethods(f);
 427 }
 428 
 429 // Temporarily mark nmethods that are claimed to be on the non-perm list.
 430 void CodeCache::mark_scavenge_root_nmethods() {
 431   FOR_ALL_ALIVE_BLOBS(cb) {
 432     if (cb->is_nmethod()) {
 433       nmethod *nm = (nmethod*)cb;
 434       assert(nm->scavenge_root_not_marked(), "clean state");
 435       if (nm->on_scavenge_root_list())
 436         nm->set_scavenge_root_marked();
 437     }
 438   }
 439 }
 440 
 441 // If the closure is given, run it on the unlisted nmethods.
 442 // Also make sure that the effects of mark_scavenge_root_nmethods is gone.
 443 void CodeCache::verify_perm_nmethods(CodeBlobClosure* f_or_null) {
 444   FOR_ALL_ALIVE_BLOBS(cb) {
 445     bool call_f = (f_or_null != NULL);
 446     if (cb->is_nmethod()) {
 447       nmethod *nm = (nmethod*)cb;
 448       assert(nm->scavenge_root_not_marked(), "must be already processed");
 449       if (nm->on_scavenge_root_list())
 450         call_f = false;  // don't show this one to the client
 451       nm->verify_scavenge_root_oops();
 452     } else {
 453       call_f = false;   // not an nmethod
 454     }
 455     if (call_f)  f_or_null->do_code_blob(cb);
 456   }
 457 }
 458 #endif //PRODUCT
 459 




























 460 
 461 void CodeCache::gc_prologue() {
 462   assert(!nmethod::oops_do_marking_is_active(), "oops_do_marking_epilogue must be called");
 463 }
 464 
 465 void CodeCache::gc_epilogue() {
 466   assert_locked_or_safepoint(CodeCache_lock);
 467   FOR_ALL_ALIVE_BLOBS(cb) {
 468     if (cb->is_nmethod()) {
 469       nmethod *nm = (nmethod*)cb;
 470       assert(!nm->is_unloaded(), "Tautology");
 471       if (needs_cache_clean()) {
 472         nm->cleanup_inline_caches();
 473       }
 474       DEBUG_ONLY(nm->verify());
 475       nm->fix_oop_relocations();
 476     }
 477   }
 478   set_needs_cache_clean(false);
 479   prune_scavenge_root_nmethods();
 480   assert(!nmethod::oops_do_marking_is_active(), "oops_do_marking_prologue must be called");
 481 
 482 #ifdef ASSERT
 483   // make sure that we aren't leaking icholders
 484   int count = 0;
 485   FOR_ALL_BLOBS(cb) {
 486     if (cb->is_nmethod()) {
 487       RelocIterator iter((nmethod*)cb);
 488       while(iter.next()) {
 489         if (iter.type() == relocInfo::virtual_call_type) {
 490           if (CompiledIC::is_icholder_call_site(iter.virtual_call_reloc())) {
 491             CompiledIC *ic = CompiledIC_at(&iter);
 492             if (TraceCompiledIC) {
 493               tty->print("noticed icholder " INTPTR_FORMAT " ", p2i(ic->cached_icholder()));
 494               ic->print();
 495             }
 496             assert(ic->cached_icholder() != NULL, "must be non-NULL");
 497             count++;
 498           }
 499         }
 500       }
 501     }
 502   }
 503 
 504   assert(count + InlineCacheBuffer::pending_icholder_count() + CompiledICHolder::live_not_claimed_count() ==
 505          CompiledICHolder::live_count(), "must agree");
 506 #endif
 507 }
 508 
 509 
 510 void CodeCache::verify_oops() {
 511   MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
 512   VerifyOopClosure voc;
 513   FOR_ALL_ALIVE_BLOBS(cb) {
 514     if (cb->is_nmethod()) {
 515       nmethod *nm = (nmethod*)cb;
 516       nm->oops_do(&voc);
 517       nm->verify_oop_relocations();
 518     }
 519   }
 520 }
 521 
 522 
 523 address CodeCache::first_address() {
 524   assert_locked_or_safepoint(CodeCache_lock);
 525   return (address)_heap->low_boundary();
 526 }
 527 
 528 




 314   FOR_ALL_ALIVE_NMETHODS(nm) {
 315     nm->do_unloading(is_alive, unloading_occurred);
 316   }
 317 }
 318 
 319 void CodeCache::blobs_do(CodeBlobClosure* f) {
 320   assert_locked_or_safepoint(CodeCache_lock);
 321   FOR_ALL_ALIVE_BLOBS(cb) {
 322     f->do_code_blob(cb);
 323 
 324 #ifdef ASSERT
 325     if (cb->is_nmethod())
 326       ((nmethod*)cb)->verify_scavenge_root_oops();
 327 #endif //ASSERT
 328   }
 329 }
 330 
 331 // Walk the list of methods which might contain non-perm oops.
 332 void CodeCache::scavenge_root_nmethods_do(CodeBlobClosure* f) {
 333   assert_locked_or_safepoint(CodeCache_lock);
 334 
 335   if (UseG1GC) {
 336     return;
 337   }
 338 
 339   debug_only(mark_scavenge_root_nmethods());
 340 
 341   for (nmethod* cur = scavenge_root_nmethods(); cur != NULL; cur = cur->scavenge_root_link()) {
 342     debug_only(cur->clear_scavenge_root_marked());
 343     assert(cur->scavenge_root_not_marked(), "");
 344     assert(cur->on_scavenge_root_list(), "else shouldn't be on this list");
 345 
 346     bool is_live = (!cur->is_zombie() && !cur->is_unloaded());
 347 #ifndef PRODUCT
 348     if (TraceScavenge) {
 349       cur->print_on(tty, is_live ? "scavenge root" : "dead scavenge root"); tty->cr();
 350     }
 351 #endif //PRODUCT
 352     if (is_live) {
 353       // Perform cur->oops_do(f), maybe just once per nmethod.
 354       f->do_code_blob(cur);
 355     }
 356   }
 357 
 358   // Check for stray marks.
 359   debug_only(verify_perm_nmethods(NULL));
 360 }
 361 
 362 void CodeCache::add_scavenge_root_nmethod(nmethod* nm) {
 363   assert_locked_or_safepoint(CodeCache_lock);
 364 
 365   if (UseG1GC) {
 366     return;
 367   }
 368 
 369   nm->set_on_scavenge_root_list();
 370   nm->set_scavenge_root_link(_scavenge_root_nmethods);
 371   set_scavenge_root_nmethods(nm);
 372   print_trace("add_scavenge_root", nm);
 373 }
 374 
 375 void CodeCache::drop_scavenge_root_nmethod(nmethod* nm) {
 376   assert_locked_or_safepoint(CodeCache_lock);
 377 
 378   if (UseG1GC) {
 379     return;
 380   }
 381 
 382   print_trace("drop_scavenge_root", nm);
 383   nmethod* last = NULL;
 384   nmethod* cur = scavenge_root_nmethods();
 385   while (cur != NULL) {
 386     nmethod* next = cur->scavenge_root_link();
 387     if (cur == nm) {
 388       if (last != NULL)
 389             last->set_scavenge_root_link(next);
 390       else  set_scavenge_root_nmethods(next);
 391       nm->set_scavenge_root_link(NULL);
 392       nm->clear_on_scavenge_root_list();
 393       return;
 394     }
 395     last = cur;
 396     cur = next;
 397   }
 398   assert(false, "should have been on list");
 399 }
 400 
 401 void CodeCache::prune_scavenge_root_nmethods() {
 402   assert_locked_or_safepoint(CodeCache_lock);
 403 
 404   if (UseG1GC) {
 405     return;
 406   }
 407 
 408   debug_only(mark_scavenge_root_nmethods());
 409 
 410   nmethod* last = NULL;
 411   nmethod* cur = scavenge_root_nmethods();
 412   while (cur != NULL) {
 413     nmethod* next = cur->scavenge_root_link();
 414     debug_only(cur->clear_scavenge_root_marked());
 415     assert(cur->scavenge_root_not_marked(), "");
 416     assert(cur->on_scavenge_root_list(), "else shouldn't be on this list");
 417 
 418     if (!cur->is_zombie() && !cur->is_unloaded()
 419         && cur->detect_scavenge_root_oops()) {
 420       // Keep it.  Advance 'last' to prevent deletion.
 421       last = cur;
 422     } else {
 423       // Prune it from the list, so we don't have to look at it any more.
 424       print_trace("prune_scavenge_root", cur);
 425       cur->set_scavenge_root_link(NULL);
 426       cur->clear_on_scavenge_root_list();
 427       if (last != NULL)
 428             last->set_scavenge_root_link(next);
 429       else  set_scavenge_root_nmethods(next);
 430     }
 431     cur = next;
 432   }
 433 
 434   // Check for stray marks.
 435   debug_only(verify_perm_nmethods(NULL));
 436 }
 437 
 438 #ifndef PRODUCT
 439 void CodeCache::asserted_non_scavengable_nmethods_do(CodeBlobClosure* f) {
 440   if (UseG1GC) {
 441     return;
 442   }
 443 
 444   // While we are here, verify the integrity of the list.
 445   mark_scavenge_root_nmethods();
 446   for (nmethod* cur = scavenge_root_nmethods(); cur != NULL; cur = cur->scavenge_root_link()) {
 447     assert(cur->on_scavenge_root_list(), "else shouldn't be on this list");
 448     cur->clear_scavenge_root_marked();
 449   }
 450   verify_perm_nmethods(f);
 451 }
 452 
 453 // Temporarily mark nmethods that are claimed to be on the non-perm list.
 454 void CodeCache::mark_scavenge_root_nmethods() {
 455   FOR_ALL_ALIVE_BLOBS(cb) {
 456     if (cb->is_nmethod()) {
 457       nmethod *nm = (nmethod*)cb;
 458       assert(nm->scavenge_root_not_marked(), "clean state");
 459       if (nm->on_scavenge_root_list())
 460         nm->set_scavenge_root_marked();
 461     }
 462   }
 463 }
 464 
 465 // If the closure is given, run it on the unlisted nmethods.
 466 // Also make sure that the effects of mark_scavenge_root_nmethods is gone.
 467 void CodeCache::verify_perm_nmethods(CodeBlobClosure* f_or_null) {
 468   FOR_ALL_ALIVE_BLOBS(cb) {
 469     bool call_f = (f_or_null != NULL);
 470     if (cb->is_nmethod()) {
 471       nmethod *nm = (nmethod*)cb;
 472       assert(nm->scavenge_root_not_marked(), "must be already processed");
 473       if (nm->on_scavenge_root_list())
 474         call_f = false;  // don't show this one to the client
 475       nm->verify_scavenge_root_oops();
 476     } else {
 477       call_f = false;   // not an nmethod
 478     }
 479     if (call_f)  f_or_null->do_code_blob(cb);
 480   }
 481 }
 482 #endif //PRODUCT
 483 
 484 void CodeCache::verify_clean_inline_caches() {
 485 #ifdef ASSERT
 486   FOR_ALL_ALIVE_BLOBS(cb) {
 487     if (cb->is_nmethod()) {
 488       nmethod* nm = (nmethod*)cb;
 489       assert(!nm->is_unloaded(), "Tautology");
 490       nm->verify_clean_inline_caches();
 491       nm->verify();
 492     }
 493   }
 494 #endif
 495 }
 496 
 497 void CodeCache::verify_icholder_relocations() {
 498 #ifdef ASSERT
 499   // make sure that we aren't leaking icholders
 500   int count = 0;
 501   FOR_ALL_BLOBS(cb) {
 502     if (cb->is_nmethod()) {
 503       nmethod* nm = (nmethod*)cb;
 504       count += nm->verify_icholder_relocations();
 505     }
 506   }
 507 
 508   assert(count + InlineCacheBuffer::pending_icholder_count() + CompiledICHolder::live_not_claimed_count() ==
 509          CompiledICHolder::live_count(), "must agree");
 510 #endif
 511 }
 512 
 513 void CodeCache::gc_prologue() {

 514 }
 515 
 516 void CodeCache::gc_epilogue() {
 517   assert_locked_or_safepoint(CodeCache_lock);
 518   FOR_ALL_ALIVE_BLOBS(cb) {
 519     if (cb->is_nmethod()) {
 520       nmethod *nm = (nmethod*)cb;
 521       assert(!nm->is_unloaded(), "Tautology");
 522       if (needs_cache_clean()) {
 523         nm->cleanup_inline_caches();
 524       }
 525       DEBUG_ONLY(nm->verify());
 526       DEBUG_ONLY(nm->verify_oop_relocations());
 527     }
 528   }
 529   set_needs_cache_clean(false);
 530   prune_scavenge_root_nmethods();























 531 
 532   verify_icholder_relocations();


 533 }

 534 
 535 void CodeCache::verify_oops() {
 536   MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
 537   VerifyOopClosure voc;
 538   FOR_ALL_ALIVE_BLOBS(cb) {
 539     if (cb->is_nmethod()) {
 540       nmethod *nm = (nmethod*)cb;
 541       nm->oops_do(&voc);
 542       nm->verify_oop_relocations();
 543     }
 544   }
 545 }
 546 
 547 
 548 address CodeCache::first_address() {
 549   assert_locked_or_safepoint(CodeCache_lock);
 550   return (address)_heap->low_boundary();
 551 }
 552 
 553