8029343: CodeCache::allocate increments '_number_of_blobs' even if allocation fails.
authoranoll
Fri, 09 May 2014 09:12:39 +0200
changeset 24439 252c634b2e1c
parent 24438 d0eddc193c1b
child 24440 7c472e3e3c57
8029343: CodeCache::allocate increments '_number_of_blobs' even if allocation fails. Summary: Incrementing the number of code blobs in CodeCache::allocate(...) is now only performed if allocation succeeds. The guarantee is fixed. Reviewed-by: kvn, iveresov Contributed-by: Tobias Hartmann <tobias.hartmann@oracle.com>
hotspot/src/share/vm/code/codeCache.cpp
--- a/hotspot/src/share/vm/code/codeCache.cpp	Thu May 08 15:16:49 2014 -0700
+++ b/hotspot/src/share/vm/code/codeCache.cpp	Fri May 09 09:12:39 2014 +0200
@@ -178,10 +178,12 @@
   // cache will contain a garbage CodeBlob until the caller can
   // run the constructor for the CodeBlob subclass he is busy
   // instantiating.
-  guarantee(size >= 0, "allocation request must be reasonable");
   assert_locked_or_safepoint(CodeCache_lock);
+  assert(size > 0, "allocation request must be reasonable");
+  if (size <= 0) {
+    return NULL;
+  }
   CodeBlob* cb = NULL;
-  _number_of_blobs++;
   while (true) {
     cb = (CodeBlob*)_heap->allocate(size, is_critical);
     if (cb != NULL) break;
@@ -199,6 +201,7 @@
   maxCodeCacheUsed = MAX2(maxCodeCacheUsed, ((address)_heap->high_boundary() -
                           (address)_heap->low_boundary()) - unallocated_capacity());
   print_trace("allocation", cb, size);
+  _number_of_blobs++;
   return cb;
 }