hotspot/src/share/vm/memory/heap.cpp
changeset 8672 26a427ab6f32
parent 7715 12998f95a334
child 8921 14bfe81f2a9d
--- a/hotspot/src/share/vm/memory/heap.cpp	Sun Mar 06 22:09:23 2011 -0800
+++ b/hotspot/src/share/vm/memory/heap.cpp	Wed Mar 09 09:15:16 2011 -0800
@@ -316,12 +316,19 @@
 }
 
 size_t CodeHeap::largest_free_block() const {
+  // First check unused space excluding free blocks.
+  size_t free_sz = size(_free_segments);
+  size_t unused  = max_capacity() - allocated_capacity() - free_sz;
+  if (unused >= free_sz)
+    return unused;
+
+  // Now check largest free block.
   size_t len = 0;
   for (FreeBlock* b = _freelist; b != NULL; b = b->link()) {
     if (b->length() > len)
       len = b->length();
   }
-  return size(len);
+  return MAX2(unused, size(len));
 }
 
 // Free list management