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

Evgeny Astigeevich eastigeevich at openjdk.org
Thu Jan 12 12:10:18 UTC 2023


On Thu, 12 Jan 2023 02:16:44 GMT, Kim Barrett <kbarrett at openjdk.org> wrote:

>> 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.

You are right no assert is needed.

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

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


More information about the hotspot-runtime-dev mailing list