src/share/vm/code/codeCache.cpp

Print this page




 107 
 108       scopes_oop_size  += nm->oops_size();
 109       scopes_metadata_size  += nm->metadata_size();
 110       scopes_data_size += nm->scopes_data_size();
 111       scopes_pcs_size  += nm->scopes_pcs_size();
 112     } else {
 113       code_size        += cb->code_size();
 114     }
 115   }
 116 };
 117 
 118 // CodeCache implementation
 119 
 120 CodeHeap * CodeCache::_heap = new CodeHeap();
 121 int CodeCache::_number_of_blobs = 0;
 122 int CodeCache::_number_of_adapters = 0;
 123 int CodeCache::_number_of_nmethods = 0;
 124 int CodeCache::_number_of_nmethods_with_dependencies = 0;
 125 bool CodeCache::_needs_cache_clean = false;
 126 nmethod* CodeCache::_scavenge_root_nmethods = NULL;
 127 nmethod* CodeCache::_saved_nmethods = NULL;
 128 
 129 int CodeCache::_codemem_full_count = 0;
 130 
 131 CodeBlob* CodeCache::first() {
 132   assert_locked_or_safepoint(CodeCache_lock);
 133   return (CodeBlob*)_heap->first();
 134 }
 135 
 136 
 137 CodeBlob* CodeCache::next(CodeBlob* cb) {
 138   assert_locked_or_safepoint(CodeCache_lock);
 139   return (CodeBlob*)_heap->next(cb);
 140 }
 141 
 142 
 143 CodeBlob* CodeCache::alive(CodeBlob *cb) {
 144   assert_locked_or_safepoint(CodeCache_lock);
 145   while (cb != NULL && !cb->is_alive()) cb = next(cb);
 146   return cb;
 147 }


 447 
 448 // If the closure is given, run it on the unlisted nmethods.
 449 // Also make sure that the effects of mark_scavenge_root_nmethods is gone.
 450 void CodeCache::verify_perm_nmethods(CodeBlobClosure* f_or_null) {
 451   FOR_ALL_ALIVE_BLOBS(cb) {
 452     bool call_f = (f_or_null != NULL);
 453     if (cb->is_nmethod()) {
 454       nmethod *nm = (nmethod*)cb;
 455       assert(nm->scavenge_root_not_marked(), "must be already processed");
 456       if (nm->on_scavenge_root_list())
 457         call_f = false;  // don't show this one to the client
 458       nm->verify_scavenge_root_oops();
 459     } else {
 460       call_f = false;   // not an nmethod
 461     }
 462     if (call_f)  f_or_null->do_code_blob(cb);
 463   }
 464 }
 465 #endif //PRODUCT
 466 
 467 /**
 468  * Remove and return nmethod from the saved code list in order to reanimate it.
 469  */
 470 nmethod* CodeCache::reanimate_saved_code(Method* m) {
 471   MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
 472   nmethod* saved = _saved_nmethods;
 473   nmethod* prev = NULL;
 474   while (saved != NULL) {
 475     if (saved->is_in_use() && saved->method() == m) {
 476       if (prev != NULL) {
 477         prev->set_saved_nmethod_link(saved->saved_nmethod_link());
 478       } else {
 479         _saved_nmethods = saved->saved_nmethod_link();
 480       }
 481       assert(saved->is_speculatively_disconnected(), "shouldn't call for other nmethods");
 482       saved->set_speculatively_disconnected(false);
 483       saved->set_saved_nmethod_link(NULL);
 484       if (PrintMethodFlushing) {
 485         saved->print_on(tty, " ### nmethod is reconnected");
 486       }
 487       if (LogCompilation && (xtty != NULL)) {
 488         ttyLocker ttyl;
 489         xtty->begin_elem("nmethod_reconnected compile_id='%3d'", saved->compile_id());
 490         xtty->method(m);
 491         xtty->stamp();
 492         xtty->end_elem();
 493       }
 494       return saved;
 495     }
 496     prev = saved;
 497     saved = saved->saved_nmethod_link();
 498   }
 499   return NULL;
 500 }
 501 
 502 /**
 503  * Remove nmethod from the saved code list in order to discard it permanently
 504  */
 505 void CodeCache::remove_saved_code(nmethod* nm) {
 506   // For conc swpr this will be called with CodeCache_lock taken by caller
 507   assert_locked_or_safepoint(CodeCache_lock);
 508   assert(nm->is_speculatively_disconnected(), "shouldn't call for other nmethods");
 509   nmethod* saved = _saved_nmethods;
 510   nmethod* prev = NULL;
 511   while (saved != NULL) {
 512     if (saved == nm) {
 513       if (prev != NULL) {
 514         prev->set_saved_nmethod_link(saved->saved_nmethod_link());
 515       } else {
 516         _saved_nmethods = saved->saved_nmethod_link();
 517       }
 518       if (LogCompilation && (xtty != NULL)) {
 519         ttyLocker ttyl;
 520         xtty->begin_elem("nmethod_removed compile_id='%3d'", nm->compile_id());
 521         xtty->stamp();
 522         xtty->end_elem();
 523       }
 524       return;
 525     }
 526     prev = saved;
 527     saved = saved->saved_nmethod_link();
 528   }
 529   ShouldNotReachHere();
 530 }
 531 
 532 void CodeCache::speculatively_disconnect(nmethod* nm) {
 533   assert_locked_or_safepoint(CodeCache_lock);
 534   assert(nm->is_in_use() && !nm->is_speculatively_disconnected(), "should only disconnect live nmethods");
 535   nm->set_saved_nmethod_link(_saved_nmethods);
 536   _saved_nmethods = nm;
 537   if (PrintMethodFlushing) {
 538     nm->print_on(tty, " ### nmethod is speculatively disconnected");
 539   }
 540   if (LogCompilation && (xtty != NULL)) {
 541     ttyLocker ttyl;
 542     xtty->begin_elem("nmethod_disconnected compile_id='%3d'", nm->compile_id());
 543     xtty->method(nm->method());
 544     xtty->stamp();
 545     xtty->end_elem();
 546   }
 547   nm->method()->clear_code();
 548   nm->set_speculatively_disconnected(true);
 549 }
 550 
 551 
 552 void CodeCache::gc_prologue() {
 553   assert(!nmethod::oops_do_marking_is_active(), "oops_do_marking_epilogue must be called");
 554 }
 555 
 556 
 557 void CodeCache::gc_epilogue() {
 558   assert_locked_or_safepoint(CodeCache_lock);
 559   FOR_ALL_ALIVE_BLOBS(cb) {
 560     if (cb->is_nmethod()) {
 561       nmethod *nm = (nmethod*)cb;
 562       assert(!nm->is_unloaded(), "Tautology");
 563       if (needs_cache_clean()) {
 564         nm->cleanup_inline_caches();
 565       }
 566       DEBUG_ONLY(nm->verify());
 567       nm->fix_oop_relocations();
 568     }
 569   }
 570   set_needs_cache_clean(false);
 571   prune_scavenge_root_nmethods();
 572   assert(!nmethod::oops_do_marking_is_active(), "oops_do_marking_prologue must be called");
 573 
 574 #ifdef ASSERT
 575   // make sure that we aren't leaking icholders




 107 
 108       scopes_oop_size  += nm->oops_size();
 109       scopes_metadata_size  += nm->metadata_size();
 110       scopes_data_size += nm->scopes_data_size();
 111       scopes_pcs_size  += nm->scopes_pcs_size();
 112     } else {
 113       code_size        += cb->code_size();
 114     }
 115   }
 116 };
 117 
 118 // CodeCache implementation
 119 
 120 CodeHeap * CodeCache::_heap = new CodeHeap();
 121 int CodeCache::_number_of_blobs = 0;
 122 int CodeCache::_number_of_adapters = 0;
 123 int CodeCache::_number_of_nmethods = 0;
 124 int CodeCache::_number_of_nmethods_with_dependencies = 0;
 125 bool CodeCache::_needs_cache_clean = false;
 126 nmethod* CodeCache::_scavenge_root_nmethods = NULL;

 127 
 128 int CodeCache::_codemem_full_count = 0;
 129 
 130 CodeBlob* CodeCache::first() {
 131   assert_locked_or_safepoint(CodeCache_lock);
 132   return (CodeBlob*)_heap->first();
 133 }
 134 
 135 
 136 CodeBlob* CodeCache::next(CodeBlob* cb) {
 137   assert_locked_or_safepoint(CodeCache_lock);
 138   return (CodeBlob*)_heap->next(cb);
 139 }
 140 
 141 
 142 CodeBlob* CodeCache::alive(CodeBlob *cb) {
 143   assert_locked_or_safepoint(CodeCache_lock);
 144   while (cb != NULL && !cb->is_alive()) cb = next(cb);
 145   return cb;
 146 }


 446 
 447 // If the closure is given, run it on the unlisted nmethods.
 448 // Also make sure that the effects of mark_scavenge_root_nmethods is gone.
 449 void CodeCache::verify_perm_nmethods(CodeBlobClosure* f_or_null) {
 450   FOR_ALL_ALIVE_BLOBS(cb) {
 451     bool call_f = (f_or_null != NULL);
 452     if (cb->is_nmethod()) {
 453       nmethod *nm = (nmethod*)cb;
 454       assert(nm->scavenge_root_not_marked(), "must be already processed");
 455       if (nm->on_scavenge_root_list())
 456         call_f = false;  // don't show this one to the client
 457       nm->verify_scavenge_root_oops();
 458     } else {
 459       call_f = false;   // not an nmethod
 460     }
 461     if (call_f)  f_or_null->do_code_blob(cb);
 462   }
 463 }
 464 #endif //PRODUCT
 465 




















































































 466 
 467 void CodeCache::gc_prologue() {
 468   assert(!nmethod::oops_do_marking_is_active(), "oops_do_marking_epilogue must be called");
 469 }

 470 
 471 void CodeCache::gc_epilogue() {
 472   assert_locked_or_safepoint(CodeCache_lock);
 473   FOR_ALL_ALIVE_BLOBS(cb) {
 474     if (cb->is_nmethod()) {
 475       nmethod *nm = (nmethod*)cb;
 476       assert(!nm->is_unloaded(), "Tautology");
 477       if (needs_cache_clean()) {
 478         nm->cleanup_inline_caches();
 479       }
 480       DEBUG_ONLY(nm->verify());
 481       nm->fix_oop_relocations();
 482     }
 483   }
 484   set_needs_cache_clean(false);
 485   prune_scavenge_root_nmethods();
 486   assert(!nmethod::oops_do_marking_is_active(), "oops_do_marking_prologue must be called");
 487 
 488 #ifdef ASSERT
 489   // make sure that we aren't leaking icholders