RFR (S): 8233702: Introduce helper function to clamp value to range

John Rose john.r.rose at oracle.com
Wed Nov 13 06:23:09 UTC 2019

On Nov 12, 2019, at 10:11 PM, Kim Barrett <kim.barrett at oracle.com> wrote:
>> On Nov 12, 2019, at 4:17 AM, Thomas Schatzl <thomas.schatzl at oracle.com <mailto:thomas.schatzl at oracle.com>> wrote:
>> Hi all,
>> I would like to introduce a small helper function to clamp a given value between a min/max value.
>> This would unclutter a few MIN(MAX(value, <min_value>), <max_value>) statements for imho better readability.
>> There are two places in (non-CMS) code remaining with the above statement, because in these cases it happens that a value min > max is passed, i.e. you potentially (already) get returned unexpected values.
>> (I did remove that assert in this webrev)
> I think the clamp function should be asserting min <= max.

I agree.  Overall I like this change.  I hope the remaining odd cases
can be recoded as clamps, because it’s helpful when reasoning
about the code to see which values are limits and which is the
variable to be kept within the limits.  The min/max idioms obscure
that distinction.

More information about the hotspot-dev mailing list