comparison src/share/vm/gc_implementation/g1/heapRegionRemSet.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 8cc89a893545
children 2c6ef90f030a
comparison
equal deleted inserted replaced
20217:6b52700a896b 20218:828056cf311f
167 bm->set_union(_bm); 167 bm->set_union(_bm);
168 } 168 }
169 169
170 // Mem size in bytes. 170 // Mem size in bytes.
171 size_t mem_size() const { 171 size_t mem_size() const {
172 return sizeof(this) + _bm.size_in_words() * HeapWordSize; 172 return sizeof(PerRegionTable) + _bm.size_in_words() * HeapWordSize;
173 } 173 }
174 174
175 // Requires "from" to be in "hr()". 175 // Requires "from" to be in "hr()".
176 bool contains_reference(OopOrNarrowOopStar from) const { 176 bool contains_reference(OopOrNarrowOopStar from) const {
177 assert(hr()->is_in_reserved(from), "Precondition."); 177 assert(hr()->is_in_reserved(from), "Precondition.");
733 sum += _first_all_fine_prts->mem_size() * _n_fine_entries; 733 sum += _first_all_fine_prts->mem_size() * _n_fine_entries;
734 } 734 }
735 sum += (sizeof(PerRegionTable*) * _max_fine_entries); 735 sum += (sizeof(PerRegionTable*) * _max_fine_entries);
736 sum += (_coarse_map.size_in_words() * HeapWordSize); 736 sum += (_coarse_map.size_in_words() * HeapWordSize);
737 sum += (_sparse_table.mem_size()); 737 sum += (_sparse_table.mem_size());
738 sum += sizeof(*this) - sizeof(_sparse_table); // Avoid double counting above. 738 sum += sizeof(OtherRegionsTable) - sizeof(_sparse_table); // Avoid double counting above.
739 return sum; 739 return sum;
740 } 740 }
741 741
742 size_t OtherRegionsTable::static_mem_size() { 742 size_t OtherRegionsTable::static_mem_size() {
743 return FromCardCache::static_mem_size(); 743 return FromCardCache::static_mem_size();
1247 } 1247 }
1248 1248
1249 #ifndef PRODUCT 1249 #ifndef PRODUCT
1250 void PerRegionTable::test_fl_mem_size() { 1250 void PerRegionTable::test_fl_mem_size() {
1251 PerRegionTable* dummy = alloc(NULL); 1251 PerRegionTable* dummy = alloc(NULL);
1252
1253 size_t min_prt_size = sizeof(void*) + dummy->bm()->size_in_words() * HeapWordSize;
1254 assert(dummy->mem_size() > min_prt_size,
1255 err_msg("PerRegionTable memory usage is suspiciously small, only has "SIZE_FORMAT" bytes. "
1256 "Should be at least "SIZE_FORMAT" bytes.", dummy->mem_size(), min_prt_size));
1252 free(dummy); 1257 free(dummy);
1253 guarantee(dummy->mem_size() == fl_mem_size(), "fl_mem_size() does not return the correct element size"); 1258 guarantee(dummy->mem_size() == fl_mem_size(), "fl_mem_size() does not return the correct element size");
1254 // try to reset the state 1259 // try to reset the state
1255 _free_list = NULL; 1260 _free_list = NULL;
1256 delete dummy; 1261 delete dummy;