diff src/share/vm/code/codeCache.cpp @ 14726:92aa6797d639

Backed out merge changeset: b51e29501f30 Backed out merge revision to its first parent (8f483e200405)
author Doug Simon <doug.simon@oracle.com>
date Mon, 24 Mar 2014 21:30:43 +0100
parents b51e29501f30
children
line wrap: on
line diff
--- a/src/share/vm/code/codeCache.cpp	Fri Mar 21 16:36:59 2014 -0700
+++ b/src/share/vm/code/codeCache.cpp	Mon Mar 24 21:30:43 2014 +0100
@@ -198,12 +198,14 @@
   }
   maxCodeCacheUsed = MAX2(maxCodeCacheUsed, ((address)_heap->high_boundary() -
                           (address)_heap->low_boundary()) - unallocated_capacity());
+  verify_if_often();
   print_trace("allocation", cb, size);
   return cb;
 }
 
 void CodeCache::free(CodeBlob* cb) {
   assert_locked_or_safepoint(CodeCache_lock);
+  verify_if_often();
 
   print_trace("free", cb);
   if (cb->is_nmethod()) {
@@ -219,6 +221,7 @@
 
   _heap->deallocate(cb);
 
+  verify_if_often();
   assert(_number_of_blobs >= 0, "sanity check");
 }
 
@@ -241,6 +244,12 @@
 }
 
 
+void CodeCache::flush() {
+  assert_locked_or_safepoint(CodeCache_lock);
+  Unimplemented();
+}
+
+
 // Iteration over CodeBlobs
 
 #define FOR_ALL_BLOBS(var)       for (CodeBlob *var =       first() ; var != NULL; var =       next(var) )
@@ -260,7 +269,7 @@
 CodeBlob* CodeCache::find_blob(void* start) {
   CodeBlob* result = find_blob_unsafe(start);
   if (result == NULL) return NULL;
-  // We could potentially look up non_entrant methods
+  // We could potientially look up non_entrant methods
   guarantee(!result->is_zombie() || result->is_locked_by_vm() || is_error_reported(), "unsafe access to zombie method");
   return result;
 }
@@ -732,26 +741,17 @@
   }
 }
 
-void CodeCache::print_memory_overhead() {
-  size_t wasted_bytes = 0;
-  CodeBlob *cb;
-  for (cb = first(); cb != NULL; cb = next(cb)) {
-    HeapBlock* heap_block = ((HeapBlock*)cb) - 1;
-    wasted_bytes += heap_block->length() * CodeCacheSegmentSize - cb->size();
-  }
-  // Print bytes that are allocated in the freelist
-  ttyLocker ttl;
-  tty->print_cr("Number of elements in freelist: %d",    freelist_length());
-  tty->print_cr("Allocated in freelist:          %dkB",  bytes_allocated_in_freelist()/K);
-  tty->print_cr("Unused bytes in CodeBlobs:      %dkB",  (int)(wasted_bytes/K));
-  tty->print_cr("Segment map size:               %dkB",  allocated_segments()/K); // 1 byte per segment
-}
-
 //------------------------------------------------------------------------------------------------
 // Non-product version
 
 #ifndef PRODUCT
 
+void CodeCache::verify_if_often() {
+  if (VerifyCodeCacheOften) {
+    _heap->verify();
+  }
+}
+
 void CodeCache::print_trace(const char* event, CodeBlob* cb, int size) {
   if (PrintCodeCache2) {  // Need to add a new flag
     ResourceMark rm;
@@ -774,7 +774,7 @@
   int nmethodUnloaded = 0;
   int nmethodJava = 0;
   int nmethodNative = 0;
-  int max_nm_size = 0;
+  int maxCodeSize = 0;
   ResourceMark rm;
 
   CodeBlob *cb;
@@ -798,11 +798,13 @@
       if(nm->is_not_entrant()) { nmethodNotEntrant++; }
       if(nm->is_zombie()) { nmethodZombie++; }
       if(nm->is_unloaded()) { nmethodUnloaded++; }
-      if(nm->method() != NULL && nm->is_native_method()) { nmethodNative++; }
+      if(nm->is_native_method()) { nmethodNative++; }
 
       if(nm->method() != NULL && nm->is_java_method()) {
         nmethodJava++;
-        max_nm_size = MAX2(max_nm_size, nm->size());
+        if (nm->insts_size() > maxCodeSize) {
+          maxCodeSize = nm->insts_size();
+        }
       }
     } else if (cb->is_runtime_stub()) {
       runtimeStubCount++;
@@ -818,19 +820,18 @@
   }
 
   int bucketSize = 512;
-  int bucketLimit = max_nm_size / bucketSize + 1;
+  int bucketLimit = maxCodeSize / bucketSize + 1;
   int *buckets = NEW_C_HEAP_ARRAY(int, bucketLimit, mtCode);
-  memset(buckets, 0, sizeof(int) * bucketLimit);
+  memset(buckets,0,sizeof(int) * bucketLimit);
 
   for (cb = first(); cb != NULL; cb = next(cb)) {
     if (cb->is_nmethod()) {
       nmethod* nm = (nmethod*)cb;
       if(nm->is_java_method()) {
-        buckets[nm->size() / bucketSize]++;
-       }
+        buckets[nm->insts_size() / bucketSize]++;
+      }
     }
   }
-
   tty->print_cr("Code Cache Entries (total of %d)",total);
   tty->print_cr("-------------------------------------------------");
   tty->print_cr("nmethods: %d",nmethodCount);
@@ -857,7 +858,6 @@
   }
 
   FREE_C_HEAP_ARRAY(int, buckets, mtCode);
-  print_memory_overhead();
 }
 
 #endif // !PRODUCT