< prev index next >

src/share/vm/code/codeCache.cpp

Print this page




  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "code/codeBlob.hpp"
  27 #include "code/codeCache.hpp"
  28 #include "code/compiledIC.hpp"
  29 #include "code/dependencies.hpp"
  30 #include "code/icBuffer.hpp"
  31 #include "code/nmethod.hpp"
  32 #include "code/pcDesc.hpp"
  33 #include "compiler/compileBroker.hpp"
  34 #include "gc_implementation/shared/markSweep.hpp"

  35 #include "memory/allocation.inline.hpp"
  36 #include "memory/gcLocker.hpp"
  37 #include "memory/iterator.hpp"
  38 #include "memory/resourceArea.hpp"
  39 #include "oops/method.hpp"
  40 #include "oops/objArrayOop.hpp"
  41 #include "oops/oop.inline.hpp"
  42 #include "runtime/handles.inline.hpp"
  43 #include "runtime/arguments.hpp"
  44 #include "runtime/deoptimization.hpp"
  45 #include "runtime/icache.hpp"
  46 #include "runtime/java.hpp"
  47 #include "runtime/mutexLocker.hpp"
  48 #include "services/memoryService.hpp"
  49 #include "trace/tracing.hpp"
  50 #include "utilities/xmlstream.hpp"
  51 

  52 // Helper class for printing in CodeCache
  53 
  54 class CodeBlob_sizes {
  55  private:
  56   int count;
  57   int total_size;
  58   int header_size;
  59   int code_size;
  60   int stub_size;
  61   int relocation_size;
  62   int scopes_oop_size;
  63   int scopes_metadata_size;
  64   int scopes_data_size;
  65   int scopes_pcs_size;
  66 
  67  public:
  68   CodeBlob_sizes() {
  69     count            = 0;
  70     total_size       = 0;
  71     header_size      = 0;


 171   return (nmethod*)cb;
 172 }
 173 
 174 static size_t maxCodeCacheUsed = 0;
 175 
 176 CodeBlob* CodeCache::allocate(int size, bool is_critical) {
 177   // Do not seize the CodeCache lock here--if the caller has not
 178   // already done so, we are going to lose bigtime, since the code
 179   // cache will contain a garbage CodeBlob until the caller can
 180   // run the constructor for the CodeBlob subclass he is busy
 181   // instantiating.
 182   guarantee(size >= 0, "allocation request must be reasonable");
 183   assert_locked_or_safepoint(CodeCache_lock);
 184   CodeBlob* cb = NULL;
 185   _number_of_blobs++;
 186   while (true) {
 187     cb = (CodeBlob*)_heap->allocate(size, is_critical);
 188     if (cb != NULL) break;
 189     if (!_heap->expand_by(CodeCacheExpansionSize)) {
 190       // Expansion failed






 191       return NULL;
 192     }
 193     if (PrintCodeCacheExtension) {
 194       ResourceMark rm;
 195       tty->print_cr("code cache extended to [" INTPTR_FORMAT ", " INTPTR_FORMAT "] (" SSIZE_FORMAT " bytes)",
 196                     (intptr_t)_heap->low_boundary(), (intptr_t)_heap->high(),
 197                     (address)_heap->high() - (address)_heap->low_boundary());
 198     }
 199   }
 200   maxCodeCacheUsed = MAX2(maxCodeCacheUsed, ((address)_heap->high_boundary() -
 201                           (address)_heap->low_boundary()) - unallocated_capacity());
 202   verify_if_often();
 203   print_trace("allocation", cb, size);
 204   return cb;
 205 }
 206 
 207 void CodeCache::free(CodeBlob* cb) {
 208   assert_locked_or_safepoint(CodeCache_lock);
 209   verify_if_often();
 210 


 762 void CodeCache::make_marked_nmethods_not_entrant() {
 763   assert_locked_or_safepoint(CodeCache_lock);
 764   FOR_ALL_ALIVE_NMETHODS(nm) {
 765     if (nm->is_marked_for_deoptimization()) {
 766       nm->make_not_entrant();
 767     }
 768   }
 769 }
 770 
 771 void CodeCache::verify() {
 772   _heap->verify();
 773   FOR_ALL_ALIVE_BLOBS(p) {
 774     p->verify();
 775   }
 776 }
 777 
 778 void CodeCache::report_codemem_full() {
 779   _codemem_full_count++;
 780   EventCodeCacheFull event;
 781   if (event.should_commit()) {

 782     event.set_startAddress((u8)low_bound());
 783     event.set_commitedTopAddress((u8)high());
 784     event.set_reservedTopAddress((u8)high_bound());
 785     event.set_entryCount(nof_blobs());
 786     event.set_methodCount(nof_nmethods());
 787     event.set_adaptorCount(nof_adapters());
 788     event.set_unallocatedCapacity(unallocated_capacity()/K);
 789     event.set_fullCount(_codemem_full_count);
 790     event.commit();
 791   }
 792 }
 793 
 794 //------------------------------------------------------------------------------------------------
 795 // Non-product version
 796 
 797 #ifndef PRODUCT
 798 
 799 void CodeCache::verify_if_often() {
 800   if (VerifyCodeCacheOften) {
 801     _heap->verify();




  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "code/codeBlob.hpp"
  27 #include "code/codeCache.hpp"
  28 #include "code/compiledIC.hpp"
  29 #include "code/dependencies.hpp"
  30 #include "code/icBuffer.hpp"
  31 #include "code/nmethod.hpp"
  32 #include "code/pcDesc.hpp"
  33 #include "compiler/compileBroker.hpp"
  34 #include "gc_implementation/shared/markSweep.hpp"
  35 #include "jfr/jfrEvents.hpp"
  36 #include "memory/allocation.inline.hpp"
  37 #include "memory/gcLocker.hpp"
  38 #include "memory/iterator.hpp"
  39 #include "memory/resourceArea.hpp"
  40 #include "oops/method.hpp"
  41 #include "oops/objArrayOop.hpp"
  42 #include "oops/oop.inline.hpp"
  43 #include "runtime/handles.inline.hpp"
  44 #include "runtime/arguments.hpp"
  45 #include "runtime/deoptimization.hpp"
  46 #include "runtime/icache.hpp"
  47 #include "runtime/java.hpp"
  48 #include "runtime/mutexLocker.hpp"
  49 #include "services/memoryService.hpp"

  50 #include "utilities/xmlstream.hpp"
  51 
  52 
  53 // Helper class for printing in CodeCache
  54 
  55 class CodeBlob_sizes {
  56  private:
  57   int count;
  58   int total_size;
  59   int header_size;
  60   int code_size;
  61   int stub_size;
  62   int relocation_size;
  63   int scopes_oop_size;
  64   int scopes_metadata_size;
  65   int scopes_data_size;
  66   int scopes_pcs_size;
  67 
  68  public:
  69   CodeBlob_sizes() {
  70     count            = 0;
  71     total_size       = 0;
  72     header_size      = 0;


 172   return (nmethod*)cb;
 173 }
 174 
 175 static size_t maxCodeCacheUsed = 0;
 176 
 177 CodeBlob* CodeCache::allocate(int size, bool is_critical) {
 178   // Do not seize the CodeCache lock here--if the caller has not
 179   // already done so, we are going to lose bigtime, since the code
 180   // cache will contain a garbage CodeBlob until the caller can
 181   // run the constructor for the CodeBlob subclass he is busy
 182   // instantiating.
 183   guarantee(size >= 0, "allocation request must be reasonable");
 184   assert_locked_or_safepoint(CodeCache_lock);
 185   CodeBlob* cb = NULL;
 186   _number_of_blobs++;
 187   while (true) {
 188     cb = (CodeBlob*)_heap->allocate(size, is_critical);
 189     if (cb != NULL) break;
 190     if (!_heap->expand_by(CodeCacheExpansionSize)) {
 191       // Expansion failed
 192       if (CodeCache_lock->owned_by_self()) {
 193         MutexUnlockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
 194         report_codemem_full();
 195       } else {
 196         report_codemem_full();
 197       }
 198       return NULL;
 199     }
 200     if (PrintCodeCacheExtension) {
 201       ResourceMark rm;
 202       tty->print_cr("code cache extended to [" INTPTR_FORMAT ", " INTPTR_FORMAT "] (" SSIZE_FORMAT " bytes)",
 203                     (intptr_t)_heap->low_boundary(), (intptr_t)_heap->high(),
 204                     (address)_heap->high() - (address)_heap->low_boundary());
 205     }
 206   }
 207   maxCodeCacheUsed = MAX2(maxCodeCacheUsed, ((address)_heap->high_boundary() -
 208                           (address)_heap->low_boundary()) - unallocated_capacity());
 209   verify_if_often();
 210   print_trace("allocation", cb, size);
 211   return cb;
 212 }
 213 
 214 void CodeCache::free(CodeBlob* cb) {
 215   assert_locked_or_safepoint(CodeCache_lock);
 216   verify_if_often();
 217 


 769 void CodeCache::make_marked_nmethods_not_entrant() {
 770   assert_locked_or_safepoint(CodeCache_lock);
 771   FOR_ALL_ALIVE_NMETHODS(nm) {
 772     if (nm->is_marked_for_deoptimization()) {
 773       nm->make_not_entrant();
 774     }
 775   }
 776 }
 777 
 778 void CodeCache::verify() {
 779   _heap->verify();
 780   FOR_ALL_ALIVE_BLOBS(p) {
 781     p->verify();
 782   }
 783 }
 784 
 785 void CodeCache::report_codemem_full() {
 786   _codemem_full_count++;
 787   EventCodeCacheFull event;
 788   if (event.should_commit()) {
 789     event.set_codeBlobType((u1)CodeBlobType::All);
 790     event.set_startAddress((u8)low_bound());
 791     event.set_commitedTopAddress((u8)high());
 792     event.set_reservedTopAddress((u8)high_bound());
 793     event.set_entryCount(nof_blobs());
 794     event.set_methodCount(nof_nmethods());
 795     event.set_adaptorCount(nof_adapters());
 796     event.set_unallocatedCapacity(unallocated_capacity()/K);
 797     event.set_fullCount(_codemem_full_count);
 798     event.commit();
 799   }
 800 }
 801 
 802 //------------------------------------------------------------------------------------------------
 803 // Non-product version
 804 
 805 #ifndef PRODUCT
 806 
 807 void CodeCache::verify_if_often() {
 808   if (VerifyCodeCacheOften) {
 809     _heap->verify();


< prev index next >