Submit this issue on behalf of Tianqi Xia from Tencent
wasted memory size looks overflow with following command
java -XX:+AlwaysPreTouch -Xlog:gc*=debug,gc+remset*=trace:gc.log::filecount=10,filesize=20m -XX:+UnlockDiagnosticVMOptions -XX:G1SummarizeRSetStatsPeriod=1 -Xms20g -Xmx20g BigRamTester
gc.log.0:[28.849s][trace][gc,remset ] GC(14) Total per region rem sets sizes = 32141880 Max = 346176 wasted = 17184923896
gc.log.0:[29.125s][trace][gc,remset ] GC(14) Total per region rem sets sizes = 15885016 Max = 245176 wasted = 2457272
gc.log.0:[36.825s][trace][gc,remset ] GC(15) Total per region rem sets sizes = 19260504 Max = 402744 wasted = 25772335544
gc.log.0:[37.104s][trace][gc,remset ] GC(15) Total per region rem sets sizes = 2344432 Max = 245896 wasted = 258768
gc.log.0:[44.926s][trace][gc,remset ] GC(16) Total per region rem sets sizes = 19598664 Max = 399448 wasted = 12886642824
gc.log.0:[45.216s][trace][gc,remset ] GC(16) Total per region rem sets sizes = 2297024 Max = 259032 wasted = 178352
gc.log.0:[53.168s][trace][gc,remset ] GC(17) Total per region rem sets sizes = 24104656 Max = 431352 wasted = 42954964120
gc.log.0:[53.454s][trace][gc,remset ] GC(17) Total per region rem sets sizes = 2249624 Max = 314848 wasted = 8590191016
gc.log.0:[61.548s][trace][gc,remset ] GC(18) Total per region rem sets sizes = 24454432 Max = 432528 wasted = 34364643192
size_t G1CardSetAllocator::wasted_mem_size() const {
uint num_wasted_slots = _segmented_array.num_available_slots() -
_segmented_array.num_allocated_slots() -
(uint)_free_slots_list.pending_count();
return num_wasted_slots * _segmented_array.slot_size();
}
when calculating the wasted memory size of G1CardSetAllocator, the code erroneously substracted both _segmented_array.num_allocated_slots() and _free_slots_list.pending_count() from _segmented_array.num_available_slots().
The correct formula should be: num_wasted_slots = _segmented_array.num_available_slots() - (_segmented_array.num_allocated_slots() - (uint)_free_slots_list.pending_count()).
This can potentially leads to an arithmetic overflow and misleading information will be displayed when G1SummarizeRSetStatsPeriod is set.