JDK-8285710 : Miscalculation of G1CardSetAllocator unused memory size
  • Type: Bug
  • Component: hotspot
  • Sub-Component: gc
  • Affected Version: 19
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2022-04-27
  • Updated: 2022-05-10
  • Resolved: 2022-05-10
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 19
19 masterFixed
Related Reports
Blocks :  
Relates :  
Relates :  
Description
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.
Comments
Changeset: 9835678a Author: dev-tianqixia <txiadev@gmail.com> Committer: Thomas Schatzl <tschatzl@openjdk.org> Date: 2022-05-10 13:43:33 +0000 URL: https://git.openjdk.java.net/jdk/commit/9835678a8658110cd2dac489cf55ab3d9074ea6d
10-05-2022

A pull request was submitted for review. URL: https://git.openjdk.java.net/jdk/pull/8424 Date: 2022-04-27 11:03:18 +0000
05-05-2022