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

Afshin Zafari duke at openjdk.org
Fri Dec 9 12:29:03 UTC 2022


On Wed, 7 Dec 2022 14:27:54 GMT, Thomas Stuefe <stuefe at openjdk.org> wrote:

> > I would return `ssize_t` instead.
> > For values >`SSIZE_MAX` and <`SSIZE_MIN` I would assert in debug (because we should never see such high numbers) and cap in release builds.
> > And of course, the print format has to be adapted to use ssize_t format
> 
> Correcting myself:
> 
> I would return int64_t (signed 64-bit).
> 
> On 32-bit platforms, where we could conceivably surpass SSIZE_MAX and SSIZE_MIN, that is large enough to hold positive and negative deltas.
> 
> On 64-bit, int64_t is the same as ssize_t. There, as I proposed, I would consider any delta > SSIZE_MIN or SSIZE_MAX to be an error. Because that indicates a negative overflow in a malloc counter.
> 
> I would actually consider any input value > 1000 TB an error as well, certainly any input > SSIZE_MAX.

So, I will do these: the return value is of type int64_t; Then, there is no need to change the printing format for the returned value in places where this function is called. Correct?
What other changes need to be done?

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

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


More information about the hotspot-runtime-dev mailing list