comparison 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
comparison
equal deleted inserted replaced
20217:6b52700a896b 20218:828056cf311f
84 cur = temp.get_chunk_at_head(); 84 cur = temp.get_chunk_at_head();
85 } 85 }
86 } 86 }
87 87
88 size_t G1CodeRootChunkManager::static_mem_size() { 88 size_t G1CodeRootChunkManager::static_mem_size() {
89 return sizeof(this); 89 return sizeof(G1CodeRootChunkManager);
90 } 90 }
91 91
92 92
93 G1CodeRootChunk* G1CodeRootChunkManager::new_chunk() { 93 G1CodeRootChunk* G1CodeRootChunkManager::new_chunk() {
94 G1CodeRootChunk* result = _free_list.get_chunk_at_head(); 94 G1CodeRootChunk* result = _free_list.get_chunk_at_head();
116 116
117 void G1CodeRootSet::purge_chunks(size_t keep_ratio) { 117 void G1CodeRootSet::purge_chunks(size_t keep_ratio) {
118 _default_chunk_manager.purge_chunks(keep_ratio); 118 _default_chunk_manager.purge_chunks(keep_ratio);
119 } 119 }
120 120
121 size_t G1CodeRootSet::static_mem_size() { 121 size_t G1CodeRootSet::free_chunks_static_mem_size() {
122 return _default_chunk_manager.static_mem_size(); 122 return _default_chunk_manager.static_mem_size();
123 } 123 }
124 124
125 size_t G1CodeRootSet::free_chunks_mem_size() { 125 size_t G1CodeRootSet::free_chunks_mem_size() {
126 return _default_chunk_manager.fl_mem_size(); 126 return _default_chunk_manager.fl_mem_size();
213 cur->nmethods_do(blk); 213 cur->nmethods_do(blk);
214 cur = (G1CodeRootChunk*)cur->next(); 214 cur = (G1CodeRootChunk*)cur->next();
215 } 215 }
216 } 216 }
217 217
218 size_t G1CodeRootSet::static_mem_size() {
219 return sizeof(G1CodeRootSet);
220 }
221
218 size_t G1CodeRootSet::mem_size() { 222 size_t G1CodeRootSet::mem_size() {
219 return sizeof(this) + _list.count() * _list.size(); 223 return G1CodeRootSet::static_mem_size() + _list.count() * _list.size();
220 } 224 }
221 225
222 #ifndef PRODUCT 226 #ifndef PRODUCT
223 227
224 void G1CodeRootSet::test() { 228 void G1CodeRootSet::test() {
225 G1CodeRootChunkManager mgr; 229 G1CodeRootChunkManager mgr;
226 230
227 assert(mgr.num_chunks_handed_out() == 0, "Must not have handed out chunks yet"); 231 assert(mgr.num_chunks_handed_out() == 0, "Must not have handed out chunks yet");
232
233 assert(G1CodeRootChunkManager::static_mem_size() > sizeof(void*),
234 err_msg("The chunk manager's static memory usage seems too small, is only "SIZE_FORMAT" bytes.", G1CodeRootChunkManager::static_mem_size()));
228 235
229 // The number of chunks that we allocate for purge testing. 236 // The number of chunks that we allocate for purge testing.
230 size_t const num_chunks = 10; 237 size_t const num_chunks = 10;
231 238
232 { 239 {
233 G1CodeRootSet set1(&mgr); 240 G1CodeRootSet set1(&mgr);
234 assert(set1.is_empty(), "Code root set must be initially empty but is not."); 241 assert(set1.is_empty(), "Code root set must be initially empty but is not.");
242
243 assert(G1CodeRootSet::static_mem_size() > sizeof(void*),
244 err_msg("The code root set's static memory usage seems too small, is only "SIZE_FORMAT" bytes", G1CodeRootSet::static_mem_size()));
235 245
236 set1.add((nmethod*)1); 246 set1.add((nmethod*)1);
237 assert(mgr.num_chunks_handed_out() == 1, 247 assert(mgr.num_chunks_handed_out() == 1,
238 err_msg("Must have allocated and handed out one chunk, but handed out " 248 err_msg("Must have allocated and handed out one chunk, but handed out "
239 SIZE_FORMAT" chunks", mgr.num_chunks_handed_out())); 249 SIZE_FORMAT" chunks", mgr.num_chunks_handed_out()));