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

Kim Barrett kim.barrett at oracle.com
Wed Nov 13 06:11:59 UTC 2019


> On Nov 12, 2019, at 4:17 AM, Thomas Schatzl <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 haven’t reviewed all of the changed uses yet, so not yet a review.

> 
> These are in
> 
> methodData.cpp:
> 
> int MethodData::compute_extra_data_count(int data_size, int empty_bc_count, bool needs_speculative_traps) {
> 
> 933:     int extra_data_count = MIN2(empty_bc_count, MAX2(4, (empty_bc_count * 30) / 100));
> 
> 
> hashtable.cpp:
> 
> template <MEMFLAGS F> BasicHashtableEntry<F>* BasicHashtable<F>::new_entry(unsigned int hashValue) {
> 
> 64:       int block_size = MIN2(512, MAX2((int)_table_size / 2, (int)_number_of_entries));
> 
> I would like to ask the responsible teams (compiler and runtime) to give an opinion on these cases, i.e. if these should be converted (these are intentional) or I should file an RFE to investigate further.
> 
> CR:
> https://bugs.openjdk.java.net/browse/JDK-8233702
> Webrev:
> http://cr.openjdk.java.net/~tschatzl/8233702/webrev/
> Testing:
> hs-tier1-5
> 
> Thanks,
>  Thomas




More information about the hotspot-dev mailing list