src/share/vm/code/codeCache.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File 8029343 Sdiff src/share/vm/code

src/share/vm/code/codeCache.cpp

Print this page




 161   return (nmethod*)cb;
 162 }
 163 
 164 nmethod* CodeCache::next_nmethod (CodeBlob* cb) {
 165   assert_locked_or_safepoint(CodeCache_lock);
 166   cb = next(cb);
 167   while (cb != NULL && !cb->is_nmethod()) {
 168     cb = next(cb);
 169   }
 170   return (nmethod*)cb;
 171 }
 172 
 173 static size_t maxCodeCacheUsed = 0;
 174 
 175 CodeBlob* CodeCache::allocate(int size, bool is_critical) {
 176   // Do not seize the CodeCache lock here--if the caller has not
 177   // already done so, we are going to lose bigtime, since the code
 178   // cache will contain a garbage CodeBlob until the caller can
 179   // run the constructor for the CodeBlob subclass he is busy
 180   // instantiating.
 181   guarantee(size >= 0, "allocation request must be reasonable");
 182   assert_locked_or_safepoint(CodeCache_lock);




 183   CodeBlob* cb = NULL;
 184   _number_of_blobs++;
 185   while (true) {
 186     cb = (CodeBlob*)_heap->allocate(size, is_critical);
 187     if (cb != NULL) break;
 188     if (!_heap->expand_by(CodeCacheExpansionSize)) {
 189       // Expansion failed
 190       return NULL;
 191     }
 192     if (PrintCodeCacheExtension) {
 193       ResourceMark rm;
 194       tty->print_cr("code cache extended to [" INTPTR_FORMAT ", " INTPTR_FORMAT "] (%d bytes)",
 195                     (intptr_t)_heap->low_boundary(), (intptr_t)_heap->high(),
 196                     (address)_heap->high() - (address)_heap->low_boundary());
 197     }
 198   }
 199   maxCodeCacheUsed = MAX2(maxCodeCacheUsed, ((address)_heap->high_boundary() -
 200                           (address)_heap->low_boundary()) - unallocated_capacity());
 201   print_trace("allocation", cb, size);

 202   return cb;
 203 }
 204 
 205 void CodeCache::free(CodeBlob* cb) {
 206   assert_locked_or_safepoint(CodeCache_lock);
 207 
 208   print_trace("free", cb);
 209   if (cb->is_nmethod()) {
 210     _number_of_nmethods--;
 211     if (((nmethod *)cb)->has_dependencies()) {
 212       _number_of_nmethods_with_dependencies--;
 213     }
 214   }
 215   if (cb->is_adapter_blob()) {
 216     _number_of_adapters--;
 217   }
 218   _number_of_blobs--;
 219 
 220   _heap->deallocate(cb);
 221 




 161   return (nmethod*)cb;
 162 }
 163 
 164 nmethod* CodeCache::next_nmethod (CodeBlob* cb) {
 165   assert_locked_or_safepoint(CodeCache_lock);
 166   cb = next(cb);
 167   while (cb != NULL && !cb->is_nmethod()) {
 168     cb = next(cb);
 169   }
 170   return (nmethod*)cb;
 171 }
 172 
 173 static size_t maxCodeCacheUsed = 0;
 174 
 175 CodeBlob* CodeCache::allocate(int size, bool is_critical) {
 176   // Do not seize the CodeCache lock here--if the caller has not
 177   // already done so, we are going to lose bigtime, since the code
 178   // cache will contain a garbage CodeBlob until the caller can
 179   // run the constructor for the CodeBlob subclass he is busy
 180   // instantiating.

 181   assert_locked_or_safepoint(CodeCache_lock);
 182   assert(size > 0, "allocation request must be reasonable");
 183   if (size <= 0) {
 184     return NULL;
 185   }
 186   CodeBlob* cb = NULL;

 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       return NULL;
 193     }
 194     if (PrintCodeCacheExtension) {
 195       ResourceMark rm;
 196       tty->print_cr("code cache extended to [" INTPTR_FORMAT ", " INTPTR_FORMAT "] (%d bytes)",
 197                     (intptr_t)_heap->low_boundary(), (intptr_t)_heap->high(),
 198                     (address)_heap->high() - (address)_heap->low_boundary());
 199     }
 200   }
 201   maxCodeCacheUsed = MAX2(maxCodeCacheUsed, ((address)_heap->high_boundary() -
 202                           (address)_heap->low_boundary()) - unallocated_capacity());
 203   print_trace("allocation", cb, size);
 204   _number_of_blobs++;
 205   return cb;
 206 }
 207 
 208 void CodeCache::free(CodeBlob* cb) {
 209   assert_locked_or_safepoint(CodeCache_lock);
 210 
 211   print_trace("free", cb);
 212   if (cb->is_nmethod()) {
 213     _number_of_nmethods--;
 214     if (((nmethod *)cb)->has_dependencies()) {
 215       _number_of_nmethods_with_dependencies--;
 216     }
 217   }
 218   if (cb->is_adapter_blob()) {
 219     _number_of_adapters--;
 220   }
 221   _number_of_blobs--;
 222 
 223   _heap->deallocate(cb);
 224 


src/share/vm/code/codeCache.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File