RFR: 8281213: Unsafe uses of long and size_t in MemReporterBase::diff_in_current_scale [v4]

Kim Barrett kbarrett at openjdk.org
Thu Jan 12 02:19:24 UTC 2023


On Wed, 11 Jan 2023 10:04:20 GMT, Evgeny Astigeevich <eastigeevich at openjdk.org> wrote:

>> Afshin Zafari has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains seven additional commits since the last revision:
>> 
>>  - 8281213: Unsafe uses of long and size_t in MemReporterBase::diff_in_current_scale
>>  - Merge branch 'master' into _8281213
>>  - 8281213: Unsafe uses of long and size_t in MemReporterBase::diff_in_current_scale
>>  - 8281213: Unsafe uses of long and size_t in MemReporterBase::diff_in_current_scale
>>  - 8281213: Unsafe uses of long and size_t in MemReporterBase::diff_in_current_scale
>>  - 8281213: Unsafe uses of long and size_t in MemReporterBase::diff_in_current_scale
>>  - 8281213: Unsafe uses of long and size_t in MemReporterBase::diff_in_current_scale
>
> src/hotspot/share/services/memReporter.hpp line 88:
> 
>> 86:     size_t scaled = (amount / _scale);
>> 87:     if ((amount % _scale) > (_scale - 1)/2) {
>> 88:       scaled += 1;
> 
> We need an assert `assert(scaled < SIZE_MAX, "size_t overflow");` for the case `_scale == 1`.

We do not need such an assert.  If `_scale == 1` then `amount % _scale` is 0 and the condition is false,
so no increment will occur.

-------------

PR: https://git.openjdk.org/jdk/pull/11514


More information about the hotspot-runtime-dev mailing list