diff src/share/vm/gc_implementation/g1/g1CodeCacheRemSet.cpp @ 20218:828056cf311f

8040792: G1: Memory usage calculation uses sizeof(this) instead of sizeof(classname) Summary: A few locations in the code use sizeof(this) which returns the size of the pointer instead of sizeof(classname) which returns the size of the sum of its members. This change fixes these errors and adds a few tests. Reviewed-by: mgerdin, brutisso
author tschatzl
date Mon, 21 Jul 2014 09:40:19 +0200
parents 82693fb204a5
children 2c6ef90f030a
line wrap: on
line diff
--- a/src/share/vm/gc_implementation/g1/g1CodeCacheRemSet.cpp	Mon Jul 21 09:40:19 2014 +0200
+++ b/src/share/vm/gc_implementation/g1/g1CodeCacheRemSet.cpp	Mon Jul 21 09:40:19 2014 +0200
@@ -86,7 +86,7 @@
 }
 
 size_t G1CodeRootChunkManager::static_mem_size() {
-  return sizeof(this);
+  return sizeof(G1CodeRootChunkManager);
 }
 
 
@@ -118,7 +118,7 @@
   _default_chunk_manager.purge_chunks(keep_ratio);
 }
 
-size_t G1CodeRootSet::static_mem_size() {
+size_t G1CodeRootSet::free_chunks_static_mem_size() {
   return _default_chunk_manager.static_mem_size();
 }
 
@@ -215,8 +215,12 @@
   }
 }
 
+size_t G1CodeRootSet::static_mem_size() {
+  return sizeof(G1CodeRootSet);
+}
+
 size_t G1CodeRootSet::mem_size() {
-  return sizeof(this) + _list.count() * _list.size();
+  return G1CodeRootSet::static_mem_size() + _list.count() * _list.size();
 }
 
 #ifndef PRODUCT
@@ -226,6 +230,9 @@
 
   assert(mgr.num_chunks_handed_out() == 0, "Must not have handed out chunks yet");
 
+  assert(G1CodeRootChunkManager::static_mem_size() > sizeof(void*),
+         err_msg("The chunk manager's static memory usage seems too small, is only "SIZE_FORMAT" bytes.", G1CodeRootChunkManager::static_mem_size()));
+
   // The number of chunks that we allocate for purge testing.
   size_t const num_chunks = 10;
 
@@ -233,6 +240,9 @@
     G1CodeRootSet set1(&mgr);
     assert(set1.is_empty(), "Code root set must be initially empty but is not.");
 
+    assert(G1CodeRootSet::static_mem_size() > sizeof(void*),
+           err_msg("The code root set's static memory usage seems too small, is only "SIZE_FORMAT" bytes", G1CodeRootSet::static_mem_size()));
+
     set1.add((nmethod*)1);
     assert(mgr.num_chunks_handed_out() == 1,
            err_msg("Must have allocated and handed out one chunk, but handed out "